Skip to content

Commit 7373659

Browse files
committed
Merge branch 'develop'
2 parents 0a1b48f + 01f37dd commit 7373659

File tree

28 files changed

+307
-138
lines changed

28 files changed

+307
-138
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Java CI with Maven
55

66
on:
77
push:
8-
# 拉取tag动作
9-
tags:
10-
- 'v*'
8+
branches: [ release ]
9+
pull_request:
10+
branches: [ release ]
1111

1212
jobs:
1313
build:
@@ -25,15 +25,15 @@ jobs:
2525
# 编译
2626
- name: Build with Maven
2727
run: mvn -B package --file pom.xml
28-
# # 规范打包目录
29-
# - name: Zip the Build
30-
# run: |
31-
# mkdir release
32-
# cd ./src/PluginCore/bin/Release
33-
# zip -r PluginCore-netcoreapp3.1.zip ./netcoreapp3.1/
34-
# zip -r PluginCore-net5.0.zip ./net5.0/
35-
# cd ../../../../
36-
# mv ./src/PluginCore/bin/Release/*.zip ./
28+
# # 规范打包目录
29+
# - name: Zip the Build
30+
# run: |
31+
# mkdir release
32+
# cd ./src/PluginCore/bin/Release
33+
# zip -r PluginCore-netcoreapp3.1.zip ./netcoreapp3.1/
34+
# zip -r PluginCore-net5.0.zip ./net5.0/
35+
# cd ../../../../
36+
# mv ./src/PluginCore/bin/Release/*.zip ./
3737
# 创建发行版
3838
- name: Create Release
3939
uses: ncipollo/release-action@v1.10.0

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ target/
1515

1616
### IntelliJ IDEA ###
1717
.idea
18+
.fleet
1819
*.iws
1920
*.iml
2021
*.ipr
@@ -29,3 +30,9 @@ build/
2930

3031
### VS Code ###
3132
.vscode/
33+
34+
### 忽略热部署 ###
35+
/nginx-ops-admin/src/main/resources/rebel.xml
36+
/nginx-ops-comm/src/main/resources/rebel.xml
37+
/nginx-ops-conf/src/main/resources/rebel.xml
38+
/nginx-ops-system/src/main/resources/rebel.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ PS: 本项目采用Google编码风格, 如果您使用IDEA编程, 请下载googl
5858

5959
## 特别鸣谢
6060

61+
<img alt="JetBrains Logo (Main) logo" height="200" src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width="200"/>

image/img.png

120 KB
Loading

