wuhongshuang hace 3 años
commit
40086a880d
Se han modificado 29 ficheros con 1257 adiciones y 0 borrados
  1. 37 0
      .gitignore
  2. 41 0
      README.md
  3. 170 0
      pom.xml
  4. 19 0
      src/main/java/com/szwl/Application.java
  5. 41 0
      src/main/java/com/szwl/config/AsyncExecutorConfig.java
  6. 23 0
      src/main/java/com/szwl/config/MybatisPlusConfig.java
  7. 44 0
      src/main/java/com/szwl/config/SwaggerConfig.java
  8. 9 0
      src/main/java/com/szwl/constant/CacheConsts.java
  9. 8 0
      src/main/java/com/szwl/constant/ConfigConsts.java
  10. 77 0
      src/main/java/com/szwl/constant/ResponseCodesEnum.java
  11. 80 0
      src/main/java/com/szwl/controller/DemoController.java
  12. 35 0
      src/main/java/com/szwl/exception/AuthenticationException.java
  13. 35 0
      src/main/java/com/szwl/exception/BizException.java
  14. 13 0
      src/main/java/com/szwl/exception/MyException.java
  15. 27 0
      src/main/java/com/szwl/exception/ParamNotFoundException.java
  16. 95 0
      src/main/java/com/szwl/exception/RestExceptionHandler.java
  17. 14 0
      src/main/java/com/szwl/feign/bean/SzwlFeign.java
  18. 16 0
      src/main/java/com/szwl/mapper/TAdminMapper.java
  19. 43 0
      src/main/java/com/szwl/mapper/xml/TAdminMapper.xml
  20. 18 0
      src/main/java/com/szwl/model/bo/BasePageQuery.java
  21. 37 0
      src/main/java/com/szwl/model/bo/R.java
  22. 78 0
      src/main/java/com/szwl/model/bo/ResponseModel.java
  23. 109 0
      src/main/java/com/szwl/model/entity/TAdmin.java
  24. 27 0
      src/main/java/com/szwl/model/query/TAdminParam.java
  25. 16 0
      src/main/java/com/szwl/service/TAdminService.java
  26. 20 0
      src/main/java/com/szwl/service/impl/TAdminServiceImpl.java
  27. 40 0
      src/main/resources/bootstrap.yml
  28. 11 0
      src/test/java/com/szwl/ApplicationTests.java
  29. 74 0
      src/test/java/com/szwl/AutoGeneratorTests.java

+ 37 - 0
.gitignore

@@ -0,0 +1,37 @@
+# Created by .ignore support plugin (hsz.mobi)
+
+# Operating System Files
+
+*.DS_Store
+Thumbs.db
+*.sw?
+.#*
+*#
+*~
+*.sublime-*
+
+# Build Artifacts
+
+.gradle/
+build/
+target/
+bin/
+dependency-reduced-pom.xml
+.factorypath
+
+# Eclipse Project Files
+
+.classpath
+.project
+.settings/
+workspace.xml
+
+# IntelliJ IDEA Files
+
+*.iml
+*.ipr
+*.iws
+*.idea
+
+# other code repositories
+.svn

+ 41 - 0
README.md

@@ -0,0 +1,41 @@
+# szwlServer 申泽移动物联
+
+## 注册中心
+http://112.74.63.148:49001/
+可以看到各子服务
+
+## 自动生成代码
+运行 AutoGeneratorTests
+
+## mybatis-plus
+增删查改
+使用参考 https://baomidou.com/pages/24112f/
+
+## swwager2 生成接口文档
+在controller 加上@Api(value = "/test", tags = {"controller描述"})
+接口方法上加上 @ApiOperation(value = "接口描述") 即可。
+文档地址:http://127.0.0.1:端口/doc.html
+
+## 接口返回
+参考 DemoController
+返回体,用 成功:R.ok()  ,默认返回码 00000
+失败:R.fail(ResponseCodesEnum.B0001,"你的错误信息");
+ResponseCodesEnum 为错误码,其中 ALL_OK("00000","SUCCESS") 表示成功
+
+## 子服务之间使用feign 互相调用
+参考 PayFeign
+
+## 使用 hutool 工具类
+参考文档 https://www.bookstack.cn/read/hutool/377f64112be7197a.md
+
+## 配置文件参数使用
+推荐将配置文件的参数,放到数据库表 sys_properties 里面。
+参考 select * from sys_properties a where a.application ='szwl-server'
+使用 参考 DemoController 的 @Value("${test.value:bbb}")
+
+## 部署说明
+把jar 包 放到 /app/appsystem/springcloud
+启动命令:/app/appsystem/startSpringCloud.sh  /app/appsystem/springcloud/你的包名.jar
+查看状态:/app/appsystem/checkSpringCloud.sh
+关闭命令:/app/appsystem/stopSpringCloud.sh /app/appsystem/springcloud/你的包名.jar
+查看日志:vi /app/applogs/szwl-server/szwl-server.log

+ 170 - 0
pom.xml

