From d30d873fa47dcf4de713cd4e4672a788bc332e0b Mon Sep 17 00:00:00 2001 From: tangwei Date: Mon, 6 Jul 2026 17:01:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MapLegendController.java | 12 -- .../service/impl/MapLegendServiceImpl.java | 142 ++++++++++++++++++ 2 files changed, 142 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/controller/MapLegendController.java b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/controller/MapLegendController.java index fe7bb242..9c2b5010 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/controller/MapLegendController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/controller/MapLegendController.java @@ -162,18 +162,6 @@ public class MapLegendController { if (legend.getDataType() == null) { throw new BizException("图例数据类型(dataType: 1=结构,2=数据)不能为空."); } - if (legend.getDataType() == 2 && StrUtil.isBlank(legend.getLayerCode())) { - throw new BizException("关联的图层编码(layerCode)不能为空."); - } - if (StrUtil.isNotBlank(legend.getName())){ - if(StrUtil.isBlank(legend.getGroupName())){ - legend.setGroupName(legend.getName()); - } - if(StrUtil.isBlank(legend.getParentName())){ - legend.setGroupName(legend.getName()); - } - } - legend.setRecordUser(SecurityUtils.getUserId()); mapLegendService.saveOrUpdate(legend); return ResponseResult.success("保存成功."); } diff --git a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLegendServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLegendServiceImpl.java index 5152e819..7e56a94f 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLegendServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_sys/mapLayer/service/impl/MapLegendServiceImpl.java @@ -11,10 +11,13 @@ import com.yfd.platform.qgc_sys.mapLayer.domain.MsMapmoduleB; import com.yfd.platform.qgc_sys.mapLayer.mapper.MsMaplegendBMapper; import com.yfd.platform.qgc_sys.mapLayer.mapper.MsMapmoduleBMapper; import com.yfd.platform.qgc_sys.mapLayer.service.IMapLegendService; +import com.yfd.platform.utils.SecurityUtils; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * 地图图例基础服务实现 @@ -94,4 +97,143 @@ public class MapLegendServiceImpl extends ServiceImpl list = getSubLegendList(legend.getParentId()); + Integer maxOrderIndex = getMaxOrderIndex(list); + legend.setOrderIndex(maxOrderIndex + 1); + MsMaplegendB parentLegend = null; + if (StrUtil.isNotBlank(legend.getParentId())) { + parentLegend = this.getById(legend.getParentId()); + if (parentLegend == null) { + throw new BizException("获取父级图例信息失败.请检查父级图例(parentId)是否存在."); + } + legend.setFullPath(parentLegend.getFullPath() + legend.getId() + ","); + legend.setTreeLevel(parentLegend.getTreeLevel() + 1); + legend.setHasChildren(0); + } else { + legend.setTreeLevel(1); + legend.setFullPath(legend.getId() + ","); + legend.setHasChildren(0); + } + if (legend.getDataType() == 1) { + legend.setGroupName(legend.getName()); + legend.setParentName(legend.getName()); + } else { + String fullPath = parentLegend.getFullPath(); + if (StrUtil.isNotBlank(fullPath)) { + String[] path = fullPath.split(","); + if (path.length == 1) { + legend.setGroupName(parentLegend.getName()); + legend.setParentName(parentLegend.getName()); + } else if (path.length == 2) { + legend.setGroupName(parentLegend.getName()); + MsMaplegendB root = this.getById(path[0]); + if (root == null) { + legend.setParentName(parentLegend.getParentName()); + } else { + legend.setParentName(root.getName()); + } + } + } + } + if (parentLegend != null && StrUtil.isBlank(legend.getLayerCode())) { + legend.setLayerCode(parentLegend.getLayerCode()); + } + legend.setIfShow(0); + legend.setInternal(0); + legend.setEnable(0); + legend.setRecordUser(SecurityUtils.getUserId()); + legend.setModifyUser(SecurityUtils.getUserId()); + this.save(legend); + if (parentLegend != null) { + MsMaplegendB temp = new MsMaplegendB(); + temp.setId(parentLegend.getId()); + temp.setHasChildren(1); + this.updateById(temp); + } + } + return true; + } + + private void updateSetLegend(MsMaplegendB legend) { + if (StrUtil.isNotBlank(legend.getParentId())) { + MsMaplegendB parent = this.getById(legend.getParentId()); + if (parent != null) { + if (legend.getDataType() == 1) { + legend.setParentName(parent.getName()); + legend.setFullPath(parent.getFullPath() + legend.getId() + ","); + } else { + legend.setGroupName(parent.getName()); + if (StrUtil.isNotBlank(parent.getFullPath())) { + MsMaplegendB root = this.getById(parent.getFullPath().split(",")[0]); + if (root != null) { + legend.setParentName(root.getName()); + } + legend.setFullPath(parent.getFullPath() + legend.getId() + ","); + } + } + if (StrUtil.isNotBlank(legend.getFullPath())) { + legend.setTreeLevel(legend.getFullPath().split(",").length); + } + } + if (legend.getDataType() == 1) { + legend.setGroupName(legend.getName()); + } + } else { + if (legend.getDataType() == 1) { + legend.setGroupName(legend.getName()); + legend.setParentName(legend.getName()); + } + legend.setFullPath(legend.getId() + ","); + legend.setTreeLevel(1); + } + } + + public List getSubLegendList(String parentId) { + if (StrUtil.isNotBlank(parentId)) { + return this.lambdaQuery() + .eq(MsMaplegendB::getParentId, parentId) + .orderByAsc(MsMaplegendB::getOrderIndex) + .list(); + } else { + return this.lambdaQuery() + .eq(MsMaplegendB::getTreeLevel, 1) + .orderByAsc(MsMaplegendB::getOrderIndex) + .list(); + } + } + + public Integer getMaxOrderIndex(List list) { + if (CollectionUtil.isEmpty(list)) { + return 0; + } else { + return list.stream() + .sorted(Comparator.comparing(MsMaplegendB::getOrderIndex).reversed()) + .toList() + .getFirst() + .getOrderIndex(); + } + } + + public boolean hasSameCode(MsMaplegendB legend) { + List list = this.lambdaQuery() + .eq(MsMaplegendB::getNameEn, legend.getNameEn()) + .list(); + return !CollectionUtil.isEmpty(list) && !list.get(0).getId().equals(legend.getId()); + } } \ No newline at end of file