xiexiang 2 anos atrás
pai
commit
4e438922f4

+ 26 - 0
pom.xml

@@ -27,6 +27,32 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.cslg</groupId>
+            <artifactId>pas</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.6.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.jcraft</groupId>
+            <artifactId>jsch</artifactId>
+            <version>0.1.53</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.6.5</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 47 - 0
src/main/java/com/example/fms/common/model/BaseEntity.java

@@ -0,0 +1,47 @@
+package com.example.fms.common.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * Entity基类
+ *
+ * @Author xiexiang
+ * @Date 2023/6/12
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class BaseEntity<T extends Model> extends Model {
+    private static final long serialVersionUID = -4851055162892178225L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "ID", type = IdType.AUTO)
+    private Integer id;
+
+//    /**
+//     * 创建人
+//     */
+//    @TableField(value = "CREATE_USER", fill = FieldFill.INSERT)
+//    private Integer createUser;
+
+//    /**
+//     * 创建时间
+//     */
+//    @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
+//    private Date createTime;
+
+//    /**
+//     * 删除标记(1是0否)
+//     */
+//    @TableField(value = "IS_DELETE")
+//    @TableLogic(value = "0", delval = "1")
+//    private int isDelete;
+
+}

+ 9 - 8
src/main/java/com/example/fms/controller/FileMangerController.java