@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.szwl</groupId>
+	<artifactId>payServer</artifactId>
+	<version>0.0.1</version>
+	<packaging>jar</packaging>
+
+	<name>payServer</name>
+
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.3.12.RELEASE</version>
+	</parent>
+
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+		<java.version>1.8</java.version>
+		<spring-cloud.version>Hoxton.SR12</spring-cloud.version>
+<!--		<mybatis-spring-boot-starter.version>2.2.0</mybatis-spring-boot-starter.version>-->
+		<mybatis-plus.version>3.4.0</mybatis-plus.version>
+		<mybatis.version>3.5.7</mybatis.version>
+	</properties>
+
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.springframework.cloud</groupId>
+				<artifactId>spring-cloud-dependencies</artifactId>
+				<version>${spring-cloud.version}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+			<dependency>
+				<groupId>org.mybatis</groupId>
+				<artifactId>mybatis</artifactId>
+				<version>${mybatis.version}</version>
+			</dependency>
+			<dependency>
+				<groupId>com.baomidou</groupId>
+				<artifactId>mybatis-plus-boot-starter</artifactId>
+				<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.mybatis.spring.boot</groupId>-->
+<!--				<artifactId>mybatis-spring-boot-starter</artifactId>-->
+<!--				<version>${mybatis-spring-boot-starter.version}</version>-->
+<!--			</dependency>-->
+		</dependencies>
+	</dependencyManagement>
+
+	<dependencies>
+		<!-- springcloud组件 start -->
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-openfeign</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-config</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-actuator</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+<!--		<dependency>-->
+<!--			<groupId>org.springframework.boot</groupId>-->
+<!--			<artifactId>spring-boot-starter-jdbc</artifactId>-->
+<!--		</dependency>-->
+		<!-- springcloud组件 end -->
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+		</dependency>
+
+		<!-- mybatis-plus -->
+		<dependency>
+			<groupId>com.baomidou</groupId>
+			<artifactId>mybatis-plus-boot-starter</artifactId>
+		</dependency>
+		<!--mybatisplus代码生成 start -->
+		<dependency>
+			<groupId>com.baomidou</groupId>
+			<artifactId>mybatis-plus-generator</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity-engine-core</artifactId>
+			<version>2.2</version>
+		</dependency>
+		<!--mybatisplus代码生成 end -->
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+		</dependency>
+		<!-- swagger2 -->
+		<dependency>
+			<groupId>com.github.xiaoymin</groupId>
+			<artifactId>knife4j-spring-boot-starter</artifactId>
+			<version>3.0.3</version>
+		</dependency>
+		<dependency>
+			<groupId>ch.ethz.ganymed</groupId>
+			<artifactId>ganymed-ssh2</artifactId>
+			<version>build210</version>
+		</dependency>
+		<!-- json -->
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.75</version>
+		</dependency>
+		<!-- hutool -->
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-core</artifactId>
+			<version>5.7.16</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<configuration>
+					<layout>ZIP</layout>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<repositories>
+		<repository>
+			<id>nexus</id>
+			<url>http://www.redouble.store:1888/repository/maven-public/</url>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+			<snapshots>
+				<enabled>false</enabled>
+			</snapshots>
+		</repository>
+	</repositories>
+
+
+</project>

+ 19 - 0
src/main/java/com/szwl/Application.java

@@ -0,0 +1,19 @@
+package com.szwl;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+@SpringBootApplication
+@EnableEurekaClient
+@EnableFeignClients
+@MapperScan("com.szwl.mapper")
+public class Application{
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
+
+

+ 41 - 0
src/main/java/com/szwl/config/AsyncExecutorConfig.java

@@ -0,0 +1,41 @@
+package com.szwl.config;
+
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+/**
+ * 异步注解线程池配置
+ *
+ * @author wuhs
+ * @date 2021-10-08 16:36
+ */
+@Configuration
+@ConditionalOnProperty(name = "ommo.common.async.executor.override", havingValue = "true")
+public class AsyncExecutorConfig implements AsyncConfigurer {
+
+    private static final int CORE_NUMS = Runtime.getRuntime().availableProcessors();
+
+    @Override
+    public Executor getAsyncExecutor() {
+        ThreadPoolTaskExecutor asyncExecutor = new ThreadPoolTaskExecutor();
+        //根据io密集型创建线程池
+        asyncExecutor.setCorePoolSize(2 * CORE_NUMS);
+        asyncExecutor.setMaxPoolSize(5 * CORE_NUMS);
+        asyncExecutor.setKeepAliveSeconds(60);
+        asyncExecutor.setQueueCapacity(100);
+        asyncExecutor.setThreadNamePrefix("async-executor-");
+        asyncExecutor.initialize();
+        return asyncExecutor;
+    }
+
+    @Override
+    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
+        return new SimpleAsyncUncaughtExceptionHandler();
+    }
+}

+ 23 - 0
src/main/java/com/szwl/config/MybatisPlusConfig.java

