|
|
@@ -30,6 +30,20 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class StorageServiceImpl {
|
|
|
|
|
|
+ /**
|
|
|
+ * gj_shouchu_xiangmu_shiji 表允许入库的字段白名单
|
|
|
+ * (除 gid / geom / create_time / update_time 外的全部业务列,外加 shp 读取时的 the_geom)
|
|
|
+ * shp 字段数量可能多于数据表字段,需通过白名单过滤多余字段
|
|
|
+ */
|
|
|
+ private static final Set<String> SHIJI_ALLOWED_COLUMNS = new HashSet<>(Arrays.asList(
|
|
|
+ "dabh", "scfs", "scjg", "scmj", "scnd", "scsj", "scwh",
|
|
|
+ "shape_area", "shape_leng", "tdzl", "wzfbck", "xzq", "yqsdw",
|
|
|
+ "ytdsyqxz", "ytdyt", "cblx", "htqdsj", "nf", "schtbh", "sczj",
|
|
|
+ "yqsxz", "yzfbck", "sccb", "mj_m", "xmmc", "ghyt", "jzwmj",
|
|
|
+ "jzwjj", "pggs", "tdpgjg", "jzwpgjg", "qyzcpg", "tctgss",
|
|
|
+ "zfjl", "bz", "the_geom"
|
|
|
+ ));
|
|
|
+
|
|
|
@Autowired
|
|
|
private GjShijiShouchuMapper gjShijiShouchuMapper;
|
|
|
|
|
|
@@ -695,19 +709,20 @@ public class StorageServiceImpl {
|
|
|
List<Map<String, Object>> shpDataList = shpGeomResult.getData();
|
|
|
log.info("远程调用geom获取,返回结果:{}", shpDataList);
|
|
|
|
|
|
- //数据字段进行校验
|
|
|
int count = 1;
|
|
|
for (Map<String, Object> shpData : shpDataList){
|
|
|
String sccb = shpData.get("sccb").toString();
|
|
|
- String scfs = shpData.get("scnf").toString();
|
|
|
+ String scnf = shpData.get("scnf").toString();
|
|
|
+ String scfs = shpData.get("scfs").toString();
|
|
|
String ghyt = shpData.get("ghyt").toString();
|
|
|
String mj_m = shpData.get("mj_m").toString();
|
|
|
- if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
|
|
|
- throw new ServiceException("关键字段不能为空(sccb,scnf,ghyt,mj_m),请检查第"+count+"条数据");
|
|
|
+ if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) ||StringUtils.isBlank(scnf) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
|
|
|
+ throw new ServiceException("关键字段不能为空(sccb,scnf,scfs,ghyt,mj_m),请检查第"+count+"条数据");
|
|
|
}
|
|
|
count++;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if("0".equals(addType)){
|
|
|
//这里把当前表清空,重新写入;
|
|
|
gjShouchuJihuaMapper.deleteByTable("gj_shouchu_xiangmu","",sourceType);
|
|
|
@@ -775,6 +790,95 @@ public class StorageServiceImpl {
|
|
|
|
|
|
|
|
|
|
|
|
+ //导入实际的数据
|
|
|
+ public Map<String, Object> importActual(String shpFilePath,String addType) {
|
|
|
+ Map<String, Object> retMap = new LinkedHashMap<>();
|
|
|
+ if(StringUtils.isBlank(shpFilePath)){
|
|
|
+ throw new ServiceException("文件不存在请重新上传!");
|
|
|
+ }
|
|
|
+ File file = new File(shpFilePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ throw new ServiceException("文件不存在请重新上传!");
|
|
|
+ }
|
|
|
+
|
|
|
+ R<List<Map<String, Object>>> shpGeomResult = remoteSpatialFilesDbService.readShpFile(shpFilePath, SecurityConstants.INNER);
|
|
|
+ List<Map<String, Object>> shpDataList = shpGeomResult.getData();
|
|
|
+ log.info("远程调用geom获取,返回结果:{}", shpDataList);
|
|
|
+
|
|
|
+ //数据字段进行校验
|
|
|
+ int count = 1;
|
|
|
+ for (Map<String, Object> shpData : shpDataList){
|
|
|
+// String scfs = shpData.get("scfs").toString();
|
|
|
+// String scnd = shpData.get("scnd").toString();
|
|
|
+// String sccb = shpData.get("sccb").toString();
|
|
|
+// String mj_m = shpData.get("mj_m").toString();
|
|
|
+// String ghyt = shpData.get("ghyt").toString();
|
|
|
+// if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) ||StringUtils.isBlank(scnd) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
|
|
|
+// throw new ServiceException("关键字段不能为空(sccb,scnd,scfs,ghyt,mj_m),请检查第"+count+"条数据");
|
|
|
+// }
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ if("0".equals(addType)){
|
|
|
+ //这里把当前表清空,重新写入;
|
|
|
+ gjShouchuJihuaMapper.deleteByTable("gj_shouchu_xiangmu_shiji","","");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 实际收储项目表 gj_shouchu_xiangmu_shiji geom 列的 SRID(建表语句中为 geometry(MULTIPOLYGON, 4326))
|
|
|
+ int shpDbSRID = 4326;
|
|
|
+ // 日期字段(shp 读取出来是 ISO8601 字符串,如 2025-12-24T00:00:00.000+08:00):
|
|
|
+ // 该表对应字段均为 varchar(100),为避免脏数据,统一截取 "T" 之前部分入库
|
|
|
+ Set<String> dateFields = new HashSet<>(Arrays.asList("scsj", "htqdsj"));
|
|
|
+ // 该表除 gid、geom、create_time、update_time 外,其余字段均为 varchar(100),
|
|
|
+ // 无需做 numeric 转换,仅做字符串清洗即可
|
|
|
+
|
|
|
+ for (Map<String, Object> shpData : shpDataList) {
|
|
|
+ Map<String, Object> insertData = new LinkedHashMap<>();
|
|
|
+ for (Map.Entry<String, Object> e : shpData.entrySet()) {
|
|
|
+ String key = e.getKey();
|
|
|
+ // shp 字段数量可能多于数据表字段,通过白名单过滤多余字段
|
|
|
+ if (!SHIJI_ALLOWED_COLUMNS.contains(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object val = e.getValue();
|
|
|
+ if (val == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (val instanceof String) {
|
|
|
+ String s = ((String) val).trim();
|
|
|
+ if (s.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (dateFields.contains(key)) {
|
|
|
+ int t = s.indexOf('T');
|
|
|
+ if (t > 0) {
|
|
|
+ s = s.substring(0, t);
|
|
|
+ }
|
|
|
+ insertData.put(key, s);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ insertData.put(key, s);
|
|
|
+ } else {
|
|
|
+ insertData.put(key, val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (MapUtils.isEmpty(insertData)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ gjShouchuJihuaMapper.insertTableActualData(
|
|
|
+ "gj_shouchu_xiangmu_shiji", insertData, shpDbSRID);
|
|
|
+ }
|
|
|
+
|
|
|
+ retMap.put("status", "success");
|
|
|
+ retMap.put("path", shpFilePath);
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|