@@ -6,10 +6,7 @@ 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.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -26,22 +23,26 @@ import java.util.List;
 public class FileMangerController {
     private final IFileManagerService fileManagerService;
 
+
     @PostMapping("/uploadSystemFile")
     @Operation(summary = "上传文件")
-    public String upload(List<MultipartFile> files, Integer sourceId) {
+    public String upload(@RequestBody List<MultipartFile> files, Integer sourceId) {
+        //sourceId为1,是FSS
         fileManagerService.add(files, sourceId);
         return Response.success("上传系统文件成功");
     }
 
-    @PostMapping()
+    @PostMapping("/downloadSystemFile")
     @Operation(summary = "取出文件")
-    public String download(){
+    public String download(@RequestBody String fileName, String savePath, Integer sourceId){
+        //sourceId为1,是FSS
+        fileManagerService.download(fileName, savePath, sourceId);
         return Response.success();
     }
 
     @PostMapping("/deleteSystemFile")
     @Operation(summary = "删除文件")
-    public String delete(@RequestParam List<Integer> ids, Integer type){
+    public String delete(@RequestBody List<Integer> ids, Integer type){
         fileManagerService.delete(ids, type);
         return Response.success("删除系统文件成功");
     }

+ 62 - 0
src/main/java/com/example/fms/controller/TestController.java

@@ -0,0 +1,62 @@
+package com.example.fms.controller;
+
+import com.example.fms.common.utils.Response;
+import com.example.fms.domain.Test;
+import com.example.fms.service.TestService;
+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 java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/6/13
+ */
+@Tag(name = "测试管理")
+@Slf4j
+@RequiredArgsConstructor
+@RestController
+@RequestMapping( "/Test")
+public class TestController {
+    private final TestService testService;
+
+    @Operation(summary = "测试新增")
+    @PostMapping("/TestAdd")
+    public String add(@RequestBody Test test) {
+        testService.add(test);
+        return Response.success();
+    }
+
+    @Operation(summary = "测试更新")
+    @PostMapping("/TestUpdate")
+    public String update(@RequestBody Test test) {
+        testService.update(test);
+        return Response.success();
+    }
+
+    @Operation(summary = "测试查询")
+    @PostMapping("/TestQuery")
+    public String query() {
+        List<Test> tests = testService.query2();
+        return Response.success(tests);
+    }
+
+    @Operation(summary = "测试查询1")
+    @PostMapping("/TestQuery1")
+    public String query1(String Name) {
+        Test test = testService.query1(Name);
+        return Response.success(test);
+    }
+
+    @Operation(summary = "测试删除")
+    @GetMapping("/TestDelete")
+    public String delete(String name){
+        testService.delete(name);
+        return Response.success();
+    }
+
+
+}

+ 37 - 0
src/main/java/com/example/fms/domain/Test.java

@@ -0,0 +1,37 @@
+package com.example.fms.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.example.fms.common.model.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/6/12
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+@TableName(value = "TEST")
+public class Test extends BaseEntity<Test> {
+
+    @TableField(value = "NAME")
+    private String name;
+
+    @TableField(value = "SEX")
+    private String sex;
+
+    @TableField(value = "ADDRESS")
+    private String address;
+
+    @TableField(value = "PHONE")
+    private String phone;
+
+    @TableField(value = "CREATE_TIME")
+    private String createTime;
+
+
+
+}

+ 13 - 0
src/main/java/com/example/fms/mapper/TestMapper.java

@@ -0,0 +1,13 @@
+package com.example.fms.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.fms.domain.Test;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/6/12
+ */
+@Mapper
+public interface TestMapper extends BaseMapper<Test> {
+}

+ 44 - 13
src/main/java/com/example/fms/service/FileFactoryService.java

@@ -4,6 +4,7 @@ import com.example.fms.common.model.dto.SystemFileDTO;
 import com.example.fms.common.model.vo.ConfigSettingVO;
 import com.example.fms.common.utils.ExcuteConfigUtils;
 import com.example.fms.common.utils.FileUtils;
+import com.example.fms.common.utils.SFTP;
 import com.example.fms.exception.XiaoShiException;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -14,7 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.util.*;
 
 /**
- * 上传文件工厂类
+ * 文件工厂类
  *
  * @Author xiexiang
  * @Date 2023/6/2
@@ -76,6 +77,48 @@ public class FileFactoryService {
         return systemFileDTOS;
     }
 
+    /**
+     * 上传到OSS阿里云
+     *
+     * @param files
+     * @param configSettingVO
+     * @return
+     */
+    public List<SystemFileDTO> uploadToOSS(List<MultipartFile> files, ConfigSettingVO configSettingVO){
+        return null;
+    }
+
+    /**
+     * 下载文件
+     *
+     * @param fileName
+     * @param savePath
+     * @param sourceId
+     */
+    public static void download(String fileName, String savePath, Integer sourceId){
+        //调用解析配置方法,获取配置信息
+        List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
+        //根据传入sourceId判断从哪里删除数据
+        ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
+        if (configSettingVO == null) {
+            throw new XiaoShiException("解析错误");
+        }
+        String sourceName = configSettingVO.getSourceName();
+        if (sourceName.equals("FSS")) {
+            return this.downloadFromFSS(configSettingVO);
+        }
+    }
+
+    public static void downloadFromFSS(String directory, String downloadFile, String saveFile, ConfigSettingVO configSettingVO){
+
+        SftpService.download(directory, downloadFile, saveFile, configSettingVO);
+    }
+    /**
+     * 删除文件
+     *
+     * @param filePath
+     * @param pType
+     */
     public static void delete(String filePath, Integer pType){
         //调用解析配置方法,获取配置信息
         List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
@@ -104,16 +147,4 @@ public class FileFactoryService {
 
 
 
-    /**
-     * 上传到OSS阿里云
-     *
-     * @param files
-     * @param configSettingVO
-     * @return
-     */
-    public List<SystemFileDTO> uploadToOSS(List<MultipartFile> files, ConfigSettingVO configSettingVO){
-        return null;
-    }
-
-
 }

+ 9 - 0
src/main/java/com/example/fms/service/IFileManagerService.java

@@ -27,4 +27,13 @@ public interface IFileManagerService {
      */
     @Transactional
     void delete(List<Integer> ids, Integer type);
+
+    /**
+     * 下载系统文件
+     *
+     * @param fileName
+     * @param savePath
+     * @param sourceId
+     */
+    void download(String fileName, String savePath, Integer sourceId);
 }

+ 39 - 3
src/main/java/com/example/fms/service/SftpService.java

@@ -10,9 +10,7 @@ import com.jcraft.jsch.*;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
+import java.io.*;
 import java.util.List;
 import java.util.Properties;
 
@@ -166,6 +164,44 @@ public class SftpService {
     }
 
     /**
+     * 下载文件
+     * @param directory 下载目录 根据SFTP设置的根目录来进行传输
+     * @param downloadFile 下载的文件
+     * @param saveFile 存在本地的路径
+     * @param configSettingVO
+     * @throws Exception
+     */
+    public static void download(String directory, String downloadFile, String saveFile, ConfigSettingVO configSettingVO) throws Exception {
+        SFTP s = new SFTP();
+        //建立连接
+        getConnect(s, configSettingVO);
+        Session session = s.getSession();
+        Channel channel = s.getChannel();
+        //sftp操作类
+        ChannelSftp sftp = s.getSftp();
+        try {
+            //进入目录
+            sftp.cd(directory);
+            File file = new File(saveFile);
+            boolean bFile;
+            bFile = false;
+            bFile = file.exists();
+            if (!bFile) {
+                //创建目录
+                bFile = file.mkdirs();
+            }
+            OutputStream out = new FileOutputStream(new File(saveFile, downloadFile));
+            sftp.get(downloadFile, out);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            throw new Exception(e.getMessage(), e);
+        } finally {
+            disConn(session, channel, sftp);
+        }
+    }
+
+    /**
      * 删除文件
      * @param directory
      * @param deleteFile

+ 54 - 0
src/main/java/com/example/fms/service/TestService.java

@@ -0,0 +1,54 @@
+package com.example.fms.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.example.fms.domain.Test;
+import com.example.fms.mapper.TestMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/6/12
+ */
+@Service
+@Slf4j
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class TestService extends ServiceImpl<TestMapper, Test> {
+
+    public void add(Test test){
+        test.setName("Tse");
+        test.setAddress("江苏省玉山镇");
+        test.setPhone("18625069786");
+        test.insert();
+    }
+
+    public void update(Test test){
+        test.setName("Sxy");
+        test.updateById();
+    }
+
+    public List<Test> query2(){
+        List<Test> tests = this.list();
+        System.out.println("tests = " + tests);
+        return tests;
+    }
+
+    public Test query1(String name){
+        LambdaQueryWrapper<Test> LW = new LambdaQueryWrapper<>();
+        LW.eq(Test::getName, name);
+        Test test = this.getOne(LW);
+        System.out.println("test = " + test);
+        return test;
+    }
+
+    public void delete(String name){
+        Test test = this.query1(name);
+        test.deleteById();
+    }
+}

+ 19 - 2
src/main/java/com/example/fms/service/impl/FileManagerServiceImpl.java

@@ -35,6 +35,12 @@ public class FileManagerServiceImpl implements IFileManagerService {
     private final ISystemFileService systemFileService;
     private final SystemFileMapper systemFileMapper;
 
+    /**
+     * 上传文件
+     *
+     * @param files
+     * @param sourceId
+     */
     @Override
     public void add(List<MultipartFile> files, Integer sourceId){
         if(files != null && files.size() != 0){
@@ -52,8 +58,17 @@ public class FileManagerServiceImpl implements IFileManagerService {
     }
 
     //取系统文件
+    @Override
+    public void download(String fileName, String savePath, Integer sourceId){
+
 
-    //删除系统文件
+    }
+    /**
+     * 删除系统文件
+     *
+     * @param ids
+     * @param type
+     */
     @Override
     public void delete(List<Integer> ids, Integer type){
         //首先判断传入的需要删除的id集合不能为空
@@ -63,7 +78,7 @@ public class FileManagerServiceImpl implements IFileManagerService {
         if(type == null){
             throw new XiaoShiException("删除类型不能为空");
         }
-        //有逻辑删除和物理删除两种,需要进行判定,传入类型为0时,物理删除;传入类型为1时,逻辑删除
+        //有逻辑删除和物理删除两种,需要进行判定,传入类型为2时,物理删除;传入类型为1时,逻辑删除
         //逻辑删除(更新isDelete字段为1)
         if(type.equals(1)){
             //遍历传入的id集合,获取需要更新的对象,赋值给实体类
@@ -95,6 +110,8 @@ public class FileManagerServiceImpl implements IFileManagerService {
                 int row = systemFileMapper.deleteById(ids.get(i));
                 if(row != 1){
                     throw new XiaoShiException("删除异常");
+                } else {
+                    log.info("删除成功");
                 }
             }
         }

+ 3 - 2
src/main/java/com/example/fms/service/impl/SystemFileServiceImpl.java

@@ -47,9 +47,10 @@ public class SystemFileServiceImpl implements ISystemFileService {
                 SystemFileDTO systemFileDTO = systemFileDTOS.get(i);
                 BeanUtils.copyProperties(systemFileDTO, systemFile);
                 //获取当前登陆人的信息
-                PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+//                PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
                 //给实体类赋值登陆人id
-                systemFile.setCreateId(personnelVO.getId());
+//                systemFile.setCreateId(personnelVO.getId());
+                systemFile.setCreateId(1);
                 //插入数据
                 int row = systemFileMapper.add(systemFile);
                 //判断正确性

+ 30 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,30 @@
+spring:
+  rabbitmq.host: 192.168.1.24
+  rabbitmq.port: 5672
+  rabbitmq.username: admin
+  rabbitmq.password: 123456
+  redis:
+    host: 192.168.1.24
+    port: 6379
+    database: 3
+    password: Xx0GWxdWQJxx6Swe
+    lettuce:
+      pool:
+        max-active: 20
+        max-idle: 20
+        min-idle: 0
+        max-wait: -1ms
+    timeout: 2000ms
+  datasource:
+    url: jdbc:mysql://192.168.1.24:3306/PCS_TEST?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=GMT%2B8
+    username: root
+    password: rrzTwWAYX8Gxh5JH
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    type: com.alibaba.druid.pool.DruidDataSource
+    druid:
+      stat-view-servlet:
+        login-username: admin
+        login-password: 123456
+      web-stat-filter:
+        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
+queueName: emailProd.queue

+ 0 - 1
src/main/resources/application.properties

@@ -1 +0,0 @@
-

+ 47 - 0
src/main/resources/application.yml

@@ -0,0 +1,47 @@
+server:
+  servlet:
+    context-path: /
+  port: 8111
+sa-token:
+  activity-timeout: 18000
+  token-name: token
+  token-style: tik
+  #  是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
+  is-concurrent: true
+  timeout: 604800
+spring:
+  thymeleaf:
+    cache: false
+    mode: HTML5
+  aop:
+    auto: true
+    proxy-target-class: true
+  application:
+    name: pcs
+  servlet:
+    multipart:
+      max-file-size: 1000MB
+      max-request-size: 1000MB
+  profiles:
+    active: dev
+  jackson:
+    default-property-inclusion: non_null
+    serialization:
+      INDENT_OUTPUT: true
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: Asia/Shanghai
+#mybatis
+mybatis-plus:
+  typeAliasesPackage: cn.cslg.permission.entity
+  global-config:
+    db-config:
+      id-type: AUTO
+      logic-delete-value: 0
+      logic-not-delete-value: 1
+  configuration:
+    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+  mapper-locations: classpath:mapper/*.xml
+
+

+ 7 - 3
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, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, IS_DELETE)
-        VALUES (#{GUID}, #{filePath}, #{fileName}, #{originalName}, #{fileLength},#{createId}, #{updateTime}, #{isDelete})
+        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>
 
 
@@ -18,6 +18,9 @@
             <if test="GUID != null">
                 GUID = #{GUID},
             </if>
+            <if test="pType != null">
+                P_TYPE = #{pType},
+            </if>
             <if test="filePath != null">
                 FILE_PATH = #{filePath},
             </if>
@@ -43,7 +46,7 @@
     <!--查询系统文件-->
     <!--SystemFileVO query(Integer id);-->
     <select id="query" resultMap="queryMap">
-        SELECT ID, GUID, FILE_PATH, FILE_NAME, ORIGINAL_NAME, FILE_LENGTH, CREATE_ID, UPDATE_TIME, CREATE_TIME, IS_DELETE
+        SELECT ID, GUID, P_TYPE, 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
@@ -52,6 +55,7 @@
     <resultMap id="queryMap" type="com.example.fms.common.model.vo.SystemFileVO">
         <id column="ID" property="id"/>
         <result column="GUID" property="GUID"/>
+        <result column="P_TYPE" property="pType"/>
         <result column="FILE_PATH" property="filePath"/>
         <result column="FILE_NAME" property="fileName"/>
         <result column="ORIGINAL_NAME" property="originalName"/>

+ 29 - 0
src/test/java/com/example/fms/service/FileFactoryServiceTests.java

@@ -0,0 +1,29 @@
+package com.example.fms.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.example.fms.common.model.vo.ConfigSettingVO;
+import com.example.fms.common.utils.DateUtils;
+import com.example.fms.common.utils.ExcuteConfigUtils;
+import com.jcraft.jsch.JSch;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/6/6
+ */
+@Slf4j
+@SpringBootTest
+public class FileFactoryServiceTests {
+
+    @Test
+    public void uploadFiles(){
+
+    }
+
+}