|
|
@@ -2,12 +2,16 @@ package com.onemap.apply.service.impl.sbjk;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.onemap.apply.domain.cggl.ScmxDTO;
|
|
|
import com.onemap.apply.domain.cggl.ScmxRecordDTO;
|
|
|
+import com.onemap.apply.domain.cggl.TCgglSjbzmlwjDto;
|
|
|
import com.onemap.apply.domain.sbjk.XzczghcgsbDTO;
|
|
|
import com.onemap.apply.mapper.cggl.EscalationMapper;
|
|
|
import com.onemap.apply.mapper.cggl.ScmxMapper;
|
|
|
import com.onemap.apply.mapper.cggl.ScmxRecordMapper;
|
|
|
+import com.onemap.apply.mapper.cggl.TCgglSjbzmlwjMapper;
|
|
|
import com.onemap.apply.mapper.sbjk.XzczghcgsbMapper;
|
|
|
import com.onemap.apply.service.sbjk.XzczghcgsbService;
|
|
|
import com.onemap.apply.utils.Md5Utils;
|
|
|
@@ -30,9 +34,9 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.onemap.common.core.utils.StringUtils.FileSearch;
|
|
|
-import static com.onemap.common.core.utils.StringUtils.readTxt;
|
|
|
+import static com.onemap.common.core.utils.StringUtils.*;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -61,13 +65,16 @@ public class XzczghcgsbServiceImpl implements XzczghcgsbService {
|
|
|
private String charset;
|
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private TCgglSjbzmlwjMapper tCgglSjbzmlwjMapper;
|
|
|
@Autowired
|
|
|
private EscalationMapper escalationMapper;
|
|
|
@Autowired
|
|
|
private ScmxMapper scmxMapper;
|
|
|
@Autowired
|
|
|
private ScmxRecordMapper scmxRecordMapper;
|
|
|
+ //规划成果包基本信息存储
|
|
|
+ private Map<String, String> xmDetailMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -175,6 +182,7 @@ public class XzczghcgsbServiceImpl implements XzczghcgsbService {
|
|
|
xzczghcgsbDTO.setCglevel("1");
|
|
|
xzczghcgsbDTO.setUploadStatus(2);
|
|
|
}
|
|
|
+ xzczghcgsbDTO.setBz(xmDetailMap.get(xzczghcgsbDTO.getFilePath()));
|
|
|
return xzczghcgsbMapper.insert(xzczghcgsbDTO);
|
|
|
}
|
|
|
|
|
|
@@ -245,85 +253,227 @@ public class XzczghcgsbServiceImpl implements XzczghcgsbService {
|
|
|
//将村庄规划成果包进行解压,并校验是否符合要求
|
|
|
String filetype = StringUtils.getFileKzmx(fileName);
|
|
|
String relFileName = StringUtils.getFileRelName(fileName);
|
|
|
+ if (!relFileName.contains("_")) {
|
|
|
+ return AjaxResult.success("成果包名称必须包含完整成果/简易成果!", new ArrayList<>());
|
|
|
+ }
|
|
|
String unzippath = fileDir;
|
|
|
if (".zip".equals(filetype)) {
|
|
|
new UnPackageUtils().unPackZip(desc, unzippath);
|
|
|
} else if (".rar".equals(filetype)) {
|
|
|
new UnPackageUtils().unPackRar(desc, unzippath);
|
|
|
}
|
|
|
- //校验文件包是否符合上传要求
|
|
|
- //名称检查 完整成果、简易成果
|
|
|
- String[] requirefilenameRule = requireFileName.split("_");
|
|
|
- String filenameRule = "";
|
|
|
+ //TODO wanger 根据成果目录要求进行审查和记录
|
|
|
+ String folderPath = unzippath + File.separator + relFileName;
|
|
|
+ String txtFilePath = FileSearch(folderPath, "基本信息.txt");
|
|
|
+ if (StringUtils.isEmpty(txtFilePath)) {
|
|
|
+ deleteCurDirectory(desc.getParent());
|
|
|
+ return AjaxResult.error("1----成果包中必须包含“xxx基本信息.txt”文件,同时注意成果包中应包含“xxx规划成果”的根目录");
|
|
|
+ }
|
|
|
+ System.out.println("txtFilePath===" + txtFilePath);
|
|
|
+ Map<String, String> txtMap = null;
|
|
|
try {
|
|
|
- filenameRule = relFileName.split("_")[1];//完整成果、简易成果
|
|
|
+ txtMap = readTxt(txtFilePath, charset);
|
|
|
} catch (Exception e) {
|
|
|
- return AjaxResult.success("成果包名称必须包含完整成果/简易成果!", new ArrayList<>());
|
|
|
+ e.printStackTrace();
|
|
|
+ deleteCurDirectory(desc.getParent());
|
|
|
+ return AjaxResult.error("2---解析规划文本txt错误,请检查格式!");
|
|
|
}
|
|
|
- String xzqdm = StringUtils.getNumStr(relFileName);
|
|
|
- String xzqmc = relFileName.replace(xzqdm, "").replace(requirefilenameRule[requirefilenameRule.length - 1] + "_" + filenameRule, "");
|
|
|
- if (StringUtils.isEmpty(xzqdm) || StringUtils.isEmpty(xzqmc)) {
|
|
|
- return AjaxResult.success("成果包名称要求为:" + requireFileName + ",请检查修改后重新上传!", new ArrayList<>());
|
|
|
+ System.out.println("txtMap===" + txtMap);
|
|
|
+ String xmmc = txtMap.get("xmmc") != null ? txtMap.get("xmmc") : relFileName;
|
|
|
+ String xzqdm = txtMap.get("行政区代码");
|
|
|
+ String xzqmc = txtMap.get("行政区名称");
|
|
|
+ String ghlxtext = txtMap.get("规划类型");
|
|
|
+ String ghcjtext = txtMap.get("规划层级");
|
|
|
+ String ghxstext = txtMap.get("成果形式");
|
|
|
+ //TODO wanger 对成果包进行校验
|
|
|
+ System.out.println("xmmc===" + xmmc);
|
|
|
+ System.out.println("ghlxtext===" + ghlxtext);
|
|
|
+ System.out.println("ghxstext===" + ghxstext);
|
|
|
+ System.out.println("ghcjtext===" + ghcjtext);
|
|
|
+ String sjbz_bsm = "";
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String txtjson = "";
|
|
|
+ try {
|
|
|
+ txtjson = objectMapper.writeValueAsString(txtMap);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- for (int i = 0; i < requirefilenameRule.length; i++) {
|
|
|
- if (i == 0) {
|
|
|
- params.put(requirefilenameRule[i], xzqdm);
|
|
|
- } else if (i == 1) {
|
|
|
- params.put(requirefilenameRule[i], xzqmc);
|
|
|
- } else if (i == 2) {
|
|
|
- params.put(requirefilenameRule[i], requirefilenameRule[i]);
|
|
|
- }
|
|
|
+ sjbz_bsm = ghlxtext + "" + ghxstext;
|
|
|
+ QueryWrapper<TCgglSjbzmlwjDto> sjbzwrapper = new QueryWrapper();
|
|
|
+ sjbzwrapper.eq("sjbz_bsm", sjbz_bsm);
|
|
|
+ sjbzwrapper.orderByAsc("px");
|
|
|
+ List<TCgglSjbzmlwjDto> sjbzlist = tCgglSjbzmlwjMapper.selectList(sjbzwrapper);
|
|
|
+ if (sjbzlist.size() == 0) {
|
|
|
+ deleteCurDirectory(desc.getParent());
|
|
|
+ return AjaxResult.error(String.format("3-----未授权的数据类型:%s,请联系管理人员!", sjbz_bsm));
|
|
|
}
|
|
|
- List<String> missfile = new ArrayList<>();
|
|
|
- String[] requireRole = requireFileList.split(",");
|
|
|
- for (int i = 0; i < requireRole.length; i++) {
|
|
|
- String cur = requireRole[i].replaceAll("\n", "").replace(requirefileSplit, File.separator);
|
|
|
- if (cur.contains("|")) {//判断是否为完整成果、简易成果单独设置的筛选条件,如果不是则跳过此筛选项
|
|
|
- String whereType = cur.split("\\|")[1];
|
|
|
- cur = cur.split("\\|")[0];
|
|
|
- if (!filenameRule.contains(whereType)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- //文件名称占位符统一替换
|
|
|
- for (String key : params.keySet()) {
|
|
|
- if (cur.contains(key)) {
|
|
|
- cur = cur.replaceAll(key, params.get(key));
|
|
|
+ //TODO wanger 处理那些根目录带有“_报审”等的数据项
|
|
|
+ if (relFileName.contains("_")) {
|
|
|
+ System.out.println("Important contains _");
|
|
|
+ int count = relFileName.split("_").length;
|
|
|
+ for (TCgglSjbzmlwjDto sjbzmlwjDto : sjbzlist) {
|
|
|
+ String bz = sjbzmlwjDto.getBz();
|
|
|
+ if (StringUtils.isNotEmpty(bz) && bz.contains("根目录")) {
|
|
|
+ String rule = sjbzmlwjDto.getGzmc();
|
|
|
+ int rulecount = rule.split("_").length;
|
|
|
+ if (rulecount == count) {
|
|
|
+ //相等就代表命名规则一样,不需要处理
|
|
|
+ } else {
|
|
|
+ sjbzmlwjDto.setGzmc(rule + "_" + relFileName.split("_")[relFileName.split("_").length - 1]);
|
|
|
+ }
|
|
|
+ System.out.println("Important handle end _" + "----" + sjbzmlwjDto.getGzmc());
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- cur = cur.replaceAll("_", "");
|
|
|
- String curFilePath = unzippath + File.separator + relFileName + "" + cur;
|
|
|
- File c = new File(curFilePath);
|
|
|
- if (c.exists()) {
|
|
|
+ }
|
|
|
+ //记录缺失的文件列表 字符串类型
|
|
|
+ List<String> missfiles = new ArrayList<>();
|
|
|
+ missfiles = checkMustFiles(unzippath, sjbzlist, "", missfiles, xzqdm, xzqmc);
|
|
|
+ if (missfiles.size() > 0) {
|
|
|
+ deleteCurDirectory(desc.getParent());
|
|
|
+ return AjaxResult.success("村庄规划成果上传失败:上传失败缺少以下文件或文件名称有误:", missfiles);
|
|
|
+ }
|
|
|
+ xmDetailMap.put(desc.getAbsolutePath(), txtjson);
|
|
|
+ return AjaxResult.success(desc.getAbsolutePath() + "******" + xmmc);
|
|
|
+ //校验文件包是否符合上传要求
|
|
|
+ //名称检查 完整成果、简易成果
|
|
|
+// String[] requirefilenameRule = requireFileName.split("_");
|
|
|
+// String filenameRule = "";
|
|
|
+// try {
|
|
|
+// filenameRule = relFileName.split("_")[1];//完整成果、简易成果
|
|
|
+// } catch (Exception e) {
|
|
|
+// return AjaxResult.success("成果包名称必须包含完整成果/简易成果!", new ArrayList<>());
|
|
|
+// }
|
|
|
+// String xzqdm = StringUtils.getNumStr(relFileName);
|
|
|
+// String xzqmc = relFileName.replace(xzqdm, "").replace(requirefilenameRule[requirefilenameRule.length - 1] + "_" + filenameRule, "");
|
|
|
+// if (StringUtils.isEmpty(xzqdm) || StringUtils.isEmpty(xzqmc)) {
|
|
|
+// return AjaxResult.success("成果包名称要求为:" + requireFileName + ",请检查修改后重新上传!", new ArrayList<>());
|
|
|
+// }
|
|
|
+// Map<String, String> params = new HashMap<>();
|
|
|
+// for (int i = 0; i < requirefilenameRule.length; i++) {
|
|
|
+// if (i == 0) {
|
|
|
+// params.put(requirefilenameRule[i], xzqdm);
|
|
|
+// } else if (i == 1) {
|
|
|
+// params.put(requirefilenameRule[i], xzqmc);
|
|
|
+// } else if (i == 2) {
|
|
|
+// params.put(requirefilenameRule[i], requirefilenameRule[i]);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// List<String> missfile = new ArrayList<>();
|
|
|
+// String[] requireRole = requireFileList.split(",");
|
|
|
+// for (int i = 0; i < requireRole.length; i++) {
|
|
|
+// String cur = requireRole[i].replaceAll("\n", "").replace(requirefileSplit, File.separator);
|
|
|
+// if (cur.contains("|")) {//判断是否为完整成果、简易成果单独设置的筛选条件,如果不是则跳过此筛选项
|
|
|
+// String whereType = cur.split("\\|")[1];
|
|
|
+// cur = cur.split("\\|")[0];
|
|
|
+// if (!filenameRule.contains(whereType)) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //文件名称占位符统一替换
|
|
|
+// for (String key : params.keySet()) {
|
|
|
+// if (cur.contains(key)) {
|
|
|
+// cur = cur.replaceAll(key, params.get(key));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// cur = cur.replaceAll("_", "");
|
|
|
+// String curFilePath = unzippath + File.separator + relFileName + "" + cur;
|
|
|
+// File c = new File(curFilePath);
|
|
|
+// if (c.exists()) {
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// missfile.add(relFileName + cur);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (missfile.size() > 0) {
|
|
|
+// return AjaxResult.success("村庄规划成果上传失败:上传失败缺少以下文件或文件名称有误:", missfile);
|
|
|
+// } else {
|
|
|
+// //TODO wanger 获取规划文本中的项目名称
|
|
|
+// //解析txt
|
|
|
+// String txtFilePath = FileSearch(unzippath + File.separator + relFileName, "基本信息.txt");
|
|
|
+// if (StringUtils.isNotEmpty(txtFilePath)) {
|
|
|
+// System.out.println("txtFilePath===" + txtFilePath);
|
|
|
+// Map<String, String> txtMap = null;
|
|
|
+// try {
|
|
|
+// txtMap = readTxt(txtFilePath, charset);
|
|
|
+// } catch (Exception e) {
|
|
|
+// }
|
|
|
+// System.out.println("txtMap===" + txtMap);
|
|
|
+// if (StringUtils.isNotEmpty(txtMap.get("xmmc"))) {
|
|
|
+// return AjaxResult.success(desc.getAbsolutePath() + "******" + txtMap.get("xmmc"));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return AjaxResult.success(desc.getAbsolutePath() + "******" + relFileName);
|
|
|
+// }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- missfile.add(relFileName + cur);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 检查缺失的成果文件 递归调用 非常重要
|
|
|
+ *
|
|
|
+ * @param unzippath 文件路径
|
|
|
+ * @param sjbzlist 约定的数据标准检查项
|
|
|
+ * @param parentname 递归遍历用 父节点
|
|
|
+ * @param missfiles 缺失的文件列表
|
|
|
+ * @param xzqdm 行政区代码
|
|
|
+ * @param xzqmc 行政区名称
|
|
|
+ * @return List<String> missfiles 缺失的文件列表
|
|
|
+ */
|
|
|
+ public List<String> checkMustFiles(String unzippath, List<TCgglSjbzmlwjDto> sjbzlist, String parentname, List<String> missfiles, String xzqdm, String xzqmc) {
|
|
|
+ List<TCgglSjbzmlwjDto> filteredList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(parentname)) {
|
|
|
+ filteredList = sjbzlist.stream()
|
|
|
+ .filter(cur -> parentname.equals(cur.getSjml()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ filteredList = sjbzlist.stream()
|
|
|
+ .filter(cur -> cur.getSjml() == null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ for (TCgglSjbzmlwjDto dto : filteredList) {
|
|
|
+ if ("O".equals(dto.getYstj()) || "C".equals(dto.getYstj())) {//跳过非必要审查项
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (missfile.size() > 0) {
|
|
|
- return AjaxResult.success("村庄规划成果上传失败:上传失败缺少以下文件或文件名称有误:", missfile);
|
|
|
+ Integer lx = dto.getLx();
|
|
|
+ String gzmc = dto.getGzmc();
|
|
|
+ String mlmc = dto.getMlmc();
|
|
|
+ String curpath = "";//当前的文件或文件夹路径地址
|
|
|
+ if (StringUtils.isNotEmpty(gzmc)) {
|
|
|
+ curpath = getAbFilepath(gzmc, xzqdm, xzqmc, unzippath);
|
|
|
} else {
|
|
|
- //TODO wanger 获取规划文本中的项目名称
|
|
|
- //解析txt
|
|
|
- String txtFilePath = FileSearch(unzippath + File.separator + relFileName, "基本信息.txt");
|
|
|
- if (StringUtils.isNotEmpty(txtFilePath)) {
|
|
|
- System.out.println("txtFilePath===" + txtFilePath);
|
|
|
- Map<String, String> txtMap = null;
|
|
|
- try {
|
|
|
- txtMap = readTxt(txtFilePath, charset);
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- System.out.println("txtMap===" + txtMap);
|
|
|
- if (StringUtils.isNotEmpty(txtMap.get("xmmc"))) {
|
|
|
- return AjaxResult.success(desc.getAbsolutePath() + "******" + txtMap.get("xmmc"));
|
|
|
+ curpath = unzippath + "\\" + mlmc;
|
|
|
+ }
|
|
|
+ if (curpath.contains("不符")) {
|
|
|
+ missfiles.add(curpath);
|
|
|
+ return missfiles;
|
|
|
+ }
|
|
|
+ File folder = new File(curpath);
|
|
|
+ if (lx == 0) {//文件夹
|
|
|
+ if (folder.exists() && folder.isDirectory()) {
|
|
|
+ if (!curpath.endsWith(".gdb")) {
|
|
|
+ checkMustFiles(curpath, sjbzlist, dto.getBsm(), missfiles, xzqdm, xzqmc);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ missfiles.add(StringUtils.isNotEmpty(gzmc) ? gzmc : mlmc);
|
|
|
+ }
|
|
|
+ } else if (lx == 1) {//文件
|
|
|
+ if (!folder.exists()) {
|
|
|
+ missfiles.add(StringUtils.isNotEmpty(gzmc) ? gzmc : mlmc);
|
|
|
}
|
|
|
- return AjaxResult.success(desc.getAbsolutePath() + "******" + relFileName);
|
|
|
}
|
|
|
+ }
|
|
|
+ return missfiles;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteCurDirectory(String parent) {
|
|
|
+ try {
|
|
|
+ FileUtils.deleteDirectory(new File(parent));
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- return AjaxResult.error(e.getMessage());
|
|
|
+ System.out.println(String.format("文件夹删除失败:%s", parent));
|
|
|
}
|
|
|
}
|
|
|
|