|
@ -1,6 +1,7 @@ |
|
|
package org.dromara.system.service.impl; |
|
|
package org.dromara.system.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
@ -13,12 +14,15 @@ import org.dromara.system.domain.SysGeospatialVectors; |
|
|
import org.dromara.system.domain.SysVectorDict; |
|
|
import org.dromara.system.domain.SysVectorDict; |
|
|
import org.dromara.system.domain.bo.SysDepartBoundaryBo; |
|
|
import org.dromara.system.domain.bo.SysDepartBoundaryBo; |
|
|
import org.dromara.system.domain.bo.SysDeptBo; |
|
|
import org.dromara.system.domain.bo.SysDeptBo; |
|
|
|
|
|
import org.dromara.system.domain.kmz.KmzResult; |
|
|
import org.dromara.system.domain.vo.SysDeptVo; |
|
|
import org.dromara.system.domain.vo.SysDeptVo; |
|
|
import org.dromara.system.mapper.SysDepartBoundaryMapper; |
|
|
import org.dromara.system.mapper.SysDepartBoundaryMapper; |
|
|
import org.dromara.system.service.ISysDepartBoundaryService; |
|
|
import org.dromara.system.service.ISysDepartBoundaryService; |
|
|
import org.dromara.system.service.ISysDeptService; |
|
|
import org.dromara.system.service.ISysDeptService; |
|
|
import org.dromara.system.service.ISysVectorDictService; |
|
|
import org.dromara.system.service.ISysVectorDictService; |
|
|
import org.dromara.system.utils.BatchProcessorUtil; |
|
|
import org.dromara.system.utils.BatchProcessorUtil; |
|
|
|
|
|
import org.dromara.system.utils.KmlParserUtil; |
|
|
|
|
|
import org.dromara.system.utils.KmzParserUtil; |
|
|
import org.dromara.system.utils.ShpAnalysisUtil; |
|
|
import org.dromara.system.utils.ShpAnalysisUtil; |
|
|
import org.dromara.common.core.exception.ServiceException; |
|
|
import org.dromara.common.core.exception.ServiceException; |
|
|
import org.dromara.common.mybatis.core.page.PageQuery; |
|
|
import org.dromara.common.mybatis.core.page.PageQuery; |
|
@ -30,10 +34,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
import java.lang.reflect.Method; |
|
|
import java.lang.reflect.Method; |
|
|
import java.util.ArrayList; |
|
|
import java.util.*; |
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -50,6 +51,13 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public TableDataInfo<SysDepartBoundary> listSysDepartBoundary(PageQuery pageQuery, SysDepartBoundary departBoundary) { |
|
|
public TableDataInfo<SysDepartBoundary> listSysDepartBoundary(PageQuery pageQuery, SysDepartBoundary departBoundary) { |
|
|
|
|
|
if (ObjectUtil.isNotEmpty(departBoundary.getDeptId())){ |
|
|
|
|
|
List<SysDeptVo> deptList = deptService.listTreeDept(departBoundary.getDeptId()); |
|
|
|
|
|
|
|
|
|
|
|
departBoundary.setDeptIds(deptList.stream().map(SysDeptVo::getDeptId).distinct().toList()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Page<SysDepartBoundary> page = baseMapper.listSysDepartBoundary(pageQuery.build(),departBoundary); |
|
|
Page<SysDepartBoundary> page = baseMapper.listSysDepartBoundary(pageQuery.build(),departBoundary); |
|
|
|
|
|
|
|
|
return TableDataInfo.build(page); |
|
|
return TableDataInfo.build(page); |
|
@ -70,11 +78,14 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public boolean uploadShpFile(MultipartFile file,Integer areaType,Long parentId) { |
|
|
public boolean uploadShpFile(MultipartFile file,Integer areaType,Long parentId) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
List<SysGeospatialVectors> geospatialVectorsList = buildGeospatialVector(file); |
|
|
List<SysGeospatialVectors> geospatialVectorsList = buildGeospatialVector(file); |
|
|
|
|
|
|
|
|
//6、生成新的对象集合存储数据表中
|
|
|
//6、生成新的对象集合存储数据表中
|
|
|
List<SysDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,areaType,parentId); |
|
|
List<SysDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,areaType,parentId); |
|
|
|
|
|
|
|
|
|
|
|
boundaryList = boundaryList.stream().filter(p-> ObjectUtil.isNotEmpty(p.getBoundary())).toList(); |
|
|
|
|
|
|
|
|
// 分批处理
|
|
|
// 分批处理
|
|
|
int startIndex = 0; // 从第 0 条开始
|
|
|
int startIndex = 0; // 从第 0 条开始
|
|
|
int batchSize = 2000; // 每批处理 2000 条
|
|
|
int batchSize = 2000; // 每批处理 2000 条
|
|
@ -97,10 +108,35 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
private List<SysGeospatialVectors> buildGeospatialVector(MultipartFile file){ |
|
|
private List<SysGeospatialVectors> buildGeospatialVector(MultipartFile file){ |
|
|
List<SysGeospatialVectors> geospatialVectorsList = new ArrayList<>(); |
|
|
List<SysGeospatialVectors> geospatialVectorsList = new ArrayList<>(); |
|
|
try { |
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, String>> mapList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
//1、首先调用解析工具拿到解析的字段集合
|
|
|
//1、首先调用解析工具拿到解析的字段集合
|
|
|
InputStream inputStream = file.getInputStream(); |
|
|
if (file.getOriginalFilename().endsWith(".zip")) { |
|
|
List<Map<String, String>> mapList = ShpAnalysisUtil.analysisShpFile(inputStream); |
|
|
|
|
|
|
|
|
mapList = ShpAnalysisUtil.analysisShpFile(file.getInputStream()); |
|
|
|
|
|
|
|
|
|
|
|
} else if (file.getOriginalFilename().endsWith(".kmz") || file.getOriginalFilename().endsWith(".ovkmz")) { |
|
|
|
|
|
|
|
|
|
|
|
List<KmzResult> kmzResults = KmzParserUtil.parseKmz(file.getInputStream()); |
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, String>> kmzList = new ArrayList<>(); |
|
|
|
|
|
kmzResults.forEach(kmzResult -> { |
|
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
|
Map<String, String> attributes = kmzResult.getAttributes(); |
|
|
|
|
|
if (ObjectUtil.isNotEmpty(attributes)) { |
|
|
|
|
|
map.putAll(attributes); |
|
|
|
|
|
} |
|
|
|
|
|
map.put("O_NAME", kmzResult.getName()); |
|
|
|
|
|
map.put("the_geom", kmzResult.getWkt()); |
|
|
|
|
|
kmzList.add(map); |
|
|
|
|
|
}); |
|
|
|
|
|
mapList = kmzList; |
|
|
|
|
|
} else if (file.getOriginalFilename().endsWith(".kml") || file.getOriginalFilename().endsWith(".ovkml")) { |
|
|
|
|
|
|
|
|
|
|
|
mapList = KmlParserUtil.parseKml(file.getInputStream()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
// 3. 构建字典map
|
|
|
// 3. 构建字典map
|
|
|
List<SysVectorDict> fieldsInfoList = vectorDictService.listVectorField(); |
|
|
List<SysVectorDict> fieldsInfoList = vectorDictService.listVectorField(); |
|
|
|
|
|
|
|
@ -197,16 +233,31 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
return List.of(child,parent); |
|
|
return List.of(child,parent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据经纬度查询部门信息 |
|
|
|
|
|
* @param lng |
|
|
|
|
|
* @param lat |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public List<SysDepartBoundary> listDepartBoundaryByLngAndLat(Double lng, Double lat) { |
|
|
|
|
|
|
|
|
|
|
|
return this.baseMapper.listDepartBoundaryByLngAndLat(lng,lat); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean deleteDepartBoundary(String id) { |
|
|
public boolean deleteDepartBoundary(String deptId) { |
|
|
SysDepartBoundary departBoundary = this.baseMapper.selectById(id); |
|
|
LambdaQueryWrapper<SysDepartBoundary> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(SysDepartBoundary::getDeptId,deptId); |
|
|
|
|
|
|
|
|
|
|
|
List<SysDepartBoundary> sysDepartBoundaries = this.baseMapper.selectList(wrapper); |
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(departBoundary)) { |
|
|
if (ObjectUtil.isEmpty(sysDepartBoundaries)) { |
|
|
throw new ServiceException("实体不存在!"); |
|
|
throw new ServiceException("实体不存在!"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.baseMapper.deleteById(departBoundary.getId())>0; |
|
|
return this.baseMapper.deleteByIds(sysDepartBoundaries.stream().map(SysDepartBoundary::getId).distinct().toList())>0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -224,40 +275,79 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
.collect(Collectors.groupingBy(item -> item.get("deptName").toString())); |
|
|
.collect(Collectors.groupingBy(item -> item.get("deptName").toString())); |
|
|
|
|
|
|
|
|
geospatialVectorsList.forEach(param->{ |
|
|
geospatialVectorsList.forEach(param->{ |
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
|
|
|
//获取区划名称
|
|
|
//获取区划名称
|
|
|
String divisionName = param.getAdminDivisionName(); |
|
|
String divisionName = param.getAdminDivisionName(); |
|
|
|
|
|
|
|
|
businessDepartBoundary.setBoundary(param.getLandCategories()); |
|
|
//是集合
|
|
|
//判断是否存在表中,在表中更新部门区域中的部门id信息
|
|
|
if (isCollectionString(param.getLandCategories())){ |
|
|
if (ObjectUtil.isNotEmpty(namePathMap.get(divisionName))){ |
|
|
List<String> geomList = convertStringToList(param.getLandCategories()); |
|
|
Map<String, Object> objectMap = namePathMap.get(divisionName).get(0); |
|
|
|
|
|
businessDepartBoundary.setDeptName(objectMap.get("deptName") + ""); |
|
|
geomList.forEach(item->{ |
|
|
businessDepartBoundary.setDeptId(Long.valueOf(objectMap.get("deptId") + "")); |
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
businessDepartBoundary.setNamePath(objectMap.get("namePath") + ""); |
|
|
|
|
|
businessDepartBoundary.setAreaType(areaType); |
|
|
businessDepartBoundary.setBoundary(item); |
|
|
resultList.add(businessDepartBoundary); |
|
|
|
|
|
|
|
|
createBoundary(businessDepartBoundary,namePathMap,divisionName,areaType,parentId); |
|
|
|
|
|
|
|
|
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}else { |
|
|
}else { |
|
|
//如果不存在在部门表中则添加
|
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
SysDeptBo sysDeptBo = new SysDeptBo(); |
|
|
|
|
|
sysDeptBo.setParentId(parentId); |
|
|
|
|
|
sysDeptBo.setDeptName(param.getAdminDivisionName()); |
|
|
|
|
|
|
|
|
|
|
|
SysDept sysDept = deptService.addBoundaryDept(sysDeptBo); |
|
|
businessDepartBoundary.setBoundary(param.getLandCategories()); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> deptNamePath = deptService.getNamePathList(sysDept.getDeptId()); |
|
|
createBoundary(businessDepartBoundary,namePathMap,divisionName,areaType,parentId); |
|
|
|
|
|
|
|
|
businessDepartBoundary.setDeptName(sysDept.getDeptName()); |
|
|
|
|
|
businessDepartBoundary.setDeptId(sysDept.getDeptId()); |
|
|
|
|
|
businessDepartBoundary.setNamePath(deptNamePath.getFirst().get("namePath").toString()); |
|
|
|
|
|
businessDepartBoundary.setAreaType(areaType); |
|
|
|
|
|
resultList.add(businessDepartBoundary); |
|
|
resultList.add(businessDepartBoundary); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
return resultList; |
|
|
return resultList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void createBoundary(SysDepartBoundary businessDepartBoundary, Map<String, List<Map<String, Object>>> namePathMap, String divisionName, Integer areaType, Long parentId) { |
|
|
|
|
|
businessDepartBoundary.setParentId(parentId); |
|
|
|
|
|
//判断是否存在表中,在表中更新部门区域中的部门id信息
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(namePathMap.get(divisionName))){ |
|
|
|
|
|
Map<String, Object> objectMap = namePathMap.get(divisionName).get(0); |
|
|
|
|
|
businessDepartBoundary.setDeptName(objectMap.get("deptName") + ""); |
|
|
|
|
|
businessDepartBoundary.setDeptId(Long.valueOf(objectMap.get("deptId") + "")); |
|
|
|
|
|
businessDepartBoundary.setNamePath(objectMap.get("namePath") + ""); |
|
|
|
|
|
businessDepartBoundary.setAreaType(areaType); |
|
|
|
|
|
}else { |
|
|
|
|
|
//如果不存在在部门表中则添加
|
|
|
|
|
|
SysDeptBo sysDeptBo = new SysDeptBo(); |
|
|
|
|
|
sysDeptBo.setParentId(parentId); |
|
|
|
|
|
sysDeptBo.setDeptName(divisionName); |
|
|
|
|
|
|
|
|
|
|
|
SysDept sysDept = deptService.addBoundaryDept(sysDeptBo); |
|
|
|
|
|
|
|
|
|
|
|
List<Map<String,Object>> deptNamePath = deptService.getNamePathList(sysDept.getDeptId()); |
|
|
|
|
|
|
|
|
|
|
|
businessDepartBoundary.setDeptName(sysDept.getDeptName()); |
|
|
|
|
|
businessDepartBoundary.setDeptId(sysDept.getDeptId()); |
|
|
|
|
|
businessDepartBoundary.setNamePath(deptNamePath.getFirst().get("namePath").toString()); |
|
|
|
|
|
businessDepartBoundary.setAreaType(areaType); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> convertStringToList(String str) { |
|
|
|
|
|
// 去除首尾的 "[" 和 "]"
|
|
|
|
|
|
str = str.substring(1, str.length() - 1); |
|
|
|
|
|
|
|
|
|
|
|
// 使用逗号分割
|
|
|
|
|
|
String[] items = str.split(", "); |
|
|
|
|
|
|
|
|
|
|
|
// 返回新的 List
|
|
|
|
|
|
return Arrays.asList(items); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 判断字符串是否是集合的字符串形式
|
|
|
|
|
|
public static boolean isCollectionString(String str) { |
|
|
|
|
|
return str != null && str.startsWith("[") && str.endsWith("]") && str.contains(","); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String capitalizeFirstLetter(String str) { |
|
|
private static String capitalizeFirstLetter(String str) { |
|
|
if (str == null || str.isEmpty()) { |
|
|
if (str == null || str.isEmpty()) { |
|
|