cr hai 5 días
pai
achega
ad43827965

+ 1 - 2
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ArchiveFileMapper.xml

@@ -240,7 +240,6 @@
             )
         </if>
         order by
-        u.sort,
         <if test="vo.nodeIds != null and vo.nodeIds != ''">
             case
             when t.tree_sort regexp '^[a-zA-Z]' then 0  -- 字母开头的排在前面
@@ -249,7 +248,7 @@
             end,
             t.tree_sort,
         </if>
-        u.sort_num,u.create_time
+        u.sort,u.sort_num,u.create_time
         limit #{current}, #{size}
     </select>
 

+ 43 - 16
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/ArchiveFileServiceImpl.java

@@ -3,6 +3,8 @@ package org.springblade.business.service.impl;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.springblade.archive.feign.ArchiveInspectionInfoClient;
 import org.springblade.business.entity.ArchiveFile;
@@ -129,6 +131,7 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
         this.saveBatch(JSONArray.parseArray(JSONObject.toJSONString(list), ArchiveFile.class));
     }
 
+
     @Override
     public void updateArchiveFileSort(List<ArchiveFileVO> list) {
         List<Integer> listInt = new ArrayList<>();
@@ -141,29 +144,53 @@ public class ArchiveFileServiceImpl extends BaseServiceImpl<ArchiveFileMapper, A
         Map<Long, Integer> mapkey = new HashMap<>();
         Collections.sort(listInt);
 
-          Map<Integer, String> resultMap = list.stream()
-                .sorted(Comparator.comparing(ArchiveFileVO::getSort)) // 按sort从小到大排序
-                .collect(Collectors.toMap(
-                        ArchiveFileVO::getSort,  // 键是sort字段
-                        ArchiveFileVO::getNodeId,    // 值是id字段
-                        (existing, replacement) -> existing, // 如果有重复的key,保留第一个
-                        LinkedHashMap::new       // 使用LinkedHashMap保持顺序
-                ));
+        // 创建原始ID到原始nodeId的映射
+        Map<Long, String> originalIdToNodeIdMap = new HashMap<>();
+        // 创建原始ID到原始排序的映射
+        Map<Long, Integer> originalIdToSortMap = new HashMap<>();
+        for (ArchiveFileVO vo : list) {
+            originalIdToNodeIdMap.put(vo.getId(), vo.getNodeId());
+            originalIdToSortMap.put(vo.getId(), vo.getSort());
+        }
 
         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);
+            ArchiveFileVO currentVO = list.get(i);
+            ids2.append(currentVO.getId() + ",");
+
+            // 保存原始数据
+            String originalNodeId = originalIdToNodeIdMap.get(currentVO.getId());
+            Integer originalSort = originalIdToSortMap.get(currentVO.getId());
+
+            // 设置新的排序值
+            currentVO.setSort(listInt.get(i));
+            currentVO.setArchiveSort(i);
+
+            // 只有位置发生变化的文件才需要更新nodeId
+            if (!listInt.get(i).equals(originalSort)) {
+                // 获取下一个文件的nodeId(如果存在)
+                if (i < list.size() - 1) {
+                    ArchiveFileVO nextVO = list.get(i + 1);
+                    String nextNodeId = originalIdToNodeIdMap.get(nextVO.getId());
+
+                    // 将当前文件的nodeId设置为下一个文件的nodeId
+                    currentVO.setNodeId(nextNodeId);
+                } else {
+                    // 如果是最后一个文件且被移动了,保持原来的nodeId
+                    currentVO.setNodeId(originalNodeId);
                 }
+            } else {
+                // 位置没有变化的文件保持原来的nodeId
+                currentVO.setNodeId(originalNodeId);
             }
-            if(resultMap.containsKey(listInt.get(i))&& !Objects.equals(resultMap.get(listInt.get(i)), list.get(i).getNodeId())){
 
+            if (currentVO.getIsUpdateUrl() != null && currentVO.getIsUpdateUrl() == 1) {
+                ids.append(currentVO.getId() + ",");
+                if (currentVO.getRectification() != null && currentVO.getRectification() == 1) {
+                    currentVO.setRectification(2);
+                }
             }
         }
+
         // 删除oss文件
         if (ids != null && ids.length() > 0) {
             List<String> removeFiles = new ArrayList<>();