@@ -0,0 +1,23 @@
+package com.szwl.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@Configuration
+@EnableTransactionManagement
+public class MybatisPlusConfig {
+    /**
+     * 分页插件,自动识别数据库类型 多租户,请参考官网【插件扩展】
+     */
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+        return interceptor;
+    }
+
+}

+ 44 - 0
src/main/java/com/szwl/config/SwaggerConfig.java

@@ -0,0 +1,44 @@
+package com.szwl.config;
+
+import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+@Configuration
+@EnableSwagger2
+@EnableKnife4j
+public class SwaggerConfig {
+    @Value("${spring.application.name:}")
+    String applicationName;
+
+    private static final String SPLIT = ";";
+
+    @Bean
+    public Docket createRestApi() {
+        return new Docket(DocumentationType.SWAGGER_2)
+                .apiInfo(apiInfo()).select()
+                .apis(RequestHandlerSelectors.basePackage("com.szwl"))
+                .paths(PathSelectors.any())
+                .build();
+    }
+    /**
+     * http://127.0.0.1:端口/doc.html
+     * @return
+     */
+    private ApiInfo apiInfo() {
+        String title = applicationName + "后台接口";
+        return new ApiInfoBuilder().title(title)
+                .description(title)
+//				.termsOfServiceUrl("www.xxx.com").license("http://www.apache.org/licenses/LICENSE-2.0")
+                .version("1.0")
+                .build();
+    }
+}

+ 9 - 0
src/main/java/com/szwl/constant/CacheConsts.java

@@ -0,0 +1,9 @@
+package com.szwl.constant;
+
+/**
+ * 缓存相关常量
+ */
+public class CacheConsts {
+    public static final String USER_ALL_LIST = "test";
+
+}

+ 8 - 0
src/main/java/com/szwl/constant/ConfigConsts.java

@@ -0,0 +1,8 @@
+package com.szwl.constant;
+
+/**
+ * 系统配置相关常量
+ */
+public class ConfigConsts {
+    public static final String TEST = "TEST";
+}

+ 77 - 0
src/main/java/com/szwl/constant/ResponseCodesEnum.java

@@ -0,0 +1,77 @@
+package com.szwl.constant;
+
+public enum ResponseCodesEnum {
+    ALL_OK("00000","SUCCESS"),
+    A0001("A0001","用户端参数错误"),
+    A0002("A0002","用户端错误"),
+    A0100("A0100","用户注册错误"),
+    A0101("A0101", "出生日期格式错误"),
+    A0200("A0200", "用户编号已存在"),
+    A0201("A0201", "用户登录名已存在"),
+    A0202("A0202", "用户手机号已存在"),
+    A0203("A0203", "用户组已存在"),
+    A0204("A0204", "用户ID集合不能为空"),
+    A0205("A0205", "用户名不能为空"),
+    A0206("A0206", "用户不存在"),
+    A0207("A0207", "用户邮箱已存在"),
+    A0300("A0300", "机构号已存在"),
+    A0301("A0301", "机构不存在"),
+    A0302("A0302", "找不到机构对应的上级机构"),
+    A0500("A0500", "角色名称已存在"),
+    A0600("A0600", "值班信息已存在"),
+    A0601("A0601", "已有值班签到记录,请勿重复签到"),
+    A0700("A0700", "通知任务不存在"),
+    A0800("A0800", "外围接口KEY已存在"),
+    A0900("A0900", "用户已绑定其他设备"),
+    A0901("A0901", "用户已绑定该设备"),
+    A0902("A0902", "用户未绑定任何设备"),
+    B0001("B0001","系统执行出错"),
+    B0002("B0002","系统插入数据出错"),
+    B0003("B0003","系统更新数据出错"),
+    B0004("B0004","系统删除数据出错"),
+    B0005("B0005","系统获取数据出错"),
+    C0001("C0001","调用第三方服务出错"),
+    C0110("C0110","RPC服务出错"),
+    C0111("C0111","RPC服务未找到"),
+    C0130("C0130","缓存服务出错"),
+    E0001("E0001","SSH连接参数错误"),
+    E0002("E0002","SSH连接失败"),
+    E0003("E0003","SSH连接执行命令失败"),
+    E0004("E0004","SSH参数错误"),
+    E0101("E0101","ZABBIX认证失败"),
+    E0102("E0102","ZABBIX参数错误"),
+    E0103("E0103","ZABBIX返回错误"),
+    E0104("E0104","SNMP参数错误"),
+    E0105("E0105","SNMP解析错误"),
+    L0001("L0001","用户未登陆"),
+    L0002("L0002","用户名或密码错误,请重新输入"),
+    L0003("L0003","用户被禁用"),
+    L0004("L0004","SECURITY内部错误"),
+    L0005("L0005","安全认证不通过"),//统一的SecurityFilter过滤器,校验请求不同过返回码
+    L0006("L0006","TOKEN不可用,请重新登录"),
+    F0000("F0000","文件上传错误"),
+    F0001("F0001","文件ID不存在"),
+    F0002("F0002","找不到文件"),
+    F0003("F0003","文件下载错误"),
+    F0004("F0004","图片预览错误"),
+    F0005("F0005","读取文件失败"),
+    S0001("S0001","定时任务不存在"),
+    P0001("P0001","无权限访问"),
+    P0002("P0002","无权限删除");
+
+
+    private final String errorCode;
+    private final String errorMessage;
+
+    private ResponseCodesEnum(String errorCode, String errorMessage) {
+        this.errorCode = errorCode;
+        this.errorMessage = errorMessage;
+    }
+    public String code() {
+        return errorCode;
+    }
+    public String message() {
+        return errorMessage;
+    }
+
+}

