|
|
@@ -2,14 +2,15 @@ package com.onemap.api.service.impl;
|
|
|
|
|
|
import ch.qos.logback.core.util.FileUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.onemap.api.domain.*;
|
|
|
-import com.onemap.api.mapper.QxcgsbrwMapper;
|
|
|
-import com.onemap.api.mapper.QxcgsbrwfpMapper;
|
|
|
-import com.onemap.api.mapper.TSysOpenUserMapper;
|
|
|
+import com.onemap.api.mapper.*;
|
|
|
import com.onemap.api.service.ResultsService;
|
|
|
import com.onemap.common.core.constant.SecurityConstants;
|
|
|
import com.onemap.common.core.domain.R;
|
|
|
import com.onemap.common.core.utils.StringUtils;
|
|
|
+import com.onemap.common.core.utils.UnPackageUtils;
|
|
|
import com.onemap.common.core.web.domain.RequestResult;
|
|
|
import com.onemap.common.security.service.TokenService;
|
|
|
import com.onemap.common.security.utils.SecurityUtils;
|
|
|
@@ -29,6 +30,7 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.onemap.api.util.Md5Utils.getMD5;
|
|
|
import static com.onemap.api.util.utils.*;
|
|
|
@@ -43,10 +45,20 @@ public class ResultsServiceImpl implements ResultsService {
|
|
|
private QxcgsbrwMapper qxcgsbrwMapper;
|
|
|
@Autowired
|
|
|
private QxcgsbrwfpMapper qxcgsbrwfpMapper;
|
|
|
+ @Autowired
|
|
|
+ private EscalationMapper escalationMapper;
|
|
|
+ @Autowired
|
|
|
+ private EscalationFileMapper escalationFileMapper;
|
|
|
+ @Autowired
|
|
|
+ private XzczghcgsbMapper xzczghcgsbMapper;
|
|
|
+ @Autowired
|
|
|
+ private TCgglSjbzmlwjMapper tCgglSjbzmlwjMapper;
|
|
|
private Rwzt rwzt = new Rwzt();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
@Value("${Cggl.temp}")
|
|
|
private String tempfolder;
|
|
|
+ //成果级别
|
|
|
+ private String cglevel = "1";
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
@@ -223,6 +235,8 @@ public class ResultsServiceImpl implements ResultsService {
|
|
|
loginfo("完成合包:" + folder);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ qxsbcg.setRwzt(rwzt.getHbsb());
|
|
|
+ qxcgsbrwMapper.update(qxsbcg, sbrwwrapper);
|
|
|
return RequestResult.error("合包失败,没找到合包后的文件,请联系管理员");
|
|
|
}
|
|
|
File targetfile = new File(targetfilepath);
|
|
|
@@ -230,9 +244,207 @@ public class ResultsServiceImpl implements ResultsService {
|
|
|
if (!fileMd5.equals(md5)) {
|
|
|
return RequestResult.error("警告:文件的MD5不一致");
|
|
|
}
|
|
|
+ //TODO wanger 进行数据解压
|
|
|
+ String filetype = StringUtils.getFileKzmx(filename);
|
|
|
+ String fileRelName = StringUtils.getFileRelName(filename);
|
|
|
+ String unzippath = folder + "" + fileRelName;
|
|
|
+ if (".zip".equals(filetype)) {
|
|
|
+ new UnPackageUtils().unPackZip(targetfile, folder);
|
|
|
+ } else if (".rar".equals(filetype)) {
|
|
|
+ //解压rar格式
|
|
|
+ new UnPackageUtils().unPackRar(targetfile, folder);
|
|
|
+ }
|
|
|
+ File unzipfile = new File(unzippath);
|
|
|
+ if (!unzipfile.exists()) {
|
|
|
+ return RequestResult.error("压缩包名称与解压后的文件名称不一致,请检查!");
|
|
|
+ }
|
|
|
+ //解析txt
|
|
|
+ String txtFilePath = FileSearch(unzippath, "基本信息.txt");
|
|
|
+ if (StringUtils.isEmpty(txtFilePath)) {
|
|
|
+ return RequestResult.error("成果包中必须包含“xxx基本信息.txt”文件,同时注意成果包中应包含“xxx规划成果”的根目录");
|
|
|
+ }
|
|
|
+ Map<String, String> txtMap = readTxt(txtFilePath);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String txtjson = "";
|
|
|
+ try {
|
|
|
+ txtjson = objectMapper.writeValueAsString(txtMap);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String xmmc = txtMap.get("项目名称");
|
|
|
+ String xzqdm = txtMap.get("行政区代码");
|
|
|
+ String xzqmc = txtMap.get("行政区名称");
|
|
|
+ String ghlxtext = txtMap.get("规划类型");
|
|
|
+ String ghcjtext = txtMap.get("规划层级");
|
|
|
+ String ghxstext = txtMap.get("成果形式");
|
|
|
+ String pzsjtext = txtMap.get("批准时间");
|
|
|
+ String lxrtext = txtMap.get("联系人");
|
|
|
+ String lxdhtext = txtMap.get("联系电话");
|
|
|
+ //TODO wanger 对成果包进行校验
|
|
|
+ String sjbz_bsm = "";
|
|
|
+ if ("村庄规划".equals(ghlxtext)) {
|
|
|
+ sjbz_bsm = ghlxtext + "" + ghxstext;
|
|
|
+ } else {
|
|
|
+ sjbz_bsm = ghcjtext + "" + ghlxtext;
|
|
|
+ }
|
|
|
+ QueryWrapper<TCgglSjbzmlwjDto> sjbzwrapper = new QueryWrapper();
|
|
|
+ sjbzwrapper.eq("sjbz_bsm", sjbz_bsm);
|
|
|
+ sjbzwrapper.eq("ystj", "M");
|
|
|
+ sjbzwrapper.orderByAsc("px");
|
|
|
+ List<TCgglSjbzmlwjDto> sjbzlist = tCgglSjbzmlwjMapper.selectList(sjbzwrapper);
|
|
|
+ if (sjbzlist.size() == 0) {
|
|
|
+ return RequestResult.error(String.format("未授权的数据类型:%s,请联系管理人员!"), sjbz_bsm);
|
|
|
+ }
|
|
|
+ //记录缺失的文件列表 字符串类型
|
|
|
+ List<String> missfiles = new ArrayList<>();
|
|
|
+ missfiles = checkMustFiles(unzippath, sjbzlist, "", missfiles, xzqdm, xzqmc);
|
|
|
+ if (missfiles.size() > 0) {
|
|
|
+ return RequestResult.error(String.format("成果数据缺少以下目录或文件:%s", String.join("\n", missfiles)), missfiles);
|
|
|
+ }
|
|
|
+ qxsbcg.setRwzt(rwzt.getWc());
|
|
|
+ qxsbcg.setCglj(unzippath);
|
|
|
+ qxsbcg.setCgwj(targetfilepath);
|
|
|
+ qxcgsbrwMapper.update(qxsbcg, sbrwwrapper);
|
|
|
+ //TODO wanger 插入到系统成果表
|
|
|
+ String ghlx = qxsbcg.getGhlx();
|
|
|
+ if ("9".equals(ghlx)) {//村庄规划
|
|
|
+ XzczghcgsbDTO xzczghcgsbDTO = new XzczghcgsbDTO();
|
|
|
+ xzczghcgsbDTO.setCglevel(cglevel);
|
|
|
+ xzczghcgsbDTO.setUuid(StringUtils.getUUID());
|
|
|
+ xzczghcgsbDTO.setFileName(xmmc);
|
|
|
+ xzczghcgsbDTO.setFilePath(targetfilepath);
|
|
|
+ xzczghcgsbDTO.setUploadStatus(2);
|
|
|
+ xzczghcgsbDTO.setUploadTime(new Date());
|
|
|
+ xzczghcgsbDTO.setXzqName(xzqmc);
|
|
|
+ xzczghcgsbDTO.setXzqCode(xzqdm);
|
|
|
+ xzczghcgsbDTO.setStatus("10");
|
|
|
+ xzczghcgsbDTO.setYear(pzsjtext);
|
|
|
+ xzczghcgsbDTO.setBz(txtjson);
|
|
|
+ if (StringUtils.isNotEmpty(instid)) {
|
|
|
+ xzczghcgsbDTO.setInstid(instid);
|
|
|
+ }
|
|
|
+ xzczghcgsbMapper.insert(xzczghcgsbDTO);
|
|
|
+ } else {//总体规划表
|
|
|
+ String fileuuid = StringUtils.getUUID();
|
|
|
+ //TODO wanger 插入file表
|
|
|
+ EscalationFileDTO filedto = new EscalationFileDTO();
|
|
|
+ filedto.setId(fileuuid);
|
|
|
+ filedto.setName(filename);
|
|
|
+ filedto.setPath(targetfilepath);
|
|
|
+ filedto.setUnzippath(unzippath);
|
|
|
+ filedto.setStatus("9");
|
|
|
+ filedto.setUsername(user.getName());
|
|
|
+ escalationFileMapper.insert(filedto);
|
|
|
+ //TODO wanger 插入主表
|
|
|
+ EscalationDTO escalationDTO = new EscalationDTO();
|
|
|
+ escalationDTO.setId(StringUtils.getUUID());
|
|
|
+ escalationDTO.setCglevel(cglevel);
|
|
|
+ escalationDTO.setFileid(fileuuid);
|
|
|
+ escalationDTO.setPlantype(ghlx);
|
|
|
+ if (StringUtils.isNotEmpty(instid)) {
|
|
|
+ escalationDTO.setInstid(instid);
|
|
|
+ }
|
|
|
+ escalationDTO.setUploadstatus("0");
|
|
|
+ escalationDTO.setXzqdm(xzqdm);
|
|
|
+ escalationDTO.setXzqmc(xzqmc);
|
|
|
+ escalationDTO.setYear(pzsjtext);
|
|
|
+ escalationDTO.setUploadtime(new Date());
|
|
|
+ escalationDTO.setUsername(user.getName());
|
|
|
+ escalationDTO.setSczt("4");
|
|
|
+ escalationDTO.setName(xmmc);
|
|
|
+ escalationDTO.setLxdh(lxdhtext);
|
|
|
+ escalationDTO.setLxr(lxrtext);
|
|
|
+ escalationMapper.insert(escalationDTO);
|
|
|
+ }
|
|
|
return RequestResult.success("操作成功", 1);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查缺失的成果文件 递归调用 非常重要
|
|
|
+ *
|
|
|
+ * @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 -> cur.getSjml() == parentname)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ filteredList = sjbzlist.stream()
|
|
|
+ .filter(cur -> cur.getSjml() == null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ for (TCgglSjbzmlwjDto dto : filteredList) {
|
|
|
+ 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 {
|
|
|
+ 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.getSjml(), 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 missfiles;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过文件验证规则 获取文件的绝对路径
|
|
|
+ *
|
|
|
+ * @param gzmc
|
|
|
+ * @param xzqdm
|
|
|
+ * @param xzqmc
|
|
|
+ * @param filepath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getAbFilepath(String gzmc, String xzqdm, String xzqmc, String filepath) {
|
|
|
+ List<String> matches = extractUniqueMatches(gzmc);
|
|
|
+ String relName = gzmc;
|
|
|
+ for (String matche : matches) {
|
|
|
+ if (matche.contains("行政区名称")) {
|
|
|
+ relName = relName.replace(matche, xzqmc);
|
|
|
+ }
|
|
|
+ if (matche.contains("行政区代码")) {
|
|
|
+ if (matche.contains(":")) {
|
|
|
+ Integer len = Integer.valueOf(matche.split(":")[1].replace("}", ""));
|
|
|
+ if (len > xzqdm.length()) {
|
|
|
+ return "基本信息文件中的行政区代码长度与数据标准不符!";
|
|
|
+ } else {
|
|
|
+ relName = relName.replace(matche, xzqdm.substring(0, len));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ relName = relName.replace(matche, xzqdm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return filepath + "\\" + relName;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过当前登录用户token获取openuser表信息
|
|
|
*
|