|
|
@ -13,12 +13,14 @@ 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.kmz.KmzResult; |
|
|
|
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.KmzParserUtil; |
|
|
|
import org.dromara.system.utils.ShpAnalysisUtil; |
|
|
|
import org.dromara.common.core.exception.ServiceException; |
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery; |
|
|
@ -30,10 +32,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -70,11 +69,14 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public boolean uploadShpFile(MultipartFile file,Integer areaType,Long parentId) { |
|
|
|
try { |
|
|
|
|
|
|
|
List<SysGeospatialVectors> geospatialVectorsList = buildGeospatialVector(file); |
|
|
|
|
|
|
|
//6、生成新的对象集合存储数据表中
|
|
|
|
List<SysDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,areaType,parentId); |
|
|
|
|
|
|
|
boundaryList = boundaryList.stream().filter(p-> ObjectUtil.isNotEmpty(p.getBoundary())).toList(); |
|
|
|
|
|
|
|
// 分批处理
|
|
|
|
int startIndex = 0; // 从第 0 条开始
|
|
|
|
int batchSize = 2000; // 每批处理 2000 条
|
|
|
@ -97,9 +99,29 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
|
private List<SysGeospatialVectors> buildGeospatialVector(MultipartFile file){ |
|
|
|
List<SysGeospatialVectors> geospatialVectorsList = new ArrayList<>(); |
|
|
|
try { |
|
|
|
|
|
|
|
List<Map<String, String>> mapList = new ArrayList<>(); |
|
|
|
|
|
|
|
//1、首先调用解析工具拿到解析的字段集合
|
|
|
|
InputStream inputStream = file.getInputStream(); |
|
|
|
List<Map<String, String>> mapList = ShpAnalysisUtil.analysisShpFile(inputStream); |
|
|
|
if (file.getOriginalFilename().endsWith(".zip")) { |
|
|
|
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("XZQMC", kmzResult.getName()); |
|
|
|
map.put("the_geom", kmzResult.getName()); |
|
|
|
kmzList.add(map); |
|
|
|
}); |
|
|
|
mapList = kmzList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 构建字典map
|
|
|
|
List<SysVectorDict> fieldsInfoList = vectorDictService.listVectorField(); |
|
|
@ -224,40 +246,94 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM |
|
|
|
.collect(Collectors.groupingBy(item -> item.get("deptName").toString())); |
|
|
|
|
|
|
|
geospatialVectorsList.forEach(param->{ |
|
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
|
//获取区划名称
|
|
|
|
String divisionName = param.getAdminDivisionName(); |
|
|
|
|
|
|
|
businessDepartBoundary.setBoundary(param.getLandCategories()); |
|
|
|
//判断是否存在表中,在表中更新部门区域中的部门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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
}else { |
|
|
|
//如果不存在在部门表中则添加
|
|
|
|
SysDeptBo sysDeptBo = new SysDeptBo(); |
|
|
|
sysDeptBo.setParentId(parentId); |
|
|
|
sysDeptBo.setDeptName(param.getAdminDivisionName()); |
|
|
|
|
|
|
|
SysDept sysDept = deptService.addBoundaryDept(sysDeptBo); |
|
|
|
//是集合
|
|
|
|
if (isCollectionString(param.getLandCategories())){ |
|
|
|
List<String> geomList = convertStringToList(param.getLandCategories()); |
|
|
|
|
|
|
|
geomList.forEach(item->{ |
|
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
|
|
|
|
|
businessDepartBoundary.setBoundary(item); |
|
|
|
//判断是否存在表中,在表中更新部门区域中的部门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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
}else { |
|
|
|
//如果不存在在部门表中则添加
|
|
|
|
SysDeptBo sysDeptBo = new SysDeptBo(); |
|
|
|
sysDeptBo.setParentId(parentId); |
|
|
|
sysDeptBo.setDeptName(param.getAdminDivisionName()); |
|
|
|
|
|
|
|
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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
|
|
|
|
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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
}else { |
|
|
|
SysDepartBoundary businessDepartBoundary = new SysDepartBoundary(); |
|
|
|
|
|
|
|
businessDepartBoundary.setBoundary(param.getLandCategories()); |
|
|
|
//判断是否存在表中,在表中更新部门区域中的部门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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
}else { |
|
|
|
//如果不存在在部门表中则添加
|
|
|
|
SysDeptBo sysDeptBo = new SysDeptBo(); |
|
|
|
sysDeptBo.setParentId(parentId); |
|
|
|
sysDeptBo.setDeptName(param.getAdminDivisionName()); |
|
|
|
|
|
|
|
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); |
|
|
|
resultList.add(businessDepartBoundary); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
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) { |
|
|
|
if (str == null || str.isEmpty()) { |
|
|
|