Bläddra i källkod

处理外部配置文件,修复外网同步,修复FTP下载之后删除文件

wukai 1 år sedan
förälder
incheckning
602ebe173f

+ 2 - 2
sync-admin/src/main/resources/application-prod.yml

@@ -47,8 +47,8 @@ spring:
         allow:
         url-pattern: /druid/*
         # 控制台管理用户名和密码
-        login-username: ruoyi
-        login-password: 123456
+        login-username: uadmin
+        login-password: uadmin
       filter:
         stat:
           enabled: true

+ 202 - 0
sync-admin/src/main/resources/my-application.yml

@@ -0,0 +1,202 @@
+# 开发环境配置
+server:
+  # 服务器的HTTP端口,默认为80
+  port: 18080
+  servlet:
+    # 应用的访问路径
+    context-path: /
+  tomcat:
+    # tomcat的URI编码
+    uri-encoding: UTF-8
+    # 连接数满后的排队数,默认为100
+    accept-count: 1000
+    threads:
+      # tomcat最大线程数,默认为200
+      max: 800
+      # Tomcat启动初始化的线程数,默认值10
+      min-spare: 100
+# 数据源配置
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driverClassName: com.mysql.cj.jdbc.Driver
+    druid:
+      # 主库数据源
+      master:
+        url: jdbc:mysql://192.168.188.88:3306/xjsync?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        username: root
+        password: 123456
+      # 从库数据源
+      slave:
+        # 从数据源开关/默认关闭
+        enabled: false
+        url:
+        username:
+        password:
+      # 初始连接数
+      initialSize: 5
+      # 最小连接池数量
+      minIdle: 10
+      # 最大连接池数量
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置连接超时时间
+      connectTimeout: 30000
+      # 配置网络超时时间
+      socketTimeout: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      # 配置一个连接在池中最大生存的时间,单位是毫秒
+      maxEvictableIdleTimeMillis: 900000
+      # 配置检测连接是否有效
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      webStatFilter:
+        enabled: true
+      statViewServlet:
+        enabled: true
+        # 设置白名单,不填则允许所有访问
+        allow:
+        url-pattern: /druid/*
+        # 控制台管理用户名和密码
+        login-username: uadmin
+        login-password: uadmin
+      filter:
+        stat:
+          enabled: true
+          # 慢SQL记录
+          log-slow-sql: true
+          slow-sql-millis: 1000
+          merge-sql: true
+        wall:
+          config:
+            multi-statement-allow: true
+
+
+  # 模板引擎
+  thymeleaf:
+    mode: HTML
+    encoding: utf-8
+    # 禁用缓存
+    cache: false
+  # 资源信息
+  messages:
+    # 国际化资源文件路径
+    basename: static/i18n/messages
+  jackson:
+    time-zone: GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
+  profiles:
+    active: dev
+  # 文件上传
+  servlet:
+    multipart:
+      # 单个文件大小
+      max-file-size: 10MB
+      # 设置总上传的文件大小
+      max-request-size: 20MB
+  # 服务模块
+  devtools:
+    restart:
+      # 热部署开关
+      enabled: true
+
+# 项目相关配置
+ruoyi:
+  # 名称
+  name: RuoYi
+  # 版本
+  version: 4.7.7
+  # 版权年份
+  copyrightYear: 2023
+  # 实例演示开关
+  demoEnabled: false
+  # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
+  profile: D:/ruoyi/uploadPath
+  # 获取ip地址开关
+  addressEnabled: false
+
+# 日志配置
+logging:
+  level:
+    com.jjt: debug
+    org.springframework: warn
+
+# 用户配置
+user:
+  password:
+    # 密码错误{maxRetryCount}次锁定10分钟
+    maxRetryCount: 5
+
+# MyBatis
+mybatis:
+  # 搜索指定包别名
+  typeAliasesPackage: com.jjt.**.domain
+  # 配置mapper的扫描,找到所有的mapper.xml映射文件
+  mapperLocations: classpath*:mapper/**/*Mapper.xml
+  # 加载全局的配置文件
+  configLocation: classpath:mybatis/mybatis-config.xml
+
+# PageHelper分页插件
+pagehelper:
+  helperDialect: mysql
+  supportMethodsArguments: true
+  params: count=countSql
+
+# Shiro
+shiro:
+  user:
+    # 登录地址
+    loginUrl: /login
+    # 权限认证失败地址
+    unauthorizedUrl: /unauth
+    # 首页地址
+    indexUrl: /index
+    # 验证码开关
+    captchaEnabled: false
+    # 验证码类型 math 数组计算 char 字符
+    captchaType: math
+  cookie:
+    # 设置Cookie的域名 默认空,即当前访问的域名
+    domain:
+    # 设置cookie的有效访问路径
+    path: /
+    # 设置HttpOnly属性
+    httpOnly: true
+    # 设置Cookie的过期时间,天为单位
+    maxAge: 30
+    # 设置密钥,务必保持唯一性(生成方式,直接拷贝到main运行即可)Base64.encodeToString(CipherUtils.generateNewKey(128, "AES").getEncoded()) (默认启动生成随机秘钥,随机秘钥会导致之前客户端RememberMe Cookie无效,如设置固定秘钥RememberMe Cookie则有效)
+    cipherKey:
+  session:
+    # Session超时时间,-1代表永不过期(默认30分钟)
+    expireTime: 30
+    # 同步session到数据库的周期(默认1分钟)
+    dbSyncPeriod: 1
+    # 相隔多久检查一次session的有效性,默认就是10分钟
+    validationInterval: 10
+    # 同一个用户最大会话数,比如2的意思是同一个账号允许最多同时两个人登录(默认-1不限制)
+    maxSession: -1
+    # 踢出之前登录的/之后登录的用户,默认踢出之前登录的用户
+    kickoutAfter: false
+  rememberMe:
+    # 是否开启记住我
+    enabled: true
+
+# 防止XSS攻击
+xss:
+  # 过滤开关
+  enabled: true
+  # 排除链接(多个用逗号分隔)
+  excludes: /system/notice/*
+  # 匹配链接
+  urlPatterns: /system/*,/monitor/*,/tool/*
+
+# Swagger配置
+swagger:
+  # 是否开启swagger
+  enabled: true

+ 2 - 2
sync-common/src/main/java/com/jjt/common/utils/FtpUtil.java

@@ -75,8 +75,8 @@ public class FtpUtil {
             // 下载目录下的文件,下载完成后删除
             for (String fileName : fileList) {
                 ftp.download(dir + fileName, FileUtil.file(localDir, fileName));
-                //TODO 先不删除
-                //ftp.delFile(dir + fileName);
+                //不删除那不重复下载了?
+                ftp.delFile(dir + fileName);
             }
             return true;
         } catch (Exception e) {

+ 4 - 3
sync-common/src/main/java/com/jjt/common/utils/LinuxCommand.java

@@ -104,8 +104,9 @@ public class LinuxCommand {
      * @throws Exception 异常说明
      */
     public static void exec(List<String> commands, String dir) throws Exception {
-        log.info("要执行命令了哟:{}", Arrays.toString(commands.toArray()));
+        log.info("要执行脚本了哟:{}", Arrays.toString(commands.toArray()));
         ProcessBuilder processBuilder = new ProcessBuilder(commands);
+
         processBuilder.directory(new File(dir));
 
         Process process = processBuilder.start();
@@ -113,9 +114,9 @@ public class LinuxCommand {
         print(process);
 
         int code = process.waitFor();
-        log.info("命令执行状态:{}", code);
+        log.info("脚本执行状态:{}", code);
         if (code != 0) {
-            throw new Exception("执行命令出错啦!");
+            throw new Exception("执行脚本出错啦!");
         }
     }
 

+ 16 - 11
sync-out/src/main/java/com/jjt/out/service/impl/OutProcessServiceImpl.java

@@ -69,9 +69,9 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
                         long sort = Long.parseLong(file.getName().split("-")[1]);
                         ObjectMapper mapper = new ObjectMapper();
                         FileDesc desc = mapper.readValue(file, FileDesc.class);
-
-                        ZipFile zipFile = new ZipFile(syncDir + desc.getName());
-                        String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.getFile().toPath()));
+                        boolean isZip = desc.getName().indexOf(".zip") != -1;
+                        File syncFile = new File(syncDir + desc.getName());
+                        String md5 = DigestUtils.md5Hex(Files.newInputStream(syncFile.toPath()));
                         if (md5.equals(desc.getMd5())) {
                             Date start = new Date();
                             //上传json文件
@@ -79,23 +79,28 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
                             boolean flag1 = false;
                             //上传zip文件
                             List<File> list = new ArrayList<>();
-                            if (zipFile.isSplitArchive()) {
-                                //如果是分卷压缩文件,则需要读取所有文件名上传
-                                list = zipFile.getSplitZipFiles();
-                                for (File f : list) {
-                                    flag1 = flag && ftpUtil.upload(f);
+                            if (isZip) {
+                                ZipFile zipFile = new ZipFile(syncFile.getPath());
+                                if (zipFile.isSplitArchive()) {
+                                    //如果是分卷压缩文件,则需要读取所有文件名上传
+                                    list = zipFile.getSplitZipFiles();
+                                    for (File f : list) {
+                                        flag1 = flag && ftpUtil.upload(f);
+                                    }
+                                } else {
+                                    flag1 = ftpUtil.upload(zipFile.getFile());
                                 }
                             } else {
-                                flag1 = ftpUtil.upload(zipFile.getFile());
-
+                                flag1 = ftpUtil.upload(syncFile);
                             }
+
                             Date end = new Date();
 
                             String status = "N";
                             if (flag && flag1) {
                                 //移动文件到备份目录
                                 Files.move(file.toPath(), Paths.get(bakDir + file.getName()), StandardCopyOption.REPLACE_EXISTING);
-                                Files.move(zipFile.getFile().toPath(), Paths.get(bakDir + zipFile.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
+                                Files.move(syncFile.toPath(), Paths.get(bakDir + syncFile.getName()), StandardCopyOption.REPLACE_EXISTING);
                                 for (File f : list) {
                                     Files.move(f.toPath(), Paths.get(bakDir + f.getName()), StandardCopyOption.REPLACE_EXISTING);
                                 }