+ 80 - 0
src/main/java/com/szwl/controller/DemoController.java

@@ -0,0 +1,80 @@
+package com.szwl.controller;
+
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.szwl.constant.ResponseCodesEnum;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.TAdmin;
+import com.szwl.model.query.TAdminParam;
+import com.szwl.service.TAdminService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+@Api(value = "/test", tags = {"测试接口"})
+@RestController
+@RequestMapping("/test")
+public class DemoController {
+    @Value("${test.value:bbb}")
+    private String testValue;
+    @Autowired
+    TAdminService tAdminService;
+
+
+    @ApiOperation(value = "测试更新")
+    @PostMapping("/update")
+    public ResponseModel<?> testUpdate(TAdmin entity) {
+        return R.ok(tAdminService.saveOrUpdate(entity));
+    }
+
+
+    @ApiOperation(value = "分页查询")
+    @GetMapping("/testPage")
+    public ResponseModel<IPage<?>> testPage(TAdminParam param) {
+        LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
+        query.eq(TAdmin::getIsEnabled,true);
+        if(StrUtil.isNotBlank(param.getName())){
+            query.like(TAdmin::getName,param.getName());
+        }
+        query.orderByDesc(TAdmin::getApplyStartTime);
+        Page<TAdmin> page = new Page<>(param.getCurrent(), param.getSize(), true);
+        IPage<TAdmin> iPage = tAdminService.page(page, query);
+        return R.ok(iPage);
+    }
+
+    @ApiOperation(value = "列表查询")
+    @GetMapping("/testList")
+    public ResponseModel<List<?>> testList(TAdminParam param) {
+        LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
+        query.eq(TAdmin::getIsEnabled,true);
+        if(StrUtil.isNotBlank(param.getName())){
+            query.like(TAdmin::getName,param.getName());
+        }
+        query.orderByDesc(TAdmin::getApplyStartTime);
+        List<TAdmin> list = tAdminService.list(query);
+        return R.ok(list);
+    }
+    @ApiOperation(value = "返回失败")
+    @GetMapping("/testError")
+    public ResponseModel<List<?>> testError(boolean success) {
+        if(success){
+            return R.ok();
+        }else{
+            return R.fail(ResponseCodesEnum.B0001,"你的错误信息");
+        }
+    }
+}
+

+ 35 - 0
src/main/java/com/szwl/exception/AuthenticationException.java

@@ -0,0 +1,35 @@
+package com.szwl.exception;
+
+import com.szwl.constant.ResponseCodesEnum;
+import lombok.Data;
+import org.springframework.util.Assert;
+
+/**
+ * 认证异常,使用统一异常处理
+ *
+ * @author wuhs
+ * @date 2021-09-29 11:03
+ */
+@Data
+public class AuthenticationException extends RuntimeException {
+
+    private String code;
+
+    private String message;
+
+    private ResponseCodesEnum responseCodesEnum;
+
+    public AuthenticationException(ResponseCodesEnum responseCodesEnum) {
+        Assert.notNull(responseCodesEnum, "enum must not be null");
+        this.code = responseCodesEnum.code();
+        this.message = responseCodesEnum.message();
+        this.responseCodesEnum = responseCodesEnum;
+    }
+
+    public AuthenticationException(ResponseCodesEnum responseCodesEnum, String msg) {
+        Assert.notNull(responseCodesEnum, "enum must not be null");
+        this.code = responseCodesEnum.code();
+        this.message = responseCodesEnum.message() +","+ msg;
+        this.responseCodesEnum = responseCodesEnum;
+    }
+}

+ 35 - 0
src/main/java/com/szwl/exception/BizException.java

@@ -0,0 +1,35 @@
+package com.szwl.exception;
+
+import com.szwl.constant.ResponseCodesEnum;
+import lombok.Data;
+import org.springframework.util.Assert;
+
+/**
+ * 业务异常,使用统一异常处理
+ *
+ * @author wuhs
+ * @date 2021-09-29 11:03
+ */
+@Data
+public class BizException extends RuntimeException {
+
+    private String code;
+
+    private String message;
+
+    private ResponseCodesEnum responseCodesEnum;
+
+    public BizException(ResponseCodesEnum responseCodesEnum) {
+        Assert.notNull(responseCodesEnum, "enum must not be null");
+        this.code = responseCodesEnum.code();
+        this.message = responseCodesEnum.message();
+        this.responseCodesEnum = responseCodesEnum;
+    }
+
+    public BizException(ResponseCodesEnum responseCodesEnum,String msg) {
+        Assert.notNull(responseCodesEnum, "enum must not be null");
+        this.code = responseCodesEnum.code();
+        this.message = responseCodesEnum.message() +","+ msg;
+        this.responseCodesEnum = responseCodesEnum;
+    }
+}

