Initial commit
This commit is contained in:
38
common/.gitignore
vendored
Normal file
38
common/.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
38
common/common-util/.gitignore
vendored
Normal file
38
common/common-util/.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
31
common/common-util/pom.xml
Normal file
31
common/common-util/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>common-util</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>provided </scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,92 @@
|
||||
package com.atguigu.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ClassName: Result
|
||||
* Package: com.atguigu.common.result
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/6 17:30
|
||||
* <p>
|
||||
* 全局统一返回结果类
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> {
|
||||
|
||||
//返回码
|
||||
private Integer code;
|
||||
|
||||
//返回消息
|
||||
private String message;
|
||||
|
||||
//返回数据
|
||||
private T data;
|
||||
|
||||
public Result() {
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
protected static <T> Result<T> build(T data) {
|
||||
Result<T> result = new Result<T>();
|
||||
if (data != null)
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> build(T body, Integer code, String message) {
|
||||
Result<T> result = build(body);
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> build(T body, ResultCodeEnum resultCodeEnum) {
|
||||
Result<T> result = build(body);
|
||||
result.setCode(resultCodeEnum.getCode());
|
||||
result.setMessage(resultCodeEnum.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> ok() {
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功
|
||||
*
|
||||
* @param data
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> Result<T> ok(T data) {
|
||||
Result<T> result = build(data);
|
||||
return build(data, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
public static <T> Result<T> fail() {
|
||||
return Result.fail(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作失败
|
||||
*
|
||||
* @param data
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> Result<T> fail(T data) {
|
||||
Result<T> result = build(data);
|
||||
return build(data, ResultCodeEnum.FAIL);
|
||||
}
|
||||
|
||||
public Result<T> message(String msg) {
|
||||
this.setMessage(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result<T> code(Integer code) {
|
||||
this.setCode(code);
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.atguigu.common.result;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ClassName: result
|
||||
* Package: com.atguigu.common
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/6 17:28
|
||||
* <p>
|
||||
* 统一返回结果状态信息类
|
||||
*/
|
||||
@Getter
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
SUCCESS(200, "成功"),
|
||||
FAIL(201, "失败"),
|
||||
SERVICE_ERROR(2012, "服务异常"),
|
||||
DATA_ERROR(204, "数据异常"),
|
||||
|
||||
LOGIN_AUTH(208, "未登陆"),
|
||||
PERMISSION(209, "没有权限");
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
private ResultCodeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
17
common/pom.xml
Normal file
17
common/pom.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>guigu-oa-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>service-util</module>
|
||||
</modules>
|
||||
</project>
|
38
common/service-util/.gitignore
vendored
Normal file
38
common/service-util/.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
38
common/service-util/pom.xml
Normal file
38
common/service-util/pom.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>service-util</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--mysql-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!--knife4j-整合Swagger-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@@ -0,0 +1,70 @@
|
||||
package com.atguigu.common.config.knife4j;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ParameterBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.service.Parameter;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: config
|
||||
* Package: com.atguigu.common.config.knife4j
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/6 17:45
|
||||
* <p>
|
||||
* knife4j配置信息
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2WebMvc
|
||||
public class Knife4jConfig {
|
||||
|
||||
@Bean
|
||||
public Docket adminApiConfig() {
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
tokenPar.name("token")
|
||||
.description("用户token")
|
||||
.defaultValue("")
|
||||
.modelRef(new ModelRef("string"))
|
||||
.parameterType("header")
|
||||
.required(false)
|
||||
.build();
|
||||
pars.add(tokenPar.build());
|
||||
//添加head参数end
|
||||
|
||||
Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("adminApi")
|
||||
.apiInfo(adminApiInfo())
|
||||
.select()
|
||||
//只显示admin路径下的页面
|
||||
.apis(RequestHandlerSelectors.basePackage("com.atguigu"))
|
||||
.paths(PathSelectors.regex("/admin/.*"))
|
||||
.build()
|
||||
.globalOperationParameters(pars);
|
||||
return adminApi;
|
||||
}
|
||||
|
||||
private ApiInfo adminApiInfo() {
|
||||
|
||||
return new ApiInfoBuilder()
|
||||
.title("后台管理系统-API文档")
|
||||
.description("本文档描述了后台管理系统微服务接口定义")
|
||||
.version("1.0")
|
||||
.contact(new Contact("atguigu", "http://atguigu.com", "atguigu@qq.com"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.atguigu.common.config.mp;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* ClassName: MybatisPlusConfig
|
||||
* Package: com.atguigu.common.config.mp
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/6 17:58
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@MapperScan("com.atguigu.auth.mapper")
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置
|
||||
* MybatisConfiguration#useDeprecatedExecutor = false
|
||||
* 避免缓存出现问题(该属性会在旧插件移除后一同移除)
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationCustomizer configurationCustomizer() {
|
||||
return configuration -> configuration.setUseDeprecatedExecutor(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.atguigu.common.execption;
|
||||
|
||||
import com.atguigu.common.result.Result;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
||||
/**
|
||||
* ClassName: GlobalExceptionHandler
|
||||
* Package: com.atguigu.common.handler
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/6 20:41
|
||||
* <p>
|
||||
* 全局异常处理类
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result error(Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.fail();
|
||||
}
|
||||
|
||||
@ExceptionHandler(ArithmeticException.class)
|
||||
@ResponseBody
|
||||
public Result error(ArithmeticException e) {
|
||||
e.printStackTrace();
|
||||
return Result.fail().message("执行了特定异常处理");
|
||||
}
|
||||
|
||||
@ExceptionHandler(GuiguException.class)
|
||||
@ResponseBody
|
||||
public Result error(GuiguException e) {
|
||||
e.printStackTrace();
|
||||
return Result.fail().message(e.getMsg()).code(e.getCode());
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package com.atguigu.common.execption;
|
||||
|
||||
import com.atguigu.common.result.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ClassName: GuiguException
|
||||
* Package: com.atguigu.common.execption
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/7 10:13
|
||||
* <p>
|
||||
* 自定义全局异常类
|
||||
*/
|
||||
@Data
|
||||
public class GuiguException extends RuntimeException {
|
||||
|
||||
private Integer code;//状态码
|
||||
private String msg;//描述信息
|
||||
|
||||
public GuiguException(Integer code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收枚举类型对象
|
||||
*
|
||||
* @param resultCodeEnum
|
||||
*/
|
||||
public GuiguException(ResultCodeEnum resultCodeEnum) {
|
||||
super(resultCodeEnum.getMessage());
|
||||
this.code = resultCodeEnum.getCode();
|
||||
this.msg = resultCodeEnum.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GuliException{" +
|
||||
"code=" + code +
|
||||
", message=" + this.getMessage() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user