Selaa lähdekoodia

附件删除逻辑修改

gushoubang 1 kuukausi sitten
vanhempi
commit
b1e05c1eef

+ 9 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/NodeAttachmentMapper.java

@@ -2,6 +2,7 @@ package com.siwei.apply.mapper;
 
 import com.siwei.apply.domain.NodeAttachment;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 记录流程对应的附件材料 Mapper 接口
@@ -52,4 +53,12 @@ public interface NodeAttachmentMapper {
      * @param nodeId 节点ID
      */
     void deleteByNodeId(String nodeId);
+
+    /**
+     * 根据节点ID删除,且排除指定ID的记录
+     *
+     * @param nodeId 节点ID
+     * @param id 排除的ID(不等于)
+     */
+    void deleteByNodeIdAndIdNotEqual(@Param("nodeId") String nodeId, @Param("id") String id);
 }

+ 20 - 5
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/NodeAttachmentImpl.java

@@ -23,7 +23,12 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
     
     @Autowired
     private NodeAttachmentMapper nodeAttachmentMapper;
-    
+
+    /**
+     * 根据ID查询附件信息
+     * @param id 附件ID
+     * @return
+     */
     @Override
     public NodeAttachment getById(String id) {
         try {
@@ -42,6 +47,11 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
         }
     }
 
+    /**
+     * 根据节点ID查询附件信息
+     * @param nodeId 节点ID
+     * @return
+     */
     @Override
     public NodeAttachment getByNodeId(String nodeId) {
         try {
@@ -59,7 +69,12 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
             return null;
         }
     }
-    
+
+    /**
+     * 处理文件并保存附件信息
+     * @param filePath 文件路径
+     * @return
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String processFileAndSave(String filePath) {
@@ -134,9 +149,9 @@ public class NodeAttachmentImpl implements NodeAttachmentService {
                 return false;
             }
 
-//            // 先根据nodeId删除其他的附件记录
-//            nodeAttachmentMapper.deleteByNodeId(nodeId);
-//            logger.info("删除nodeId对应的其他附件记录,nodeId: {}", nodeId);
+            // 先根据nodeId删除其他的附件记录
+            nodeAttachmentMapper.deleteByNodeIdAndIdNotEqual(nodeId, nodeAttachmentId);
+            logger.info("删除nodeId对应的其他附件记录,nodeId: {}", nodeId);
 
             // 再查询要更新的记录是否存在
             NodeAttachment existing = nodeAttachmentMapper.selectById(nodeAttachmentId);

+ 9 - 1
siwei-modules/siwei-apply/src/main/resources/mapper/NodeAttachmentMapper.xml

@@ -25,12 +25,13 @@
         WHERE id = #{id}
     </select>
 
-    <!-- 根据节点ID查询附件信息 -->
+    <!-- 根据节点ID查询附件信息(只返回一条) -->
     <select id="selectByNodeId" resultMap="BaseResultMap" parameterType="String">
         SELECT
         <include refid="Base_Column_List"/>
         FROM t_node_attachment
         WHERE node_id = #{nodeId}
+        LIMIT 1
     </select>
 
     <!-- 插入附件记录 -->
@@ -68,4 +69,11 @@
         DELETE FROM t_node_attachment WHERE node_id = #{nodeId}
     </delete>
 
+    <!-- 根据节点ID删除且排除指定ID的记录 -->
+    <delete id="deleteByNodeIdAndIdNotEqual" parameterType="map">
+        DELETE FROM t_node_attachment
+        WHERE node_id = #{nodeId}
+          AND id != #{id}
+    </delete>
+
 </mapper>