+ 13 - 0
src/main/java/com/szwl/exception/MyException.java

@@ -0,0 +1,13 @@
+package com.szwl.exception;
+
+import lombok.Data;
+
+@Data
+public class MyException extends RuntimeException {
+    private static final long serialVersionUID = -2565431806475335331L;
+    String message;
+
+    public MyException(String message) {
+        this.message = message;
+    }
+}

+ 27 - 0
src/main/java/com/szwl/exception/ParamNotFoundException.java

@@ -0,0 +1,27 @@
+package com.szwl.exception;
+
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+/**
+ * 参数不符或缺失时报错
+ *
+ * @author 吴洪双
+ */
+@Accessors(chain = true)
+@Setter
+public class ParamNotFoundException extends RuntimeException {
+
+    private static final long serialVersionUID = -2565431806475335331L;
+    private String paramName;
+
+    public ParamNotFoundException(String paramName) {
+        this.paramName = paramName;
+    }
+
+    @Override
+    public String getMessage() {
+        return paramName + " 不能为空";
+    }
+
+}

+ 95 - 0
src/main/java/com/szwl/exception/RestExceptionHandler.java

@@ -0,0 +1,95 @@
+package com.szwl.exception;
+
+import com.alibaba.fastjson.JSON;
+import com.szwl.constant.ResponseCodesEnum;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.BindException;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.servlet.http.HttpServletRequest;
+
+@Slf4j
+@RestControllerAdvice
+public class RestExceptionHandler {
+
+    @ExceptionHandler(Exception.class)
+    public ResponseModel<Void> otherExceptionHandler(Exception exception) {
+        log.error("un caught exception: ", exception);
+        return R.fail("内部异常[%s],请联系管理员。", exception.getMessage());
+    }
+
+    @ExceptionHandler(MyException.class)
+    public ResponseModel<Void> myExceptionHandler(Exception exception) {
+        log.error("my exception: ", exception);
+        return R.fail("业务异常[%s],请联系管理员。", exception.getMessage());
+    }
+
+    @ExceptionHandler(ParamNotFoundException.class)
+    public ResponseModel<Void> paramNotFoundExceptionHandler(Exception exception) {
+        log.error("param not found exception: ", exception);
+        return R.fail(ResponseCodesEnum.A0001,"参数异常[%s],请联系管理员。", exception.getMessage());
+    }
+
+    /**
+     * 处理业务异常
+     *
+     * @param e
+     * @return
+     */
+    @ExceptionHandler(BizException.class)
+    public ResponseModel<Void> handlerBizException(BizException e) {
+        log.error("biz exception: {}", e.getMessage());
+        return R.fail(e.getResponseCodesEnum(), "业务异常[%s],请联系管理员。", e.getMessage());
+    }
+
+    /**
+     * 校验错误拦截处理
+     *
+     * @param ex 错误信息集合
+     * @return 错误信息
+     * @Title: methodArgumentNotValidHandler
+     */
+    @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
+    public ResponseModel<Void> methodArgumentNotValidHandler(HttpServletRequest request, Exception ex) {
+        BindingResult result = null;
+        if (ex instanceof BindException) {
+            BindException bindException = (BindException) ex;
+            result = bindException.getBindingResult();
+        } else if (ex instanceof MethodArgumentNotValidException) {
+            MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) ex;
+            result = methodArgumentNotValidException.getBindingResult();
+        }
+        StringBuilder msg = new StringBuilder();
+        if (result != null) {
+            if (result.getFieldErrorCount() > 0) {
+                for (FieldError fieldErr : result.getFieldErrors()) {
+                    msg.append(fieldErr.getField() + ":" + fieldErr.getDefaultMessage()).append("|");
+                }
+            }
+            log.error("error by url:{}", request.getRequestURI().toString());
+            log.error("request param:{}", JSON.toJSONString(result.getTarget()));
+            log.error("response msg:{}", msg.toString());
+        }
+        return R.fail(ResponseCodesEnum.A0001, "接口参数错误:%s", msg);
+    }
+
+    /**
+     * 认证异常
+     *
+     * @param exception
+     * @return
+     */
+    @ExceptionHandler(AuthenticationException.class)
+    public ResponseModel<Void> authenticationExceptionHandler(AuthenticationException exception) {
+        log.error("common authentication exception: ", exception);
+        return R.fail(exception.getResponseCodesEnum(), exception.getMessage());
+    }
+
+
+}