nginx-ops-admin/src/main/java/io/github/nginx/ops/server/admin/config/MybatisPlusConfig.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
99
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
1010
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
11-
import io.github.nginx.ops.server.system.domain.dto.UserInfo;
12-
import io.github.nginx.ops.server.system.util.UserInfoUtils;
1311
import lombok.extern.slf4j.Slf4j;
1412
import net.sf.jsqlparser.expression.Expression;
1513
import net.sf.jsqlparser.expression.StringValue;
@@ -27,10 +25,6 @@
2725
@Configuration
2826
public class MybatisPlusConfig implements MetaObjectHandler {
2927

30-
public static void main(String[] args) {
31-
System.out.println("\"sys\".equals(\"nginx\") = " + "sys".equals("nginx"));
32-
}
33-
3428
@Override
3529
public void insertFill(MetaObject metaObject) {
3630
log.debug("start insert fill ....");
@@ -53,9 +47,8 @@ public void insertFill(MetaObject metaObject) {
5347
public void updateFill(MetaObject metaObject) {
5448
log.debug("start update fill ....");
5549
DateTime dateTime = new DateTime();
56-
UserInfo userInfo = UserInfoUtils.getUserInfo();
57-
this.strictInsertFill(
58-
metaObject, "updateBy", String.class, userInfo.getSysUser().getLoginName());
50+
// UserInfo userInfo = UserInfoUtils.getUserInfo();
51+
this.strictInsertFill(metaObject, "updateBy", String.class, "test");
5952
this.strictUpdateFill(metaObject, "updateTime", Date.class, dateTime);
6053
}
6154

nginx-ops-admin/src/main/java/io/github/nginx/ops/server/admin/config/SaTokenConfigure.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.nginx.ops.server.admin.config;
22

3-
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
3+
import cn.dev33.satoken.interceptor.SaInterceptor;
4+
import cn.dev33.satoken.stp.StpUtil;
45
import org.springframework.context.annotation.Configuration;
56
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
67
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -19,7 +20,18 @@ public class SaTokenConfigure implements WebMvcConfigurer {
1920
*/
2021
@Override
2122
public void addInterceptors(InterceptorRegistry registry) {
22-
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
23-
registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
23+
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
24+
registry
25+
.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
26+
.addPathPatterns("/**")
27+
.excludePathPatterns("/doLogin", "/captcha")
28+
.excludePathPatterns(
29+
"/swagger-resources/**",
30+
"/webjars/**",
31+
"/v2/**",
32+
"/swagger-ui.html/**",
33+
"/doc.html/**",
34+
"/error",
35+
"/favicon.ico");
2436
}
2537
}

nginx-ops-admin/src/main/java/io/github/nginx/ops/server/admin/constant/AdminReturnCodeConstant.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@
77
*/
88
public class AdminReturnCodeConstant {
99

10-
/** 验证码已过期 */
10+
/** 验证码过期 */
1111
public static final String CAPTCHA_HAS_EXPIRED = "A0001";
1212
/** 登录名或密码错误 */
1313
public static final String USER_DOES_NOT_EXIST = "A0002";
1414
/** 账号被停用 */
1515
public static final String USER_NOT_ENABLE = "A0003";
16+
/** 验证码错误 */
17+
public static final String CAPTCHA_ERROR = "A0004";
18+
/** 未提供token */
19+
public static final String NOT_TOKEN = "A0005";
20+
/** token无效 */
21+
public static final String INVALID_TOKEN = "A0006";
22+
/** token已过期 */
23+
public static final String TOKEN_TIMEOUT = "A0007";
24+
/** token已被顶下线 */
25+
public static final String BE_REPLACED = "A0008";
26+
/** token已被踢下线 */
27+
public static final String KICK_OUT = "A0009";
1628
}

nginx-ops-admin/src/main/java/io/github/nginx/ops/server/admin/controller/AdminController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.github.nginx.ops.server.comm.annotation.OperationLog;
88
import io.github.nginx.ops.server.comm.domain.vo.R;
99
import io.github.nginx.ops.server.comm.enums.BusinessTypeEnum;
10+
import io.github.nginx.ops.server.system.domain.dto.UserInfo;
1011
import io.swagger.annotations.Api;
1112
import io.swagger.annotations.ApiOperation;
1213
import lombok.RequiredArgsConstructor;
@@ -41,6 +42,14 @@ public R login(@RequestBody @Valid LoginDTO dto, HttpServletRequest request) {
4142
return R.success("登录成功!", saTokenInfo);
4243
}
4344

45+
@GetMapping("user/info")
46+
@ApiOperation("获取用户信息")
47+
@OperationLog(title = "获取用户信息", businessType = BusinessTypeEnum.SELECT)
48+
public R getUserInfo() {
49+
UserInfo userInfo = server.getUserInfo();
50+
return R.success("登录成功!", userInfo);
51+
}
52+
4453
@PostMapping("logout")
4554
@ApiOperation("登出接口")
4655
@OperationLog(title = "登出", businessType = BusinessTypeEnum.LOGIN)
@@ -51,7 +60,7 @@ public R logout() {
5160

5261
@GetMapping("captcha")
5362
@ApiOperation("获取验证码")
54-
@OperationLog(title = "获取验证码", businessType = BusinessTypeEnum.LOGIN)
63+
@OperationLog(title = "获取验证码", businessType = BusinessTypeEnum.SELECT)
5564
public R captcha() {
5665
CaptchaVO captchaVO = server.captcha();
5766
return R.success("获取验证码成功!", captchaVO);

nginx-ops-admin/src/main/java/io/github/nginx/ops/server/admin/handler/GlobalExceptionHandler.java

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.github.nginx.ops.server.admin.handler;
22

3+
import cn.dev33.satoken.exception.NotLoginException;
4+
import io.github.nginx.ops.server.admin.constant.AdminReturnCodeConstant;
5+
import io.github.nginx.ops.server.comm.constant.CommReturnCodeConstant;
36
import io.github.nginx.ops.server.comm.domain.vo.R;
47
import io.github.nginx.ops.server.comm.exception.BusinessException;
58
import io.github.nginx.ops.server.system.service.SysReturnService;
@@ -31,45 +34,52 @@ public class GlobalExceptionHandler {
3134
@ExceptionHandler(BusinessException.class)
3235
public R handleBusinessException(BusinessException e, HttpServletRequest request) {
3336
log.warn("业务异常, 异常信息为:{}", e.getMessage(), e);
34-
return R.error(sysReturnService.getMessage(e.getCode()));
37+
return R.error(e.getCode(), sysReturnService.getMessage(e.getCode()));
3538
}
3639

37-
/** 拦截未知的运行时异常 */
38-
@ExceptionHandler(RuntimeException.class)
39-
public R handleRuntimeException(RuntimeException e, HttpServletRequest request) {
40-
String requestURI = request.getRequestURI();
41-
log.error("请求地址:{},发生未知异常.", requestURI, e);
42-
return R.error(e.getMessage());
43-
}
44-
45-
/** 系统异常 */
46-
@ExceptionHandler(Exception.class)
47-
public R handleException(Exception e, HttpServletRequest request) {
48-
String requestURI = request.getRequestURI();
49-
log.error("请求地址:{},发生系统异常.", requestURI, e);
50-
return R.error(e.getMessage());
40+
/** 业务异常 */
41+
@ExceptionHandler(NotLoginException.class)
42+
public R handlerNotLoginException(NotLoginException e, HttpServletRequest request) {
43+
log.warn("鉴权异常, 异常信息为:{}", e.getMessage(), e);
44+
String returnCode = AdminReturnCodeConstant.NOT_TOKEN;
45+
if (e.getType().equals(NotLoginException.INVALID_TOKEN)) {
46+
returnCode = AdminReturnCodeConstant.INVALID_TOKEN;
47+
} else if (e.getType().equals(NotLoginException.TOKEN_TIMEOUT)) {
48+
returnCode = AdminReturnCodeConstant.TOKEN_TIMEOUT;
49+
} else if (e.getType().equals(NotLoginException.BE_REPLACED)) {
50+
returnCode = AdminReturnCodeConstant.BE_REPLACED;
51+
} else if (e.getType().equals(NotLoginException.KICK_OUT)) {
52+
returnCode = AdminReturnCodeConstant.KICK_OUT;
53+
}
54+
return R.error(returnCode, sysReturnService.getMessage(returnCode));
5155
}
5256

53-
/** 自定义验证异常 */
57+
/** 参数异常 */
5458
@ExceptionHandler(BindException.class)
5559
public R handleBindException(BindException e) {
56-
log.error(e.getMessage(), e);
57-
String message = e.getAllErrors().get(0).getDefaultMessage();
58-
return R.error(message, message);
60+
log.warn("参数校验失败, 异常简介为:{}", e.getMessage(), e);
61+
String returnCode = e.getBindingResult().getFieldError().getDefaultMessage();
62+
return R.error(
63+
CommReturnCodeConstant.CAPTCHA_HAS_EXPIRED, sysReturnService.getMessage(returnCode));
5964
}
6065

66+
/** 参数异常 */
6167
@ExceptionHandler(MethodArgumentNotValidException.class)
6268
public R handleBindException(MethodArgumentNotValidException e) {
6369
log.warn("参数校验失败, 异常简介为:{}", e.getMessage(), e);
70+
String returnCode = e.getBindingResult().getFieldError().getDefaultMessage();
6471
return R.error(
65-
sysReturnService.getMessage(e.getBindingResult().getFieldError().getDefaultMessage()));
72+
CommReturnCodeConstant.CAPTCHA_HAS_EXPIRED, sysReturnService.getMessage(returnCode));
6673
}
6774

75+
/** 参数异常 */
6876
@ExceptionHandler(ConstraintViolationException.class)
6977
public R handleBindException(ConstraintViolationException e) {
7078
log.warn("参数校验失败, 异常简介为:{}", e.getMessage(), e);
7179
for (ConstraintViolation<?> constraintViolation : e.getConstraintViolations()) {
72-
return R.error(sysReturnService.getMessage(constraintViolation.getMessage()));
80+
return R.error(
81+
CommReturnCodeConstant.CAPTCHA_HAS_EXPIRED,
82+
sysReturnService.getMessage(constraintViolation.getMessage()));
7383
}
7484
return null;
7585
}
@@ -80,6 +90,22 @@ public R handleHttpRequestMethodNotSupported(
8090
HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
8191
String requestURI = request.getRequestURI();
8292
log.error("请求地址:{},不支持{}请求", requestURI, e.getMethod());
83-
return R.error(e.getMessage());
93+
return R.error(CommReturnCodeConstant.HTTP_REQUEST_METHOD_NOT_SUPPORTED, e.getMessage());
94+
}
95+
96+
/** 拦截未知的运行时异常 */
97+
@ExceptionHandler(RuntimeException.class)
98+
public R handleRuntimeException(RuntimeException e, HttpServletRequest request) {
99+
String requestURI = request.getRequestURI();
100+
log.error("请求地址:{},发生未知异常.", requestURI, e);
101+
return R.error(CommReturnCodeConstant.EXCEPTION, e.getMessage());
102+
}
103+
104+
/** 系统异常 */
105+
@ExceptionHandler(Exception.class)
106+
public R handleException(Exception e, HttpServletRequest request) {
107+
String requestURI = request.getRequestURI();
108+
log.error("请求地址:{},发生系统异常.", requestURI, e);
109+
return R.error(CommReturnCodeConstant.EXCEPTION, e.getMessage());
84110
}
85111
}

0 commit comments

Comments
 (0)