Forráskód Böngészése

Merge branch 'feature/lgs/定时任务' of huabei/admin-api into develop

luguangshan 1 éve
szülő
commit
ed5008b4a0

+ 18 - 4
pom.xml

@@ -15,6 +15,7 @@
     <description>后台管理系统API</description>
     <properties>
         <java.version>1.8</java.version>
+        <mybatis-plus.version>3.4.1</mybatis-plus.version>
     </properties>
 
     <dependencies>
@@ -110,9 +111,18 @@
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
-            <version>3.2.0</version>
+            <version>${mybatis-plus.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-generator</artifactId>
+            <version>${mybatis-plus.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.28</version>
         </dependency>
-
         <!--数据源-->
         <dependency>
             <groupId>com.alibaba</groupId>
@@ -168,8 +178,6 @@
             </exclusions>
         </dependency>
 
-
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
@@ -228,6 +236,12 @@
             <artifactId>juniversalchardet</artifactId>
             <version>1.0.3</version>
         </dependency>
+        <!-- xxl-job依赖 -->
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+            <version>2.3.1</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 0 - 4
src/main/java/com/kexun/admin/TestController.java

@@ -1,4 +0,0 @@
-package com.kexun.admin;
-
-public class TestController {
-}

+ 54 - 0
src/main/java/com/kexun/config/XxlJobConfig.java

@@ -0,0 +1,54 @@
+package com.kexun.config;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Description:
+ *
+ * @author lgs
+ * @date 2023/05/04
+ */
+@Configuration
+@Slf4j
+public class XxlJobConfig {
+
+    @Value("${xxl.job.admin.addresses}")
+    private String adminAddresses;
+
+    @Value("${xxl.job.accessToken}")
+    private String accessToken;
+
+    @Value("${xxl.job.executor.appname}")
+    private String appname;
+
+    @Value("${xxl.job.executor.ip}")
+    private String ip;
+
+    @Value("${xxl.job.executor.port}")
+    private int port;
+
+    @Value("${xxl.job.executor.logpath}")
+    private String logPath;
+
+    @Value("${xxl.job.executor.logretentiondays}")
+    private int logRetentionDays;
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+        log.info(">>>>>>>>>>> xxl-job config init.");
+        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+        xxlJobSpringExecutor.setAppname(appname);
+        xxlJobSpringExecutor.setIp(ip);
+        xxlJobSpringExecutor.setPort(port);
+        xxlJobSpringExecutor.setAccessToken(accessToken);
+        xxlJobSpringExecutor.setLogPath(logPath);
+        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+        return xxlJobSpringExecutor;
+    }
+
+}

+ 1 - 7
src/main/java/com/kexun/admin/FieldController.java → src/main/java/com/kexun/controller/FieldController.java

@@ -1,22 +1,16 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.BaseField;
-import com.kexun.entity.CustomizedModel;
 import com.kexun.service.BaseFieldService;
-import com.kexun.service.CustomizedModelService;
 import lombok.extern.java.Log;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
 import java.util.List;
 
 

+ 1 - 6
src/main/java/com/kexun/admin/FileUploadController.java → src/main/java/com/kexun/controller/FileUploadController.java

@@ -1,10 +1,8 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;
-import com.alibaba.fastjson.JSON;
 import com.kexun.common.FileUploadUtil;
-import com.kexun.common.GlobalResult;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.SysUser;
 import com.kexun.entity.UserApproval;
@@ -13,11 +11,9 @@ import com.kexun.service.UserApprovalService;
 import com.kexun.service.UserModelService;
 import lombok.extern.java.Log;
 //import org.aspectj.util.FileUtil;
-import org.apache.tomcat.util.http.fileupload.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.FileCopyUtils;
-import org.springframework.util.FileSystemUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -25,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 
 /**
  * @Author zhangming

+ 1 - 3
src/main/java/com/kexun/admin/LoginController.java → src/main/java/com/kexun/controller/LoginController.java

@@ -1,4 +1,4 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -10,7 +10,6 @@ import com.kexun.common.utils.Result;
 import com.kexun.entity.SysRights;
 import com.kexun.entity.SysRoleRights;
 import com.kexun.entity.SysUser;
-import com.kexun.entity.UserInfo;
 import com.kexun.service.SysRightsService;
 import com.kexun.service.SysRoleRightsService;
 import com.kexun.service.SysUserService;
@@ -21,7 +20,6 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;

+ 1 - 11
src/main/java/com/kexun/admin/ModelController.java → src/main/java/com/kexun/controller/ModelController.java

@@ -1,28 +1,18 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.JSONWriter;
-import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kexun.common.JsonFile;
-import com.kexun.common.User;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.*;
 import com.kexun.service.*;
 //import com.sun.xml.internal.bind.v2.TODO;
-import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.*;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
 import java.util.*;
-import java.sql.*;
 
 /*
  * 目标:实现对字段组合,用户自定义模型的全部操作

+ 1 - 1
src/main/java/com/kexun/admin/ParseController.java → src/main/java/com/kexun/controller/ParseController.java

@@ -1,4 +1,4 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;

+ 1 - 10
src/main/java/com/kexun/admin/PartnerController.java → src/main/java/com/kexun/controller/PartnerController.java

@@ -1,30 +1,21 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.PartnerInfo;
-import com.kexun.entity.SysRole;
-import com.kexun.entity.SysRoleRights;
 import com.kexun.service.PartnerInfoService;
 import lombok.extern.java.Log;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.sql.Time;
 import java.util.Date;
 import java.util.List;
-import java.util.*;
 
 /*
 新添加

+ 1 - 8
src/main/java/com/kexun/admin/RoleController.java → src/main/java/com/kexun/controller/RoleController.java

@@ -1,24 +1,17 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.JSONWriter;
-import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kexun.common.JsonFile;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.*;
 import com.kexun.service.*;
-import org.apache.catalina.User;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.*;
 
 /*

+ 4 - 0
src/main/java/com/kexun/controller/TestController.java

@@ -0,0 +1,4 @@
+package com.kexun.controller;
+
+public class TestController {
+}

+ 1 - 12
src/main/java/com/kexun/admin/TimingPlan.java → src/main/java/com/kexun/controller/TimingPlan.java

@@ -1,25 +1,14 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.kexun.common.FileUploadUtil;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.ParseAuto;
-import com.kexun.entity.SysUser;
-import com.kexun.entity.UserApproval;
-import com.kexun.entity.UserModel;
-import com.kexun.service.CreditUploadService;
 import com.kexun.service.ParseAutoService;
-import com.kexun.service.UserApprovalService;
-import com.kexun.service.UserModelService;
 import lombok.extern.java.Log;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.util.FileCopyUtils;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;

+ 1 - 18
src/main/java/com/kexun/admin/UploadController.java → src/main/java/com/kexun/controller/UploadController.java

@@ -1,35 +1,18 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.kexun.common.FileUploadUtil;
-import com.kexun.common.GlobalResult;
-import com.kexun.common.JsonFile;
-import com.kexun.common.utils.PageResult;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.*;
 import com.kexun.service.CustomizedModelService;
-import com.kexun.service.SysRoleService;
-import com.kexun.service.UserApprovalService;
-import com.kexun.service.UserModelService;
 import lombok.extern.java.Log;
 //import org.aspectj.util.FileUtil;
 import org.apache.commons.lang.StringUtils;
-import org.apache.tomcat.util.http.fileupload.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.util.FileSystemUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.util.List;
 

+ 1 - 2
src/main/java/com/kexun/admin/UserController.java → src/main/java/com/kexun/controller/UserController.java

@@ -1,4 +1,4 @@
-package com.kexun.admin;
+package com.kexun.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -10,7 +10,6 @@ import com.kexun.common.utils.PageResult;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.SysRole;
 import com.kexun.entity.SysUser;
-import com.kexun.entity.UserInfo;
 import com.kexun.service.SysRoleService;
 import com.kexun.service.SysUserService;
 //import com.sun.org.apache.regexp.internal.RE;

+ 9 - 9
src/main/java/com/kexun/entity/FilterResult.java

@@ -30,31 +30,31 @@ public class FilterResult implements Serializable {
     /**
      * 所选字段列表
      */
-    @TableId(value = "filter_info")
+    @TableField(value = "filter_info")
     private String filterInfo;
 
-    @TableId(value = "parse_info")
+    @TableField(value = "parse_info")
     private String parseInfo;
 
-    @TableId(value = "bus_name")
+    @TableField(value = "bus_name")
     private String busName;
 
-    @TableId(value = "model_name")
+    @TableField(value = "model_name")
     private String modelName;
 
-    @TableId(value = "product_num")
+    @TableField(value = "product_num")
     private String productNum;
 
-    @TableId(value = "start_time")
+    @TableField(value = "start_time")
     private String startTime;
 
-    @TableId(value = "end_time")
+    @TableField(value = "end_time")
     private String endTime;
 
-    @TableId(value = "filter_status")
+    @TableField(value = "filter_status")
     private String filterStatus;
 
-    @TableId(value = "model_status")
+    @TableField(value = "model_status")
     private String modelStatus;
     /**
      * 插入数据者

+ 26 - 0
src/main/java/com/kexun/task/DemoJobHandler.java

@@ -0,0 +1,26 @@
+package com.kexun.task;
+
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * Description:
+ *
+ * @author lgs
+ * @date 2023/05/04
+ */
+@Component
+@Slf4j
+public class DemoJobHandler {
+
+    @XxlJob("testHandler")
+    public void test() throws Exception{
+
+        XxlJobHelper.log("XXL-job,Hello World");
+        log.info("testJob");
+
+    }
+
+}

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

@@ -76,6 +76,25 @@ config:
     path: "D:/jin_rong/model_data/"
     warpath: "D:/jin_rong/model_data/"
 
+xxl:
+  job:
+    admin:
+      addresses: http://localhost:8080/xxl-job-admin/
+      ### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
+    executor:
+      appname: admin-api
+      ### 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
+      address:
+      ### 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
+      ip:
+        ### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
+      port: 18888
+        ### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
+      logpath: /Users/lgs/work/code/logs/xxl-job/
+        ### 执行器日志保存天数 [选填] :值大于3时生效,启用执行器Log文件定期清理功能,否则不生效;
+      logretentiondays: 7
+      ### 执行器通讯TOKEN [选填]:非空时启用;
+    accessToken: default_token
 
 
 

+ 96 - 0
src/test/java/com/kexun/MybatisPlusCodeGenerator.java

@@ -0,0 +1,96 @@
+package com.kexun;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.rules.DateType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
+
+/**
+ * Description:
+ *
+ * @author lgs
+ * @date 2023/05/05
+ */
+public class MybatisPlusCodeGenerator {
+
+    public static void main(String[] args) {
+        //====================配置变量区域=====================//
+        String author="lgs";//生成文件的作者,可以不填
+        String rootPackage="com.kexun";//生成的entity、controller、service等包所在的公共上一级包路径全限定名
+
+        String moduleName="admin-api";
+        //数据库配置
+        String url="jdbc:mysql://39.101.189.130:33306/cr_loan?useSSL=false&characterEncoding=utf8";
+        String driverClassName="com.mysql.jdbc.Driver";//或者com.mysql.cj.jdbc.Driver
+        String username="root";
+        String password="1q2w3e4r";
+        String tableNames="field_define";//表名,多个使用,分隔
+        //====================配置变量区域=====================//
+
+        // 代码生成器
+        AutoGenerator generator = new AutoGenerator();
+        // 全局配置
+        GlobalConfig globalConfig = new GlobalConfig();
+        String projectPath = System.getProperty("user.dir");
+        System.out.println(projectPath);
+
+        globalConfig.setOutputDir(projectPath +"/"+moduleName+"/src/main/java");
+        globalConfig.setFileOverride(false);//是否覆盖已有文件,默认false
+        globalConfig.setOpen(false);//是否打开输出目录
+        globalConfig.setAuthor(author);
+        globalConfig.setServiceName("%sService");//去掉service接口的首字母I
+        globalConfig.setBaseResultMap(true);//开启 BaseResultMap
+        globalConfig.setDateType(DateType.ONLY_DATE);//只使用 java.util.date代替
+        globalConfig.setIdType(IdType.ASSIGN_ID);//分配ID (主键类型为number或string)
+        generator.setGlobalConfig(globalConfig);
+
+        // 数据源配置
+        DataSourceConfig dataSourceConfig = new DataSourceConfig();
+        dataSourceConfig.setUrl(url);
+        dataSourceConfig.setDbType(DbType.MYSQL);//数据库类型
+        dataSourceConfig.setDriverName(driverClassName);
+        dataSourceConfig.setUsername(username);
+        dataSourceConfig.setPassword(password);
+        generator.setDataSource(dataSourceConfig);
+
+        // 包配置
+        PackageConfig packageConfig = new PackageConfig();
+        //父包名
+        packageConfig.setParent(rootPackage);//例:org.jeecg.modules.xqxy
+        //父包模块名 默认值无
+        //packageConfig.setModuleName(scanner("模块名"));
+        packageConfig.setController("controller");
+        //Entity 包名
+        packageConfig.setEntity("entity");
+        //Service 包名
+        packageConfig.setService("service");
+        //Service Impl 包名
+        packageConfig.setServiceImpl("service.impl");
+        //Mapper 包名
+        packageConfig.setMapper("mapper");
+        generator.setPackageInfo(packageConfig);
+        //注意:模板引擎在mybatisplus依赖中的templates目录下,可以依照此默认模板进行自定义
+        // 策略配置:配置根据哪张表生成代码
+        StrategyConfig strategy = new StrategyConfig();
+        strategy.setInclude(tableNames);//表名,多个英文逗号分割(与exclude二选一配置)
+        //表名-下划线转驼峰命名
+        strategy.setNaming(NamingStrategy.underline_to_camel);
+        //列名-下划线转驼峰命名
+        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+
+        //strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
+        strategy.setEntityLombokModel(true);//lombok模型,@Accessors(chain = true)setter链式操作
+        strategy.setRestControllerStyle(true);//controller生成@RestController
+        strategy.setEntityTableFieldAnnotationEnable(true);//是否生成实体时,生成字段注解
+
+        generator.setStrategy(strategy);
+        generator.setTemplateEngine(new FreemarkerTemplateEngine());
+        generator.execute();
+    }
+}