+ 14 - 0
src/main/java/com/szwl/feign/bean/SzwlFeign.java

@@ -0,0 +1,14 @@
+package com.szwl.feign.bean;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.szwl.model.bo.ResponseModel;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+
+
+@FeignClient(name = "pay-server")
+public interface SzwlFeign {
+
+    @GetMapping("/test/testPay")
+    ResponseModel<IPage<?>> testPay(String id);
+}

+ 16 - 0
src/main/java/com/szwl/mapper/TAdminMapper.java

@@ -0,0 +1,16 @@
+package com.szwl.mapper;
+
+import com.szwl.model.entity.TAdmin;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-03-28
+ */
+public interface TAdminMapper extends BaseMapper<TAdmin> {
+
+}

+ 43 - 0
src/main/java/com/szwl/mapper/xml/TAdminMapper.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.szwl.mapper.TAdminMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.szwl.model.entity.TAdmin">
+        <id column="id" property="id" />
+        <result column="create_date" property="createDate" />
+        <result column="modify_date" property="modifyDate" />
+        <result column="area_id" property="areaId" />
+        <result column="email" property="email" />
+        <result column="is_admined" property="isAdmined" />
+        <result column="is_enabled" property="isEnabled" />
+        <result column="is_locked" property="isLocked" />
+        <result column="locked_date" property="lockedDate" />
+        <result column="login_date" property="loginDate" />
+        <result column="login_failure_count" property="loginFailureCount" />
+        <result column="login_ip" property="loginIp" />
+        <result column="trade_merchant_no" property="tradeMerchantNo" />
+        <result column="name" property="name" />
+        <result column="parent_id" property="parentId" />
+        <result column="password" property="password" />
+        <result column="notice_id" property="noticeId" />
+        <result column="type" property="type" />
+        <result column="username" property="username" />
+        <result column="phone" property="phone" />
+        <result column="is_refund" property="isRefund" />
+        <result column="if_foreign" property="ifForeign" />
+        <result column="open" property="open" />
+        <result column="promo_code_open" property="promoCodeOpen" />
+        <result column="apply_start_time" property="applyStartTime" />
+        <result column="apply_end_time" property="applyEndTime" />
+        <result column="code" property="code" />
+        <result column="pay_platform" property="payPlatform" />
+        <result column="relation_admin_id" property="relationAdminId" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, create_date, modify_date, area_id, email, is_admined, is_enabled, is_locked, locked_date, login_date, login_failure_count, login_ip, trade_merchant_no, name, parent_id, password, notice_id, type, username, phone, is_refund, if_foreign, open, promo_code_open, apply_start_time, apply_end_time, code, pay_platform, relation_admin_id
+    </sql>
+
+</mapper>

+ 18 - 0
src/main/java/com/szwl/model/bo/BasePageQuery.java

@@ -0,0 +1,18 @@
+package com.szwl.model.bo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class BasePageQuery {
+    /**
+     * 当前页,默认第一页
+     */
+    @ApiModelProperty(value = "当前页,默认第一页,1")
+    long current = 1L;
+    /**
+     * 每页多少条数据,默认10条
+     */
+    @ApiModelProperty(value = "每页多少条数据,默认10条")
+    long size = 10L;
+}

+ 37 - 0
src/main/java/com/szwl/model/bo/R.java

@@ -0,0 +1,37 @@
+package com.szwl.model.bo;
+
+
+import com.szwl.constant.ResponseCodesEnum;
+
+public class R<T> {
+
+    public static <T> ResponseModel<T> ok(T data) {
+        return ResponseModel.ok(data);
+    }
+
+    public static <T> ResponseModel<T> ok(T data, String message) {
+        return ResponseModel.ok(data, message);
+    }
+
+    public static <T> ResponseModel<T> ok() {
+        return ResponseModel.ok();
+    }
+    public static <T> ResponseModel<T> okByMsg(String message) {
+        return ResponseModel.okByMsg(message);
+    }
+    public static <T> ResponseModel<T> fail(ResponseCodesEnum code, String message) {
+        return ResponseModel.fail(code,message);
+    }
+
+    public static <T> ResponseModel<T> fail(ResponseCodesEnum code) {
+        return ResponseModel.fail(code);
+    }
+
+    public static <T> ResponseModel<T> fail(String formatter, Object... obj) {
+        return ResponseModel.fail(String.format(formatter, obj));
+    }
+
+    public static <T> ResponseModel<T> fail(ResponseCodesEnum code, String formatter, Object... obj) {
+        return ResponseModel.fail(code, String.format(formatter, obj));
+    }
+}

+ 78 - 0
src/main/java/com/szwl/model/bo/ResponseModel.java

