Browse Source

Merge branch 'master' into dev2

# Conflicts:
#	src/main/java/com/example/fms/service/FileFactoryService.java
#	target/classes/configSetting.json
lwhhszx 2 năm trước cách đây
mục cha
commit
80c6cc60ba

+ 5 - 0
src/main/java/com/example/fms/common/model/dto/SystemFileDTO.java

@@ -21,6 +21,11 @@ public class SystemFileDTO {
     private String GUID;
 
     /**
+     * 配置类型id
+     */
+    private Integer sourceId;
+
+    /**
      * 存储位置
      */
     private Integer pType;

+ 2 - 0
src/main/java/com/example/fms/common/model/vo/SystemFileVO.java

@@ -29,6 +29,8 @@ public class SystemFileVO {
      */
     private Integer pType;
 
+    private Integer sourceId;
+
     /**
      * 文件路径
      */

+ 6 - 0
src/main/java/com/example/fms/domain/SystemFile.java

@@ -30,6 +30,12 @@ public class SystemFile extends BaseEntity<SystemFile> {
     private Integer pType;
 
     /**
+     * 配置类型id
+     */
+    @TableField("SOURCE_ID")
+    private Integer sourceId;
+
+    /**
      * 文件路径
      */
     @TableField("FILE_PATH")

+ 19 - 21
src/main/java/com/example/fms/service/FileFactoryService.java

@@ -33,16 +33,17 @@ public class FileFactoryService {
      * @param sourceId
      * @return
      */
-    public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId) {
-        if (files != null && files.size() != 0) {
+    public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId){
+        if(files != null && files.size() != 0) {
             //调用解析配置方法,获取配置信息
             List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
-            ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
+            //根据配置id获得配置
+            ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(sourceId)).findFirst().orElse(null);
             if (configSettingVO == null) {
                 return null;
             }
             String sourceName = configSettingVO.getSourceName();
-            if (sourceName.equals("FSS")) {
+            if(sourceName.equals("FSS")) {
                 return this.uploadToFSS(files, configSettingVO);
             }
             return null;
@@ -58,13 +59,14 @@ public class FileFactoryService {
      * @param configSettingVO
      * @return
      */
-    public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO) {
+    public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO){
         List<SystemFileDTO> systemFileDTOS = new ArrayList<>();
-        for (MultipartFile file : files) {
+        for(MultipartFile file:files){
             try {
                 String directoryName = fileUtils.getDirectoryName();
                 SystemFileDTO systemFileDTO = SftpService.upload(configSettingVO.getFilePath() + directoryName, file, configSettingVO);
-                systemFileDTO.setPType(configSettingVO.getSourceId());
+                systemFileDTO.setPType(configSettingVO.getId());
+                systemFileDTO.setSourceId(configSettingVO.getSourceId());
                 systemFileDTO.setOriginalName(file.getOriginalFilename());
                 systemFileDTO.setFilePath(configSettingVO.getFilePath() + directoryName + "/" + systemFileDTO.getFileName());
                 systemFileDTOS.add(systemFileDTO);
@@ -78,7 +80,6 @@ public class FileFactoryService {
 
     /**
      * 下载文件
-     *
      * @param downloadSysFileDTO
      * @throws Exception
      */
@@ -99,16 +100,16 @@ public class FileFactoryService {
             return null;
         }
     }
-
     /**
-     * @param //directory    下载目录 根据SFTP设置的根目录来进行传输
+     * @param //directory 下载目录 根据SFTP设置的根目录来进行传输
      * @param //downloadFile 下载的文件
-     * @param //saveFile     存在本地的路径
+     * @param //saveFile 存在本地的路径
      */
     public byte[] downloadFromFSS(DownloadSysFileDTO downloadSysFileDTO, ConfigSettingVO configSettingVO) throws Exception {
         //下载目录,也是存储路径
         String filePath = downloadSysFileDTO.getFilePath();
-        String directory = filePath.substring(0, filePath.lastIndexOf("/"));
+        int index = filePath.lastIndexOf("/");
+        String directory = filePath.substring(0,index);
         //下载的文件,也就是文件名
         String downloadFile = downloadSysFileDTO.getFileName();
         //存在本地的路径,随机生成
@@ -117,21 +118,19 @@ public class FileFactoryService {
         byte[] fileData = SftpService.download(directory, downloadFile, configSettingVO);
         return fileData;
     }
-
     /**
      * 删除文件
      *
      * @param filePath
-     * @param pType
+     * @param sourceId
      */
-    public static void delete(String filePath, Integer pType) {
+    public static void delete(String filePath, Integer sourceId){
         //调用解析配置方法,获取配置信息
         List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
+        ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
         //根据传入类型判断从哪里删除数据
         //如果为1,则为服务器
-        if (pType.equals(1)) {
-            int sourceId = 1;
-            ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
+        if(sourceId.equals(1)){
             //拆分路径字符串
             int index = filePath.lastIndexOf('/');
             //要删除文件所在目录
@@ -143,11 +142,10 @@ public class FileFactoryService {
             } catch (Exception e) {
                 throw new XiaoShiException("删除错误");
             }
-        } else if (pType.equals(2)) {//类型为2,则为阿里云OSS
-            int sourceId = 2;
-            ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
+        } else if(sourceId.equals(2)){//类型为2,则为阿里云OSS
         }
     }
 
 
+
 }

+ 2 - 2
src/main/java/com/example/fms/service/FileMangerService.java

@@ -105,9 +105,9 @@ public class FileMangerService {
                 //根据id到表中查询该文件记录的数据
                 SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
                 //pType判断是服务器还是阿里云OSS
-                int pType = systemFileVO.getPType();
+                int sourceId = systemFileVO.getSourceId();
                 String filePath = systemFileVO.getFilePath();
-                fileFactoryService.delete(filePath, pType);
+                fileFactoryService.delete(filePath, sourceId);
                 int row = systemFileMapper.deleteById(ids.get(i));
                 if (row != 1) {
                     throw new XiaoShiException("删除异常");

+ 7 - 3
src/main/java/com/example/fms/service/SystemFileService.java

@@ -3,7 +3,10 @@ package com.example.fms.service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.example.fms.common.model.dto.SystemFileDTO;
 import com.example.fms.common.model.dto.SystemFileUpdateDTO;
+import com.example.fms.common.model.vo.PersonnelVO;
 import com.example.fms.common.model.vo.SystemFileVO;
+import com.example.fms.common.utils.CacheUtils;
+import com.example.fms.common.utils.SecurityUtils.LoginUtils;
 import com.example.fms.domain.SystemFile;
 import com.example.fms.exception.XiaoShiException;
 import com.example.fms.mapper.SystemFileMapper;
@@ -24,7 +27,8 @@ import java.util.List;
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class SystemFileService extends ServiceImpl<SystemFileMapper, SystemFile> {
-
+    private final CacheUtils cacheUtils;
+    private final LoginUtils loginUtils;
     /**
      * 新增系统文件(批量)
      *
@@ -40,9 +44,9 @@ public class SystemFileService extends ServiceImpl<SystemFileMapper, SystemFile>
                 //取集合中的dto对象,并赋值给实体类
                 SystemFileDTO systemFileDTO = systemFileDTOS.get(i);
                 BeanUtils.copyProperties(systemFileDTO, systemFile);
-                //获取当前登陆人的信息
+//                //获取当前登陆人的信息
 //                PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
-                //给实体类赋值登陆人id
+//                //给实体类赋值登陆人id
 //                systemFile.setCreateId(personnelVO.getId());
                 systemFile.setCreateId(1);
                 systemFile.setPType(sourceId);

+ 5 - 4
src/main/resources/mapper/SystemFileMapper.xml

@@ -5,8 +5,8 @@
     <!--新增系统文件-->
     <!--int add(SystemFile systemFile);-->
     <insert id="add" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO SYSTEM_FILE(GUID, P_TYPE, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, IS_DELETE)
-        VALUES (#{GUID}, #{pType}, #{filePath}, #{fileName}, #{originalName}, #{fileLength},#{createId}, #{updateTime}, #{isDelete})
+        INSERT INTO SYSTEM_FILE(GUID, P_TYPE, SOURCE_ID, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, IS_DELETE)
+        VALUES (#{GUID}, #{pType}, #{sourceId}, #{filePath}, #{fileName}, #{originalName}, #{fileLength},#{createId}, #{updateTime}, #{isDelete})
     </insert>
 
 
@@ -46,14 +46,14 @@
     <!--查询系统文件-->
     <!--SystemFileVO query(Integer id);-->
     <select id="query" resultMap="queryMap">
-        SELECT ID, GUID, P_TYPE, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, CREATE_TIME, IS_DELETE
+        SELECT ID, GUID, P_TYPE, SOURCE_ID, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, CREATE_TIME, IS_DELETE
         FROM SYSTEM_FILE
         WHERE ID = #{id}
         ORDER BY CREATE_TIME DESC
     </select>
 
     <select id="getSystemFile" resultMap="queryMap">
-        SELECT ID, GUID, P_TYPE, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, CREATE_TIME, IS_DELETE
+        SELECT ID, GUID, P_TYPE, SOURCE_ID, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, CREATE_TIME, IS_DELETE
         FROM SYSTEM_FILE
         WHERE FILE_NAME = #{fileName}
         ORDER BY CREATE_TIME DESC
@@ -64,6 +64,7 @@
         <id column="ID" property="id"/>
         <result column="GUID" property="GUID"/>
         <result column="P_TYPE" property="pType"/>
+        <result column="SOURCE_ID" property="sourceId"/>
         <result column="FILE_PATH" property="filePath"/>
         <result column="FILE_NAME" property="fileName"/>
         <result column="ORIGINAL_NAME" property="originalName"/>

+ 36 - 36
target/classes/configSetting.json

@@ -1,38 +1,38 @@
 [
-  {
-    "sourceId": "1",
-    "sourceName": "FSS",
-    "name": "192.168.1.24",
-    "id": 1,
-    "userName": "root",
-    "passWord": "xiaoshi221101",
-    "filePath": "/project/pas/prod/file/"
-  },
-  {
-    "sourceId": "2",
-    "sourceName": "FSS",
-    "name": "192.168.1.24",
-    "id": 1,
-    "userName": "root",
-    "passWord": "xiaoshi221101",
-    "filePath": "/project/rms/prod/file/"
-  },
-  {
-    "sourceId": "3",
-    "sourceName": "FSS",
-    "name": "139.224.24.90",
-    "id": 1,
-    "userName": "root",
-    "passWord": "cslg-pas-820f1e412aaf",
-    "filePath": "/project/pas/prod/file/"
-  },
-  {
-    "sourceId": "4",
-    "sourceName": "FSS",
-    "name": "139.224.24.90",
-    "id": 1,
-    "userName": "root",
-    "passWord": "cslg-pas-820f1e412aaf",
-    "filePath": "/project/rms/prod/file/"
-  }
+    {
+        "sourceId": "1",
+        "sourceName": "FSS",
+        "name": "192.168.1.24",
+        "id": 1,
+        "userName": "root",
+        "passWord": "xiaoshi221101",
+        "filePath": "/project/pas/prod/file/"
+    },
+    {
+        "sourceId": "1",
+        "sourceName": "FSS",
+        "name": "192.168.1.24",
+        "id": 2,
+        "userName": "root",
+        "passWord": "xiaoshi221101",
+        "filePath": "/project/rms/prod/file/"
+    },
+    {
+        "sourceId": "1",
+        "sourceName": "FSS",
+        "name": "139.224.24.90",
+        "id": 3,
+        "userName": "root",
+        "passWord": "cslg-pas-820f1e412aaf",
+        "filePath": "/project/pas/prod/file/"
+    },
+    {
+        "sourceId": "1",
+        "sourceName": "FSS",
+        "name": "139.224.24.90",
+        "id": 4,
+        "userName": "root",
+        "passWord": "cslg-pas-820f1e412aaf",
+        "filePath": "/project/rms/prod/file/"
+    }
 ]