Browse Source

替换文件代码

chendayu 2 years ago
parent
commit
8b5cd4b6ef

+ 6 - 0
RMS/src/main/java/cn/cslg/report/common/model/vo/FilesVO.java

@@ -68,4 +68,10 @@ public class FilesVO {
      * 文件名
      */
     private String fileName;
+
+    /**
+     * 所属后续事项id
+     */
+    private Integer followUpId;
+
 }

+ 25 - 0
RMS/src/main/java/cn/cslg/report/common/utils/SystemFileToReportFile.java

@@ -0,0 +1,25 @@
+package cn.cslg.report.common.utils;
+
+import cn.cslg.report.entity.ReportFiles;
+import cn.cslg.report.entity.SystemFile;
+
+import java.io.Serializable;
+
+/**
+ * @Author chenyu
+ * @Date 2023/8/25
+ */
+public class SystemFileToReportFile implements Serializable {
+
+    public static void systemFileToReportFile(ReportFiles reportFile, SystemFile systemFile) {
+        reportFile.setId(systemFile.getId());
+        reportFile.setName(systemFile.getOriginalName().substring(0, systemFile.getOriginalName().lastIndexOf(".")));
+        reportFile.setUrl(systemFile.getFilePath().substring(systemFile.getFilePath().indexOf("file") + 4));
+        reportFile.setCreateTime(systemFile.getUpdateTime());
+        reportFile.setCreateBy(systemFile.getCreateId());
+        reportFile.setSize(Integer.valueOf(systemFile.getFileLength()));
+        reportFile.setSuffix(systemFile.getFilePath().substring(systemFile.getFilePath().lastIndexOf(".") + 1));
+        reportFile.setFileName(systemFile.getFileName());
+    }
+
+}

+ 9 - 5
RMS/src/main/java/cn/cslg/report/controller/FollowUpController.java

@@ -8,7 +8,6 @@ import cn.cslg.report.common.model.dto.FollowUpUpdateDTO;
 import cn.cslg.report.common.model.dto.RegisterDTO;
 import cn.cslg.report.common.model.vo.FollowUpVO;
 import cn.cslg.report.common.utils.Response;
-import cn.cslg.report.entity.Report;
 import cn.cslg.report.mapper.FollowUpMapper;
 import cn.cslg.report.service.IFollowUpService;
 import com.alibaba.fastjson.JSONObject;
@@ -16,9 +15,13 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.util.List;
 
@@ -61,9 +64,10 @@ public class FollowUpController {
             return Response.success("修改后续事项完成");
         }
     }
+
     @Operation(summary = "根据报告id查询后续事项数据信息")
     @PostMapping("/query")