@@ -0,0 +1,78 @@
+package com.szwl.model.bo;
+
+import com.szwl.constant.ResponseCodesEnum;
+import com.fasterxml.jackson.annotation.JsonView;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Accessors(chain = true)
+public class ResponseModel<T> extends R<T> {
+
+	public interface NormalView {}
+	public interface FullView extends NormalView {}
+
+	@ApiModelProperty(value = "返回码")
+	@JsonView({NormalView.class})
+	private String code;
+
+	@ApiModelProperty(value = "返回信息")
+	@JsonView({NormalView.class})
+	private String message = "";
+
+	@ApiModelProperty(value = "返回数据")
+	@JsonView({NormalView.class})
+	private T data;
+
+	public static <T> ResponseModel<T> ok(T data) {
+		return new ResponseModel<T>()
+				.setCode(ResponseCodesEnum.ALL_OK.code())
+				.setData(data);
+	}
+	
+	public static <T> ResponseModel<T> ok(T data, String message) {
+		return new ResponseModel<T>()
+				.setCode(ResponseCodesEnum.ALL_OK.code())
+				.setMessage(message)
+				.setData(data);
+	}
+	
+	public static <T> ResponseModel<T> ok() {
+		return new ResponseModel<T>()
+				.setCode(ResponseCodesEnum.ALL_OK.code());
+	}
+	public static <T> ResponseModel<T> okByMsg(String message) {
+		return new ResponseModel<T>()
+				.setCode(ResponseCodesEnum.ALL_OK.code())
+				.setMessage(message);
+	}
+	public static <T> ResponseModel<T> fail(ResponseCodesEnum code,String message) {
+		return new ResponseModel<T>()
+				.setCode(code.code())
+				.setMessage(message);
+	}
+
+	public static <T> ResponseModel<T> fail(ResponseCodesEnum code) {
+		return new ResponseModel<T>()
+				.setCode(code.code())
+				.setMessage(code.message());
+	}
+
+	public static <T> ResponseModel<T> fail(String message) {
+		return new ResponseModel<T>()
+				.setCode(ResponseCodesEnum.B0001.code())
+				.setMessage(message);
+	}
+
+	/**
+	 * 校验是否成功
+	 *
+	 * @return
+	 */
+	public boolean isSuccess() {
+		return ResponseCodesEnum.ALL_OK.code().equalsIgnoreCase(this.getCode());
+	}
+}

+ 109 - 0
src/main/java/com/szwl/model/entity/TAdmin.java

@@ -0,0 +1,109 @@
+package com.szwl.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-03-28
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="TAdmin对象", description="")
+public class TAdmin implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    private Date createDate;
+
+    private Date modifyDate;
+
+    private Long areaId;
+
+    @ApiModelProperty(value = "邮箱;")
+    private String email;
+
+    @ApiModelProperty(value = "设置是否普通管理员(0:管理员,1:子账户);")
+    private Boolean isAdmined;
+
+    @ApiModelProperty(value = "是否启用;")
+    private Boolean isEnabled;
+
+    @ApiModelProperty(value = "是否锁定;")
+    private Boolean isLocked;
+
+    @ApiModelProperty(value = "锁定时间;")
+    private Date lockedDate;
+
+    @ApiModelProperty(value = "登录时间;")
+    private Date loginDate;
+
+    @ApiModelProperty(value = "连续登录失败次数;")
+    private Integer loginFailureCount;
+
+    private String loginIp;
+
+    @ApiModelProperty(value = "商户报备号;")
+    private String tradeMerchantNo;
+
+    private String name;
+
+    @ApiModelProperty(value = "如果is_admined=1,说明这个账户是子账户,它的拥有者的adminId就是parent_id;")
+    private Long parentId;
+
+    private String password;
+
+    @ApiModelProperty(value = "当前查看过公告的id;")
+    private Long noticeId;
+
+    @ApiModelProperty(value = "类型(暂时作废);")
+    private Integer type;
+
+    @ApiModelProperty(value = "登录名;")
+    private String username;
+
+    @ApiModelProperty(value = "电话;")
+    private String phone;
+
+    @ApiModelProperty(value = "是否退款;")
+    private String isRefund;
+
+    @ApiModelProperty(value = "是否国外;")
+    private String ifForeign;
+
+    @ApiModelProperty(value = "是否开启远程开关机")
+    private String open;
+
+    @ApiModelProperty(value = "是否开通0折优惠码;0:开通;1:关闭")
+    private String promoCodeOpen;
+
+    @ApiModelProperty(value = "机器连接服务器免审核开始时间")
+    private Date applyStartTime;
+
+    @ApiModelProperty(value = "机器连接服务器免审核结束时间")
+    private Date applyEndTime;
+
+    @ApiModelProperty(value = "短信验证码;")
+    private String code;
+
+    @ApiModelProperty(value = "支付平台; 0或null为汇聚,1为杉德支付")
+    private String payPlatform;
+
+    @ApiModelProperty(value = "关联商家,相当于以前的parent_id")
+    private String relationAdminId;
+
+
+}

+ 27 - 0
src/main/java/com/szwl/model/query/TAdminParam.java

@@ -0,0 +1,27 @@
+package com.szwl.model.query;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.szwl.model.bo.BasePageQuery;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-03-28
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="查询 TAdmin", description="")
+public class TAdminParam extends BasePageQuery {
+    String name;
+}

