瀏覽代碼

代码合并

lwhhszx 2 年之前
父節點
當前提交
2400e0b1cf

+ 23 - 0
RMS/src/main/java/cn/cslg/report/common/model/dto/FMSDeleteFileDTO.java

@@ -0,0 +1,23 @@
+package cn.cslg.report.common.model.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 调用FMS系统删除文件接口
+ * @Author xiexiang
+ * @Date 2023/8/14
+ */
+@Data
+public class FMSDeleteFileDTO {
+    /**
+     * 需删除的ids
+     */
+    private List<Integer> ids;
+
+    /**
+     * 删除类型
+     */
+    private Integer type;
+}

+ 114 - 0
RMS/src/main/java/cn/cslg/report/service/file/FileManagerService.java

@@ -0,0 +1,114 @@
+package cn.cslg.report.service.file;
+
+import cn.cslg.report.common.model.dto.FMSDeleteFileDTO;
+import com.google.gson.Gson;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.FileCopyUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+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
+ */
+@RequiredArgsConstructor
+@Slf4j
+@Service
+public class FileManagerService {
+    @Value("${authorUrl}")
+    private String PCSUrl;
+    @Value("${OPSUrl}")
+    private String OPSUrl;
+    @Value("${PASUrl}")
+    private String PASUrl;
+    @Value("${RMSUrl}")
+    private String RMSUrl;
+    @Value("${FMSUrl}")
+    private String FMSUrl;
+    @Value("${FileSource}")
+    private Integer FileSource;
+    public String uploadFile(List<MultipartFile> multipartFiles) throws IOException {
+        List<File> files = new ArrayList<>();
+        for(MultipartFile multipartFile:multipartFiles){
+            File file = new File(multipartFile.getOriginalFilename());
+            FileCopyUtils.copy(multipartFile.getBytes(),file);
+            files.add(file);
+        }
+        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()
+                .setType(MultipartBody.FORM);
+        for(File file:files){
+            //根据文件名获取文件的MIME类型
+            String mimeType = getMimeType(file.getPath());
+            multipartBodyBuilder.addFormDataPart("files",file.getName(),RequestBody.create(MediaType.parse(mimeType), file));
+        }
+        RequestBody requestBody =multipartBodyBuilder
+                .addFormDataPart("sourceId", String.valueOf(FileSource))
+                .build();
+        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/uploadSystemFile")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    /**
+     * 调用文件系统查询接口
+     * @return
+     * @throws IOException
+     */
+    public String getSystemFileFromFMS(List<Integer> fileIds) throws IOException {
+        String param = new Gson().toJson(fileIds);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        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/getFileData")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    /**
+     * 调用文件系统删除接口
+     * @return
+     * @throws IOException
+     */
+    public String deleteFileFromFMS(List<Integer> ids) throws IOException {
+        FMSDeleteFileDTO fmsDeleteFileDTO =new FMSDeleteFileDTO();
+        fmsDeleteFileDTO.setIds(ids);
+        fmsDeleteFileDTO.setType(2);
+        String param = new Gson().toJson(fmsDeleteFileDTO);
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+        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/deleteSystemFile")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+}

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

@@ -155,7 +155,6 @@ 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,9 +168,7 @@ public class FollowUpServiceImpl implements IFollowUpService {
             log.info("登记结果失败,{}", message);
         }
         log.info("登记结果完成");
-
         //删除
-
         //简化定义后续事项id
         int followUpId = register.getFollowUpId();
         //根据后续事项id查询关联表找出所有fileId
@@ -200,8 +197,6 @@ public class FollowUpServiceImpl implements IFollowUpService {
         }else if(filesVOs != null && filesVOs.size() == 0){//传入为空数组 等于附件需要全部删除
             followUpMapper.deleteAssoId(followUpId,fileIdS);
         }
-        //新增文件
-
         //上传附件 进行关联绑定
         if (files != null && files.size() != 0) {
             //将文档上传并返回文件入库的Id