Przeglądaj źródła

维护全文检索数据

chenendian 2 miesięcy temu
rodzic
commit
5e57ecec8a

+ 6 - 3
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/NodeAttachmentController.java

@@ -64,7 +64,7 @@ public class NodeAttachmentController extends BaseController {
                 gdType= "出让".equals(gdType) ? "1" : "划拨".equals(gdType)? "2":"1";
             }
             String id = nodeAttachmentService.processFileAndSave(filePath,projectWorkflow.getNodeTableName(),gdType);
-
+            nodeAttachmentService.modifyAttachmentInfo(projectId,nodeId,id);
             if (id != null) {
                 Map<String, String> responseData = new HashMap<>();
                 responseData.put("nodeAttachmentId", id);
@@ -103,7 +103,7 @@ public class NodeAttachmentController extends BaseController {
                 return R.fail("附件id不能为空");
             }
 
-            String id = nodeAttachmentService.deleteFileAndSave(path,nodeAttachmentId,filePath);
+            String id = nodeAttachmentService.deleteFileAndSave(nodeId,path,nodeAttachmentId,filePath);
 
             if (id != null) {
                 Map<String, String> responseData = new HashMap<>();
@@ -212,6 +212,8 @@ public class NodeAttachmentController extends BaseController {
             }
 
             boolean success = nodeAttachmentService.updateNodeId(nodeAttachmentId, nodeId);
+            //更新数据
+            nodeAttachmentService.modifyAttachmentInfo("",nodeId,nodeAttachmentId);
 
             Map<String, Object> responseData = new java.util.HashMap<>();
             responseData.put("nodeAttachmentId", nodeAttachmentId);
@@ -246,12 +248,13 @@ public class NodeAttachmentController extends BaseController {
             //文件移动
             String moveAfterPath = ServiceFileUtil.moveFileToDirectory(filePath,fileUploadPath);
             nodeAttachmentService.restFileAttachment(rootPath,nodeAttachmentId);
+            nodeAttachmentService.modifyAttachmentInfo("","",nodeAttachmentId);
             Map<String, String> responseData = new HashMap<>();
             responseData.put("nodeAttachmentId", nodeAttachmentId);
             return R.ok(responseData);
         } catch (Exception e) {
             logger.error("处理文件异常", e);
-            return R.fail("处理一个文件异常:" + e.getMessage());
+            return R.fail(502,"处理一个文件异常:" + e.getMessage());
         }
     }
 

+ 2 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/NodeAttachmentService.java

@@ -50,7 +50,7 @@ public interface NodeAttachmentService {
      */
     boolean updateNodeId(String nodeAttachmentId, String nodeId);
 
-    String deleteFileAndSave(String path,String nodeAttachmentId ,String filePath);
+    String deleteFileAndSave(String nodeId, String path,String nodeAttachmentId ,String filePath);
 
     List<NodeAttachment> getByNodeIdList(List<String> nodeIdList);
 
@@ -62,5 +62,6 @@ public interface NodeAttachmentService {
 
     String restFileAttachment(String rootPath,String nodeAttachmentId);
 
+    Boolean  modifyAttachmentInfo(String projectId,String nodeId,String nodeAttachmentId);
 
     }

+ 31 - 8
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -8,6 +8,7 @@ import com.siwei.apply.mapper.NodeAttachmentMapper;
 import com.siwei.apply.mapper.ProjectAttachmentInfoMapper;
 import com.siwei.apply.mapper.ProjectMapper;
 import com.siwei.apply.mapper.ProjectWorkflowMapper;
+import com.siwei.apply.service.LandOneCodeService;
 import com.siwei.apply.service.NodeAttachmentService;
 import com.siwei.apply.service.TdgyService;
 import com.siwei.apply.utils.FileExtractUtil;
@@ -54,6 +55,9 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     @Autowired
     private ProjectAttachmentInfoMapper projectAttachmentInfoMapper;
 
+    @Autowired
+    private LandOneCodeService landOneCodeService;
+
 
 
     /**
@@ -188,12 +192,15 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
      * @return
      */
     @Override
-    public String deleteFileAndSave(String path,String nodeAttachmentId,String filePath) {
+    public String deleteFileAndSave(String nodeId,String path,String nodeAttachmentId,String filePath) {
         try {
             //先删除当前 文件
             Path deleteFile = Paths.get(filePath);
             Files.deleteIfExists(deleteFile);
-            return this.restFileAttachment(path,nodeAttachmentId);
+            nodeAttachmentId = this.restFileAttachment(path,nodeAttachmentId);
+            //更新关于附件相关信息
+            this.modifyAttachmentInfo("",nodeId,nodeAttachmentId);
+            return nodeAttachmentId;
         } catch (Exception e) {
             logger.error("处理文件并保存附件信息异常,filePath: {}", filePath, e);
             return null;
@@ -612,24 +619,40 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
      * 3.找出要删除的
      * 3.再次更新
      *
-     *
      * 更新附件信息关联全文检索
-     * @param projectId
-     * @param nodeId
-     * @param rootPath
+     * @param paramProjectId
+     * @param paramnodeId
+     * @param nodeAttachmentId
      * @return
      */
-    public  Boolean  modifyAttachmentInfo(String projectId,String nodeId,String rootPath){
+    @Override
+    public  Boolean  modifyAttachmentInfo(String paramProjectId,String paramnodeId,String nodeAttachmentId){
+        if(StringUtils.isBlank(nodeAttachmentId)){
+            throw new ServiceException("附件id不能为空!");
+        }
         //这里使用异步方法
         CompletableFuture.supplyAsync(()->{
             try {
+                    logger.info("一部方法开始执行,projectId: {},nodeId: {},nodeAttachmentId: {}", paramProjectId,paramnodeId,nodeAttachmentId);
+                    String projectId = paramProjectId;
+                    String nodeId = paramnodeId;
+                    NodeAttachment nodeAttachment = this.getById(nodeAttachmentId);
+                    if(StringUtils.isBlank(nodeId)){
+                        nodeId = nodeAttachment.getNodeId();
+                    }
+                    if(StringUtils.isBlank(projectId)){
+                        //这里根据id,查询项目id
+                        ProjectWorkflow projectWorkflow = landOneCodeService.getProjectWorkflowByNodeId(nodeId);
+                        projectId = projectWorkflow.getProjectId();
+                    }
+                    String rootPath = String.valueOf(nodeAttachment.getAttachment().get("path"));
+                    logger.info("全文检索根目录路径,rootPath: {}", rootPath);
                     //先进行删除
                     List<ProjectAttachmentInfo> projectAttachmentInfoList =  projectAttachmentInfoMapper.selectByProjectIdNodeId(projectId,nodeId);
                     if(CollectionUtils.isEmpty(projectAttachmentInfoList)){
                         List<String> ids =  projectAttachmentInfoList.stream().map(BaseId::getId).collect(Collectors.toList());
                         projectAttachmentInfoMapper.deleteByIds(ids);
                     }
-
                     //再进行更新
                     List<Path> fileList = ServiceFileUtil.getDirectoryFileList(rootPath);
                     if(CollectionUtils.isEmpty(fileList)){

+ 0 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ProjectImpl.java

@@ -131,7 +131,6 @@ public class ProjectImpl implements ProjectService {
                     project.setGeomDbId(String.valueOf(geomInfo.get("geomDbId")));
                 }
             }
-
         }
 
         Map<String, Object> map = new HashMap<>();

+ 1 - 2
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceFileUtil.java

@@ -142,12 +142,11 @@ public class ServiceFileUtil {
             return null;
         }
         List<Path> list = Files.walk(dirPath, Integer.MAX_VALUE)
-        .filter(Files::isRegularFile).map(o->o.getFileName()).collect(Collectors.toList());
+        .filter(Files::isRegularFile).map(Path::getFileName).collect(Collectors.toList());
         return  list;
     }
 
 
-
     public static void test() throws Exception {
         Path dirPath = Paths.get("C:\\Users\\Administrator\\Desktop\\01\\一码管地相关\\数据库.docx");
         String extension = FilenameUtils.getExtension(dirPath.toString());