+ 16 - 0
src/main/java/com/szwl/service/TAdminService.java

@@ -0,0 +1,16 @@
+package com.szwl.service;
+
+import com.szwl.model.entity.TAdmin;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-03-28
+ */
+public interface TAdminService extends IService<TAdmin> {
+
+}

+ 20 - 0
src/main/java/com/szwl/service/impl/TAdminServiceImpl.java

@@ -0,0 +1,20 @@
+package com.szwl.service.impl;
+
+import com.szwl.model.entity.TAdmin;
+import com.szwl.mapper.TAdminMapper;
+import com.szwl.service.TAdminService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-03-28
+ */
+@Service
+public class TAdminServiceImpl extends ServiceImpl<TAdminMapper, TAdmin> implements TAdminService {
+
+}

+ 40 - 0
src/main/resources/bootstrap.yml

@@ -0,0 +1,40 @@
+spring:
+  application:
+    name: pay-server
+  cloud:
+    config:
+      name: pay-server
+      discovery:
+        service-id: config-server
+        # 是否获取配置中心配置
+        enabled: false
+  datasource:
+    url: jdbc:mysql://rm-wz995mu26a1479kz0so.mysql.rds.aliyuncs.com:3306/szwl
+    username: root
+    password: sunzee@020
+    driver-class-name: com.mysql.jdbc.Driver
+
+server:
+  port: 49011
+
+management:
+  endpoints:
+    web:
+      exposure:
+        include: refresh
+eureka:
+  client:
+    service-url:
+      defaultZone: http://112.74.63.148:49001/eureka/
+    register-with-eureka: true
+  instance:
+    prefer-ip-address: true
+#    ip-address: 10.241.20.241
+
+mybatis-plus:
+  mapper-locations: classpath:com/szwl/mapper/xml/*.xml
+
+logging:
+  level:
+    com.szwl: debug
+

+ 11 - 0
src/test/java/com/szwl/ApplicationTests.java

@@ -0,0 +1,11 @@
+package com.szwl;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@Slf4j
+@SpringBootTest
+class ApplicationTests {
+
+
+}

+ 74 - 0
src/test/java/com/szwl/AutoGeneratorTests.java

@@ -0,0 +1,74 @@
+package com.szwl;
+
+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 lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@Slf4j
+@SpringBootTest
+class AutoGeneratorTests {
+	@Test
+	void contextLoads() {
+		AutoGenerator autoGenerator = new AutoGenerator();
+
+		//获取工程的根目录
+		String projectPath = System.getProperty("user.dir");//得到当前项目的路径
+		//全局配置
+		GlobalConfig globalConfig = new GlobalConfig();
+		globalConfig.setAuthor("wuhs")
+				.setOutputDir(projectPath + "/src/main/java")//设置输出路径,项目所在路径
+				.setFileOverride(true)//设置文件覆盖
+				.setOpen(false)//是否生成代码后打开本地目录
+				.setSwagger2(true) //实体属性 Swagger2 注解
+				.setIdType(IdType.ASSIGN_ID)//设置主键生成策略
+				.setServiceName("%sService")//service接口的名称
+				.setDateType(DateType.ONLY_DATE)
+				.setBaseResultMap(true)//基本结果集合
+				.setBaseColumnList(true)//设置基本的列
+				.setControllerName("%sController");
+
+		//配置数据源
+		//配置数据源
+		DataSourceConfig dataSourceConfig = new DataSourceConfig();
+		dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver")
+				.setUrl("jdbc:mysql://rm-wz995mu26a1479kz0so.mysql.rds.aliyuncs.com:3306/szwl")
+				.setUsername("root").setPassword("sunzee@020");
+
+		//策略配置
+		StrategyConfig strategyConfig = new StrategyConfig();
+		strategyConfig
+//				.setCapitalMode(true)//设置全局大写命名
+				.setInclude(new String[]{
+						"t_admin"
+				})//只会生成该表
+				.setEntityLombokModel(true)//实体类生成之后自动添加lombok注解
+				.setNaming(NamingStrategy.underline_to_camel)//数据库表映射到实体的命名策略
+				.setColumnNaming(NamingStrategy.underline_to_camel)//将数据库中带下划线的转成驼峰规则
+				//.setTablePrefix("tbl_")//设置表名前缀
+				.setRestControllerStyle(true)//controller是否使用restful风格
+		;
+
+		//包名配置
+		PackageConfig packageConfig = new PackageConfig();
+		packageConfig.setParent("com.szwl")
+				.setMapper("mapper")//包路径
+				.setService("service")
+				.setController("controller")
+				.setEntity("model.entity")
+//		.setXml()
+		;
+
+		autoGenerator.setGlobalConfig(globalConfig).setDataSource(dataSourceConfig)
+				.setStrategy(strategyConfig).setPackageInfo(packageConfig);
+
+		autoGenerator.execute();
+	}
+}