Prechádzať zdrojové kódy

档案文件排序回退正式环境版本

cr 2 dní pred
rodič
commit
d6c8d7b6a2

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/feignClient/ArchiveFileClientImpl.java

@@ -65,7 +65,7 @@ public class ArchiveFileClientImpl implements ArchiveFileClient {
 
     @Override
     public void updateArchiveFileSort(ArchiveFileVO vo) {
-        this.iArchiveFileService.updateArchiveFileSort(vo.getList(),vo.getOldList());
+        this.iArchiveFileService.updateArchiveFileSort(vo.getList());
     }
 
     @Override

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/IArchiveFileService.java

@@ -57,7 +57,7 @@ public interface IArchiveFileService extends BaseService<ArchiveFile> {
 
     void saveArchiveFile(List<ArchiveFileVO> list);
 
-    void updateArchiveFileSort(List<ArchiveFileVO> list,List<ArchiveFileVO> oldList);
+    void updateArchiveFileSort(List<ArchiveFileVO> list);
 
     boolean updateArchiveFileByBoxName(Map<String, Object> jsons);
 

+ 41 - 163
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/ArchiveFileServiceImpl.java

@@ -133,99 +133,29 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
 
 
     @Override
-    public void updateArchiveFileSort(List<ArchiveFileVO> list, List<ArchiveFileVO> oldList) {
-        // 1. 准备工作
+    public void updateArchiveFileSort(List<ArchiveFileVO> list) {
         List<Integer> listInt = new ArrayList<>();
         for (int i = 0; i < list.size(); i++) {
             listInt.add(list.get(i).getSort());
         }
-        Collections.sort(listInt);
 
         StringBuffer ids = new StringBuffer();
         StringBuffer ids2 = new StringBuffer();
         Map<Long, Integer> mapkey = new HashMap<>();
-
-        // 2. 构建原始数据映射
-        Map<Long, String> originalIdToNodeIdMap = new HashMap<>();
-        Map<Long, Integer> originalIdToSortMap = new HashMap<>();
-
-        // 按原始排序构建文件顺序
-        List<ArchiveFileVO> sortedOldList = oldList.stream()
-                .sorted(Comparator.comparing(ArchiveFileVO::getSort))
-                .collect(Collectors.toList());
-
-        List<Long> originalOrderIds = new ArrayList<>();
-        for (int i = 0; i < sortedOldList.size(); i++) {
-            ArchiveFileVO vo = sortedOldList.get(i);
-            originalIdToNodeIdMap.put(vo.getId(), vo.getNodeId());
-            originalIdToSortMap.put(vo.getId(), vo.getSort());
-            originalOrderIds.add(vo.getId());
-        }
-
-        // 3. 按新排序构建文件顺序
-        List<ArchiveFileVO> sortedNewList = list.stream()
-                .sorted(Comparator.comparing(ArchiveFileVO::getSort))
-                .collect(Collectors.toList());
-
-        List<Long> newOrderIds = new ArrayList<>();
-        for (ArchiveFileVO vo : sortedNewList) {
-            newOrderIds.add(vo.getId());
-        }
-
-        // 4. 找出移动的文件(基于位置变化)
-        Set<Long> movedFileIds = new HashSet<>();
-        for (int i = 0; i < newOrderIds.size(); i++) {
-            Long fileId = newOrderIds.get(i);
-            int originalIndex = originalOrderIds.indexOf(fileId);
-            if (originalIndex != i) {
-                movedFileIds.add(fileId);
-                System.out.println("检测到移动文件: ID=" + fileId + ", 从位置 " + originalIndex + " 移动到 " + i);
-            }
-        }
-
-        // 5. 创建ID到VO的映射,便于查找
-        Map<Long, ArchiveFileVO> idToVoMap = new HashMap<>();
-        for (ArchiveFileVO vo : list) {
-            idToVoMap.put(vo.getId(), vo);
-        }
-
-        // 6. 更新排序和节点信息
-        for (int i = 0; i < newOrderIds.size(); i++) {
-            Long fileId = newOrderIds.get(i);
-            ArchiveFileVO currentVO = idToVoMap.get(fileId);
-
-            ids2.append(fileId).append(",");
-
-            // 设置新的排序值
-            currentVO.setSort(listInt.get(i));
-            currentVO.setArchiveSort(i);
-
-            // 处理节点更新
-            String originalNodeId = originalIdToNodeIdMap.get(fileId);
-
-            if (movedFileIds.contains(fileId)) {
-                // 移动的文件:继承新位置后面文件的节点
-                String targetNodeId = findTargetNodeId(i, newOrderIds, originalIdToNodeIdMap);
-                if (targetNodeId != null && !targetNodeId.equals(originalNodeId)) {
-                    System.out.println("更新文件节点: ID=" + fileId + ", 从 " + originalNodeId + " 改为 " + targetNodeId);
-                    currentVO.setNodeId(targetNodeId);
-                }
-            } else {
-                // 未移动的文件保持原节点
-                currentVO.setNodeId(originalNodeId);
-            }
-
-            // 处理URL更新逻辑
-            if (currentVO.getIsUpdateUrl() != null && currentVO.getIsUpdateUrl() == 1) {
-                ids.append(fileId).append(",");
-                if (currentVO.getRectification() != null && currentVO.getRectification() == 1) {
-                    currentVO.setRectification(2);
+        Collections.sort(listInt);
+        for (int i = 0; i < list.size(); i++) {
+            ids2.append(list.get(i).getId() + ",");
+            list.get(i).setSort(listInt.get(i));
+            list.get(i).setArchiveSort(i);
+            if (list.get(i).getIsUpdateUrl() != null && list.get(i).getIsUpdateUrl() == 1) {
+                ids.append(list.get(i).getId() + ",");
+                if (list.get(i).getRectification() != null && list.get(i).getRectification() == 1) {
+                    list.get(i).setRectification(2);
                 }
             }
         }
-
-        // 7. 处理OSS文件删除
-        if (ids.length() > 0) {
+        // 删除oss文件
+        if (ids != null && ids.length() > 0) {
             List<String> removeFiles = new ArrayList<>();
             List<ArchiveFile> archiveFileByFileIds = baseMapper.getArchiveFileByFileIds(Func.toLongList(ids.toString()));
             if (archiveFileByFileIds != null && archiveFileByFileIds.size() > 0) {
@@ -241,8 +171,8 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
             }
         }
 
-        // 8. 获取所有文件状态
-        if (ids2.length() > 0) {
+        //获取所有文件
+        if (ids2 != null && ids2.length() > 0) {
             List<ArchiveFile> archiveFileByFileIds = baseMapper.getArchiveFileByFileIds(Func.toLongList(ids2.toString()));
             if (archiveFileByFileIds != null && archiveFileByFileIds.size() > 0) {
                 for (ArchiveFile archiveFile : archiveFileByFileIds) {
@@ -251,9 +181,8 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
             }
         }
 
-        // 9. 处理审批状态更新
-        for (ArchiveFileVO vo : list) {
-            // 认证状态处理
+        for (ArchiveFile vo : list) {
+            // 修改所有的认证状态,如果是不需要认证就设置为已认证,如果是需要认证就设置为未认证
             if (Func.isNotEmpty(vo.getIsNeedCertification())) {
                 if (vo.getIsNeedCertification() == 0) {
                     vo.setIsCertification(1);
@@ -261,93 +190,42 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
                     vo.setIsCertification(0);
                 }
             }
-
-            // 审批状态处理
+            //循环查看是否把需要审批改为不需要审批,  不可能把不需要审批改为需要审批 ,0不需要,1需要
             if (vo.getStatus() != null && vo.getStatus() == 0 && vo.getIsApproval() != null && vo.getIsApproval() == 0) {
                 vo.setStatus(2);
             }
-
             if (vo.getIsApproval() != null && vo.getIsApproval() == 1 && vo.getIsApproval() != mapkey.get(vo.getId())) {
-                handleApprovalStatusChange(vo, mapkey);
-            }
-        }
-
-        // 10. 批量更新数据库
-        this.updateBatchById(JSONArray.parseArray(JSONObject.toJSONString(list), ArchiveFile.class));
-    }
-
-    /**
-     * 查找目标位置的节点ID
-     */
-    private String findTargetNodeId(int currentIndex, List<Long> newOrderIds, Map<Long, String> originalIdToNodeIdMap) {
-        // 优先查找后面的文件
-        if (currentIndex + 1 < newOrderIds.size()) {
-            Long nextFileId = newOrderIds.get(currentIndex + 1);
-            String nextNodeId = originalIdToNodeIdMap.get(nextFileId);
-            if (nextNodeId != null) {
-                return nextNodeId;
-            }
-        }
-
-        // 如果后面没有文件,查找前面的文件
-        if (currentIndex - 1 >= 0) {
-            Long prevFileId = newOrderIds.get(currentIndex - 1);
-            String prevNodeId = originalIdToNodeIdMap.get(prevFileId);
-            if (prevNodeId != null) {
-                return prevNodeId;
-            }
-        }
-
-        return null;
-    }
-
-    /**
-     * 处理审批状态变更
-     */
-    private void handleApprovalStatusChange(ArchiveFileVO vo, Map<Long, Integer> mapkey) {
-        Set<String> aopParamsSet = new HashSet<>();
-
-        try {
-            ArchiveFile archiveFile = jdbcTemplate.queryForObject(
-                    "select * from u_archive_file where id = " + vo.getId(),
-                    new BeanPropertyRowMapper<>(ArchiveFile.class));
-
-            if (archiveFile != null) {
-                if (archiveFile.getIsApproval() != null && archiveFile.getIsApproval() == 0) {
-                    // 不需要审批的文件,直接更新状态
-                    jdbcTemplate.execute("update u_archive_file set status = 3,is_certification = 0,e_visa_file = null where id = " + vo.getId());
-                } else {
-                    // 需要审批的文件,查找任务并更新状态
-                    Task task = jdbcTemplate.query(
-                            "select id,status,process_instance_id from u_task where task_create_timestamp is not null and status in (1,2) and form_data_id = '" + vo.getId() + "'",
-                            new BeanPropertyRowMapper<>(Task.class)).stream().findAny().orElse(null);
-
-                    if (task != null) {
-                        // 更新档案文件状态
+                Set<String> aopParamsSet = new HashSet<>();
+                //判断现在的数据是否是待审批数据,只有上报状态、未认证状态的数据才能撤销
+                ArchiveFile archiveFile = jdbcTemplate.queryForObject("select * from u_archive_file where id = " + vo.getId(), new BeanPropertyRowMapper<>(ArchiveFile.class));
+                if (archiveFile != null) {
+                    if (archiveFile.getIsApproval() != null && archiveFile.getIsApproval() == 0) {
+                        //此文件为不需要审批文件,所以没有任务信息,直接修改状态
                         jdbcTemplate.execute("update u_archive_file set status = 3,is_certification = 0,e_visa_file = null where id = " + vo.getId());
-                        // 更新任务状态
-                        jdbcTemplate.execute("update u_task set status = 3 where id = " + task.getId());
-                        jdbcTemplate.execute("update u_task_parallel set status = 3 where process_instance_id = '" + task.getProcessInstanceId() + "'");
-
-                        // 发送通知
-                        List<TaskParallel> taskParallelList = jdbcTemplate.query(
-                                "SELECT task_user FROM u_task_parallel WHERE process_instance_id = '" + task.getProcessInstanceId() + "'",
-                                new BeanPropertyRowMapper<>(TaskParallel.class));
-
-                        for (TaskParallel taskParallel : taskParallelList) {
-                            String param = taskParallel.getTaskUser() + "," + vo.getProjectId() + "," + vo.getContractId();
-                            aopParamsSet.add(param);
+                    } else {
+                        /*此处任务会查询出多条,因为存在多次废除任务,那么form_data_id指向同一个id,所以在新增的时候去重判断,status=1或2,有且只有一条*/
+                        Task task = jdbcTemplate.query("select id,status,process_instance_id from u_task where task_create_timestamp is not null and status in (1,2) and form_data_id = '" + vo.getId() + "'", new BeanPropertyRowMapper<>(Task.class)).stream().findAny().orElse(null);
+                        if (task != null) {
+                            //修改档案文件收集业务数据状态=已废除
+                            jdbcTemplate.execute("update u_archive_file set status = 3,is_certification = 0,e_visa_file = null where id = " + vo.getId());
+                            //待审批审批任务=已废除
+                            jdbcTemplate.execute("update u_task set status = 3 where id = " + task.getId());
+                            //审批任务详情=已废除
+                            jdbcTemplate.execute("update u_task_parallel set status = 3 where process_instance_id = '" + task.getProcessInstanceId() + "'");
+                            /*通知*/
+                            List<TaskParallel> taskParallelList = jdbcTemplate.query("SELECT task_user FROM u_task_parallel WHERE process_instance_id = '" + task.getProcessInstanceId() + "'", new BeanPropertyRowMapper<>(TaskParallel.class));
+                            for (TaskParallel taskParallel : taskParallelList) {
+                                String param = taskParallel.getTaskUser() + "," + vo.getProjectId() + "," + vo.getContractId();
+                                aopParamsSet.add(param);
+                            }
                         }
                     }
                 }
+                vo.setStatus(0);
             }
-            vo.setStatus(0);
-        } catch (Exception e) {
-            // 处理数据库查询异常
-            System.err.println("处理审批状态变更时出错: " + e.getMessage());
         }
+        this.updateBatchById(JSONArray.parseArray(JSONObject.toJSONString(list), ArchiveFile.class));
     }
-
     @Override
     public boolean updateArchiveFileByBoxName(Map<String, Object> jsons) {
         List<Object> list = (List<Object>) jsons.get("list");