From b25ebe0f5d290a38b514d7b3407aae09f4221c19 Mon Sep 17 00:00:00 2001 From: zzl <961867786@qq.com> Date: Mon, 1 Sep 2025 18:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=8C=E6=94=BF=E5=8C=BA=E5=88=92=E6=94=B9?= =?UTF-8?q?=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysDeptController.java | 117 ++-- .../src/main/resources/application-third.yml | 4 + .../ruoyi/common/core/domain/BaseEntity.java | 98 ++-- .../common/core/domain/entity/SysDept.java | 66 ++- .../com/ruoyi/common/utils/WorldMapUtils.java | 88 +++ .../src/main/resources/vm/vue/index.vue.vm | 4 + ruoyi-system/SysMapLocation.java | 15 + .../ruoyi/system/domain/SysMapLocation.java | 15 + .../com/ruoyi/system/domain/SysMapWorld.java | 15 + .../ruoyi/system/mapper/SysDeptMapper.java | 57 +- .../ruoyi/system/service/ISysDeptService.java | 49 +- .../service/impl/SysDeptServiceImpl.java | 551 +++++++++++++++--- .../resources/mapper/system/SysDeptMapper.xml | 146 ++++- 13 files changed, 988 insertions(+), 237 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/WorldMapUtils.java create mode 100644 ruoyi-system/SysMapLocation.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapLocation.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapWorld.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java index 59e7588..ff6385a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -1,48 +1,52 @@ package com.ruoyi.web.controller.system; -import java.util.List; -import org.apache.commons.lang3.ArrayUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.service.ISysDeptService; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * 部门信息 - * + * * @author ruoyi */ @RestController @RequestMapping("/system/dept") -public class SysDeptController extends BaseController -{ +public class SysDeptController extends BaseController { @Autowired private ISysDeptService deptService; + @Autowired + private TokenService tokenService; + /** * 获取部门列表 */ @PreAuthorize("@ss.hasPermi('system:dept:list')") @GetMapping("/list") - public AjaxResult list(SysDept dept) - { + public TableDataInfo list(SysDept dept) { + startPage(); List depts = deptService.selectDeptList(dept); - return success(depts); + return getDataTable(depts); } /** @@ -50,8 +54,7 @@ public class SysDeptController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:dept:list')") @GetMapping("/list/exclude/{deptId}") - public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) - { + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { List depts = deptService.selectDeptList(new SysDept()); depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); return success(depts); @@ -62,8 +65,7 @@ public class SysDeptController extends BaseController */ @PreAuthorize("@ss.hasPermi('system:dept:query')") @GetMapping(value = "/{deptId}") - public AjaxResult getInfo(@PathVariable Long deptId) - { + public AjaxResult getInfo(@PathVariable Long deptId) { deptService.checkDeptDataScope(deptId); return success(deptService.selectDeptById(deptId)); } @@ -74,10 +76,8 @@ public class SysDeptController extends BaseController @PreAuthorize("@ss.hasPermi('system:dept:add')") @Log(title = "部门管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysDept dept) - { - if (!deptService.checkDeptNameUnique(dept)) - { + public AjaxResult add(@Validated @RequestBody SysDept dept) { + if (!deptService.checkDeptNameUnique(dept)) { return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); } dept.setCreateBy(getUsername()); @@ -90,20 +90,14 @@ public class SysDeptController extends BaseController @PreAuthorize("@ss.hasPermi('system:dept:edit')") @Log(title = "部门管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysDept dept) - { + public AjaxResult edit(@Validated @RequestBody SysDept dept) { Long deptId = dept.getDeptId(); deptService.checkDeptDataScope(deptId); - if (!deptService.checkDeptNameUnique(dept)) - { + if (!deptService.checkDeptNameUnique(dept)) { return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); - } - else if (dept.getParentId().equals(deptId)) - { + } else if (dept.getParentId().equals(deptId)) { return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); - } - else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) - { + } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { return error("该部门包含未停用的子部门!"); } dept.setUpdateBy(getUsername()); @@ -116,17 +110,54 @@ public class SysDeptController extends BaseController @PreAuthorize("@ss.hasPermi('system:dept:remove')") @Log(title = "部门管理", businessType = BusinessType.DELETE) @DeleteMapping("/{deptId}") - public AjaxResult remove(@PathVariable Long deptId) - { - if (deptService.hasChildByDeptId(deptId)) - { + public AjaxResult remove(@PathVariable Long deptId) { + if (deptService.hasChildByDeptId(deptId)) { return warn("存在下级部门,不允许删除"); } - if (deptService.checkDeptExistUser(deptId)) - { + if (deptService.checkDeptExistUser(deptId)) { return warn("部门存在用户,不允许删除"); } deptService.checkDeptDataScope(deptId); return toAjax(deptService.deleteDeptById(deptId)); } + + /** + * 部门导入模板 + */ + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) { + ExcelUtil util = new ExcelUtil(SysDept.class); + util.importTemplateExcel(response, "部门数据"); + } + + /** + * 部门导入 + */ + @Log(title = "部门", businessType = BusinessType.IMPORT) + @PreAuthorize("@ss.hasPermi('system:dept:import')") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil(SysDept.class); + List list = util.importExcel(file.getInputStream(), 0); + String message = deptService.importSysDept(list, updateSupport, getUsername()); + return AjaxResult.success(message); + } + + /** + * 更新所有部门的坐标信息 + */ + //@ApiOperation("更新所有部门的坐标信息") + @PreAuthorize("@ss.hasPermi('system:dept:point')") + @GetMapping("/coordinatesUpdate") + public AjaxResult coordinatesUpdate() { + if(deptService.coordinatesUpdateRunning()) + return AjaxResult.success("最近的任务正在处理中,请等待完成结果"); + LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + SysUser user = loginUser.getUser(); + SysDept dept = new SysDept(); + List deptList = deptService.selectDeptList(dept); + deptService.coordinatesUpdate(deptList, user); + return AjaxResult.success("处理中,请等待..."); + } + } diff --git a/ruoyi-admin/src/main/resources/application-third.yml b/ruoyi-admin/src/main/resources/application-third.yml index e69de29..591bf58 100644 --- a/ruoyi-admin/src/main/resources/application-third.yml +++ b/ruoyi-admin/src/main/resources/application-third.yml @@ -0,0 +1,4 @@ +# 天地图 +map: + world: + key: cc4aba6e967096098249efa069733067 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java index 15bf66b..dfa4aa0 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java @@ -1,118 +1,130 @@ package com.ruoyi.common.core.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; + import java.io.Serializable; import java.util.Date; import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; /** * Entity基类 - * + * * @author ruoyi */ -public class BaseEntity implements Serializable -{ +public class BaseEntity implements Serializable { private static final long serialVersionUID = 1L; - /** 搜索值 */ + /** + * 搜索值 + */ @JsonIgnore private String searchValue; - /** 创建者 */ + /** + * 创建者 + */ private String createBy; - /** 创建时间 */ + /** + * 创建时间 + */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; - /** 更新者 */ + /** + * 更新者 + */ private String updateBy; - /** 更新时间 */ + /** + * 更新时间 + */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; - /** 备注 */ + /** + * 备注 + */ private String remark; - /** 请求参数 */ + /** + * 请求参数 + */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private Map params; - public String getSearchValue() - { + public String getSearchValue() { return searchValue; } - public void setSearchValue(String searchValue) - { + public void setSearchValue(String searchValue) { this.searchValue = searchValue; } - public String getCreateBy() - { + public String getCreateBy() { return createBy; } - public void setCreateBy(String createBy) - { + public void setCreateBy(String createBy) { this.createBy = createBy; } - public Date getCreateTime() - { + public Date getCreateTime() { return createTime; } - public void setCreateTime(Date createTime) - { + public void setCreateTime(Date createTime) { this.createTime = createTime; } - public String getUpdateBy() - { + public String getUpdateBy() { return updateBy; } - public void setUpdateBy(String updateBy) - { + public void setUpdateBy(String updateBy) { this.updateBy = updateBy; } - public Date getUpdateTime() - { + public Date getUpdateTime() { return updateTime; } - public void setUpdateTime(Date updateTime) - { + public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } - public String getRemark() - { + public String getRemark() { return remark; } - public void setRemark(String remark) - { + public void setRemark(String remark) { this.remark = remark; } - public Map getParams() - { - if (params == null) - { + public Map getParams() { + if (params == null) { params = new HashMap<>(); } return params; } - public void setParams(Map params) - { + public void setParams(Map params) { this.params = params; } + + public Object obtainParam(String name) { + if (params == null) + return null; + return params.get(name); + } + + @SuppressWarnings("unchecked") + public T putParam(String name, Object value) { + getParams().put(name, value); + return (T) this; + } + } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java index fb18c5c..8442f94 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java @@ -1,18 +1,20 @@ package com.ruoyi.common.core.domain.entity; -import java.util.ArrayList; -import java.util.List; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.core.domain.BaseEntity; +import java.util.ArrayList; +import java.util.List; /** * 部门表 sys_dept - * + * * @author ruoyi */ public class SysDept extends BaseEntity @@ -20,6 +22,7 @@ public class SysDept extends BaseEntity private static final long serialVersionUID = 1L; /** 部门ID */ + @Excel(name = "部门ID", type = Excel.Type.EXPORT) private Long deptId; /** 父部门ID */ @@ -29,6 +32,7 @@ public class SysDept extends BaseEntity private String ancestors; /** 部门名称 */ + @Excel(name = "部门名称") private String deptName; /** 显示顺序 */ @@ -51,10 +55,26 @@ public class SysDept extends BaseEntity /** 父部门名称 */ private String parentName; - + + /** 导入代码 */ + @Excel(name = "导入代码") + private String importCode; + + /** 行政代码 */ + @Excel(name = "行政代码") + private String orgCode; + + /** 经度 */ + private String longitude; + + /** 纬度 */ + private String latitude; + /** 子部门 */ private List children = new ArrayList(); + + public Long getDeptId() { return deptId; @@ -181,6 +201,38 @@ public class SysDept extends BaseEntity this.children = children; } + public String getImportCode() { + return importCode; + } + + public void setImportCode(String importCode) { + this.importCode = importCode; + } + + public String getOrgCode() { + return orgCode; + } + + public void setOrgCode(String orgCode) { + this.orgCode = orgCode; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/WorldMapUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/WorldMapUtils.java new file mode 100644 index 0000000..a3bad32 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/WorldMapUtils.java @@ -0,0 +1,88 @@ +package com.ruoyi.common.utils; + +import cn.hutool.core.util.URLUtil; +import lombok.extern.slf4j.Slf4j; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +/** + * @description: 天地图接口 + * @author: zzl + * @date: Created in 2021/8/9 15:22 + * @version: v1.0 + * @modified By: + */ +@Slf4j +public class WorldMapUtils { + + + public static void main(String[] args){ + + String info=getLonLat("环翠区","cc4aba6e967096098249efa069733067"); + System.out.println("info:"+info); + + /** + {"msg":"ok","location":{"level":"地名地址","lon":122.11852599978,"lat":37.50107099973,"keyWord":"环翠区"},"searchVersion":"6.0.0","status":"0"} + */ + } + + /** + * @description 获取经纬度坐标 + * @author zzl + * @date 2021/8/9 15:41 + * @param location + * @param tk + * @return java.lang.String + */ + public static String getLonLat(String location, String tk){ + + //拼接路径获取经度纬度 + String name_org = "{\"keyWord\":\"" + location +"\"}"; + Map query = new HashMap<>(); + query.put("ds", name_org); + query.put("tk", tk); + String queryStr = URLUtil.buildQuery(query, StandardCharsets.UTF_8); + String urlAll ="https://api.tianditu.gov.cn/geocoder?"+ queryStr; + log.info("请求天地图坐标:{}", urlAll); + BufferedReader in = null; + try { + URL urlObject = new URL(urlAll); + URLConnection uc = urlObject.openConnection(); + uc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8")); + String line; + StringBuilder result = new StringBuilder(); + while ((line = in.readLine()) != null) { + result.append(line); + } + String jsons = result.toString(); + log.info("返回天地图坐标:{}", jsons); + return jsons; + } catch (MalformedURLException e) { + e.printStackTrace(); + log.error("坐标获取失败:{}", urlAll); + return null; + } catch (IOException e) { + e.printStackTrace(); + log.error("坐标获取失败:{}", urlAll); + return null; + }finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } +} diff --git a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm index 55ba31f..436c4d1 100644 --- a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm @@ -752,6 +752,10 @@ export default { this.$alert("
" + response.msg + "
", "导入结果", { dangerouslyUseHTMLString: true }) this.getList() }, + // 提交上传文件 + submitFileForm() { + this.$refs.upload.submit() + }, #foreach($column in $columns) #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload") getFileIcon(file) { diff --git a/ruoyi-system/SysMapLocation.java b/ruoyi-system/SysMapLocation.java new file mode 100644 index 0000000..14ae93a --- /dev/null +++ b/ruoyi-system/SysMapLocation.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.domain; + +import lombok.Data; + +@Data +public class SysMapLocation { + + private String level; + + private String longitude; + + private String latitude; + + private String keyWord; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapLocation.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapLocation.java new file mode 100644 index 0000000..196a11b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapLocation.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.domain; + +import lombok.Data; + +@Data +public class SysMapLocation { + + private String level; + + private String lon; + + private String lat; + + private String keyWord; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapWorld.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapWorld.java new file mode 100644 index 0000000..f024443 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMapWorld.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.domain; + +import lombok.Data; + +@Data +public class SysMapWorld { + + private String msg; + + private SysMapLocation location; + + private String searchVersion; + + private String status; +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 384a9b6..3423023 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -1,19 +1,20 @@ package com.ruoyi.system.mapper; -import java.util.List; -import org.apache.ibatis.annotations.Param; import com.ruoyi.common.core.domain.entity.SysDept; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 部门管理 数据层 - * + * * @author ruoyi */ public interface SysDeptMapper { /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ @@ -21,7 +22,7 @@ public interface SysDeptMapper /** * 根据角色ID查询部门树信息 - * + * * @param roleId 角色ID * @param deptCheckStrictly 部门树选择项是否关联显示 * @return 选中部门列表 @@ -30,7 +31,7 @@ public interface SysDeptMapper /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @@ -38,7 +39,7 @@ public interface SysDeptMapper /** * 根据ID查询所有子部门 - * + * * @param deptId 部门ID * @return 部门列表 */ @@ -46,7 +47,7 @@ public interface SysDeptMapper /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @@ -54,7 +55,7 @@ public interface SysDeptMapper /** * 是否存在子节点 - * + * * @param deptId 部门ID * @return 结果 */ @@ -62,7 +63,7 @@ public interface SysDeptMapper /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 */ @@ -70,7 +71,7 @@ public interface SysDeptMapper /** * 校验部门名称是否唯一 - * + * * @param deptName 部门名称 * @param parentId 父部门ID * @return 结果 @@ -79,7 +80,7 @@ public interface SysDeptMapper /** * 新增部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -87,7 +88,7 @@ public interface SysDeptMapper /** * 修改部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -95,14 +96,14 @@ public interface SysDeptMapper /** * 修改所在部门正常状态 - * + * * @param deptIds 部门ID组 */ public void updateDeptStatusNormal(Long[] deptIds); /** * 修改子元素关系 - * + * * @param depts 子元素 * @return 结果 */ @@ -110,9 +111,33 @@ public interface SysDeptMapper /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ public int deleteDeptById(Long deptId); + + /** + * 批量修改 部门 + * + * @param list 部门 + * @return 结果 + */ + public int updateSysDeptBatch(List list); + + /** + * 批量新增部门 + * + * @param list 部门 + * @return 结果 + */ + public int insertSysDeptBatch(List list); + + public int deleteAllDept(); + + public SysDept selectDeptByOrgCode(String orgCode); + + public SysDept selectDeptByImportCode(String importCode); + + public Long selectDeptNextOrderNum(SysDept sysDept); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index f228208..7eb68cd 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -1,19 +1,21 @@ package com.ruoyi.system.service; -import java.util.List; import com.ruoyi.common.core.domain.TreeSelect; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysUser; + +import java.util.List; /** * 部门管理 服务层 - * + * * @author ruoyi */ public interface ISysDeptService { /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ @@ -21,7 +23,7 @@ public interface ISysDeptService /** * 查询部门树结构信息 - * + * * @param dept 部门信息 * @return 部门树信息集合 */ @@ -29,7 +31,7 @@ public interface ISysDeptService /** * 构建前端所需要树结构 - * + * * @param depts 部门列表 * @return 树结构列表 */ @@ -37,7 +39,7 @@ public interface ISysDeptService /** * 构建前端所需要下拉树结构 - * + * * @param depts 部门列表 * @return 下拉树结构列表 */ @@ -45,7 +47,7 @@ public interface ISysDeptService /** * 根据角色ID查询部门树信息 - * + * * @param roleId 角色ID * @return 选中部门列表 */ @@ -53,7 +55,7 @@ public interface ISysDeptService /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @@ -61,7 +63,7 @@ public interface ISysDeptService /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @@ -69,7 +71,7 @@ public interface ISysDeptService /** * 是否存在部门子节点 - * + * * @param deptId 部门ID * @return 结果 */ @@ -77,7 +79,7 @@ public interface ISysDeptService /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 true 存在 false 不存在 */ @@ -85,7 +87,7 @@ public interface ISysDeptService /** * 校验部门名称是否唯一 - * + * * @param dept 部门信息 * @return 结果 */ @@ -93,14 +95,14 @@ public interface ISysDeptService /** * 校验部门是否有数据权限 - * + * * @param deptId 部门id */ public void checkDeptDataScope(Long deptId); /** * 新增保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -108,7 +110,7 @@ public interface ISysDeptService /** * 修改保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @@ -116,9 +118,24 @@ public interface ISysDeptService /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ public int deleteDeptById(Long deptId); + + + /** + * 导入部门数据 + * + * @param list 部门数据列表 + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 + * @param userName 操作用户 + * @return 结果 + */ + public String importSysDept(List list, Boolean isUpdateSupport, String userName); + + void coordinatesUpdate(List deptList, SysUser user); + + boolean coordinatesUpdateRunning(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 54b605d..c43e44f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -1,11 +1,8 @@ package com.ruoyi.system.service.impl; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.TreeSelect; @@ -14,75 +11,87 @@ import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.WorldMapUtils; import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.domain.SysMapWorld; import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import java.util.stream.Collectors; /** * 部门管理 服务实现 - * + * * @author ruoyi */ @Service -public class SysDeptServiceImpl implements ISysDeptService -{ +public class SysDeptServiceImpl implements ISysDeptService { @Autowired private SysDeptMapper deptMapper; @Autowired private SysRoleMapper roleMapper; + @Value("${map.world.key}") + private String tk; + + public static volatile boolean _coordinatesUpdateRunning = false; + private static final Object _coordinatesUpdateLock = new Object(); + /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ @Override @DataScope(deptAlias = "d") - public List selectDeptList(SysDept dept) - { + public List selectDeptList(SysDept dept) { return deptMapper.selectDeptList(dept); } /** * 查询部门树结构信息 - * + * * @param dept 部门信息 * @return 部门树信息集合 */ @Override - public List selectDeptTreeList(SysDept dept) - { + public List selectDeptTreeList(SysDept dept) { List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); return buildDeptTreeSelect(depts); } /** * 构建前端所需要树结构 - * + * * @param depts 部门列表 * @return 树结构列表 */ @Override - public List buildDeptTree(List depts) - { + public List buildDeptTree(List depts) { List returnList = new ArrayList(); List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); - for (SysDept dept : depts) - { + for (SysDept dept : depts) { // 如果是顶级节点, 遍历该父节点的所有子节点 - if (!tempList.contains(dept.getParentId())) - { + if (!tempList.contains(dept.getParentId())) { recursionFn(depts, dept); returnList.add(dept); } } - if (returnList.isEmpty()) - { + if (returnList.isEmpty()) { returnList = depts; } return returnList; @@ -90,93 +99,85 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 构建前端所需要下拉树结构 - * + * * @param depts 部门列表 * @return 下拉树结构列表 */ @Override - public List buildDeptTreeSelect(List depts) - { + public List buildDeptTreeSelect(List depts) { List deptTrees = buildDeptTree(depts); return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); } /** * 根据角色ID查询部门树信息 - * + * * @param roleId 角色ID * @return 选中部门列表 */ @Override - public List selectDeptListByRoleId(Long roleId) - { + public List selectDeptListByRoleId(Long roleId) { SysRole role = roleMapper.selectRoleById(roleId); return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); } /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @Override - public SysDept selectDeptById(Long deptId) - { + public SysDept selectDeptById(Long deptId) { return deptMapper.selectDeptById(deptId); } /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @Override - public int selectNormalChildrenDeptById(Long deptId) - { + public int selectNormalChildrenDeptById(Long deptId) { return deptMapper.selectNormalChildrenDeptById(deptId); } /** * 是否存在子节点 - * + * * @param deptId 部门ID * @return 结果 */ @Override - public boolean hasChildByDeptId(Long deptId) - { + public boolean hasChildByDeptId(Long deptId) { int result = deptMapper.hasChildByDeptId(deptId); return result > 0; } /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 true 存在 false 不存在 */ @Override - public boolean checkDeptExistUser(Long deptId) - { + public boolean checkDeptExistUser(Long deptId) { int result = deptMapper.checkDeptExistUser(deptId); return result > 0; } /** * 校验部门名称是否唯一 - * + * * @param dept 部门信息 * @return 结果 */ @Override - public boolean checkDeptNameUnique(SysDept dept) - { + public boolean checkDeptNameUnique(SysDept dept) { Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); - if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) - { + if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -184,19 +185,16 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 校验部门是否有数据权限 - * + * * @param deptId 部门id */ @Override - public void checkDeptDataScope(Long deptId) - { - if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId)) - { + public void checkDeptDataScope(Long deptId) { + if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId)) { SysDept dept = new SysDept(); dept.setDeptId(deptId); List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); - if (StringUtils.isEmpty(depts)) - { + if (StringUtils.isEmpty(depts)) { throw new ServiceException("没有权限访问部门数据!"); } } @@ -204,17 +202,15 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 新增保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @Override - public int insertDept(SysDept dept) - { + public int insertDept(SysDept dept) { SysDept info = deptMapper.selectDeptById(dept.getParentId()); // 如果父节点不为正常状态,则不允许新增子节点 - if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) - { + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); @@ -223,17 +219,15 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 修改保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @Override - public int updateDept(SysDept dept) - { + public int updateDept(SysDept dept) { SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); - if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) - { + if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) { String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); String oldAncestors = oldDept.getAncestors(); dept.setAncestors(newAncestors); @@ -241,8 +235,7 @@ public class SysDeptServiceImpl implements ISysDeptService } int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) - && !StringUtils.equals("0", dept.getAncestors())) - { + && !StringUtils.equals("0", dept.getAncestors())) { // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatusNormal(dept); } @@ -251,11 +244,10 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 修改该部门的父级部门状态 - * + * * @param dept 当前部门 */ - private void updateParentDeptStatusNormal(SysDept dept) - { + private void updateParentDeptStatusNormal(SysDept dept) { String ancestors = dept.getAncestors(); Long[] deptIds = Convert.toLongArray(ancestors); deptMapper.updateDeptStatusNormal(deptIds); @@ -263,48 +255,41 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 修改子元素关系 - * - * @param deptId 被修改的部门ID + * + * @param deptId 被修改的部门ID * @param newAncestors 新的父ID集合 * @param oldAncestors 旧的父ID集合 */ - public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) - { + public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { List children = deptMapper.selectChildrenDeptById(deptId); - for (SysDept child : children) - { + for (SysDept child : children) { child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); } - if (children.size() > 0) - { + if (children.size() > 0) { deptMapper.updateDeptChildren(children); } } /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ @Override - public int deleteDeptById(Long deptId) - { + public int deleteDeptById(Long deptId) { return deptMapper.deleteDeptById(deptId); } /** * 递归列表 */ - private void recursionFn(List list, SysDept t) - { + private void recursionFn(List list, SysDept t) { // 得到子节点列表 List childList = getChildList(list, t); t.setChildren(childList); - for (SysDept tChild : childList) - { - if (hasChild(list, tChild)) - { + for (SysDept tChild : childList) { + if (hasChild(list, tChild)) { recursionFn(list, tChild); } } @@ -313,15 +298,12 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 得到子节点列表 */ - private List getChildList(List list, SysDept t) - { + private List getChildList(List list, SysDept t) { List tlist = new ArrayList(); Iterator it = list.iterator(); - while (it.hasNext()) - { + while (it.hasNext()) { SysDept n = (SysDept) it.next(); - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) - { + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { tlist.add(n); } } @@ -331,8 +313,389 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 判断是否有子节点 */ - private boolean hasChild(List list, SysDept t) - { + private boolean hasChild(List list, SysDept t) { return getChildList(list, t).size() > 0; } + + /** + * 导入部门数据 + * + * @param list 部门数据列表 + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 + * @param operName 操作用户 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public String importSysDept(List list, Boolean isUpdateSupport, String operName) { + if (StringUtils.isEmpty(list)) { + throw new ServiceException("导入部门数据不能为空!"); + } + + int successNum = 0; + int[] failureNum = {0}; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + + // 检验excel表中 【xxx】 是否存在重复,有重复的终止导入 + List repeatList = list.stream().collect(Collectors.groupingBy(SysDept::getOrgCode, Collectors.counting())) + .entrySet().stream().filter(e -> e.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(repeatList)) { + failureMsg.insert(0, "很抱歉,存在重复项,导入失败!共 " + repeatList.size() + " 个重复错错误如下:"); + for (int i = 0; i < repeatList.size(); i++) { + String item = repeatList.get(i); + failureNum[0] = repeatList.size(); + failureMsg.append("
" + failureNum + "、行政区划代码 " + item + " 重复"); + } + return failureMsg.toString(); + } + + + // 检验excel表中 【xxx】 是否存在重复,有重复的终止导入 + List repeatList2 = list.stream().collect(Collectors.groupingBy(SysDept::getImportCode, Collectors.counting())) + .entrySet().stream().filter(e -> e.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(repeatList2)) { + failureMsg.insert(0, "很抱歉,存在重复项,导入失败!共 " + repeatList2.size() + " 个重复错错误如下:"); + for (int i = 0; i < repeatList2.size(); i++) { + String item = repeatList2.get(i); + failureNum[0] = repeatList.size(); + failureMsg.append("
" + failureNum + "、导入代码 " + item + " 重复"); + } + return failureMsg.toString(); + } + + // 初始化清空表 + if (!isUpdateSupport) + deptMapper.deleteAllDept(); // 事务 + + final Consumer updateOrInsertFunc = (dept) -> { + SysDept d = deptMapper.selectDeptByImportCode(dept.getImportCode()); + if (null != d) { + d.setDeptName(dept.getDeptName()); + deptMapper.updateDept(d); + } else { + dept.setOrderNum(Integer.parseInt(deptMapper.selectDeptNextOrderNum(dept) + "")); + deptMapper.insertDept(dept); + } + }; + + int[] index = {0}; + list.forEach((x) -> x.putParam("index", ++index[0])); + AtomicInteger total = new AtomicInteger(0); + AtomicInteger orderNnum = new AtomicInteger(0); + Map> orgCodeLengthMap = list.stream().collect(Collectors.groupingBy(sysDept -> StrUtil.length(sysDept.getImportCode()))); + orgCodeLengthMap.forEach((orgCodeLength, sysDepts) -> { + switch (orgCodeLength) { + case 2: + if (isUpdateSupport) { + sysDepts.forEach((x) -> { + SysDept dept = deptMapper.selectDeptByImportCode(x.getImportCode()); + if (null != dept) // 存在则更新名称 + { + dept.setDeptName(x.getDeptName()); + deptMapper.updateDept(dept); + } else { + failureMsg.append(String.format("
第%s行插入新增时不允许添加省级部门.", x.obtainParam("index"))); + failureNum[0]++; + } + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + sysDept.setDeptId(100L); //最高级默认100 + sysDept.setParentId(0L); + sysDept.setAncestors(StrUtil.join(",", sysDept.getParentId())); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + case 4: + if (isUpdateSupport) { + sysDepts.forEach(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 2)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + } else { + failureMsg.append(String.format("
第%s行插入新增地市级时上级地区不存在.", sysDept.obtainParam("index"))); + failureNum[0]++; + return; + } + sysDept.setOrderNum(orderNnum.incrementAndGet()); + updateOrInsertFunc.accept(sysDept); + total.incrementAndGet(); + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 2)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + } else { + sysDept.setDeptId(100L); //最高级默认100 + sysDept.setParentId(0L); + sysDept.setAncestors(StrUtil.join(",", sysDept.getParentId())); + } + sysDept.setOrderNum(orderNnum.incrementAndGet()); + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + case 6: + if (isUpdateSupport) { + orderNnum.set(0); + sysDepts.forEach(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 4)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + } else { + failureMsg.append(String.format("
第%s行插入新增区县级时上级地区不存在.", sysDept.obtainParam("index"))); + failureNum[0]++; + return; + } + sysDept.setOrderNum(orderNnum.incrementAndGet()); + updateOrInsertFunc.accept(sysDept); + total.incrementAndGet(); + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 4)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + } else { + sysDept.setDeptId(100L); //最高级默认100 + sysDept.setParentId(0L); + sysDept.setAncestors(StrUtil.join(",", sysDept.getParentId())); + } + sysDept.setOrderNum(orderNnum.incrementAndGet()); + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + case 9: + if (isUpdateSupport) { + sysDepts.forEach(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 6)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } else { + failureMsg.append(String.format("
第%s行插入新增镇街级时上级地区不存在.", sysDept.obtainParam("index"))); + failureNum[0]++; + return; + } + updateOrInsertFunc.accept(sysDept); + total.incrementAndGet(); + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 6)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + case 12: + if (isUpdateSupport) { + sysDepts.forEach(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 9)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } else { + failureMsg.append(String.format("
第%s行插入新增村级时上级地区不存在.", sysDept.obtainParam("index"))); + failureNum[0]++; + return; + } + updateOrInsertFunc.accept(sysDept); + total.incrementAndGet(); + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 9)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + case 14: + if (isUpdateSupport) { + sysDepts.forEach(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 12)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } else { + failureMsg.append(String.format("
第%s行插入新增组级时上级地区不存在.", sysDept.obtainParam("index"))); + failureNum[0]++; + return; + } + updateOrInsertFunc.accept(sysDept); + total.incrementAndGet(); + }); + } else { + orderNnum.set(0); + sysDepts.stream().peek(sysDept -> { + SysDept parentDept = deptMapper.selectDeptByImportCode(StringUtils.substring(sysDept.getImportCode(), 0, 12)); + if (Objects.nonNull(parentDept)) { + sysDept.setAncestors(StrUtil.join(",", parentDept.getAncestors(), parentDept.getDeptId())); + sysDept.setParentId(parentDept.getDeptId()); + sysDept.setOrderNum(orderNnum.incrementAndGet()); + } + }).forEach(sysDept -> { + deptMapper.insertDept(sysDept); + total.incrementAndGet(); + }); + } + break; + default: + break; + } + }); + + + if (failureNum[0] > 0) { + failureMsg.insert(0, "很抱歉,存在导入失败数据!,共 " + failureNum[0] + " 条,如下:"); + //throw new CustomException(failureMsg.toString()); + return failureMsg.toString(); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + total + " 条。"); + return successMsg.toString(); + } + } + + @Override + public boolean coordinatesUpdateRunning() { + return _coordinatesUpdateRunning; + } + + /** + * 更新所有部门的坐标信息 + * 异步线程处理 + */ + @Override + @Async("threadPoolTaskExecutor") + public void coordinatesUpdate(List deptList, SysUser user) { + synchronized (_coordinatesUpdateLock) { + if (_coordinatesUpdateRunning) + return; + _coordinatesUpdateRunning = true; + + deptList.forEach(d -> { + if (StringUtils.isNotEmpty(d.getLongitude())) { + return; + } + d.setUpdateBy(user.getUserName()); + d.setUpdateTime(DateUtils.getNowDate()); + String d_orgCode = d.getOrgCode(); + String deptName = d.getDeptName(); + if (d_orgCode.length() == 4) { // 地市级 + String json = WorldMapUtils.getLonLat(deptName, tk); + if (StringUtils.isNull(json)) { + return; + } + JSONObject jsonObject = JSON.parseObject(json); + SysMapWorld mw = (SysMapWorld) JSON.toJavaObject(jsonObject, SysMapWorld.class); + if (StringUtils.isNull(mw.getLocation())) { + return; + } + d.setLatitude(mw.getLocation().getLat()); + d.setLongitude(mw.getLocation().getLon()); + + } else if (d_orgCode.length() == 6) { // 县级 + List filterDept = deptList.stream().filter(dl -> dl.getDeptId().equals(d.getParentId())).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(filterDept)) { + deptName = filterDept.get(0).getDeptName() + deptName; + } + String json = WorldMapUtils.getLonLat(deptName, tk); + if (StringUtils.isNull(json)) { + return; + } + JSONObject jsonObject = JSON.parseObject(json); + SysMapWorld mw = (SysMapWorld) JSON.toJavaObject(jsonObject, SysMapWorld.class); + if (StringUtils.isNull(mw.getLocation())) { + return; + } + d.setLatitude(mw.getLocation().getLat()); + d.setLongitude(mw.getLocation().getLon()); + + } else if (d_orgCode.length() == 9) { // 镇级 + List filterDept = deptList.stream().filter(dl -> dl.getDeptId().equals(d.getParentId())).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(filterDept)) { + deptName = filterDept.get(0).getDeptName() + deptName; + } + String json = WorldMapUtils.getLonLat(deptName, tk); + if (StringUtils.isNull(json)) { + return; + } + JSONObject jsonObject = JSON.parseObject(json); + SysMapWorld mw = (SysMapWorld) JSON.toJavaObject(jsonObject, SysMapWorld.class); + if (StringUtils.isNull(mw.getLocation())) { + return; + } + d.setLatitude(mw.getLocation().getLat()); + d.setLongitude(mw.getLocation().getLon()); + + } else if (d_orgCode.length() == 12) { // 村级 + List filterZhen = deptList.stream().filter(dl -> dl.getDeptId().equals(d.getParentId())).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(filterZhen)) { + SysDept zhen = filterZhen.get(0); + deptName = zhen.getDeptName() + deptName; + List filterXian = deptList.stream().filter(dl -> dl.getDeptId().equals(zhen.getParentId())).collect(Collectors.toList()); + if (StringUtils.isNotEmpty(filterXian)) { + deptName = filterXian.get(0).getDeptName() + deptName; + } + } + String json = WorldMapUtils.getLonLat(deptName, tk); + if (StringUtils.isNull(json)) { + return; + } + JSONObject jsonObject = JSON.parseObject(json); + SysMapWorld mw = (SysMapWorld) JSON.toJavaObject(jsonObject, SysMapWorld.class); + if (StringUtils.isNull(mw.getLocation())) { + return; + } + d.setLatitude(mw.getLocation().getLat()); + d.setLongitude(mw.getLocation().getLon()); + + } else { // 组级 + return; + + } + deptMapper.updateDept(d); + }); + _coordinatesUpdateRunning = false; + } + + + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index cf439f6..b11626f 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -16,17 +16,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + - + - select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time, + d.import_code, d.org_code, d.longitude, d.latitude from sys_dept d - + - + - + - + - + - + - + - + - + insert into sys_dept( dept_id, @@ -98,6 +106,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" phone, email, status, + import_code, + org_code, + longitude, + latitude, create_by, create_time )values( @@ -110,11 +122,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{phone}, #{email}, #{status}, + #{importCode}, + #{orgCode}, + #{longitude}, + #{latitude}, #{createBy}, sysdate() ) - + update sys_dept @@ -126,12 +142,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" phone = #{phone}, email = #{email}, status = #{status}, + import_code = #{importCode}, + org_code = #{orgCode}, + longitude = #{longitude}, + latitude = #{latitude}, update_by = #{updateBy}, update_time = sysdate() where dept_id = #{deptId} - + update sys_dept set ancestors = - + - update sys_dept set status = '0' where dept_id in + update sys_dept set status = '0' where dept_id in #{deptId} - + update sys_dept set del_flag = '2' where dept_id = #{deptId} - \ No newline at end of file + + insert into sys_dept + + parent_id, + ancestors, + dept_name, + order_num, + leader, + phone, + email, + status, + del_flag, + import_code, + org_code, + longitude, + latitude, + create_by, + create_time, + + values + + + #{item.parentId}, + #{item.ancestors}, + #{item.deptName}, + #{item.orderNum}, + #{item.leader}, + #{item.phone}, + #{item.email}, + #{item.status}, + #{item.delFlag}, + #{item.importCode}, + #{item.orgCode}, + #{item.longitude}, + #{item.latitude}, + #{item.createBy}, + #{item.createTime}, + + + + + + + + update sys_dept + + parent_id = #{item.parentId}, + ancestors = #{item.ancestors}, + dept_name = #{item.deptName}, + order_num = #{item.orderNum}, + leader = #{item.leader}, + phone = #{item.phone}, + email = #{item.email}, + status = #{item.status}, + del_flag = #{item.delFlag}, + import_code = #{item.importCode}, + org_code = #{item.orgCode}, + longitude = #{item.longitude}, + latitude = #{item.latitude}, + update_by = #{item.updateBy}, + update_time = #{item.updateTime}, + + where dept_id = #{item.deptId} + + + + + delete from sys_dept + + + + + + + + + +