-    public String query(@RequestBody QueryFUEntity queryFUEntity){
+    public String query(@RequestBody QueryFUEntity queryFUEntity) throws IOException {
         List<FollowUpVO> queryResult = followUpService.findAllByPage(queryFUEntity);
         PageHelperT pageHelperT = new PageHelperT();
         pageHelperT.setList(queryResult);
@@ -75,7 +79,7 @@ public class FollowUpController {
 
     @Operation(summary = "根据ids删除后续事项数据信息")
     @PostMapping("/delete")
-    public String delete(@RequestBody List<Integer> ids) {
+    public String delete(@RequestBody List<Integer> ids) throws IOException {
         log.info("开始处理【删除后续事项】的请求,请求参数为:{}", ids);
         if (ids != null) {
             followUpService.delete(ids);
@@ -86,7 +90,7 @@ public class FollowUpController {
 
     @Operation(summary = "登记结果")
     @PostMapping("/register")
-    public String register(String register, List<MultipartFile> files) throws ParseException {
+    public String register(String register, List<MultipartFile> files) throws ParseException, IOException {
         if (register != null) {
             RegisterDTO register1 = JSONObject.parseObject(register, RegisterDTO.class);
             followUpService.register(register1, files);

+ 16 - 12
RMS/src/main/java/cn/cslg/report/controller/InvalidRecordController.java

@@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.util.List;
+
 @SuppressWarnings({"all"})
 @Tag(name = "无效记录")
 @RestController
@@ -24,41 +25,44 @@ import java.util.List;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class InvalidRecordController {
     public final InvalidRecordService invalidRecordService;
+
     @RequestMapping(value = "/addInvalidRecord", method = RequestMethod.POST)
     @Operation(summary = "增加无效记录")
-    public  String addInvalidRecord(String jsons, List<MultipartFile> files) throws IOException{
-        InvalidRecord invalidRecord = JSONObject.parseObject(jsons,InvalidRecord.class);
-        return invalidRecordService.addInvalidRecord(invalidRecord,files);
+    public String addInvalidRecord(String jsons, List<MultipartFile> files) throws IOException {
+        InvalidRecord invalidRecord = JSONObject.parseObject(jsons, InvalidRecord.class);
+        return invalidRecordService.addInvalidRecord(invalidRecord, files);
     }
+
     @RequestMapping(value = "/updateInvalidRecord", method = RequestMethod.POST)
     @Operation(summary = "修改无效记录")
     @Transactional(rollbackFor = Exception.class)
-    public String updateInvalidRecord( String jsons, List<MultipartFile> files)throws IOException{
-        InvalidRecord invalidRecord = JSONObject.parseObject(jsons,InvalidRecord.class);
-      Boolean flag=  invalidRecordService.updateInvalidRecord(invalidRecord,files);
-      if(flag) {
-          return Response.success();
-      }
+    public String updateInvalidRecord(String jsons, List<MultipartFile> files) throws IOException {
+        InvalidRecord invalidRecord = JSONObject.parseObject(jsons, InvalidRecord.class);
+        Boolean flag = invalidRecordService.updateInvalidRecord(invalidRecord, files);
+        if (flag) {
+            return Response.success();
+        }
         return Response.error();
 
     }
+
     @GetMapping(value = "/deleInvalidRecord")
     @Operation(summary = "删除无效记录")
-    public String deleInvalidRecord(int id)throws IOException{
+    public String deleInvalidRecord(int id) throws IOException {
         return invalidRecordService.deleteInvalidRecord(id);
     }
 
     @PostMapping(value = "/queryInvalidRecord")
     @Operation(summary = "查询无效记录")
     @Transactional(rollbackFor = Exception.class)
-    public String queryInvalidRecord(@RequestBody InvalidRecord invalidRecord)throws IOException{
+    public String queryInvalidRecord(@RequestBody InvalidRecord invalidRecord) throws IOException {
         return invalidRecordService.queryInvalidRecord(invalidRecord);
     }
 
     @GetMapping(value = "/exportInvalid")
     @Operation(summary = "查询无效记录")
     @Transactional(rollbackFor = Exception.class)
-    public String exportInvalid(@RequestBody InvalidRecord invalidRecord)throws IOException{
+    public String exportInvalid(@RequestBody InvalidRecord invalidRecord) throws IOException {
         return invalidRecordService.queryInvalidRecord(invalidRecord);
     }
 

+ 9 - 0
RMS/src/main/java/cn/cslg/report/entity/AssoFollowUpFile.java

@@ -1,5 +1,9 @@
 package cn.cslg.report.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
@@ -11,24 +15,29 @@ import java.io.Serializable;
  * @Author TseSean
  * @Data 2023/04/03
  */
+@TableName(value = "ASSO_FOLLOW_UP_FILE")
 @Accessors(chain = true)
 @Data
 public class AssoFollowUpFile implements Serializable {
     /**
      * 主键ID
      */
+    @TableId(value = "ID", type = IdType.AUTO)
     private Integer id;
     /**
      * 后续事项ID
      */
+    @TableField(value = "FOLLOW_UP_ID")
     private Integer followUpId;
     /**
      * 文件ID
      */
+    @TableField(value = "FILE_ID")
     private Integer fileId;
     /**
      * 文件使用类型 0=什么类型, 1=什么类型, 2=什么类型
      */
+    @TableField(value = "FILE_TYPE")
     private Integer fileType;
 
 }

+ 61 - 0
RMS/src/main/java/cn/cslg/report/entity/SystemFile.java

@@ -0,0 +1,61 @@
+package cn.cslg.report.entity;
+
+import cn.cslg.report.common.model.BaseEntity;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 系统文件实体类
+ *
+ * @Author xiexiang
+ * @Date 2023/6/1
+ */
+@Data
+public class SystemFile extends BaseEntity<SystemFile> {
+    /**
+     * 唯一标识id
+     */
+    private String GUID;
+    /**
+     * 存储位置
+     */
+    private Integer pType;
+    /**
+     * 配置类型id
+     */
+    private Integer sourceId;
+    /**
+     * 文件路径
+     */
+    private String filePath;
+    /**
+     * 文件名称
+     */
+    private String fileName;
+    /**
+     * 原始名称
+     */
+    private String originalName;
+    /**
+     * 文件大小
+     */
+    private String fileLength;
+    /**
+     * 创建人id
+     */
+    private Integer createId;
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+    /**
+     * 是否删除
+     */
+    private Integer isDelete;
+
+}

+ 11 - 0
RMS/src/main/java/cn/cslg/report/mapper/AssoFollowUpFileMapper.java

@@ -0,0 +1,11 @@
+package cn.cslg.report.mapper;
+
+import cn.cslg.report.entity.AssoFollowUpFile;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @Author chenyu
+ * @Date 2023/8/25
+ */
+public interface AssoFollowUpFileMapper extends BaseMapper<AssoFollowUpFile> {
+}

+ 14 - 0
RMS/src/main/java/cn/cslg/report/service/AssoFollowUpFileService.java

@@ -0,0 +1,14 @@
+package cn.cslg.report.service;
+
+import cn.cslg.report.entity.AssoFollowUpFile;
+import cn.cslg.report.mapper.AssoFollowUpFileMapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author chenyu
+ * @Date 2023/8/25
+ */
+@Service
+public class AssoFollowUpFileService extends ServiceImpl<AssoFollowUpFileMapper, AssoFollowUpFile> {
+}

+ 4 - 3
RMS/src/main/java/cn/cslg/report/service/IFollowUpService.java

@@ -9,6 +9,7 @@ import io.swagger.v3.oas.models.security.SecurityScheme;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.util.List;
 
@@ -44,7 +45,7 @@ public interface IFollowUpService {
     /**
      * 分页查询
      */
-    List<FollowUpVO> findAllByPage(QueryFUEntity queryFUEntity);
+    List<FollowUpVO> findAllByPage(QueryFUEntity queryFUEntity) throws IOException;
 
     /**
      * 根据ids删除许可记录数据
@@ -52,7 +53,7 @@ public interface IFollowUpService {
      * @param ids
      */
     @Transactional
-    void delete(List<Integer> ids);
+    void delete(List<Integer> ids) throws IOException;
 
     /**
      * 根据后续事项id和文件id删除许可记录数据
@@ -70,7 +71,7 @@ public interface IFollowUpService {
      * @param files
      */
     @Transactional
-    void register(RegisterDTO register, List<MultipartFile> files) throws ParseException;
+    void register(RegisterDTO register, List<MultipartFile> files) throws ParseException, IOException;
 
     /**
      * 上传关联后续事项id和附件ids

+ 73 - 39
RMS/src/main/java/cn/cslg/report/service/business/InvalidRecordService.java

@@ -1,9 +1,14 @@
 package cn.cslg.report.service.business;
 
 import cn.cslg.report.common.utils.Response;
+import cn.cslg.report.common.utils.SystemFileToReportFile;
+import cn.cslg.report.common.utils.ThrowException;
 import cn.cslg.report.entity.*;
 import cn.cslg.report.entity.asso.AssoInvalidRecordFile;
 import cn.cslg.report.mapper.InvalidRecordMapper;
+import cn.cslg.report.service.file.FileManagerService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -14,6 +19,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -27,58 +33,75 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
     public final InvalidRecordMapper invalidRecordMapper;
     private final ReportFileService reportFileService;
     private final AssoInvalidRecordFileService assoInvalidRecordFileService;
+    private final FileManagerService fileManagerService;
 
     /**
-     * @function 删除无效记录对比方案与对比记录也要删除
      * @param id
      * @return
      * @throws IOException
+     * @function 删除无效记录
      */
     public String deleteInvalidRecord(int id) throws IOException {
-        InvalidRecord invalidRecord =this.getById(id);
+        InvalidRecord invalidRecord = this.getById(id);
+
+        //查询无效记录与文件关联数据
+        LambdaQueryWrapper<AssoInvalidRecordFile> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(AssoInvalidRecordFile::getInvalidId, invalidRecord.getId());
+        List<AssoInvalidRecordFile> assoInvalidRecordFiles = assoInvalidRecordFileService.list(wrapper);
+
+        if (assoInvalidRecordFiles != null && assoInvalidRecordFiles.size() > 0) {
+            //根据任务id 删除对比方案与对比记录
+            //reportFileService.removeByIds(fileIds);
+            //删除文件(调用文件系统删除文件接口)
+            List<Integer> fileIds = assoInvalidRecordFiles.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
+            fileManagerService.deleteFileFromFMS(fileIds);
+            //删除无效记录与文件关联数据
+            List<Integer> assoInvalidRecordFilesIds = assoInvalidRecordFiles.stream().map(AssoInvalidRecordFile::getId).collect(Collectors.toList());
+            assoInvalidRecordFileService.remove(wrapper);
+        }
+
+        //删除无效记录
         this.removeById(id);
-        LambdaQueryWrapper<AssoInvalidRecordFile> wrapper =new LambdaQueryWrapper<>();
-        wrapper.eq(AssoInvalidRecordFile::getInvalidId,invalidRecord.getId());
-        List<AssoInvalidRecordFile> assoes= assoInvalidRecordFileService.list(wrapper);
-        List<Integer> fileIds =assoes.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
-        //根据任务id 删除对比方案与对比记录
-        reportFileService.removeByIds(fileIds);
-        assoInvalidRecordFileService.remove(wrapper);
         return Response.success();
     }
 
     /**
-     * @function: 修改无效记录
      * @param invalidRecord 无效记录
-     * @param files 对比文件
+     * @param files         对比文件
      * @return 是否修改成功
      * @throws IOException
+     * @function: 修改无效记录
      */
     public Boolean updateInvalidRecord(InvalidRecord invalidRecord, List<MultipartFile> files) throws IOException {
         // 根据无效Id查询对应的附件Id
-        LambdaQueryWrapper<AssoInvalidRecordFile> wrapper =new LambdaQueryWrapper<>();
-        wrapper.eq(AssoInvalidRecordFile::getInvalidId,invalidRecord.getId());
-        List<AssoInvalidRecordFile> assoes= assoInvalidRecordFileService.list(wrapper);
-        List<Integer> fileIds =assoes.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
+        LambdaQueryWrapper<AssoInvalidRecordFile> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(AssoInvalidRecordFile::getInvalidId, invalidRecord.getId());
+        List<AssoInvalidRecordFile> assoes = assoInvalidRecordFileService.list(wrapper);
+        List<Integer> fileIds = assoes.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
         // 获得更新后的附件Id
-        List<Integer> updateFileId =new ArrayList<>();
-        if(invalidRecord.getReportFiles()!=null){
+        List<Integer> updateFileId = new ArrayList<>();
+        if (invalidRecord.getReportFiles() != null) {
             updateFileId = invalidRecord.getReportFiles().stream().map(ReportFiles::getId).collect(Collectors.toList());
-            fileIds.removeAll(updateFileId);}
+            fileIds.removeAll(updateFileId);
+        }
         //做差获得被删除的文件Id
-        if(fileIds.size()!=0){
+        if (fileIds.size() != 0) {
             //根据文件Id删除报告文件关联表记录
             LambdaQueryWrapper<AssoInvalidRecordFile> deleteWrapper = new LambdaQueryWrapper<>();
-            deleteWrapper.in(AssoInvalidRecordFile::getFileId,fileIds);
+            deleteWrapper.in(AssoInvalidRecordFile::getFileId, fileIds);
             assoInvalidRecordFileService.remove(deleteWrapper);
-            //根据文件Id删除文件表记录
-            reportFileService.removeByIds(fileIds);
+            //删除文件(调用文件系统删除文件接口)
+            //reportFileService.removeByIds(fileIds);
+            fileManagerService.deleteFileFromFMS(fileIds);
         }
-         //添加附件
-        if (files!=null&&files.size() != 0) {
+        //添加附件
+        if (files != null && files.size() != 0) {
             //将文档上传并返回文件入库的Id
-            List<Integer> fileIdList = reportFileService.uploadFiles(files);
-            assoInvalidRecordFileService.addAsso(invalidRecord.getId(), fileIdList);
+            //List<Integer> fileIdList = reportFileService.uploadFiles(files);
+            String res = fileManagerService.uploadFile(files);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            List<Integer> newFileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
+            assoInvalidRecordFileService.addAsso(invalidRecord.getId(), newFileIds);
 
         }
 
@@ -90,40 +113,43 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
         invalidRecord.insert();
         if (files != null && files.size() != 0) {
             //将文档上传并返回文件入库的Id
-            List<Integer> fileIds = reportFileService.uploadFiles(files);
+//            List<Integer> fileIds = reportFileService.uploadFiles(files);
+            String res = fileManagerService.uploadFile(files);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            List<Integer> fileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
             assoInvalidRecordFileService.addAsso(invalidRecord.getId(), fileIds);
         }
         return Response.success();
     }
 
     /**
-     *@function:查找无效记录
      * @param invalidRecord
      * @return 无效记录
+     * @function:查找无效记录
      */
 
-    public String queryInvalidRecord(InvalidRecord invalidRecord) {
+    public String queryInvalidRecord(InvalidRecord invalidRecord) throws IOException {
         LambdaQueryWrapper<InvalidRecord> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(InvalidRecord::getPatentNo, invalidRecord.getPatentNo());
         //分页
-        if (invalidRecord.getSize() != null && invalidRecord.getCurrent()!= null) {
+        if (invalidRecord.getSize() != null && invalidRecord.getCurrent() != null) {
             IPage<InvalidRecord> pages = this.page(new Page<>(invalidRecord.getCurrent(), invalidRecord.getSize()), wrapper);
             pages.setRecords(this.thisInvaliRecord(pages.getRecords()));
             return Response.success(pages);
         } else {
             List<InvalidRecord> invalidRecords = this.list(wrapper);
-            invalidRecords =thisInvaliRecord(invalidRecords);
+            invalidRecords = thisInvaliRecord(invalidRecords);
             return Response.success(invalidRecords);
         }
     }
 
     /**
-     * @function 装载无效记录
      * @param invalidRecords
      * @return
+     * @function 装载无效记录
      */
 
-    public List<InvalidRecord> thisInvaliRecord(List<InvalidRecord> invalidRecords) {
+    public List<InvalidRecord> thisInvaliRecord(List<InvalidRecord> invalidRecords) throws IOException {
         //获得无效记录的Id
         List<Integer> ids = invalidRecords.stream().map(InvalidRecord::getId).collect(Collectors.toList());
         if (ids.size() != 0) {
@@ -134,17 +160,26 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
             //根据关联信息查询附件信息
             if (assoInvalidRecordFiles.size() != 0) {
                 List<Integer> fileIds = assoInvalidRecordFiles.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
-                LambdaQueryWrapper<ReportFiles> wrapper = new LambdaQueryWrapper<>();
-                wrapper.in(ReportFiles::getId, fileIds);
-                List<ReportFiles> reportFiles = reportFileService.list(wrapper);
+//                LambdaQueryWrapper<ReportFiles> wrapper = new LambdaQueryWrapper<>();
+//                wrapper.in(ReportFiles::getId, fileIds);
+//                List<ReportFiles> reportFiles = reportFileService.list(wrapper);
+                String res = fileManagerService.getSystemFileFromFMS(fileIds);
+                List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
+
                 //遍历装载文件信息
                 invalidRecords.forEach(item -> {
                     List<AssoInvalidRecordFile> partAsso = assoInvalidRecordFiles.stream().filter(tem -> tem.getInvalidId().equals(item.getId())).collect(Collectors.toList());
                     List<ReportFiles> reportFilesList = new ArrayList<>();
                     if (partAsso.size() != 0) {
                         List<Integer> partFileIds = partAsso.stream().map(AssoInvalidRecordFile::getFileId).collect(Collectors.toList());
-                        List<ReportFiles> reportFiles1 = reportFiles.stream().filter(tem -> partFileIds.contains(tem.getId())).collect(Collectors.toList());
-                        reportFilesList = reportFiles1;
+//                        List<ReportFiles> reportFiles1 = reportFiles.stream().filter(tem -> partFileIds.equals(tem.getId())).collect(Collectors.toList());
+//                        reportFilesList = reportFiles1;
+                        List<SystemFile> systemFiles1 = systemFiles.stream().filter(tem -> partFileIds.contains(tem.getId())).collect(Collectors.toList());
+                        systemFiles1.forEach(systemFile -> {
+                            ReportFiles reportFile = new ReportFiles();
+                            SystemFileToReportFile.systemFileToReportFile(reportFile, systemFile);
+                            reportFilesList.add(reportFile);
+                        });
                     }
                     item.setReportFiles(reportFilesList);
                 });
@@ -156,6 +191,5 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
     }
 
 
-
 }
 

+ 46 - 14
RMS/src/main/java/cn/cslg/report/service/file/FileManagerService.java

@@ -5,6 +5,7 @@ import com.google.gson.Gson;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.*;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.FileCopyUtils;
@@ -16,10 +17,12 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
+
 import static cn.hutool.core.io.FileUtil.getMimeType;
 
 /**
  * Okhttp调用FMS上传文件接口
+ *
  * @Author xiexiang
  * @Date 2023/8/10
  */
@@ -27,26 +30,31 @@ import static cn.hutool.core.io.FileUtil.getMimeType;
 @Slf4j
 @Service
 public class FileManagerService {
-
     @Value("${FMSUrl}")
     private String FMSUrl;
     @Value("${FileSource}")
     private Integer FileSource;
+
+    /**
+     * 调用文件系统上传文件接口
+     *
+     * @param multipartFiles 文件
+     */
     public String uploadFile(List<MultipartFile> multipartFiles) throws IOException {
         List<File> files = new ArrayList<>();
-        for(MultipartFile multipartFile:multipartFiles){
+        for (MultipartFile multipartFile : multipartFiles) {
             File file = new File(multipartFile.getOriginalFilename());
-            FileCopyUtils.copy(multipartFile.getBytes(),file);
+            FileCopyUtils.copy(multipartFile.getBytes(), file);
             files.add(file);
         }
         MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
-        for(File file:files){
+        for (File file : files) {
             //根据文件名获取文件的MIME类型
             String mimeType = getMimeType(file.getPath());
-            multipartBodyBuilder.addFormDataPart("files",file.getName(),RequestBody.create(MediaType.parse(mimeType), file));
+            multipartBodyBuilder.addFormDataPart("files", file.getName(), RequestBody.create(MediaType.parse(mimeType), file));
         }
-        RequestBody requestBody =multipartBodyBuilder
+        RequestBody requestBody = multipartBodyBuilder
                 .addFormDataPart("sourceId", String.valueOf(FileSource))
                 .build();
         OkHttpClient okHttpClient = new OkHttpClient.Builder()
@@ -58,13 +66,37 @@ public class FileManagerService {
                 .url(FMSUrl + "/fileManager/uploadSystemFile")
                 .post(requestBody)
                 .build();
-        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+        Response response = null;
+        response = okHttpClient.newCall(request).execute();
+        // 最后记得删除临时文件
+        for (File file : files) {
+            FileUtils.deleteQuietly(file);
+        }
+        return Objects.requireNonNull(response.body()).string();
+    }
+
+    /**
+     * 调用文件系统取出文件接口(获得文件流)
+     *
+     * @param fieldId 文件id
+     */
+    public byte[] downloadSystemFileFromFMS(Integer fieldId) throws IOException {
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(FMSUrl + "/fileManager/downloadSystemFile?fileId=" + fieldId)
+                .get()
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).bytes();
     }
 
     /**
-     * 调用文件系统查询接口
-     * @return
-     * @throws IOException
+     * 调用文件系统获取文件信息接口
+     *
+     * @param fileIds 文件ids
      */
     public String getSystemFileFromFMS(List<Integer> fileIds) throws IOException {
         String param = new Gson().toJson(fileIds);
@@ -82,12 +114,12 @@ public class FileManagerService {
     }
 
     /**
-     * 调用文件系统删除接口
-     * @return
-     * @throws IOException
+     * 调用文件系统删除文件接口
+     *
+     * @param ids 需要删除的文件ids
      */
     public String deleteFileFromFMS(List<Integer> ids) throws IOException {
-        FMSDeleteFileDTO fmsDeleteFileDTO =new FMSDeleteFileDTO();
+        FMSDeleteFileDTO fmsDeleteFileDTO = new FMSDeleteFileDTO();
         fmsDeleteFileDTO.setIds(ids);
         fmsDeleteFileDTO.setType(2);
         String param = new Gson().toJson(fmsDeleteFileDTO);

+ 122 - 38
RMS/src/main/java/cn/cslg/report/service/impl/FollowUpServiceImpl.java

@@ -12,25 +12,36 @@ import cn.cslg.report.common.utils.Response;
 import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.report.entity.AssoFollowUpFile;
 import cn.cslg.report.entity.FollowUp;
+import cn.cslg.report.entity.SystemFile;
 import cn.cslg.report.exception.XiaoShiException;
 import cn.cslg.report.mapper.FollowUpMapper;
+import cn.cslg.report.service.AssoFollowUpFileService;
 import cn.cslg.report.service.IFollowUpService;
 import cn.cslg.report.service.business.ReportFileService;
+import cn.cslg.report.service.file.FileManagerService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 后续事项的Service层实现类
+ *
  * @Author xiexiang
  * @Date 2023/4/1
  */
@@ -40,8 +51,12 @@ import java.util.List;
 public class FollowUpServiceImpl implements IFollowUpService {
     private final FollowUpMapper followUpMapper;
     private final ReportFileService reportFileService;
+    private final AssoFollowUpFileService assoFollowUpFileService;
+    private final FileManagerService fileManagerService;
     private final CacheUtils cacheUtils;
     private final LoginUtils loginUtils;
+    @Value("${FileSource}")
+    private Integer fileSource;
 
     /**
      * 新增后续事项
@@ -52,13 +67,13 @@ public class FollowUpServiceImpl implements IFollowUpService {
     public void add(List<FollowUpDTO> followUps) {
         log.info("开始处理【新增后续事项】的业务,参数为:{}", followUps);
         FollowUp followUp = new FollowUp();
-        for(FollowUpDTO followUpDTO:followUps){
-            if(followUpDTO.getFollowUpName() == null){
+        for (FollowUpDTO followUpDTO : followUps) {
+            if (followUpDTO.getFollowUpName() == null) {
                 log.info("后续事项名称不可为空");
             }
         }
         //判断传入列表不为空
-        if (followUps != null && followUps.size() > 0 ) {
+        if (followUps != null && followUps.size() > 0) {
             //遍历传入列表
             for (int i = 0; i < followUps.size(); i++) {
                 //DTO赋值给后续事项表实体类
@@ -78,7 +93,8 @@ public class FollowUpServiceImpl implements IFollowUpService {
                     log.info("数据入后续事项表失败,{}", message);
                     throw new XiaoShiException(message);
                 }
-            }log.info("新增后续事项完成");
+            }
+            log.info("新增后续事项完成");
         }
     }
 
@@ -88,7 +104,7 @@ public class FollowUpServiceImpl implements IFollowUpService {
      * @param followUpUpdateDTOList 修改后续事项的前端传输DTO数据对象
      */
     @Override
-    public void update(List<FollowUpUpdateDTO> followUpUpdateDTOList){
+    public void update(List<FollowUpUpdateDTO> followUpUpdateDTOList) {
         log.info("开始处理【修改后续事项】的业务,参数为:{}", followUpUpdateDTOList);
         //DTO赋值给后续事项表实体类
         FollowUp followUp = new FollowUp();
@@ -104,7 +120,8 @@ public class FollowUpServiceImpl implements IFollowUpService {
                     String message = "第" + i + "条失败";
                     log.info("修改后续事项表数据失败,{}", message);
                 }
-            }log.info("修改后续事项完成");
+            }
+            log.info("修改后续事项完成");
         }
     }
 
@@ -114,31 +131,90 @@ public class FollowUpServiceImpl implements IFollowUpService {
     }
 
     /**
-     * 根据报告id查询
+     * 根据报告id查询后续事项列表
      *
      * @param queryFUEntity
      */
     @Override
-    public List<FollowUpVO> findAllByPage(QueryFUEntity queryFUEntity){
+    public List<FollowUpVO> findAllByPage(QueryFUEntity queryFUEntity) throws IOException {
         PageHelper.startPage(queryFUEntity.getCurrent(), queryFUEntity.getSize());
+        //分页查询出后续事项列表
         List<FollowUpVO> followUpVOS = followUpMapper.query(queryFUEntity.getReportId());
+        if (followUpVOS != null && followUpVOS.size() > 0) {
+            //过滤出后续事项ids
+            List<Integer> followUpIds = followUpVOS.stream().map(FollowUpVO::getId).collect(Collectors.toList());
+            //查询出后续事项ids对应的后续事项和文件关联数据
+            List<AssoFollowUpFile> assoFollowUpFiles = assoFollowUpFileService.list(new LambdaQueryWrapper<AssoFollowUpFile>().in(AssoFollowUpFile::getFollowUpId, followUpIds));
+            if (assoFollowUpFiles != null && assoFollowUpFiles.size() > 0) {
+                //过滤出文件ids
+                List<Integer> fileIds = assoFollowUpFiles.stream().map(AssoFollowUpFile::getFileId).collect(Collectors.toList());
+                //调用文件系统获取文件信息接口,获得文件systemFiles
+                String res = fileManagerService.getSystemFileFromFMS(fileIds);
+                List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
+
+                ArrayList<FilesVO> files = new ArrayList<>();
+                //遍历后续事项文件关联数据assoFollowUpFiles与文件systemFiles,装载文件信息files
+                assoFollowUpFiles.forEach(assoFollowUpFile -> {
+                    systemFiles.forEach(systemFile -> {
+                        if (systemFile.getId().equals(assoFollowUpFile.getFileId())) {
+                            FilesVO fileVO = new FilesVO();
+                            fileVO.setFollowUpId(assoFollowUpFile.getFollowUpId());  //文件信息中装载后续事项id
+                            fileVO.setFileId(systemFile.getId());
+                            fileVO.setName(systemFile.getOriginalName().substring(0, systemFile.getOriginalName().lastIndexOf(".")));
+                            fileVO.setUrl(systemFile.getFilePath().substring(systemFile.getFilePath().indexOf("file") + 4));
+                            fileVO.setUId(systemFile.getCreateId());
+                            fileVO.setSuffix(systemFile.getFilePath().substring(systemFile.getFilePath().lastIndexOf(".") + 1));
+                            fileVO.setFileName(systemFile.getFileName());
+                            fileVO.setUpdateTime(systemFile.getUpdateTime());
+                            files.add(fileVO);
+                        }
+                    });
+                });
+
+                //遍历后续事项followUpVOS和上一步装载的文件信息files,装载后续事项的文件
+                followUpVOS.forEach(followUpVO -> {
+                    ArrayList<FilesVO> filesVOS = new ArrayList<>();
+                    files.forEach(file -> {
+                        if (file.getFollowUpId().equals(followUpVO.getId())) {
+                            file.setFollowUpId(null);  //再去除文件信息中的后续事项id
+                            filesVOS.add(file);
+                        }
+                    });
+                    followUpVO.setFilesVOs(filesVOS);
+                });
+            }
+        }
+
+
         return followUpVOS;
     }
 
     /**
-     * 根据ids删除许可记录数据
+     * 根据ids删除后续事项
      *
-     * @param ids
+     * @param ids 后续事项ids
      */
     @Override
-    public void delete(List<Integer> ids) {
-        log.info("开始处理【删除许可记录】的业务,参数为:{}", ids);
-        if (ids != null) {
-            followUpMapper.delete(ids);
-            log.info("产品删除完成");
-        } else {
-            log.info("删除产品失败,产品不存在");
+    public void delete(List<Integer> ids) throws IOException {
+        log.info("开始处理【删除后续事项】的业务,参数为:{}", ids);
+
+        LambdaQueryWrapper<AssoFollowUpFile> wrapper = new LambdaQueryWrapper<AssoFollowUpFile>().in(AssoFollowUpFile::getFollowUpId, ids);
+        //查询出这些后续事项对应的文件
+        List<AssoFollowUpFile> assoFollowUpFiles = assoFollowUpFileService.list(wrapper);
+
+        if (assoFollowUpFiles != null && assoFollowUpFiles.size() > 0) {
+            //删除文件(调用文件系统删除文件接口)
+            List<Integer> fileIds = assoFollowUpFiles.stream().map(AssoFollowUpFile::getFileId).collect(Collectors.toList());
+            fileManagerService.deleteFileFromFMS(fileIds);
+            //删除后续事项与文件关联数据
+            assoFollowUpFileService.remove(wrapper);
         }
+
+        //删除所有后续事项
+        followUpMapper.delete(ids);
+
+        log.info("后续事项删除完成");
+
     }
 
     /**
@@ -148,13 +224,13 @@ public class FollowUpServiceImpl implements IFollowUpService {
      * @param files
      */
     @Override
-    public void register(RegisterDTO register, List<MultipartFile> files) throws ParseException {
+    public void register(RegisterDTO register, List<MultipartFile> files) throws ParseException, IOException {
         //获取当前时间
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
         String date = dateFormat.format(new Date());//date为当前时间 是String类型的时间
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date finishTime = simpleDateFormat.parse(date);//转换为Date类型
-        System.out.println("等级结果当前完成时间"+ finishTime);
+        System.out.println("等级结果当前完成时间" + finishTime);
         FollowUp followUp = new FollowUp();
         //从registerDTO中取出后续事项id进行对应的操作
         followUp.setId(register.getFollowUpId());
@@ -174,49 +250,56 @@ public class FollowUpServiceImpl implements IFollowUpService {
         //根据后续事项id查询关联表找出所有fileId
         List<Integer> fileIdS = followUpMapper.queryFileIdByFollowUpId(followUpId);
         //判断第二次登记结果时候文件数量
-        List<FilesVO> filesVOs= register.getFilesVOs();
-        if(filesVOs != null){//传入不为空
+        List<FilesVO> filesVOs = register.getFilesVOs();
+        if (filesVOs != null) {//传入不为空
             //遍历前端传入数据,取得fileId的集合ids
             List<Integer> ids = new ArrayList<>();
-            for(FilesVO filesVO:filesVOs){
+            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,就是没有,需要删除
+            for (Integer fileId : fileIdS) {
+                if (ids.contains(fileId) != true) {//不为true,就是没有,需要删除
                     deleteIds.add(fileId);
                 }
             }
-            if(deleteIds.size()>0) {
+            if (deleteIds.size() > 0) {
                 followUpMapper.deleteAssoId(followUpId, deleteIds);
                 log.info("多余关联附件删除完成");
+                //删除文件(调用文件系统删除文件接口)
+                fileManagerService.deleteFileFromFMS(deleteIds);
             }
-        }else if(filesVOs != null && filesVOs.size() == 0){//传入为空数组 等于附件需要全部删除
-            followUpMapper.deleteAssoId(followUpId,fileIdS);
+        } else if (filesVOs != null && filesVOs.size() == 0) {//传入为空数组 等于附件需要全部删除
+            followUpMapper.deleteAssoId(followUpId, fileIdS);
+            //删除文件(调用文件系统删除文件接口)
+            fileManagerService.deleteFileFromFMS(fileIdS);
         }
         //上传附件 进行关联绑定
         if (files != null && files.size() != 0) {
             //将文档上传并返回文件入库的Id
-            List<Integer> fileIds = reportFileService.uploadFiles(files);
+            //List<Integer> fileIds = reportFileService.uploadFiles(files);
+            String res = fileManagerService.uploadFile(files);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            List<Integer> fileIds = JSON.parseArray(jsonObject.get("data").toString(), Integer.class);
             this.addAsso(register.getFollowUpId(), fileIds);
         }
         //批量新增后续事项
-        if(register.getFollowUps() != null && register.getFollowUps().size()>0) {
+        if (register.getFollowUps() != null && register.getFollowUps().size() > 0) {
             this.add(register.getFollowUps());
         }
     }
 
     /**
      * @param followUpId 后续事项id
-     * @param fileIds  文件id
+     * @param fileIds    文件id
      * @return
      * @function 上传后续事项与文件关联表 对应实体AssoFollowUpFile 0代表上传文件为附件
      */
     public String addAsso(Integer followUpId, List<Integer> fileIds) {
-        for(int i = 0; i < fileIds.size(); i++){
+        for (int i = 0; i < fileIds.size(); i++) {
             Integer fileId = fileIds.get(i);
             AssoFollowUpFile assoFollowUpFile = new AssoFollowUpFile();
             assoFollowUpFile.setFollowUpId(followUpId);
@@ -224,11 +307,12 @@ public class FollowUpServiceImpl implements IFollowUpService {
             assoFollowUpFile.setFileType(0);
             int rows = followUpMapper.addAssoIds(assoFollowUpFile);
             System.out.println(rows);
-            if(rows != 1){
+            if (rows != 1) {
                 String message = "第" + i + "条失败";
                 log.info("新增后续事项和附件id关联表数据失败,{}", message);
             }
-        }log.info("新增后续事项和附件id关联表完成");
+        }
+        log.info("新增后续事项和附件id关联表完成");
         return Response.success();
     }
 
@@ -236,13 +320,13 @@ public class FollowUpServiceImpl implements IFollowUpService {
      * 第二次登记结果,根据传入的register中的followUpId和filesVOs中的fileId删除关联表中的多出的数据
      *
      * @param followUpId 后续事项id
-     * @param fileIds 附件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);
+    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("删除多余关联附件失败,多余关联附件不存在");

+ 24 - 13
RMS/src/main/resources/mapper/FollowUpMapper.xml

@@ -8,10 +8,9 @@
         INSERT INTO FOLLOW_UP(REPORT_ID, PARENT_ID, FOLLOW_UP_NAME, REMARK, TIME_LIMIT,
                               AGENT, ASSIST_PERSON, FINISH_TIME, STATUS, CONCLUSION, CREATE_PERSON_ID,
                               CREATE_PERSON_NAME)
-        VALUES
-            (#{reportId}, #{parentId}, #{followUpName}, #{remark},
-             #{timeLimit}, #{agent}, #{assistPerson}, #{finishTime}, #{status},
-             #{conclusion}, #{createPersonId}, #{createPersonName})
+        VALUES (#{reportId}, #{parentId}, #{followUpName}, #{remark},
+                #{timeLimit}, #{agent}, #{assistPerson}, #{finishTime}, #{status},
+                #{conclusion}, #{createPersonId}, #{createPersonName})
     </insert>
     <!--根据id修改数据-->
     <!--int update(FollowUp followUp);-->
@@ -98,12 +97,23 @@
     <!--    </select>-->
 
     <select id="query" resultMap="queryMap">
-        SELECT a.ID, a.REPORT_ID, a.PARENT_ID, a.FOLLOW_UP_NAME,a.REMARK,a.TIME_LIMIT,a.AGENT,a.ASSIST_PERSON,a.FINISH_TIME,a.STATUS, a.CONCLUSION,
-               a.CREATE_PERSON_ID, a.CREATE_PERSON_NAME, a.CREATE_TIME, d.FILE_ID, d.NAME, d.ADDRESS, d.ZID,d.FILEREMARK, d.UPDATE_TIME, d.UID,d.TYPE, d.SIZE, d.SUFFIX, d.FILE_NAME
-        FROM FOLLOW_UP a LEFT JOIN (SELECT b.FOLLOW_UP_ID, b.FILE_ID, c.ID, c.NAME, c.ADDRESS, c.ZID, c.REMARK AS FILEREMARK, c.UPDATE_TIME, c.UID, c.TYPE, c.SIZE, c.SUFFIX, c.FILE_NAME
-                                    FROM ASSO_FOLLOW_UP_FILE b LEFT JOIN REPORT_FILE c ON b.FILE_ID = c.ID) d
-                                    ON a.ID = d.FOLLOW_UP_ID
-        WHERE a.REPORT_ID = #{reportId} ORDER BY CREATE_TIME DESC
+        SELECT ID,
+               REPORT_ID,
+               PARENT_ID,
+               FOLLOW_UP_NAME,
+               REMARK,
+               TIME_LIMIT,
+               AGENT,
+               ASSIST_PERSON,
+               FINISH_TIME,
+               STATUS,
+               CONCLUSION,
+               CREATE_PERSON_ID,
+               CREATE_PERSON_NAME,
+               CREATE_TIME
+        FROM FOLLOW_UP
+        WHERE REPORT_ID = #{reportId}
+        ORDER BY CREATE_TIME DESC
     </select>
 
     <!--根据报告id统计后续事项数量-->
@@ -141,7 +151,9 @@
     <!--根据报告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 FILE_ID
+        FROM ASSO_FOLLOW_UP_FILE
+        WHERE FOLLOW_UP_ID = #{followUpId};
     </select>
 
 
@@ -149,8 +161,7 @@
     <!--int addAssoIds(AssoFollowUpFile assoFollowUpFile);-->
     <insert id="addAssoIds" useGeneratedKeys="true" keyProperty="id">
         INSERT INTO ASSO_FOLLOW_UP_FILE(FOLLOW_UP_ID, FILE_ID, FILE_TYPE)
-        VALUES
-            (#{followUpId}, #{fileId}, #{fileType})
+        VALUES (#{followUpId}, #{fileId}, #{fileType})
     </insert>
 
 </mapper>