fix: 图例方法优化
This commit is contained in:
parent
2cfee388c1
commit
0d9e007599
@ -3,6 +3,8 @@ package com.yfd.platform.qgc_sys.mapLayer.mapper;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.yfd.platform.qgc_sys.mapLayer.domain.MsMaplegendB;
|
import com.yfd.platform.qgc_sys.mapLayer.domain.MsMaplegendB;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地图图例表 Mapper 接口
|
* 地图图例表 Mapper 接口
|
||||||
@ -11,4 +13,10 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MsMaplegendBMapper extends BaseMapper<MsMaplegendB> {
|
public interface MsMaplegendBMapper extends BaseMapper<MsMaplegendB> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改图例名称,解决Oracle/m³变成m3的问题
|
||||||
|
*/
|
||||||
|
@Update("UPDATE MS_MAPLEGEND_B SET NAME = #{name} WHERE ID = #{id}")
|
||||||
|
void updateModelName(@Param("id") String id, @Param("name") String name);
|
||||||
}
|
}
|
||||||
@ -13,9 +13,11 @@ import com.yfd.platform.qgc_sys.mapLayer.mapper.MsMapmoduleBMapper;
|
|||||||
import com.yfd.platform.qgc_sys.mapLayer.service.IMapLegendService;
|
import com.yfd.platform.qgc_sys.mapLayer.service.IMapLegendService;
|
||||||
import com.yfd.platform.utils.SecurityUtils;
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -31,6 +33,12 @@ public class MapLegendServiceImpl extends ServiceImpl<MsMaplegendBMapper, MsMapl
|
|||||||
@Resource
|
@Resource
|
||||||
private MsMapmoduleBMapper msMapmoduleBMapper;
|
private MsMapmoduleBMapper msMapmoduleBMapper;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.druid.master.driverClassName}")
|
||||||
|
private String jdbcDriver;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.druid.slave.driverClassName}")
|
||||||
|
private String slaveJdbcDriver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delelteByIds(List<String> ids) {
|
public void delelteByIds(List<String> ids) {
|
||||||
if (CollectionUtil.isEmpty(ids)) {
|
if (CollectionUtil.isEmpty(ids)) {
|
||||||
@ -101,13 +109,20 @@ public class MapLegendServiceImpl extends ServiceImpl<MsMaplegendBMapper, MsMapl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean saveOrUpdate(MsMaplegendB legend) {
|
public boolean saveOrUpdate(MsMaplegendB legend) {
|
||||||
|
// 修改: 不能有编码一样的数据
|
||||||
if (hasSameCode(legend)) {
|
if (hasSameCode(legend)) {
|
||||||
throw new BizException("存在相同编码的数据");
|
throw new BizException("存在相同编码的数据");
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(legend.getId())) {
|
if (StrUtil.isNotBlank(legend.getId())) {
|
||||||
|
// 更新父级,分组等
|
||||||
updateSetLegend(legend);
|
updateSetLegend(legend);
|
||||||
|
legend.setModifyUser(SecurityUtils.getUserId());
|
||||||
|
legend.setModifyTime(new Date());
|
||||||
super.updateById(legend);
|
super.updateById(legend);
|
||||||
|
// 对图例名称操作,解决m³变成m3
|
||||||
|
updateModelName(legend);
|
||||||
} else {
|
} else {
|
||||||
|
// 如果是新增数据,则必须有父级
|
||||||
if (legend.getDataType() == 2 && StrUtil.isBlank(legend.getParentId())) {
|
if (legend.getDataType() == 2 && StrUtil.isBlank(legend.getParentId())) {
|
||||||
throw new BizException("请先创建图例父级结构再添加数据.");
|
throw new BizException("请先创建图例父级结构再添加数据.");
|
||||||
}
|
}
|
||||||
@ -119,22 +134,32 @@ public class MapLegendServiceImpl extends ServiceImpl<MsMaplegendBMapper, MsMapl
|
|||||||
legend.setOrderIndex(maxOrderIndex + 1);
|
legend.setOrderIndex(maxOrderIndex + 1);
|
||||||
MsMaplegendB parentLegend = null;
|
MsMaplegendB parentLegend = null;
|
||||||
if (StrUtil.isNotBlank(legend.getParentId())) {
|
if (StrUtil.isNotBlank(legend.getParentId())) {
|
||||||
|
// 获取父级信息
|
||||||
parentLegend = this.getById(legend.getParentId());
|
parentLegend = this.getById(legend.getParentId());
|
||||||
if (parentLegend == null) {
|
if (parentLegend == null) {
|
||||||
throw new BizException("获取父级图例信息失败.请检查父级图例(parentId)是否存在.");
|
throw new BizException("获取父级图例信息失败.请检查父级图例(parentId)是否存在.");
|
||||||
}
|
}
|
||||||
|
// 设置fullPath
|
||||||
legend.setFullPath(parentLegend.getFullPath() + legend.getId() + ",");
|
legend.setFullPath(parentLegend.getFullPath() + legend.getId() + ",");
|
||||||
legend.setTreeLevel(parentLegend.getTreeLevel() + 1);
|
// 设置treeLevel
|
||||||
|
Integer parentLevel = parentLegend.getTreeLevel();
|
||||||
|
int newLevel = (parentLevel != null) ? parentLevel + 1 : 1; // 如果父级为空,则从1开始
|
||||||
|
legend.setTreeLevel(newLevel);
|
||||||
|
// 设置hasChildren
|
||||||
legend.setHasChildren(0);
|
legend.setHasChildren(0);
|
||||||
} else {
|
} else {
|
||||||
|
// 无父级,则为创建的顶级图例
|
||||||
legend.setTreeLevel(1);
|
legend.setTreeLevel(1);
|
||||||
legend.setFullPath(legend.getId() + ",");
|
legend.setFullPath(legend.getId() + ",");
|
||||||
legend.setHasChildren(0);
|
legend.setHasChildren(0);
|
||||||
}
|
}
|
||||||
if (legend.getDataType() == 1) {
|
if (legend.getDataType() == 1) {
|
||||||
|
// 为结构的时候,groupName,parentName 等于自己
|
||||||
legend.setGroupName(legend.getName());
|
legend.setGroupName(legend.getName());
|
||||||
legend.setParentName(legend.getName());
|
legend.setParentName(legend.getName());
|
||||||
} else {
|
} else {
|
||||||
|
// 为数据的时候,groupName 取二级名称,parentName 取一级名称
|
||||||
|
// (暂时只有2级结构,如果没有二级,groupName和parentName一样,都取一级名称)
|
||||||
String fullPath = parentLegend.getFullPath();
|
String fullPath = parentLegend.getFullPath();
|
||||||
if (StrUtil.isNotBlank(fullPath)) {
|
if (StrUtil.isNotBlank(fullPath)) {
|
||||||
String[] path = fullPath.split(",");
|
String[] path = fullPath.split(",");
|
||||||
@ -155,18 +180,24 @@ public class MapLegendServiceImpl extends ServiceImpl<MsMaplegendBMapper, MsMapl
|
|||||||
if (parentLegend != null && StrUtil.isBlank(legend.getLayerCode())) {
|
if (parentLegend != null && StrUtil.isBlank(legend.getLayerCode())) {
|
||||||
legend.setLayerCode(parentLegend.getLayerCode());
|
legend.setLayerCode(parentLegend.getLayerCode());
|
||||||
}
|
}
|
||||||
|
// 设置是否显示
|
||||||
legend.setIfShow(0);
|
legend.setIfShow(0);
|
||||||
|
// 设置是否内置
|
||||||
legend.setInternal(0);
|
legend.setInternal(0);
|
||||||
|
// 设置启用
|
||||||
legend.setEnable(0);
|
legend.setEnable(0);
|
||||||
legend.setRecordUser(SecurityUtils.getUserId());
|
legend.setRecordUser(SecurityUtils.getUserId());
|
||||||
legend.setModifyUser(SecurityUtils.getUserId());
|
legend.setModifyUser(SecurityUtils.getUserId());
|
||||||
this.save(legend);
|
this.save(legend);
|
||||||
|
// 新增完成后,设置父级hasChildren为1
|
||||||
if (parentLegend != null) {
|
if (parentLegend != null) {
|
||||||
MsMaplegendB temp = new MsMaplegendB();
|
MsMaplegendB temp = new MsMaplegendB();
|
||||||
temp.setId(parentLegend.getId());
|
temp.setId(parentLegend.getId());
|
||||||
temp.setHasChildren(1);
|
temp.setHasChildren(1);
|
||||||
this.updateById(temp);
|
this.updateById(temp);
|
||||||
}
|
}
|
||||||
|
// 对图例名称操作,解决m³变成m3
|
||||||
|
updateModelName(legend);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -237,4 +268,27 @@ public class MapLegendServiceImpl extends ServiceImpl<MsMaplegendBMapper, MsMapl
|
|||||||
.list();
|
.list();
|
||||||
return !CollectionUtil.isEmpty(list) && !list.get(0).getId().equals(legend.getId());
|
return !CollectionUtil.isEmpty(list) && !list.get(0).getId().equals(legend.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改图例名称,解决Oracle/m³变成m3的问题
|
||||||
|
*/
|
||||||
|
public void updateModelName(MsMaplegendB legend) {
|
||||||
|
if (StrUtil.isNotBlank(legend.getName())) {
|
||||||
|
String jdbcDriver = this.jdbcDriver;
|
||||||
|
if (jdbcDriver != null &&
|
||||||
|
(jdbcDriver.toLowerCase().contains("oracle")
|
||||||
|
|| jdbcDriver.toLowerCase().contains("dm")
|
||||||
|
|| jdbcDriver.toLowerCase().contains("kingbase8"))) {
|
||||||
|
String name = legend.getName();
|
||||||
|
if (name.contains("m³")) {
|
||||||
|
name = name.replace("m³", "m\\00b3");
|
||||||
|
}
|
||||||
|
if (name.contains("m²")) {
|
||||||
|
name = name.replace("m²", "m\\00b2");
|
||||||
|
}
|
||||||
|
legend.setName(name);
|
||||||
|
this.baseMapper.updateModelName(legend.getId(), legend.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user