From 55b3f1676c549dde70224e0f9ab5511443aaf930 Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Thu, 5 Jun 2025 11:46:41 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=8C=BA=E5=9F=9F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/system/api/RemoteDeptService.java | 2 +- .../business/domain/BusinessLayer.java | 5 ++ .../business/domain/bo/BusinessLayerBo.java | 8 +++ .../business/domain/vo/BusinessLayerVo.java | 7 +++ .../mapper/business/BusinessLayerMapper.xml | 1 + .../system/SysDepartBoundaryController.java | 29 +++-------- .../system/domain/SysDepartBoundary.java | 39 ++------------- .../system/dubbo/RemoteDeptServiceImpl.java | 4 +- .../dromara/system/mapper/SysDeptMapper.java | 2 +- .../service/ISysDepartBoundaryService.java | 2 +- .../system/service/ISysDeptService.java | 5 +- .../impl/SysDepartBoundaryServiceImpl.java | 50 +++++++++++++------ .../service/impl/SysDeptServiceImpl.java | 19 ++++++- .../mapper/system/SysDepartBoundaryMapper.xml | 21 +++----- .../resources/mapper/system/SysDeptMapper.xml | 16 ++++-- 15 files changed, 111 insertions(+), 99 deletions(-) diff --git a/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java b/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java index d40fc45..0277739 100644 --- a/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java +++ b/dk-api/api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java @@ -24,7 +24,7 @@ public interface RemoteDeptService { RemoteDeptVo selectDeptById(Long deptId); - List> getNamePathList(); + List> getNamePathList(Long deptId); List selectListByParentId(String deptId); diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessLayer.java b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessLayer.java index f204838..c0bd716 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessLayer.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/BusinessLayer.java @@ -42,6 +42,11 @@ public class BusinessLayer { @Translation(type = TransConstant.DICT_TYPE_TO_LABEL, mapper = "layerType", other = "layer_type") private String layerTypeName; + /** + * 图层url + */ + private String layerUrl; + //租户id private String tenantId; //部门id diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessLayerBo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessLayerBo.java index 2b1304c..757367d 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessLayerBo.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessLayerBo.java @@ -37,9 +37,17 @@ public class BusinessLayerBo { * */ private Date createTime; + /** + * 0目录 1地址 + */ @NotNull(message = "图层类型不能为空", groups = { AddGroup.class}) private Integer layerType; + /** + * 图层url + */ + private String layerUrl; + private String tenantId; @NotNull(message = "部门id不能为空", groups = { AddGroup.class}) private Long deptId; diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessLayerVo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessLayerVo.java index 59a9016..a0fa479 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessLayerVo.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessLayerVo.java @@ -6,10 +6,12 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.github.linpeilie.annotations.AutoMapper; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; import org.dromara.business.domain.BusinessLayer; import org.dromara.business.domain.BusinessTask; +import org.dromara.common.core.validate.AddGroup; import org.dromara.common.translation.annotation.Translation; import org.dromara.common.translation.constant.TransConstant; @@ -44,6 +46,11 @@ public class BusinessLayerVo { private String tenantId; private Long deptId; + /** + * 图层url + */ + private String layerUrl; + private String deptName; private String remark; diff --git a/dk-modules/business/src/main/resources/mapper/business/BusinessLayerMapper.xml b/dk-modules/business/src/main/resources/mapper/business/BusinessLayerMapper.xml index f4a3b90..7faca95 100644 --- a/dk-modules/business/src/main/resources/mapper/business/BusinessLayerMapper.xml +++ b/dk-modules/business/src/main/resources/mapper/business/BusinessLayerMapper.xml @@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t.enable, t.remark, t.layer_type as layerType, + t.layer_url as layerUrl, t.dept_id as deptId, t.dept_name AS deptName, t.tenant_id as tenantId, diff --git a/dk-modules/system/src/main/java/org/dromara/system/controller/system/SysDepartBoundaryController.java b/dk-modules/system/src/main/java/org/dromara/system/controller/system/SysDepartBoundaryController.java index 3caef4e..27dc2e7 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/controller/system/SysDepartBoundaryController.java +++ b/dk-modules/system/src/main/java/org/dromara/system/controller/system/SysDepartBoundaryController.java @@ -5,19 +5,17 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.common.satoken.utils.LoginHelper; -import org.dromara.system.domain.SysDepartBoundary ; import org.dromara.common.core.domain.R; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.web.core.BaseController; +import org.dromara.system.domain.SysDepartBoundary; import org.dromara.system.domain.bo.SysDepartBoundaryBo; import org.dromara.system.service.ISysDepartBoundaryService; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.List; -import java.util.Map; /** * 部门区域 @@ -40,7 +38,6 @@ public class SysDepartBoundaryController extends BaseController { @Operation(summary ="查询部门的地理位置",description = "查询部门的地理位置") @GetMapping(value = "/listJson") public R> listJson(SysDepartBoundary departBoundary) { -// departBoundary.setDeptId(String.valueOf(LoginHelper.getDeptId())); List listJson = departBoundaryService.listJson(departBoundary); return R.ok("查询成功!",listJson); } @@ -61,22 +58,12 @@ public class SysDepartBoundaryController extends BaseController { * 解析shp文件 * @return */ - @Operation(summary ="批量新增部门区域",description = "批量新增部门区域") + @Operation(summary ="新增部门区域",description = "新增部门区域(areaType: 0:市级 1:区级(县) 2:镇级(街道) 3:村级)") @RequestMapping(value = "/upload", method = RequestMethod.POST) - public R uploadShpFile(@RequestParam("file") MultipartFile file,@RequestParam("areaType") Integer areaType) { - return toAjax(departBoundaryService.uploadShpFile(file,areaType)); - } - - /** - * 编辑 - * - * @param - * @return - */ - @Operation(summary ="编辑部门区域",description = "编辑部门区域") - @RequestMapping(value = "/update", method = RequestMethod.POST) - public R updateDepartBoundary(@RequestBody SysDepartBoundary departBoundary) { - return toAjax(departBoundaryService.updateDepartBoundary(departBoundary)); + public R uploadShpFile(@RequestParam("file") MultipartFile file, + @RequestParam("areaType") Integer areaType, + @RequestParam("parentId") Long parentId) { + return toAjax(departBoundaryService.uploadShpFile(file,areaType,parentId)); } @@ -91,8 +78,4 @@ public class SysDepartBoundaryController extends BaseController { public R deleteDepartBoundary(@RequestParam(name = "id") String id) { return toAjax(departBoundaryService.deleteDepartBoundary(id)); } - - - - } diff --git a/dk-modules/system/src/main/java/org/dromara/system/domain/SysDepartBoundary.java b/dk-modules/system/src/main/java/org/dromara/system/domain/SysDepartBoundary.java index 6310c68..7398145 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/domain/SysDepartBoundary.java +++ b/dk-modules/system/src/main/java/org/dromara/system/domain/SysDepartBoundary.java @@ -25,53 +25,24 @@ public class SysDepartBoundary extends BaseEntity { @TableId(type = IdType.AUTO) private String id; - /** - * 租户Id - */ - private String tenantId; - /**机构ID*/ - private String deptId; + private Long deptId; + /**机构/部门名称*/ private String deptName; - /**是否显示0显示,1不显示*/ - private Integer type; - - /**边界*/ - private String communityName; + /**部门全路径*/ + private String namePath; /**边界*/ private String boundary; /** - * 周长 - */ - private Double perimeter; - - /** - * 面积平方公里 - */ - private Double area; - - /** - * 面积亩 - */ - private Double areaMu; - - /** - * 编号 - */ - private String shpNo; - - /** - * 区域类别 + * 区域类别 areaType: 0:市级 1:区级(县) 2:镇级(街道) 3:村级 */ private Integer areaType; /**删除状态(0,正常,1已删除)*/ private String delFlag; - private List deptIds; - } diff --git a/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java index 93de8ac..524e362 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java +++ b/dk-modules/system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java @@ -50,8 +50,8 @@ public class RemoteDeptServiceImpl implements RemoteDeptService { } @Override - public List> getNamePathList() { - return sysDeptService.getNamePathList(); + public List> getNamePathList(Long deptId) { + return sysDeptService.getNamePathList(deptId); } @Override diff --git a/dk-modules/system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java b/dk-modules/system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java index cd3caaf..019c1d4 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java +++ b/dk-modules/system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java @@ -71,7 +71,7 @@ public interface SysDeptMapper extends BaseMapperPlus { }) Page selectPageDeptList(@Param("page") Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper); - List> getNamePathList(); + List> getNamePathList(@Param("deptId") Long deptId); List listTreeDept(@Param("deptId") Long deptId, @Param("tbPrefix") ProjectTablePrefixConfig tbPrefix); } diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/ISysDepartBoundaryService.java b/dk-modules/system/src/main/java/org/dromara/system/service/ISysDepartBoundaryService.java index 9a4f39d..71e5c5a 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/service/ISysDepartBoundaryService.java +++ b/dk-modules/system/src/main/java/org/dromara/system/service/ISysDepartBoundaryService.java @@ -20,7 +20,7 @@ public interface ISysDepartBoundaryService extends IService{ List queryByDeptId(String deptId); - boolean uploadShpFile(MultipartFile file,Integer areaType); + boolean uploadShpFile(MultipartFile file,Integer areaType,Long parentId); boolean deleteDepartBoundary(String id); diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/ISysDeptService.java b/dk-modules/system/src/main/java/org/dromara/system/service/ISysDeptService.java index 8a1aa4f..05a0a95 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/service/ISysDeptService.java +++ b/dk-modules/system/src/main/java/org/dromara/system/service/ISysDeptService.java @@ -1,6 +1,7 @@ package org.dromara.system.service; import cn.hutool.core.lang.tree.Tree; +import org.dromara.system.domain.SysDept; import org.dromara.system.domain.bo.SysDeptBo; import org.dromara.system.domain.vo.SysDeptVo; @@ -144,7 +145,7 @@ public interface ISysDeptService { * 查询每个部门的所属的部门全路径 * @return */ - List> getNamePathList(); + List> getNamePathList(Long deptId); /** * 根据父级找子级 @@ -157,4 +158,6 @@ public interface ISysDeptService { SysDeptVo getByParentId(String deptId); List listTreeDept(Long deptId); + + SysDept addBoundaryDept(SysDeptBo sysDeptBo); } diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java index d16ce1d..4c249aa 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java +++ b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java @@ -8,11 +8,15 @@ import lombok.RequiredArgsConstructor; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.system.api.domain.vo.RemoteDeptVo; import org.dromara.system.domain.SysDepartBoundary; +import org.dromara.system.domain.SysDept; import org.dromara.system.domain.SysGeospatialVectors; import org.dromara.system.domain.SysVectorDict; import org.dromara.system.domain.bo.SysDepartBoundaryBo; +import org.dromara.system.domain.bo.SysDeptBo; +import org.dromara.system.domain.vo.SysDeptVo; import org.dromara.system.mapper.SysDepartBoundaryMapper; import org.dromara.system.service.ISysDepartBoundaryService; +import org.dromara.system.service.ISysDeptService; import org.dromara.system.service.ISysVectorDictService; import org.dromara.system.utils.BatchProcessorUtil; import org.dromara.system.utils.ShpAnalysisUtil; @@ -42,8 +46,7 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl listSysDepartBoundary(PageQuery pageQuery, SysDepartBoundary departBoundary) { @@ -65,12 +68,12 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl geospatialVectorsList = buildGeospatialVector(file); //6、生成新的对象集合存储数据表中 - List boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,areaType); + List boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,areaType,parentId); // 分批处理 int startIndex = 0; // 从第 0 条开始 @@ -176,20 +179,20 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl listJson(SysDepartBoundary departBoundary) { - if(StringUtils.isBlank(departBoundary.getDeptId())){ + if(ObjectUtil.isEmpty(departBoundary.getDeptId())){ throw new ServiceException("部门【id】不存在"); } SysDepartBoundaryBo child = new SysDepartBoundaryBo(); child.setDepartId(String.valueOf(departBoundary.getDeptId())); child.setAreaType(SysDepartBoundaryBo.AreaType.DistrictLevel); - child.setLandCategoriesJson(this.baseMapper.listJson(departBoundary.getDeptId())); + child.setLandCategoriesJson(this.baseMapper.listJson(String.valueOf(departBoundary.getDeptId()))); - RemoteDeptVo remoteDeptVo = remoteDeptService.getByParentId(departBoundary.getDeptId()); + SysDeptVo sysDeptVo = deptService.getByParentId(String.valueOf(departBoundary.getDeptId())); SysDepartBoundaryBo parent = new SysDepartBoundaryBo(); - parent.setDepartId(String.valueOf(remoteDeptVo.getDeptId())); + parent.setDepartId(String.valueOf(sysDeptVo.getDeptId())); parent.setAreaType(SysDepartBoundaryBo.AreaType.Municipal); - parent.setLandCategoriesJson(this.baseMapper.listJson(String.valueOf(remoteDeptVo.getDeptId()))); + parent.setLandCategoriesJson(this.baseMapper.listJson(String.valueOf(sysDeptVo.getDeptId()))); return List.of(child,parent); } @@ -202,6 +205,7 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl0; } @@ -211,12 +215,12 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl buildBusinessDepartBoundary(List geospatialVectorsList, Integer areaType) { + private List buildBusinessDepartBoundary(List geospatialVectorsList, Integer areaType,Long parentId) { List resultList = new ArrayList<>(); - List> namePathList = remoteDeptService.getNamePathList(); + List> namePathList = deptService.getNamePathList(null); - Map>> namePathMap = namePathList.stream() + Map>> namePathMap = namePathList.stream().filter(p-> Long.valueOf(p.get("parentId").toString()).equals(parentId)) .collect(Collectors.groupingBy(item -> item.get("deptName").toString())); geospatialVectorsList.forEach(param->{ @@ -225,14 +229,30 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl objectMap = namePathMap.get(divisionName).get(0); - businessDepartBoundary.setShpNo(ObjectUtil.isEmpty(objectMap.get("shpNo"))?null:(String)objectMap.get("shpNo")); businessDepartBoundary.setDeptName(objectMap.get("deptName") + ""); - businessDepartBoundary.setDeptId(objectMap.get("deptId") + ""); - businessDepartBoundary.setCommunityName(objectMap.get("namePath") + ""); + businessDepartBoundary.setDeptId(Long.valueOf(objectMap.get("deptId") + "")); + businessDepartBoundary.setNamePath(objectMap.get("namePath") + ""); businessDepartBoundary.setAreaType(areaType); resultList.add(businessDepartBoundary); + }else { + //如果不存在在部门表中则添加 + SysDeptBo sysDeptBo = new SysDeptBo(); + sysDeptBo.setParentId(parentId); + sysDeptBo.setDeptName(param.getAdminDivisionName()); + + SysDept sysDept = deptService.addBoundaryDept(sysDeptBo); + + List> deptNamePath = deptService.getNamePathList(sysDept.getDeptId()); + + businessDepartBoundary.setDeptName(sysDept.getDeptName()); + businessDepartBoundary.setDeptId(sysDept.getDeptId()); + businessDepartBoundary.setNamePath(deptNamePath.getFirst().get("namePath").toString()); + businessDepartBoundary.setAreaType(areaType); + resultList.add(businessDepartBoundary); + } }); return resultList; diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index fc6b37e..9ee2afe 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -365,8 +365,8 @@ public class SysDeptServiceImpl implements ISysDeptService { @Override - public List> getNamePathList() { - return baseMapper.getNamePathList(); + public List> getNamePathList(Long deptId) { + return baseMapper.getNamePathList(deptId); } @Override @@ -392,4 +392,19 @@ public class SysDeptServiceImpl implements ISysDeptService { return baseMapper.listTreeDept(deptId, ptPrefix); //.getTableCloud() } + @Override + public SysDept addBoundaryDept(SysDeptBo bo) { + SysDept info = baseMapper.selectById(bo.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { + throw new ServiceException("部门停用,不允许新增"); + } + SysDept dept = MapstructUtils.convert(bo, SysDept.class); + dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); + + baseMapper.insert(dept); + + return dept; + } + } diff --git a/dk-modules/system/src/main/resources/mapper/system/SysDepartBoundaryMapper.xml b/dk-modules/system/src/main/resources/mapper/system/SysDepartBoundaryMapper.xml index 9d2a302..bf0fc36 100644 --- a/dk-modules/system/src/main/resources/mapper/system/SysDepartBoundaryMapper.xml +++ b/dk-modules/system/src/main/resources/mapper/system/SysDepartBoundaryMapper.xml @@ -79,13 +79,9 @@ INSERT INTO sys_depart_boundary ( dept_id, dept_name, - community_name, + name_path, boundary, - perimeter, - area, - area_mu, - shp_no, - village_type, + area_type, create_by, create_time, update_by, @@ -96,13 +92,9 @@ (#{item.deptId}, #{item.deptName}, - #{item.communityName}, + #{item.namePath}, ST_GeomFromText(#{item.boundary}), - #{item.perimeter}, - #{item.area}, - #{item.areaMu}, - #{item.shpNo}, - #{item.villageType}, + #{item.areaType}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, @@ -126,9 +118,8 @@ JSON_OBJECT( 'deptId', l.dept_id, 'deptName', l.dept_name, - 'adcode', l.shp_no, - 'name', l.community_name, - 'community_name', l.community_name + 'name', l.name_path, + 'community_name', l.name_path ), 'geometry', ST_AsGeoJSON(l.boundary) diff --git a/dk-modules/system/src/main/resources/mapper/system/SysDeptMapper.xml b/dk-modules/system/src/main/resources/mapper/system/SysDeptMapper.xml index a0af8f3..d823dfc 100644 --- a/dk-modules/system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/dk-modules/system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -52,7 +52,8 @@ sd.dept_name deptName, CAST(sd.dept_name AS CHAR(500)) AS namePath, sd.shp_no shpNo, - sd.tenant_id + sd.tenant_id, + sd.parent_id FROM sys_dept sd WHERE @@ -66,7 +67,8 @@ d.dept_name deptName, CONCAT(dp.namePath, '', d.dept_name) AS namePath, d.shp_no shpNo, - d.tenant_id + d.tenant_id, + d.parent_id FROM sys_dept d INNER JOIN @@ -77,9 +79,15 @@ namePath, shpNo, deptName, - tenant_id + tenant_id, + parent_id parentId FROM - DeptPath + DeptPath dp + + + dp.deptId = #{deptId} + + ORDER BY deptId