xiexiang пре 2 година
родитељ
комит
0dc4343445

+ 6 - 0
RMS/src/main/java/cn/cslg/report/common/model/dto/RegisterDTO.java

@@ -1,5 +1,6 @@
 package cn.cslg.report.common.model.dto;
 
+import cn.cslg.report.common.model.vo.FilesVO;
 import lombok.Data;
 
 import java.util.List;
@@ -28,6 +29,11 @@ public class RegisterDTO {
     private String conclusion;
 
     /**
+     * 文件信息
+     */
+    private List<FilesVO> filesVOs;
+
+    /**
      * 批量新增后续事项
      *
      * @param followUpDTOList

+ 17 - 0
RMS/src/main/java/cn/cslg/report/mapper/FollowUpMapper.java

@@ -59,6 +59,23 @@ public interface FollowUpMapper {
     int delete(List<Integer> ids);
 
     /**
+     * 根据后续事项id和文件id删除关联数据
+     *
+     * @param followUpId 后续事项id
+     * @param fileIds 文件ids
+     * @return 返回受影响的行数
+     */
+    int deleteAssoId(Integer followUpId, List<Integer> fileIds);
+
+    /**
+     * 根据传入后续事项id查询关联表中有的全部fileId
+     *
+     * @param followUpId
+     * @return
+     */
+    List<Integer> queryFileIdByFollowUpId(Integer followUpId);
+
+    /**
      * 插入后续事项id和附件id关联表
      *
      * @param assoFollowUpFile

+ 9 - 0
RMS/src/main/java/cn/cslg/report/service/IFollowUpService.java

@@ -55,6 +55,15 @@ public interface IFollowUpService {
     void delete(List<Integer> ids);
 
     /**
+     * 根据后续事项id和文件id删除许可记录数据
+     *
+     * @param followUpId 后续事项id
+     * @param fileIds 文件id
+     */
+    @Transactional
+    void deleteAssoId(Integer followUpId,List<Integer> fileIds);
+
+    /**
      * 登记结果
      *
      * @param register

+ 45 - 0
RMS/src/main/java/cn/cslg/report/service/impl/FollowUpServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -150,6 +151,7 @@ public class FollowUpServiceImpl implements IFollowUpService {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date finishTime = simpleDateFormat.parse(date);//转换为Date类型
         System.out.println("等级结果当前完成时间"+ finishTime);
+
         FollowUp followUp = new FollowUp();
         //从registerDTO中取出后续事项id进行对应的操作
         followUp.setId(register.getFollowUpId());
@@ -169,6 +171,32 @@ public class FollowUpServiceImpl implements IFollowUpService {
             List<Integer> fileIds = reportFileService.uploadFiles(files);
             this.addAsso(register.getFollowUpId(), fileIds);
         }
+        //简化定义后续事项id
+        int followUpId = register.getFollowUpId();
+        //根据后续事项id查询关联表找出所有fileId
+        List<Integer> fileIdS = followUpMapper.queryFileIdByFollowUpId(followUpId);
+        //判断第二次登记结果时候文件数量
+        if(register.getFilesVOs() != null){//传入不为空
+            List<FilesVO> filesVOs= register.getFilesVOs();
+            //遍历前端传入数据,取得fileId的集合ids
+            List<Integer> ids = new ArrayList<>();
+            for(FilesVO filesVO:filesVOs){
+                int id = filesVO.getFileId();
+                ids.add(id);
+            }
+            //定义一个list存放需要删除的fileId
+            List<Integer> deleteIds = new ArrayList<>();
+            //遍历数据库中存在的fileId
+            for(Integer fileId : fileIdS){
+                if(ids.contains(fileId) != true){//不为true,就是没有,需要删除
+                    deleteIds.add(fileId);
+                }
+            }
+            followUpMapper.deleteAssoId(followUpId,deleteIds);
+            log.info("多余关联附件删除完成");
+        }else{//传入为空数组 等于附件需要全部删除
+            followUpMapper.deleteAssoId(followUpId,fileIdS);
+        }
         //批量新增后续事项
         this.add(register.getFollowUps());
     }
@@ -194,4 +222,21 @@ public class FollowUpServiceImpl implements IFollowUpService {
         }log.info("新增后续事项和附件id关联表完成");
         return Response.success();
     }
+
+    /**
+     * 第二次登记结果,根据传入的register中的followUpId和filesVOs中的fileId删除关联表中的多出的数据
+     *
+     * @param followUpId 后续事项id
+     * @param fileIds 附件id
+     */
+    @Override
+    public void deleteAssoId(Integer followUpId,List<Integer> fileIds){
+        log.info("开始处理【删除多余关联附件】的业务,参数为:{}", followUpId,fileIds);
+        if (followUpId != null && fileIds !=null) {
+            followUpMapper.deleteAssoId(followUpId,fileIds);
+            log.info("多余关联附件删除完成");
+        } else {
+            log.info("删除多余关联附件失败,多余关联附件不存在");
+        }
+    }
 }

+ 20 - 0
RMS/src/main/resources/mapper/FollowUpMapper.xml

@@ -125,6 +125,26 @@
         </foreach>
     </delete>
 
+    <!--根据后续事项id和文件id删除数据-->
+    <!--int deleteAssoId(Integer followUpId, Integer fileId);-->
+    <delete id="deleteAssoId">
+        delete
+        from asso_follow_up_file
+        where follow_up_id = #{followUpId}
+        and FILE_ID in
+            <foreach collection="fileIds" item="fileId" index="index" open="(" close=")" separator=",">
+                #{fileId}
+            </foreach>
+    </delete>
+
+
+    <!--根据报告id统计后续事项数量-->
+    <!--List<Integer> queryFileIdByFollowUpId(Integer followUpId);-->
+    <select id="queryFileIdByFollowUpId" resultType="Integer">
+        SELECT FILE_ID FROM asso_follow_up_file WHERE FOLLOW_UP_ID = #{followUpId};
+    </select>
+
+
     <!--插入数据-->
     <!--int addAssoIds(List<AssoFollowUpFile> assoFollowUpFiles);-->
     <insert id="addAssoIds" useGeneratedKeys="true" keyProperty="id">