浏览代码

测试附件查找内容

chenendian 19 小时之前
父节点
当前提交
71d0ca348b

+ 4 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/common/Constant.java

@@ -83,6 +83,10 @@ public class Constant {
             "国有建设用地使用权及房屋所有权首次登记"
     );
 
+    //项目excel导入路径
+    public static final String  IMPORT_EXCEL_DATA_FILE_PATH = "D:\\one_code_manage\\project_excel_data";
+
+    public static final String  FILE_UPLOAD_PATH = "D:\\home\\siwei\\uploadPath\\2026\\05\\26";
 
 
 }

+ 3 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/third/DealExcelController.java

@@ -1,5 +1,6 @@
 package com.siwei.apply.controller.third;
 
+import com.siwei.apply.common.Constant;
 import com.siwei.apply.service.third.impl.DealExcelServiceImpl;
 import com.siwei.common.core.domain.R;
 import com.siwei.common.core.web.controller.BaseController;
@@ -41,7 +42,7 @@ public class DealExcelController extends BaseController {
     @GetMapping("excelDeal_v2/{fileName}")
     public R<Map<String, List<Map<String,String>>>> excelDeal_v2(@PathVariable String fileName) {
         try {
-            String uploadFile = "D:\\workspace\\one-code-manage\\node_modules\\excel_deom\\"+fileName;
+            String uploadFile = Constant.IMPORT_EXCEL_DATA_FILE_PATH+"\\"+fileName;
             Path filePath = Paths.get(uploadFile);
             File file = filePath.toFile();
             Map<String, List<Map<String, String>>> dataMap = readExcelWithMergedHeaders(file);
@@ -56,6 +57,7 @@ public class DealExcelController extends BaseController {
 //            }
             return R.ok(dataMap);
         } catch (Exception e) {
+            e.printStackTrace();
             return R.fail(e.getMessage());
         }
     }

+ 273 - 48
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/DealExcelServiceImpl.java

@@ -1,25 +1,31 @@
 package com.siwei.apply.service.third.impl;
 
-import com.siwei.apply.domain.Project;
+import com.siwei.apply.common.Constant;
+import com.siwei.apply.domain.LandType;
 import com.siwei.apply.domain.ProjectWorkflow;
+import com.siwei.apply.domain.YdbpData;
+import com.siwei.apply.domain.res.TdgyRes;
 import com.siwei.apply.domain.vo.ProjectVo;
 import com.siwei.apply.domain.vo.TdgyVo;
 import com.siwei.apply.enums.AloneWorkFlowEnum;
+import com.siwei.apply.mapper.LandTypeMapper;
 import com.siwei.apply.mapper.ProjectWorkflowMapper;
-import com.siwei.apply.service.NodeLandService;
-import com.siwei.apply.service.ProjectService;
-import com.siwei.apply.service.TdgyService;
-import com.siwei.apply.utils.HttpClientUtil;
+import com.siwei.apply.service.*;
 import com.siwei.common.core.utils.StringUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * excel 导入数据处理类
@@ -28,6 +34,8 @@ import java.util.Map;
 @Service
 public class DealExcelServiceImpl{
 
+    private static List<LandType> allLandTypeList =new ArrayList<>();
+
     @Autowired
     private ProjectService projectService;
 
@@ -35,13 +43,62 @@ public class DealExcelServiceImpl{
     private ProjectWorkflowMapper projectWorkflowMapper;
 
     @Autowired
-    private NodeLandService nodeLandService;
+    private LandTypeMapper landTypeMapper;
 
+    @Autowired
+    private NodeLandService nodeLandService;
 
     @Autowired
     private TdgyService tdgyService;
 
 
+    @Autowired
+    private NodeAttachmentService nodeAttachmentService;
+
+    @Autowired
+    private YdbpDataService ydbpDataService;
+
+
+
+    /**
+     * 检查excel数据到数据库
+     * @param dataMap
+     * @return
+     */
+    public String checkExcelDataToDb(Map<String, List<Map<String, String>>> dataMap) {
+        List<Map<String, String>> xmList = dataMap.get("项目信息");
+        int i = 0;
+        for (Map<String, String> xm : xmList) {
+            ProjectVo projectVo = new ProjectVo();
+            String projectType =  xm.get("项目类型(必填)");
+
+            if(projectType.equalsIgnoreCase("单独选址")){
+                projectVo.setProjectType(1);
+            }else if(projectType.equalsIgnoreCase("批次报批")){
+                projectVo.setProjectType(2);
+            }else {
+                writeToLog("xm_err.log","行("+i+")项目类型不合法,项目类型只能是单独选址或者批次报批");
+            }
+
+        }
+
+
+        // -----------------第一部分增加项目结束-------------------------------
+        List<Map<String, String>> tdgyList = dataMap.get("土地供应");
+        for (Map<String, String> tdgyExcel : tdgyList) {
+            String tdyt = tdgyExcel.get("土地用途");
+            String tdytCode = getTdytCodeByName(tdyt);
+            if(StringUtils.isBlank(tdytCode)){
+                writeToLog("tdgy_err.log","行("+i+")项目类型不合法,项目类型只能是单独选址或者批次报批");
+            }
+        }
+
+
+        return "successs";
+    }
+
+
+
 
 
     /**
@@ -50,13 +107,18 @@ public class DealExcelServiceImpl{
      * @return
      */
     public String addExcelDataToDb(Map<String, List<Map<String, String>>> dataMap) {
-        List<Map<String, String>> xmList = Collections.singletonList((Map<String, String>) dataMap.get("项目信息"));
-        List<Map<String, String>> tdgyList = Collections.singletonList((Map<String, String>) dataMap.get("土地供应"));
+        String rootPath2019 = Constant.IMPORT_EXCEL_DATA_FILE_PATH+"\\数据治理批量导入示例数据\\赣江新区项目文件夹建立\\1.出让项目\\2019";
+        String rootPath2020 = Constant.IMPORT_EXCEL_DATA_FILE_PATH+"\\数据治理批量导入示例数据\\赣江新区项目文件夹建立\\1.出让项目\\2020";
+        //String targectDir = "D:\\home\\siwei\\uploadPath\\2026\\0525\\14\\";
+        String targectDir = Constant.FILE_UPLOAD_PATH;
+
+        List<Map<String, String>> xmList = dataMap.get("项目信息");
+        List<Map<String, String>> tdgyList = dataMap.get("土地供应");
+        List<Map<String, String>> jdList = dataMap.get("阶段");
 
         int i = 0;
 
         for (Map<String, String> xm : xmList) {
-
             ProjectVo projectVo = new ProjectVo();
             String projectType =  xm.get("项目类型(必填)");
             if(projectType.equalsIgnoreCase("单独选址")){
@@ -86,45 +148,199 @@ public class DealExcelServiceImpl{
 
            // -----------------第一部分增加项目结束-------------------------------
 
-
             TdgyVo tdgyVo = new TdgyVo();
+            tdgyVo.setProjectId(projectId);
+
             Map<String, String>  tdgyExcel =  tdgyList.get(i);
-            tdgyExcel.get("项目ID");
+            String srf = tdgyExcel.get("土地受让人");
+            tdgyVo.setSrf(srf);
 
-            // 土地受让人	土地用途(源版)	土地用途	建设位置	供地面积(平方米)(源数据)	供地面积	面积单位	供地方式	是否完成征转
-            // 用地划拨/出让方案批复文号	土地权属来源	"划拨决定书/出让合同编号
-            // (必填)"	划拨决定书/出让合同日期	供地单位
+            String tdyt = tdgyExcel.get("土地用途");
+            String tdytCode = getTdytCodeByName(tdyt);
+            if(StringUtils.isBlank(tdytCode)){
+                log.warn("土地用途{}没有找到对应的code,默认设置为{}", tdyt, tdytCode);
+            }
+            tdgyVo.setTdyt(tdytCode);
 
+            String gdArea = tdgyExcel.get("供地面积");
+            if(StringUtils.isBlank(gdArea)){
+                log.warn("供地面积为空,默认设置为0");
+                gdArea = "0";
+            }
+            tdgyVo.setGdArea(Float.parseFloat(gdArea));
 
+            String gdUnit = tdgyExcel.get("面积单位");
+            if(StringUtils.isBlank(gdUnit)){
+                log.warn("供地面积为空,默认设置为0");
+                gdUnit = "";
+            }
+            tdgyVo.setGdUnit(gdUnit);
+
+            String jswz = tdgyExcel.get("建设位置");
+            tdgyVo.setJswz(jswz);
+
+            String gdType = tdgyExcel.get("供地方式");
+            tdgyVo.setGdType(gdType);
+
+            String hasZz = tdgyExcel.get("是否完成征转");
+            if(hasZz.equalsIgnoreCase("是")){
+                hasZz = "已报已征";
+            }else if(hasZz.equalsIgnoreCase("否")){
+                hasZz = "未报未征";
+            }else {
+                log.warn("是否完成征转{}不合法,默认设置为否", hasZz);
+                hasZz = "";
+            }
+            tdgyVo.setHasZz(hasZz);
+
+            String hbcrfapfwh = tdgyExcel.get("用地划拨/出让方案批复文号");
+            tdgyVo.setHbcrfapfwh(hbcrfapfwh);
+
+            String hbcrhtbh = tdgyExcel.get("划拨决定书/出让合同编号(必填)");
+            tdgyVo.setHbcrhtbh(hbcrhtbh);
+
+            String hbcrhtDate = tdgyExcel.get("划拨决定书/出让合同日期");
+            tdgyVo.setHbcrhtDate(hbcrhtDate);
             String id = tdgyService.add(tdgyVo);
 
+            //附件材料处理  -- 数据治理文件名
+            Map<String, String> jdMap =  jdList.get(i);
+            String projectFileName =  jdMap.get("数据治理文件名");
+            String fullFilePath = "";
 
+            String nodeFileName ="03土地供应阶段";
+
+            Path filePath = Paths.get(rootPath2019+"\\"+projectFileName);
+            if(Files.exists(filePath) && Files.isDirectory(filePath)){
+                fullFilePath = copyFileToDirectory(rootPath2019+"\\"+projectFileName,targectDir+"\\"+projectFileName,nodeFileName);
+            }
 
+            if(StringUtils.isBlank(fullFilePath)){
+                filePath = Paths.get(rootPath2020+"\\"+projectFileName);
+                if(!Files.exists(filePath) || !Files.isDirectory(filePath)){
+                    fullFilePath = copyFileToDirectory(rootPath2019+"\\"+projectFileName,targectDir+"\\"+projectFileName,nodeFileName);
+                }
+            }
+
+            if(StringUtils.isNotBlank(fullFilePath)) {
+                //这里进行文件关联
+                String nodeAttachmentId = associationFile(fullFilePath, projectId, id);
+                log.info("关于项目{}的土地供应环节,文件{}关联结果{}", projectId, nodeFileName, nodeAttachmentId);
+            }
+
+            // -----------------第二部分增加项目关联的(土地供应)环节结束-------------------------------
             i++;
+            if (i>2) {
+                log.warn("目前只支持处理一条土地供应数据,后续增加处理逻辑");
+                break;
+            }
         }
 
+        return "successs";
+    }
+
 
 
 
 
 
 
+    public static String copyFileToDirectory(String sourceFilePath, String targetDirectoryPath,String FileName){
+        String fullTargetFilePath = "";
+        try {
+            File sourceDir = new File(sourceFilePath, FileName);
+            File targetDir = new File(targetDirectoryPath);
 
+            if (!targetDir.exists()) {
+                targetDir.mkdirs();
+            }
 
+            FileUtils.copyDirectoryToDirectory(sourceDir, targetDir);
+            fullTargetFilePath = Paths.get(targetDirectoryPath, FileName).toString();
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
+         return fullTargetFilePath;
 
+    }
 
 
 
+    public String getTdytCodeByName(String useName) {
+        if(allLandTypeList.isEmpty()){
+            List<LandType> all = landTypeMapper.selectAll();
+            allLandTypeList.addAll(all);
+        }
+        String code = "";
+        // 转换为节点
+        Optional<LandType> filterRes = allLandTypeList.stream().filter(s->s.getName().equalsIgnoreCase(useName)).findFirst();
+        if(filterRes.isPresent()){
+            code = filterRes.get().getCode();
+        }
+        return code;
+    }
 
 
 
+    /**
+     *  关于提交相关信息
+     * @return
+     */
+    public static String writeToLog(String fileName, String msg) {
+        // 转换为节点
+        String filePath = "D:\\workspace\\one-code-manage\\node_modules\\excel_deom\\" + fileName;
+        //todo 完善当前方法,功能:1.将msg写入到filePath指定的文件中;2.如果文件不存在则创建;3.每次写入都追加到文件末尾;4.写入完成后返回写入结果(成功/失败)
+        // 文件就是一个文本文件,每次写入一行日志,格式为:时间戳 + msg
+        try {
+            File file = new File(filePath);
+            // 确保父目录存在
+            if (!file.getParentFile().exists()) {
+                file.getParentFile().mkdirs();
+            }
+            // 时间戳 + msg
+            String timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+            String logEntry = timestamp + " " + msg + System.lineSeparator();
+
+            // 追加写入
+            FileUtils.writeStringToFile(file, logEntry, StandardCharsets.UTF_8, true);
+            return "成功";
+        } catch (IOException e) {
+            log.error("写入日志文件失败: {}", e.getMessage(), e);
+            return "失败";
+        }
 
 
 
+    }
 
 
-        return null;
+    public String  associationFile(String filePath , String projectId, String nodeId) {
+        try {
+            String tableName = "";
+            String gdType = "";
+            ProjectWorkflow projectWorkflow = projectService.getProjectWorkflowByNodeId(projectId,nodeId);
+            if(Objects.nonNull(projectWorkflow)){
+                if(AloneWorkFlowEnum.NODE_2.getTableName().equals(projectWorkflow.getNodeTableName())){
+                    TdgyRes tdgy = tdgyService.getById(nodeId);
+                    gdType = tdgy.getGdType();
+                    gdType= "出让".equals(gdType) ? "1" : "划拨".equals(gdType)? "2":"1";
+                }
+                tableName = projectWorkflow.getNodeTableName();
+            }else {
+                YdbpData data = ydbpDataService.getById(nodeId);
+                if(Objects.nonNull(data)){
+                    tableName = AloneWorkFlowEnum.NODE_1.getTableName();
+                }
+            }
+            String id = nodeAttachmentService.processFileAndSave(filePath,tableName,gdType);
+            nodeAttachmentService.modifyAttachmentInfo(projectId,nodeId,id);
+            return id;
+        } catch (Exception e) {
+            log.error("处理文件异常", e);
+        }
+        return "";
     }
 
 
@@ -137,36 +353,8 @@ public class DealExcelServiceImpl{
 
 
 
-    public Map<String, String> getImmobileCode(String projectId) {
-        Map<String, String> retMap = new LinkedHashMap<>();
 
-        Project project = projectService.get(projectId);
-        String firstPlotCode = project.getFirstPlotCode();
-        String secondPlotCode = project.getSecondPlotCode();
-        String tableName = AloneWorkFlowEnum.NODE_2.getTableName(); // 土地供应图斑
 
-        List<ProjectWorkflow> projectWorkflows = projectWorkflowMapper.selectByProjectIdAndNodeTableName(projectId, tableName);
-        if (CollectionUtils.isNotEmpty(projectWorkflows)) {
-            String nodeId = projectWorkflows.get(0).getNodeId();
-            Map<String, Object> paramMap = new LinkedHashMap<>();
-            paramMap.put("batchId", projectId);
-            paramMap.put("plotCode", firstPlotCode + secondPlotCode);
-            paramMap.put("geoms", "");
-            Map<String, Object> geomInfo = nodeLandService.getGeomByNodeId(nodeId);
-            if (geomInfo.get("geoms") instanceof List) {
-                List<String> geoms = (List<String>) geomInfo.get("geoms");
-                paramMap.put("geoms", geoms);
-            }
-            // todo 这里调用 httpClient 进行远程调用
-            String result = HttpClientUtil.doGet("https://www.baidu.com", paramMap);
-            // log.error("解析节点附件json失败",e);
-            log.info("获取解析数据为:{}", result);
-            // 构造结果进行入库
-        }
-        retMap.put("code", "12345678");
-        retMap.put("projectId", projectId);
-        return retMap;
-    }
 
 
 
@@ -174,5 +362,42 @@ public class DealExcelServiceImpl{
 
 
 
+//    public Map<String, String> getImmobileCode(String projectId) {
+//        Map<String, String> retMap = new LinkedHashMap<>();
+//
+//        Project project = projectService.get(projectId);
+//        String firstPlotCode = project.getFirstPlotCode();
+//        String secondPlotCode = project.getSecondPlotCode();
+//        String tableName = AloneWorkFlowEnum.NODE_2.getTableName(); // 土地供应图斑
+//
+//        List<ProjectWorkflow> projectWorkflows = projectWorkflowMapper.selectByProjectIdAndNodeTableName(projectId, tableName);
+//        if (CollectionUtils.isNotEmpty(projectWorkflows)) {
+//            String nodeId = projectWorkflows.get(0).getNodeId();
+//            Map<String, Object> paramMap = new LinkedHashMap<>();
+//            paramMap.put("batchId", projectId);
+//            paramMap.put("plotCode", firstPlotCode + secondPlotCode);
+//            paramMap.put("geoms", "");
+//            Map<String, Object> geomInfo = nodeLandService.getGeomByNodeId(nodeId);
+//            if (geomInfo.get("geoms") instanceof List) {
+//                List<String> geoms = (List<String>) geomInfo.get("geoms");
+//                paramMap.put("geoms", geoms);
+//            }
+//            // todo 这里调用 httpClient 进行远程调用
+//            String result = HttpClientUtil.doGet("https://www.baidu.com", paramMap);
+//            // log.error("解析节点附件json失败",e);
+//            log.info("获取解析数据为:{}", result);
+//            // 构造结果进行入库
+//        }
+//        retMap.put("code", "12345678");
+//        retMap.put("projectId", projectId);
+//        return retMap;
+//    }
+//
+//
+
+
+
+
+
 
 }