Compare commits

...

14 Commits

Author SHA1 Message Date
黄昕 766bf0486f 1. 更新发布文档 2024-04-15 17:17:05 +08:00
黄昕 f9c8d505b4 1. 更新安全扫描执行条件 2024-04-09 15:38:29 +08:00
黄昕 60b69e4e23 1. 修正语法检查 2024-04-09 14:59:15 +08:00
黄昕 0c84a7a61f 1. 修正多语言key错误 2024-04-09 14:58:41 +08:00
黄昕 772df51023 1. 修正语法检查 2024-04-09 14:55:55 +08:00
黄昕 b09994e130 1. 修正语法检查 2024-04-09 14:54:33 +08:00
黄昕 ec3a59ffad 1. 操作日志支持国际化 2024-04-09 14:52:58 +08:00
黄昕 41aecab513 1. 更新 mybatis-flex 版本 2024-04-07 16:07:10 +08:00
黄昕 91eab74af8 1. 修正语法检查 2024-03-25 16:36:03 +08:00
黄昕 7149e5597b 1. 增加全局异常拦截和处理
2. 认证key异常支持国际化
2024-03-25 16:35:07 +08:00
黄昕 b446d327b1 1. 参数校验支持国际化 2024-03-25 16:07:21 +08:00
黄昕 e654fc3fe5 1. 枚举字典支持国际化 2024-03-24 11:25:36 +08:00
黄昕 76df3543e1 1. 错误码支持国际化 2024-03-24 09:56:49 +08:00
黄昕 b9e4be0866 1. 备份修改 2024-03-22 18:06:24 +08:00
61 changed files with 786 additions and 201 deletions

View File

@ -11,6 +11,8 @@ security-scan:
stage: scan stage: scan
tags: tags:
- linux-maven - linux-maven
only:
- master
script: script:
- echo "=============== 开始安全扫描任务 ===============" - echo "=============== 开始安全扫描任务 ==============="
- $OPENSCA_CLI -path $CI_PROJECT_DIR -token $OPENSCA_TOKEN -proj "" -out $CI_PROJECT_DIR/results/result.html,$CI_PROJECT_DIR/results/result.dsdx.json - $OPENSCA_CLI -path $CI_PROJECT_DIR -token $OPENSCA_TOKEN -proj "" -out $CI_PROJECT_DIR/results/result.html,$CI_PROJECT_DIR/results/result.dsdx.json

View File

@ -4,4 +4,7 @@
* 支持多模块项目 * 支持多模块项目
* 支持 SpringBoot Security * 支持 SpringBoot Security
* 支持集成测试 * 支持集成测试
* Gitlab CI/CD 自动化配置 * Gitlab CI/CD 自动化配置
*
# v0.0.3-dev
* 支持国际化框架

View File

@ -52,6 +52,10 @@ spring :
mode : always mode : always
enabled : true enabled : true
spring:
messages:
basename: i18n/messages
#mybatis #mybatis
mybatis : mybatis :
mapper-locations : classpath*:mappers/*.xml mapper-locations : classpath*:mappers/*.xml

View File

@ -5,12 +5,12 @@ spring :
data-locations : file:../config/rbac/data.sql data-locations : file:../config/rbac/data.sql
datasource: datasource:
url : jdbc:mysql://xajhuang.com:3307/common_framework?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true #url : jdbc:mysql://xajhuang.com:3307/common_framework?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true
username : xajhuang #username : xajhuang
password : wkj!nky5cjb!GMV6guq #password : wkj!nky5cjb!GMV6guq
#url : jdbc:mysql://localhost:3306/common_framework?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true url : jdbc:mysql://localhost:3306/common_framework?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true
#username : root username : root
#password : aaaHuang1 password : aaaHuang1
#config log #config log
logging : logging :

View File

@ -156,6 +156,7 @@ CREATE TABLE IF NOT EXISTS `sys_operation_log`
`operation_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作类型', `operation_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作类型',
`operation_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作状态', `operation_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作状态',
`description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作说明', `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作说明',
`access_user` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '访问用户',
`request_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求来源 IP 地址', `request_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求来源 IP 地址',
`call_function` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求接口', `call_function` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求接口',
`http_method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'HTTP 请求类型', `http_method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'HTTP 请求类型',

View File

@ -1,5 +1,6 @@
package com.cf.cs.authentication.interceptor; package com.cf.cs.authentication.interceptor;
import com.cf.cs.base.common.ConstValue;
import com.cf.cs.base.misc.ApiContextUtils; import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.HelperUtils; import com.cf.cs.base.misc.HelperUtils;
import com.cf.cs.protocol.misc.ProtocolJsonUtils; import com.cf.cs.protocol.misc.ProtocolJsonUtils;
@ -74,6 +75,8 @@ public class RequestBodyCacheWrapper extends HttpServletRequestWrapper {
} catch (Exception e) { } catch (Exception e) {
body = ""; body = "";
} finally { } finally {
String language = request.getHeader(ConstValue.LANGUAGE_HEAD);
ApiContextUtils.setRequestLocal(language);
ApiContextUtils.setRequestInfo(body, reqTimeStamp); ApiContextUtils.setRequestInfo(body, reqTimeStamp);
} }
} }

View File

@ -5,6 +5,8 @@ import com.cf.cs.authentication.exception.CommonAuthException;
import com.cf.cs.base.common.ConstValue; import com.cf.cs.base.common.ConstValue;
import com.cf.cs.base.common.ErrorCode; import com.cf.cs.base.common.ErrorCode;
import com.cf.cs.base.config.JwtConfigure; import com.cf.cs.base.config.JwtConfigure;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.crypto.arithmetic.CryptoHelper; import com.cf.cs.crypto.arithmetic.CryptoHelper;
import com.cf.cs.database.pojo.entity.User; import com.cf.cs.database.pojo.entity.User;
import com.cf.cs.database.service.UserDataBaseService; import com.cf.cs.database.service.UserDataBaseService;
@ -108,13 +110,13 @@ public class JwtUtils {
return user; return user;
} catch (MalformedJwtException e) { } catch (MalformedJwtException e) {
throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, "密钥算法或者密钥转换错误"); throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, MessageUtil.get("err.auth.key.convert", ApiContextUtils.getLanguare()));
} catch (MissingClaimException e) { } catch (MissingClaimException e) {
throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, "密钥缺少校验数据"); throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, MessageUtil.get("err.auth.key.verify", ApiContextUtils.getLanguare()));
} catch (ExpiredJwtException e) { } catch (ExpiredJwtException e) {
throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, "密钥已过期"); throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, MessageUtil.get("err.auth.key.timeout", ApiContextUtils.getLanguare()));
} catch (JwtException e) { } catch (JwtException e) {
throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, "密钥解析错误"); throw new CommonAuthException(ErrorCode.ERR_TOKEN_KEY, MessageUtil.get("err.auth.key.prase", ApiContextUtils.getLanguare()));
} }
} }

View File

@ -28,7 +28,7 @@ public class JwtAccessDeniedHandler implements AccessDeniedHandler {
HttpServletResponse response, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException { AccessDeniedException accessDeniedException) throws IOException {
response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setStatus(HttpServletResponse.SC_FORBIDDEN);
SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_PERMISSION, accessDeniedException.getMessage(), SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_PERMISSION, ErrorCode.ERR_PERMISSION.getStringValue(),
optLogDbService); optLogDbService);
} }
} }

View File

@ -27,6 +27,6 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
HttpServletResponse response, HttpServletResponse response,
AuthenticationException authException) throws IOException { AuthenticationException authException) throws IOException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_PARAMEXCEPTION, authException.getMessage(), optLogDbService); SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_PARAMEXCEPTION, ErrorCode.ERR_PARAMEXCEPTION.getStringValue(), optLogDbService);
} }
} }

View File

@ -95,6 +95,6 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
private void handleException(HttpServletRequest request, HttpServletResponse response, ErrorCode err) throws IOException { private void handleException(HttpServletRequest request, HttpServletResponse response, ErrorCode err) throws IOException {
// 特定处理逻辑例如设置响应状态记录日志重定向等 // 特定处理逻辑例如设置响应状态记录日志重定向等
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
SecurityResponseUtils.authenticationResponse(request, response, err, err.getDescription(), optLogDbService); SecurityResponseUtils.authenticationResponse(request, response, err, err.getStringValue(), optLogDbService);
} }
} }

View File

@ -39,7 +39,6 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -74,7 +73,7 @@ public class JwtCustomUsernamePassword extends UsernamePasswordAuthenticationFil
try { try {
ProtocolReq<LoginReq> loginReq = ProtocolJsonUtils.jsonGetObject(request.getInputStream(), ProtocolReq<LoginReq> loginReq = ProtocolJsonUtils.jsonGetObject(request.getInputStream(),
new TypeReference<>() { new TypeReference<>() {
}); });
List<String> validate = HelperUtils.validate(loginReq, ValidGroups.ProtocolCommonValid.class, List<String> validate = HelperUtils.validate(loginReq, ValidGroups.ProtocolCommonValid.class,
ValidGroups.LogoutReqValid.class); ValidGroups.LogoutReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -131,12 +130,15 @@ public class JwtCustomUsernamePassword extends UsernamePasswordAuthenticationFil
if (failed instanceof AuthenticationServiceException) { if (failed instanceof AuthenticationServiceException) {
if (failed.getCause() instanceof CommonAuthException ex) { if (failed.getCause() instanceof CommonAuthException ex) {
err = ex.getErr();
rsp.setStatus(ex.getErr().getCode()); rsp.setStatus(ex.getErr().getCode());
} else { } else {
err = ErrorCode.ERR_ACCOUNT;
rsp.setStatus(ErrorCode.ERR_ACCOUNT.getCode()); rsp.setStatus(ErrorCode.ERR_ACCOUNT.getCode());
} }
rsp.setMessage(new String[] {failed.getMessage()}); rsp.setMessage(new String[] {failed.getMessage()});
} else if (failed instanceof CommonAuthException ex) { } else if (failed instanceof CommonAuthException ex) {
err = ex.getErr();
rsp.setStatus(ex.getErr().getCode()); rsp.setStatus(ex.getErr().getCode());
rsp.setMessage(ex.getDescription()); rsp.setMessage(ex.getDescription());
} else { } else {
@ -144,8 +146,7 @@ public class JwtCustomUsernamePassword extends UsernamePasswordAuthenticationFil
rsp.setMessage(new String[] {err.getDescription()}); rsp.setMessage(new String[] {err.getDescription()});
} }
SecurityResponseUtils.authenticationResponse(request, response, rsp, Arrays.toString(rsp.getMessage()), SecurityResponseUtils.authenticationResponse(request, response, rsp, err.getStringValue(), optLogDbService);
optLogDbService);
} }
@Override @Override
@ -182,8 +183,7 @@ public class JwtCustomUsernamePassword extends UsernamePasswordAuthenticationFil
ApiContextUtils.setJwtUserInfo(jwt, au.getUsername(), au.getUid(), au.getId()); ApiContextUtils.setJwtUserInfo(jwt, au.getUsername(), au.getUid(), au.getId());
try { try {
SecurityResponseUtils.authenticationResponse(request, response, loginRsp, SecurityResponseUtils.authenticationResponse(request, response, loginRsp, "SYSLOG_DESC_LOGIN", optLogDbService);
"[" + authResult.getName() + "] login", optLogDbService);
} finally { } finally {
ApiContextUtils.clear(); ApiContextUtils.clear();
} }

View File

@ -17,7 +17,6 @@ import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
/** /**
* The type Jwt logout handler. * The type Jwt logout handler.
@ -40,20 +39,20 @@ public class JwtLogoutHandler implements LogoutHandler {
try { try {
ApiContext ctx = ApiContextUtils.get(); ApiContext ctx = ApiContextUtils.get();
String username = ctx.getUsername(); String username = ctx.getUsername();
ErrorCode err;
if (!HelperUtils.stringNotEmptyOrNull(username)) { if (!HelperUtils.stringNotEmptyOrNull(username)) {
rsp.setStatus(ErrorCode.ERR_TOKENNOTFOUND.getCode()); err = ErrorCode.ERR_TOKENNOTFOUND;
rsp.setMessage(new String[] {ErrorCode.ERR_TOKENNOTFOUND.getDescription()});
} else { } else {
// 校验通过才会执行业务逻辑处理 // 校验通过才会执行业务逻辑处理
accountJwtCacheService.deleteAccountJwtCache(ctx.getUid()); accountJwtCacheService.deleteAccountJwtCache(ctx.getUid());
rsp.setStatus(ErrorCode.ERR_OK.getCode()); err = ErrorCode.ERR_OK;
rsp.setMessage(new String[] {ErrorCode.ERR_OK.getDescription()});
} }
rsp.setStatus(err.getCode());
rsp.setMessage(new String[] {err.getDescription()});
rsp.setUsername(username); rsp.setUsername(username);
SecurityResponseUtils.authenticationResponse(request, response, rsp, Arrays.toString(rsp.getMessage()), SecurityResponseUtils.authenticationResponse(request, response, rsp, err.getStringValue(), optLogDbService);
optLogDbService);
} catch (IOException e) { } catch (IOException e) {
throw new AuthenticationServiceException(e.getMessage()); throw new AuthenticationServiceException(e.getMessage());
} }

View File

@ -32,6 +32,6 @@ public class JwtLogoutSuccessHandler implements LogoutSuccessHandler {
new SecurityContextLogoutHandler().logout(request, response, authentication); new SecurityContextLogoutHandler().logout(request, response, authentication);
} }
SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_OK, "logout", optLogDbService); SecurityResponseUtils.authenticationResponse(request, response, ErrorCode.ERR_OK, "SYSLOG_DESC_LOGOUT", optLogDbService);
} }
} }

View File

@ -1,5 +1,7 @@
package com.cf.cs.base.common; package com.cf.cs.base.common;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.houkunlin.system.dict.starter.DictEnum; import com.houkunlin.system.dict.starter.DictEnum;
import com.houkunlin.system.dict.starter.json.DictType; import com.houkunlin.system.dict.starter.json.DictType;
@ -35,6 +37,15 @@ public enum CommonStatus implements BaseEnum, DictEnum<Integer> {
this.readme = readme; this.readme = readme;
} }
/**
* Gets string value.
*
* @return the string value
*/
public String getStringValue() {
return this.name();
}
@Override @Override
public Integer getValue() { public Integer getValue() {
return this.code; return this.code;
@ -47,6 +58,6 @@ public enum CommonStatus implements BaseEnum, DictEnum<Integer> {
@Override @Override
public String getDescription() { public String getDescription() {
return this.readme; return MessageUtil.get(getStringValue(), ApiContextUtils.getLanguare());
} }
} }

View File

@ -20,9 +20,21 @@ public class ConstValue {
* The constant STRING_HTTP_AUTH_HEAD. * The constant STRING_HTTP_AUTH_HEAD.
*/ */
public static final String STRING_HTTP_AUTH_HEAD = "Bearer "; public static final String STRING_HTTP_AUTH_HEAD = "Bearer ";
/**
* The constant LANGUAGE_HEAD.
*/
public static final String LANGUAGE_HEAD = "language";
/**
* The constant MS_OF_SECONDS.
*/
public static final long MS_OF_SECONDS = 1000L; public static final long MS_OF_SECONDS = 1000L;
public static final long SECOND_OF_MINUTE = 60; public static final long SECOND_OF_MINUTE = 60;
/**
* The constant MAX_IPV4_LEN.
*/
public static final int MAX_IPV4_LEN = 15; public static final int MAX_IPV4_LEN = 15;
/** /**

View File

@ -1,5 +1,7 @@
package com.cf.cs.base.common; package com.cf.cs.base.common;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.houkunlin.system.dict.starter.DictEnum; import com.houkunlin.system.dict.starter.DictEnum;
import com.houkunlin.system.dict.starter.json.DictType; import com.houkunlin.system.dict.starter.json.DictType;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -292,6 +294,6 @@ public enum ErrorCode implements BaseEnum, DictEnum<Integer> {
@Override @Override
public String getDescription() { public String getDescription() {
return this.errMsg; return MessageUtil.get(getStringValue(), ApiContextUtils.getLanguare());
} }
} }

View File

@ -1,5 +1,7 @@
package com.cf.cs.base.common; package com.cf.cs.base.common;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.houkunlin.system.dict.starter.DictEnum; import com.houkunlin.system.dict.starter.DictEnum;
import com.houkunlin.system.dict.starter.json.DictType; import com.houkunlin.system.dict.starter.json.DictType;
@ -61,6 +63,6 @@ public enum ProtoCryptoType implements BaseEnum, DictEnum<Integer> {
@Override @Override
public String getDescription() { public String getDescription() {
return this.readme; return MessageUtil.get(getStringValue(), ApiContextUtils.getLanguare());
} }
} }

View File

@ -0,0 +1,44 @@
package com.cf.cs.base.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import java.util.Locale;
/**
* The type Locale config.
*
* @author xajhuang @163.com
*/
@Configuration
public class LocaleConfig {
/**
* Message source resource bundle message source.
*
* @return the resource bundle message source
*/
@Bean
public ResourceBundleMessageSource messageSource() {
Locale.setDefault(Locale.CHINA);
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
//设置国际化文件存储路径和名称 i18n目录messages文件名
source.setBasenames("i18n/message", "i18n/errorMessage", "i18n/enumMessage", "i18n/syslogMessage");
//设置根据key如果没有获取到对应的文本信息,则返回key作为信息
source.setUseCodeAsDefaultMessage(true);
//设置字符编码
source.setDefaultEncoding("UTF-8");
return source;
}
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("i18n/validationMessage");
localValidatorFactoryBean.setValidationMessageSource(messageSource);
return localValidatorFactoryBean;
}
}

View File

@ -41,6 +41,20 @@ public class ApiContextUtils {
context.setRequestTime(reqTime); context.setRequestTime(reqTime);
} }
public static String getLanguare() {
return HelperUtils.stringNotEmptyOrNull(get().getReqLocal()) ? get().getReqLocal() : "zh_CN";
}
/**
* Sets request local.
*
* @param local the local
*/
public static void setRequestLocal(String local) {
ApiContext context = get();
context.setReqLocal(local);
}
/** /**
* Sets jwt user info. * Sets jwt user info.
* *

View File

@ -7,9 +7,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation; import org.springframework.context.i18n.LocaleContextHolder;
import jakarta.validation.ValidatorFactory; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.hibernate.validator.HibernateValidator;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -26,6 +25,7 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -35,12 +35,12 @@ import java.util.Set;
* @author xajhuang @163.com * @author xajhuang @163.com
*/ */
public class HelperUtils { public class HelperUtils {
private static final ObjectMapper OBJ_MAPPER = ObjectMapperProvider.getMapper();
private HelperUtils() { private HelperUtils() {
throw new AssertionError("Instantiating utility class."); throw new AssertionError("Instantiating utility class.");
} }
private static final ObjectMapper OBJ_MAPPER = ObjectMapperProvider.getMapper();
/** /**
* Gets json. * Gets json.
* *
@ -155,15 +155,13 @@ public class HelperUtils {
*/ */
public static <T> List<String> validate(T t, Class<?>... groups) { public static <T> List<String> validate(T t, Class<?>... groups) {
Set<ConstraintViolation<T>> set; Set<ConstraintViolation<T>> set;
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class) LocaleContextHolder.setLocale(Locale.forLanguageTag(ApiContextUtils.getLanguare().replace('_', '-')));
.configure() LocalValidatorFactoryBean localValidatorFactory = SpringBootBeanUtils.getBean(LocalValidatorFactoryBean.class);
.failFast(false)
.buildValidatorFactory();
if (groups != null && groups.length > 0) { if (groups != null && groups.length > 0) {
set = validatorFactory.getValidator().validate(t, groups); set = localValidatorFactory.getValidator().validate(t, groups);
} else { } else {
set = validatorFactory.getValidator().validate(t); set = localValidatorFactory.getValidator().validate(t);
} }
List<String> validateError = new ArrayList<>(); List<String> validateError = new ArrayList<>();
if (!set.isEmpty()) { if (!set.isEmpty()) {

View File

@ -0,0 +1,77 @@
package com.cf.cs.base.misc;
import io.micrometer.common.util.StringUtils;
import org.springframework.context.MessageSource;
import java.util.Locale;
/**
* The type Message util.
*
* @author xajhuang @163.com
*/
public class MessageUtil {
private static final int ARRAY_SIZE = 2;
private MessageUtil() {
throw new AssertionError("Instantiating utility class.");
}
/**
* Get string.
*
* @param key the key
* @param language the language
* @return the string
*/
public static String get(String key, String language) {
if (!StringUtils.isEmpty(language)) {
String[] arrs = language.split("_");
if (arrs.length == ARRAY_SIZE) {
return get(key, new Locale(arrs[0], arrs[1]));
}
}
//使用默认的国际化语言
return get(key, Locale.getDefault());
}
/**
* Get string.
*
* @param key the key
* @param params the params
* @param language the language
* @return the string
*/
public static String get(String key, Object[] params, String language) {
if (!StringUtils.isEmpty(language)) {
String[] arrs = language.split("_");
if (arrs.length == ARRAY_SIZE) {
return get(key, params, new Locale(arrs[0], arrs[1]));
}
}
return get(key, params, Locale.getDefault());
}
private static String get(String key, Locale language) {
return get(key, new String[0], language);
}
private static String get(String key, Object[] params, Locale language) {
String ret = getInstance().getMessage(key, params, language);
if (HelperUtils.stringNotEmptyOrNull(ret)) {
return ret;
}
return key;
}
private static MessageSource getInstance() {
return Lazy.MESSAGE_SOURCE;
}
private static class Lazy {
private static final MessageSource MESSAGE_SOURCE = SpringBootBeanUtils.getBean(MessageSource.class);
}
}

View File

@ -15,6 +15,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ApiContext { public class ApiContext {
private String reqLocal;
private String requestBody; private String requestBody;
private Long requestTime; private Long requestTime;
private String jwt; private String jwt;

View File

@ -0,0 +1,9 @@
NORMAL=Normal
LOCKED=Locked
DISABLED=Disabled
DELETED=Deleted
CRYPTO_NONE=Unencrypted
CRYPTO_BASE64=Base64 encoding
CRYPTO_AES128=AES128 encryption
CRYPTO_DES=DES symmetric encryption
CRYPTO_AES256=AES256 encryption

View File

@ -0,0 +1,9 @@
NORMAL=\u6B63\u5E38
LOCKED=\u5DF2\u9501\u5B9A
DISABLED=\u5DF2\u7981\u7528
DELETED=\u5DF2\u5220\u9664
CRYPTO_NONE=\u4E0D\u52A0\u5BC6
CRYPTO_BASE64=Base64\u7F16\u7801
CRYPTO_AES128=AES128\u52A0\u5BC6
CRYPTO_DES=DES\u5BF9\u79F0\u52A0\u5BC6
CRYPTO_AES256=AES256\u52A0\u5BC6

View File

@ -0,0 +1,58 @@
ERR_OK=Successful
ERR_PASSWORD=Incorrect password
ERR_USERNOTFOUND=User does not exist
ERR_PASSWORDMORE=The number of consecutive incorrect passwords reaches the upper limit
ERR_USERLOCK=Password error reaches the upper limit, The user is locked
ERR_PASSWORD_EXPIRED=The password has expired
ERR_ACCOUNT=The user account is abnormal
ERR_USEREXIST=The user already exists
ERR_PASSWORDSIMPLE=The user password strength does not meet the requirement. ERR_INPUTFORMAT=The input information format is incorrect
ERR_INPUTMISS=No necessary input information
ERR_PERMISSION=Operator permission is insufficient
ERR_REQTIMEOUT=Request timeout
ERR_PARAMS=Parameter error
ERR_SYSTEMEXCEPTION=System exception
ERR_UNKNOWNCMD=Unknown command
ERR_LOGOUT=User not logged in
ERR_TOKENTIMEOUT=Token timeout
ERR_TOKENNOTFOUND=Illegal Token
ERR_TOKEN_KEY=Token key error
ERR_MISSAUTHHEAD=Http request missing authentication header
ERR_NOSUCHITEM=No such content
ERR_ITEMEXISTS=The content already exists
ERR_PARAMEXCEPTION=Parameter exception
ERR_DEVICELOCKED=Device locked
ERR_VERSION=Protocol version incompatible, Please upgrade the system
ERR_NOSUCHTYPE=No device of this type exists
ERR_REMOVEMORE=Disable deleting multiple devices at the same time
ERR_TASKRUNNING=Similar tasks are running
ERR_UNSUPPORT=Unsupported operations
ERR_INTERRUPT=Operation interruption
ERR_CALLDEVICE=Failed to call the device
ERR_NOSUCHTASK=No task
ERR_TASKNOTRUNNING=No task is running
ERR_REQUESTTIMEOUT=Request timeout
ERR_UNABLEDISPOSEIP=Unable to handle the IP
ERR_DATABASE=Failed to operate the database
ERR_UNTRUSTHOST=Unauthorized client
ERR_UNTRUSTTOKEN=Unauthorized Token
ERR_UNKNOWNINTERFACE=Interface not provided
ERR_DECRYPT_BASE64=BASE64 decryption failure
ERR_ENCRYPT_BASE64=BASE64 encryption failure
ERR_DECRYPT_AES128=AES128 decryption failure
ERR_ENCRYPT_AES128=AES128 encryption failure
ERR_DECRYPT_3DES=3DES decryption failure
ERR_ENCRYPT_3DES=3DES Encryption failure
ERR_DECRYPT_UNKNOWN=Unsupported decryption algorithm
ERR_ENCRYPT_UNKNOWN=unsupported encryption algorithm
ERR_JSON_ENCODE=Json Sequence number error
ERR_JSON_DECODE=Json deserialization error
ERR_ENCRYPT_AES256=AES256 Encryption failure
ERR_DECRYPT_AES256=AES256 decryption failure
ERR_CRYPTO_KEY=Wrong secret key
ERR_USER_ROLE_NOTEXISTS=The user role does not exist
ERR_RESOURCE_USED=Resource used
err.auth.key.convert=Key algorithm or key conversion error
err.auth.key.verify=Key missing verification data
err.auth.key.timeout=Key expired
err.auth.key.prase=Key resolution error

View File

@ -0,0 +1,59 @@
ERR_OK=\u6210\u529F
ERR_PASSWORD=\u5BC6\u7801\u9519\u8BEF
ERR_USERNOTFOUND=\u7528\u6237\u4E0D\u5B58\u5728
ERR_PASSWORDMORE=\u8FDE\u7EED\u5BC6\u7801\u9519\u8BEF\u8FBE\u4E0A\u9650\uFF0C\u518D\u6B21\u8F93\u5165\u9519\u8BEF\u5C06\u9501\u5B9A\u7528\u6237
ERR_USERLOCK=\u5BC6\u7801\u9519\u8BEF\u8FBE\u4E0A\u9650\uFF0C\u7528\u6237\u88AB\u9501\u5B9A
ERR_PASSWORD_EXPIRED=\u5BC6\u7801\u5DF2\u7ECF\u8FC7\u671F
ERR_ACCOUNT=\u7528\u6237\u8D26\u6237\u5F02\u5E38
ERR_USEREXIST=\u8BE5\u7528\u6237\u5DF2\u7ECF\u5B58\u5728
ERR_PASSWORDSIMPLE=\u7528\u6237\u5BC6\u7801\u5F3A\u5EA6\u4E0D\u7B26\u5408\u8981\u6C42
ERR_INPUTFORMAT=\u8F93\u5165\u4FE1\u606F\u683C\u5F0F\u6709\u8BEF
ERR_INPUTMISS=\u7F3A\u5C11\u5FC5\u8981\u8F93\u5165\u4FE1\u606F
ERR_PERMISSION=\u64CD\u4F5C\u5458\u6743\u9650\u4E0D\u8DB3
ERR_REQTIMEOUT=\u8BF7\u6C42\u8D85\u65F6
ERR_PARAMS=\u53C2\u6570\u9519\u8BEF
ERR_SYSTEMEXCEPTION=\u7CFB\u7EDF\u5F02\u5E38
ERR_UNKNOWNCMD=\u672A\u77E5\u547D\u4EE4
ERR_LOGOUT=\u7528\u6237\u672A\u767B\u5F55
ERR_TOKENTIMEOUT=Token\u8D85\u65F6
ERR_TOKENNOTFOUND=\u975E\u6CD5Token
ERR_TOKEN_KEY=Token \u79D8\u94A5\u9519\u8BEF
ERR_MISSAUTHHEAD=Http \u8BF7\u6C42\u7F3A\u5C11\u8BA4\u8BC1\u5934\u90E8
ERR_NOSUCHITEM=\u6CA1\u6709\u8BE5\u5185\u5BB9
ERR_ITEMEXISTS=\u8BE5\u5185\u5BB9\u5DF2\u7ECF\u5B58\u5728
ERR_PARAMEXCEPTION=\u53C2\u6570\u5F02\u5E38
ERR_DEVICELOCKED=\u8BBE\u5907\u5DF2\u9501\u5B9A
ERR_VERSION=\u534F\u8BAE\u7248\u672C\u4E0D\u517C\u5BB9\uFF0C\u8BF7\u5347\u7EA7\u7CFB\u7EDF
ERR_NOSUCHTYPE=\u6CA1\u6709\u8FD9\u4E2A\u7C7B\u578B\u7684\u8BBE\u5907
ERR_REMOVEMORE=\u7981\u6B62\u540C\u65F6\u5220\u9664\u591A\u4E2A\u8BBE\u5907
ERR_TASKRUNNING=\u540C\u7C7B\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C
ERR_UNSUPPORT=\u4E0D\u652F\u6301\u7684\u64CD\u4F5C
ERR_INTERRUPT=\u64CD\u4F5C\u4E2D\u65AD
ERR_CALLDEVICE=\u8C03\u7528\u8BBE\u5907\u5931\u8D25
ERR_NOSUCHTASK=\u6CA1\u6709\u8BE5\u4EFB\u52A1
ERR_TASKNOTRUNNING=\u8BE5\u4EFB\u52A1\u6CA1\u6709\u8FD0\u884C
ERR_REQUESTTIMEOUT=\u8BF7\u6C42\u8D85\u65F6
ERR_UNABLEDISPOSEIP=\u65E0\u6CD5\u5904\u7F6E\u8BE5IP
ERR_DATABASE=\u64CD\u4F5C\u6570\u636E\u5E93\u5931\u8D25
ERR_UNTRUSTHOST=\u672A\u7ECF\u6388\u6743\u7684\u5BA2\u6237\u7AEF
ERR_UNTRUSTTOKEN=\u672A\u7ECF\u6388\u6743\u7684Token
ERR_UNKNOWNINTERFACE=\u672A\u63D0\u4F9B\u8BE5\u63A5\u53E3
ERR_DECRYPT_BASE64=BASE64\u89E3\u5BC6\u5931\u8D25
ERR_ENCRYPT_BASE64=BASE64\u52A0\u5BC6\u5931\u8D25
ERR_DECRYPT_AES128=AES128\u89E3\u5BC6\u5931\u8D25
ERR_ENCRYPT_AES128=AES128\u52A0\u5BC6\u5931\u8D25
ERR_DECRYPT_3DES=3DES\u89E3\u5BC6\u5931\u8D25
ERR_ENCRYPT_3DES=3DES\u52A0\u5BC6\u5931\u8D25
ERR_DECRYPT_UNKNOWN=\u4E0D\u652F\u6301\u7684\u89E3\u5BC6\u7B97\u6CD5
ERR_ENCRYPT_UNKNOWN=\u4E0D\u652F\u6301\u7684\u52A0\u5BC6\u7B97\u6CD5
ERR_JSON_ENCODE=Json \u5E8F\u5217\u53F7\u9519\u8BEF
ERR_JSON_DECODE=Json \u53CD\u5E8F\u5217\u5316\u9519\u8BEF
ERR_ENCRYPT_AES256=AES256\u52A0\u5BC6\u5931\u8D25
ERR_DECRYPT_AES256=AES256\u89E3\u5BC6\u5931\u8D25
ERR_CRYPTO_KEY=\u9519\u8BEF\u7684\u79D8\u94A5
ERR_USER_ROLE_NOTEXISTS=\u7528\u6237\u89D2\u8272\u4E0D\u5B58\u5728
ERR_RESOURCE_USED=\u8D44\u6E90\u88AB\u5360\u7528
err.auth.key.convert=\u5BC6\u94A5\u7B97\u6CD5\u6216\u8005\u5BC6\u94A5\u8F6C\u6362\u9519\u8BEF
err.auth.key.verify=\u5BC6\u94A5\u7F3A\u5C11\u6821\u9A8C\u6570\u636E
err.auth.key.timeout=\u5BC6\u94A5\u5DF2\u8FC7\u671F
err.auth.key.prase=\u5BC6\u94A5\u89E3\u6790\u9519\u8BEF

View File

@ -0,0 +1,37 @@
SYSLOG_MOD_COMMON=Universal Module
SYSLOG_MOD_SYSLOG=Operation Log Module
SYSLOG_MOD_AUTH=Rights Management Module
SYSLOG_MOD_DICT=Dictionary Module
SYSLOG_MOD_SYSINFO=System Information Module
SYSLOG_MOD_USER_MGR=User Management Module
SYSLOG_MOD_SECURITY=System Safety Module
SYSLOG_TYPE_AUTH=Authentication/Authentication
SYSLOG_TYPE_READ=READ
SYSLOG_TYPE_CREATE=CREATE
SYSLOG_TYPE_DEL=DELETE
SYSLOG_TYPE_MODIFY=MODIFY
SYSLOG_DESC_GET_VERSION=Obtain the current system version information
SYSLOG_DESC_GET_SYSLOG_SUMMARY=Obtain the brief information about operationlogs
SYSLOG_DESC_GET_SYSLOG_DETAIL=Obtain operation logdetails
SYSLOG_DESC_GET_CUR_USR_RES_RIGHT=Get the current user resource rights
SYSLOG_DESC_GET_USR_RES_RIGHT=Obtain user resource rights
SYSLOG_DESC_GET_ALL_USR_GROUP=Get all current user groups
SYSLOG_DESC_CREATE_RESOURCE=Register a new resource
SYSLOG_DESC_DEL_RESOURCE=Delete resource
SYSLOG_DESC_GET_ALL_ENUM_DICT=Get all enumeration dictionary type information of the system
SYSLOG_DESC_GET_ENUM_DETAIL=Gets the details of the system enumeration dictionary
SYSLOG_DESC_CREATE_USER_DICT=Creating a user dictionary
SYSLOG_DESC_MODIFY_USER_DICT=Modify the contents of the user dictionary
SYSLOG_DESC_GET_ALL_USER_DICT=Get all user dictionaries
SYSLOG_DESC_GET_USER_DETAIL=Get the user dictionary content item
SYSLOG_DESC_CREATE_USER_DICT_ITEM=Add user dictionary content items
SYSLOG_DESC_GET_OS_INFO=Obtain information about the current operating system
SYSLOG_DESC_GET_CPU_INFO=Gets current processor information
SYSLOG_DESC_GET_HW_INFO=Obtain system hardware information
SYSLOG_DESC_GET_USER=Get user information
SYSLOG_DESC_GET_USER_LIST=Get user list
SYSLOG_DESC_GET_CUR_USER=get current user information
SYSLOG_DESC_CREATE_USER=Create new user
SYSLOG_DESC_DEL_USER=Delete user
SYSLOG_DESC_LOGOUT=Logout
SYSLOG_DESC_LOGIN=Login

View File

@ -0,0 +1,37 @@
SYSLOG_MOD_COMMON=\u901A\u7528\u6A21\u5757
SYSLOG_MOD_SYSLOG=\u64CD\u4F5C\u65E5\u5FD7\u6A21\u5757
SYSLOG_MOD_AUTH=\u6743\u9650\u7BA1\u7406\u6A21\u5757
SYSLOG_MOD_DICT=\u5B57\u5178\u6A21\u5757
SYSLOG_MOD_SYSINFO=\u7CFB\u7EDF\u4FE1\u606F\u6A21\u5757
SYSLOG_MOD_USER_MGR=\u7528\u6237\u7BA1\u7406\u6A21\u5757
SYSLOG_MOD_SECURITY=\u7CFB\u7EDF\u5B89\u5168\u6A21\u5757
SYSLOG_TYPE_AUTH=\u8BA4\u8BC1/\u9274\u6743
SYSLOG_TYPE_READ=\u8BFB\u53D6
SYSLOG_TYPE_CREATE=\u521B\u5EFA
SYSLOG_TYPE_DEL=\u5220\u9664
SYSLOG_TYPE_MODIFY=\u4FEE\u6539
SYSLOG_DESC_GET_VERSION=\u83B7\u53D6\u5F53\u524D\u7CFB\u7EDF\u7248\u672C\u4FE1\u606F
SYSLOG_DESC_GET_SYSLOG_SUMMARY=\u83B7\u53D6\u64CD\u4F5C\u65E5\u5FD7\u7B80\u8981\u4FE1\u606F
SYSLOG_DESC_GET_SYSLOG_DETAIL=\u83B7\u53D6\u64CD\u4F5C\u65E5\u5FD7\u8BE6\u7EC6\u4FE1\u606F
SYSLOG_DESC_GET_CUR_USR_RES_RIGHT=\u83B7\u53D6\u5F53\u524D\u7528\u6237\u8D44\u6E90\u6743\u9650
SYSLOG_DESC_GET_USR_RES_RIGHT=\u83B7\u53D6\u7528\u6237\u8D44\u6E90\u6743\u9650
SYSLOG_DESC_GET_ALL_USR_GROUP=\u83B7\u53D6\u5F53\u524D\u6240\u6709\u7528\u6237\u7EC4
SYSLOG_DESC_CREATE_RESOURCE=\u6CE8\u518C\u65B0\u7684\u8D44\u6E90
SYSLOG_DESC_DEL_RESOURCE=\u5220\u9664\u8D44\u6E90
SYSLOG_DESC_GET_ALL_ENUM_DICT=\u83B7\u53D6\u7CFB\u7EDF\u6240\u6709\u679A\u4E3E\u5B57\u5178\u7C7B\u578B\u4FE1\u606F
SYSLOG_DESC_GET_ENUM_DETAIL=\u83B7\u53D6\u7CFB\u7EDF\u679A\u4E3E\u5B57\u5178\u8BE6\u7EC6\u5185\u5BB9
SYSLOG_DESC_CREATE_USER_DICT=\u65B0\u5EFA\u7528\u6237\u5B57\u5178
SYSLOG_DESC_MODIFY_USER_DICT=\u4FEE\u6539\u7528\u6237\u5B57\u5178\u5185\u5BB9
SYSLOG_DESC_GET_ALL_USER_DICT=\u83B7\u53D6\u6240\u6709\u7528\u6237\u5B57\u5178
SYSLOG_DESC_GET_USER_DETAIL=\u83B7\u53D6\u7528\u6237\u5B57\u5178\u5185\u5BB9\u9879
SYSLOG_DESC_CREATE_USER_DICT_ITEM=\u65B0\u589E\u7528\u6237\u5B57\u5178\u5185\u5BB9\u9879
SYSLOG_DESC_GET_OS_INFO=\u83B7\u53D6\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u4FE1\u606F
SYSLOG_DESC_GET_CPU_INFO=\u83B7\u53D6\u5F53\u524D\u5904\u7406\u5668\u4FE1\u606F
SYSLOG_DESC_GET_HW_INFO=\u83B7\u53D6\u7CFB\u7EDF\u786C\u4EF6\u4FE1\u606F
SYSLOG_DESC_GET_USER=\u83B7\u53D6\u7528\u6237\u4FE1\u606F
SYSLOG_DESC_GET_USER_LIST=\u83B7\u53D6\u7528\u6237\u5217\u8868
SYSLOG_DESC_GET_CUR_USER=\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F
SYSLOG_DESC_CREATE_USER=\u521B\u5EFA\u65B0\u7528\u6237
SYSLOG_DESC_DEL_USER=\u5220\u9664\u7528\u6237
SYSLOG_DESC_LOGOUT=\u6CE8\u9500
SYSLOG_DESC_LOGIN=\u767B\u5F55

View File

@ -0,0 +1,14 @@
item.not_null=field cannot be null
item.not_empty=field cannot be empty string
item.value_range=Field value range [{min}, {max}]
item.value_min=Minimum value is {min}
array.value_range=Array/List size range [{min}, {max}]
array.not_empty=Arrays/List cannot be NULL and elements cannot be empty
timestamp.timeout=The difference between the field value and the current time cannot be greater than the timeout configuration
page.item_size=The value must be an integer multiple of 5
uuid.format=UUID string must match format(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
invalid.character=Invalid character strings exist
password.length=The password size must be SHA256 length
http.request_invalid=Not a legitimate HTTP request method
timeout.current.format=Request time[{0}] greater than current server time[{1}]
timeout.server.format=Request time [{0}] Delay exceeds current server time [{1}] Allowed range {2}(S)

View File

@ -0,0 +1,14 @@
item.not_null=\u5B57\u6BB5\u4E0D\u80FD\u4E3A NULL
item.not_empty=\u5B57\u6BB5\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32
item.value_range=\u5B57\u6BB5\u53D6\u503C\u8303\u56F4 [{min}, {max}]
item.value_min=\u6700\u5C0F\u503C\u4E3A {min}
array.value_range=\u6570\u7EC4/\u94FE\u8868\u5143\u7D20\u4E2A\u6570\u53D6\u503C\u8303\u56F4 [{min}, {max}]
array.not_empty=\u6570\u7EC4/\u94FE\u8868\u4E0D\u80FD\u4E3ANULL\u4E14\u5143\u7D20\u4E0D\u80FD\u4E3A\u7A7A
timestamp.timeout=\u5B57\u6BB5\u503C\u4E0E\u5F53\u524D\u65F6\u95F4\u5DEE\u4E0D\u80FD\u5927\u4E8E\u8D85\u65F6\u914D\u7F6E
page.item_size=\u53D6\u503C\u5FC5\u987B\u4E3A 5 \u7684\u6574\u6570\u500D
uuid.format=\u5FC5\u987B\u4E3A\u7B26\u5408UUID\u89C4\u8303(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)\u7684\u5B57\u7B26\u4E32
invalid_character=\u5B57\u7B26\u4E32\u5B58\u5728\u975E\u6CD5\u5B57\u7B26
password.length=\u5BC6\u7801\u957F\u5EA6\u5FC5\u987B\u4E3ASHA256\u7F16\u7801\u540E\u7684\u957F\u5EA6
http.request_invalid=\u4E0D\u662F\u5408\u6CD5\u7684 HTTP \u8BF7\u6C42\u65B9\u6CD5
timeout.current.format=\u8BF7\u6C42\u65F6\u95F4[{0}] \u5927\u4E8E\u5F53\u524D\u670D\u52A1\u5668\u65F6\u95F4[{1}]
timeout.server.format=\u8BF7\u6C42\u65F6\u95F4[{0}] \u5EF6\u65F6\u8D85\u8FC7\u5F53\u524D\u670D\u52A1\u5668\u65F6\u95F4[{1}] \u5141\u8BB8\u8303\u56F4 {2}(S)

View File

@ -59,6 +59,10 @@ public class OperationLog {
@Column(value = "description") @Column(value = "description")
private String description; private String description;
@Schema(description = "访问用户")
@Column(value = "access_user")
private String accessUser;
/** /**
* 请求来源 IP 地址 * 请求来源 IP 地址
*/ */

View File

@ -58,8 +58,8 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
OperationLogAnnotation annotation, OperationLogAnnotation annotation,
ErrorCode errorCode) { ErrorCode errorCode) {
if (annotation != null) { if (annotation != null) {
systemOperationLog(call, request, result, annotation.OperationModule(), annotation.OperationType(), systemOperationLog(call, request, result, annotation.OperationModule(), annotation.OperationType(), annotation.OperationDesc(),
annotation.OperationDesc(), errorCode); errorCode);
} else { } else {
systemOperationLog(call, request, result, "", "", "", errorCode); systemOperationLog(call, request, result, "", "", "", errorCode);
} }
@ -76,12 +76,13 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
return; return;
} }
optLog.setOperationStatus(errorCode.getDescription()); optLog.setOperationStatus(errorCode.getStringValue());
//获取注解操作信息 //获取注解操作信息
optLog.setModule("系统安全模块"); optLog.setModule("SYSLOG_MOD_SECURITY");
optLog.setOperationType("认证/鉴权"); optLog.setOperationType("SYSLOG_TYPE_AUTH");
optLog.setDescription(readme); optLog.setDescription(readme);
optLog.setAccessUser(ctx.getUsername());
optLog.setUserId(-1L); optLog.setUserId(-1L);
//操作时间 //操作时间
@ -108,7 +109,6 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
} }
if (HelperUtils.stringNotEmptyOrNull(ctx.getJwt())) { if (HelperUtils.stringNotEmptyOrNull(ctx.getJwt())) {
optLog.setDescription(ctx.getUsername() + " " + optLog.getDescription());
optLog.setUserId(ctx.getId() != null ? ctx.getId() : -1L); optLog.setUserId(ctx.getId() != null ? ctx.getId() : -1L);
} }
} }
@ -141,10 +141,7 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
} }
@Override @Override
public Page<OperationLog> getSystemOperationSummary(Long pageNumber, public Page<OperationLog> getSystemOperationSummary(Long pageNumber, Long pageSize, Long totalSize, List<String> userName) {
Long pageSize,
Long totalSize,
List<String> userName) {
QueryWrapper wrapper; QueryWrapper wrapper;
ApiContext ctx = ApiContextUtils.get(); ApiContext ctx = ApiContextUtils.get();
@ -163,19 +160,17 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
.where(OPERATION_LOG.USER_ID.eq(USER.ID) .where(OPERATION_LOG.USER_ID.eq(USER.ID)
.and(USER.ID.in(idArray)) .and(USER.ID.in(idArray))
.and(USER.ROLE_ID.ge( .and(USER.ROLE_ID.ge(
select(distinct(USER.ROLE_ID)).from( select(distinct(USER.ROLE_ID))
USER.as("u")) .from(USER.as("u"))
.where(USER.ID.eq( .where(USER.ID.eq(ctx.getId())))));
ctx.getId())))));
} else { } else {
wrapper = new QueryWrapper().select(OPERATION_LOG.ALL_COLUMNS) wrapper = new QueryWrapper().select(OPERATION_LOG.ALL_COLUMNS)
.from(OPERATION_LOG.as("o"), USER.as("u1")) .from(OPERATION_LOG.as("o"), USER.as("u1"))
.where(OPERATION_LOG.USER_ID.eq(USER.ID) .where(OPERATION_LOG.USER_ID.eq(USER.ID)
.and(USER.ROLE_ID.ge( .and(USER.ROLE_ID.ge(
select(distinct(USER.ROLE_ID)).from( select(distinct(USER.ROLE_ID))
USER.as("u")) .from(USER.as("u"))
.where(USER.ID.eq( .where(USER.ID.eq(ctx.getId())))));
ctx.getId())))));
} }
return operationLogMapper.paginate(pageNumber, pageSize, totalSize, wrapper); return operationLogMapper.paginate(pageNumber, pageSize, totalSize, wrapper);
@ -187,10 +182,7 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
@Override @Override
public List<OperationLog> getSystemOperationDetails(List<Long> operationId) { public List<OperationLog> getSystemOperationDetails(List<Long> operationId) {
QueryWrapper wrapper = QueryWrapper.create() QueryWrapper wrapper = QueryWrapper.create().from(OPERATION_LOG).select().where(OPERATION_LOG.ID.in(operationId));
.from(OPERATION_LOG)
.select()
.where(OPERATION_LOG.ID.in(operationId));
return operationLogMapper.selectListByQuery(wrapper); return operationLogMapper.selectListByQuery(wrapper);
} }
@ -210,12 +202,13 @@ public class OperationLogDataBaseServiceImpl extends ServiceImpl<OperationLogMap
return; return;
} }
optLog.setOperationStatus(errorCode.getDescription()); optLog.setOperationStatus(errorCode.getStringValue());
optLog.setCallFunction(call); optLog.setCallFunction(call);
//获取注解操作信息 //获取注解操作信息
optLog.setModule(module); optLog.setModule(module);
optLog.setOperationType(optType); optLog.setOperationType(optType);
optLog.setDescription(desc); optLog.setDescription(desc);
optLog.setAccessUser(ctx.getUsername());
//操作时间 //操作时间
optLog.setOperationTime(new Timestamp(System.currentTimeMillis())); optLog.setOperationTime(new Timestamp(System.currentTimeMillis()));
// 请求方法 // 请求方法

View File

@ -30,16 +30,16 @@ public class BaseProtocol<T> implements Serializable {
@Serial @Serial
private static final long serialVersionUID = -32326523643641L; private static final long serialVersionUID = -32326523643641L;
@NotNull(message = "ver 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class) @NotNull(message = "ver {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 1, max = 9999, message = "ver 字段最小值为 1", groups = ValidGroups.ProtocolCommonValid.class) @Range(min = 1, max = 9999, message = "ver {item.value_range}", groups = ValidGroups.ProtocolCommonValid.class)
private Integer ver; private Integer ver;
@NotNull(message = "cryptoType 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class) @NotNull(message = "cryptoType {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 0, max = 4, message = "cryptoType 字段取值为 [0, 4]", groups = ValidGroups.ProtocolCommonValid.class) @Range(min = 0, max = 4, message = "cryptoType {item.value_range}", groups = ValidGroups.ProtocolCommonValid.class)
private Integer cryptoType; private Integer cryptoType;
@NotNull(message = "timeStamp 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class) @NotNull(message = "timeStamp {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@ValidProtocolTimestamp(message = "timeStamp 字段值与当前时间差不能大于超时配置", groups = ValidGroups.ProtocolCommonValid.class) @ValidProtocolTimestamp(message = "timeStamp {timestamp.timeout}", groups = ValidGroups.ProtocolCommonValid.class)
private Long timeStamp; private Long timeStamp;
@Valid @Valid

View File

@ -27,10 +27,10 @@ import java.util.List;
@Schema(name = "AddDictContentReq", description = "新增用户字典内容请求参数") @Schema(name = "AddDictContentReq", description = "新增用户字典内容请求参数")
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class AddDictContentReq { public class AddDictContentReq {
@NotBlank(message = "dictTpe 字典名称不能为空", groups = ValidGroups.DictReqValid.class) @NotBlank(message = "dictTpe {item.not_empty}", groups = ValidGroups.DictReqValid.class)
private String dictName; private String dictName;
@NotNull(message = "dictContent 字典内容值不能为 NULL", groups = ValidGroups.DictReqValid.class) @NotNull(message = "dictContent {item.not_null}", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "字典内容至少需要指定 1 个,最多只能指定 100 个", groups = ValidGroups.DictReqValid.class) @Size(min = 1, max = 100, message = "DictDetails {array.value_range}", groups = ValidGroups.DictReqValid.class)
private List<@Valid DictDetails> dictContent; private List<@Valid DictDetails> dictContent;
} }

View File

@ -4,12 +4,12 @@ import com.cf.cs.protocol.validation.group.ValidGroups;
import com.cf.cs.protocol.validation.valids.ValidPageSize; import com.cf.cs.protocol.validation.valids.ValidPageSize;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;
/** /**
* The type Base paged req. * The type Base paged req.
@ -23,15 +23,14 @@ import lombok.NoArgsConstructor;
@Schema(name = "BasePagedReq", description = "分页请求基础参数") @Schema(name = "BasePagedReq", description = "分页请求基础参数")
public class BasePagedReq { public class BasePagedReq {
@Schema(description = "分页号最小值为1") @Schema(description = "分页号最小值为1")
@NotNull(message = "pageNumber 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class) @NotNull(message = "pageNumber {item.not_null}", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 1, message = "pageNumber 最小值为1", groups = ValidGroups.BasePagedReqValid.class) @Min(value = 1, message = "pageNumber 最小值为1", groups = ValidGroups.BasePagedReqValid.class)
private Long pageNumber; private Long pageNumber;
@Schema(description = "分页大小最小值为5 最大值100 取值必须为5的整数倍") @Schema(description = "分页大小最小值为5 最大值100 取值必须为5的整数倍")
@NotNull(message = "pageSize 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class) @NotNull(message = "pageSize {item.not_null}", groups = ValidGroups.BasePagedReqValid.class)
@ValidPageSize(message = "pageSize 取值必须为 5 的整数倍", groups = ValidGroups.BasePagedReqValid.class) @ValidPageSize(message = "pageSize {page.item_size}", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 5, message = "pageSize 最小值为5", groups = ValidGroups.BasePagedReqValid.class) @Range(min = 5, max = 100, message = "pageSize {item.value_range}", groups = ValidGroups.BasePagedReqValid.class)
@Max(value = 100, message = "pageSize 最大值为100", groups = ValidGroups.BasePagedReqValid.class)
private Long pageSize; private Long pageSize;
@Schema(description = "数据总数未知时可以为空或者小于0 存在时可以加快后端数据库查询速度") @Schema(description = "数据总数未知时可以为空或者小于0 存在时可以加快后端数据库查询速度")

View File

@ -26,7 +26,7 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class DictContentReq { public class DictContentReq {
@Schema(description = "字典名") @Schema(description = "字典名")
@NotNull(message = "dictTpe 字典名称不能为NULL", groups = ValidGroups.DictReqValid.class) @NotNull(message = "dictTpe {item.not_null}", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "dictTpe 单次查询字典名称条数为 [1, 100]", groups = ValidGroups.DictReqValid.class) @Size(min = 1, max = 100, message = "dictTpe {array.value_range}", groups = ValidGroups.DictReqValid.class)
private List<@NotBlank(message = "dictTpe 字典名称不能为空", groups = ValidGroups.DictReqValid.class) String> dictTpe; private List<@NotBlank(message = "dictTpe 字典名称不能为空", groups = ValidGroups.DictReqValid.class) String> dictTpe;
} }

View File

@ -26,10 +26,10 @@ public class IdArrayReq {
/** /**
* The Ids. * The Ids.
*/ */
@NotNull(message = "ids 不能为 NULL", groups = ValidGroups.UserIdReqValid.class) @NotNull(message = "ids {item.not_null}", groups = ValidGroups.UserIdReqValid.class)
@Size(min = 1, max = 100, message = "ids 元素个数最小为1 最大为100", groups = ValidGroups.UserIdReqValid.class) @Size(min = 1, max = 100, message = "ids {array.value_range}", groups = ValidGroups.UserIdReqValid.class)
List<@NotBlank(message = "guid 不能为空", groups = ValidGroups.UserIdReqValid.class) List<@NotBlank(message = "guid {item.not_empty}", groups = ValidGroups.UserIdReqValid.class)
@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", @Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
message = "uid 必须为符号UUID规范(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)的字符串", groups = ValidGroups.UserIdReqValid.class) message = "uid {uuid.format}", groups = ValidGroups.UserIdReqValid.class)
String> ids; String> ids;
} }

View File

@ -22,23 +22,23 @@ import org.hibernate.validator.constraints.Length;
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class LoginReq { public class LoginReq {
@NotBlank(message = "username 用户名不能为空", groups = ValidGroups.LogoutReqValid.class) @NotBlank(message = "username {item.not_empty}", groups = ValidGroups.LogoutReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS, @Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE, flags = Pattern.Flag.CASE_INSENSITIVE,
message = "username 用户名存在非法字符串", message = "username {invalid.character}",
groups = ValidGroups.LogoutReqValid.class) groups = ValidGroups.LogoutReqValid.class)
private String username; private String username;
/** /**
* The Password. * The Password.
*/ */
@NotBlank(message = "password 密码不能为空", groups = ValidGroups.LoginReqValid.class) @NotBlank(message = "password {item.not_empty}", groups = ValidGroups.LoginReqValid.class)
@Length(min = 32, max = 64, @Length(min = 32, max = 64,
message = "password 密码长度必须为SHA256编码后的长度", message = "password {password.length}",
groups = ValidGroups.LoginReqValid.class) groups = ValidGroups.LoginReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS, @Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE, flags = Pattern.Flag.CASE_INSENSITIVE,
message = "password 密码存在非法字符串", message = "password {invalid.character}",
groups = ValidGroups.LoginReqValid.class) groups = ValidGroups.LoginReqValid.class)
private String password; private String password;
} }

View File

@ -23,14 +23,14 @@ import lombok.NoArgsConstructor;
@Schema(name = "NewUserDictReq", description = "新增用户字典请求参数") @Schema(name = "NewUserDictReq", description = "新增用户字典请求参数")
public class NewUserDictReq { public class NewUserDictReq {
@Schema(description = "字典名,用于标识各个不同的字典") @Schema(description = "字典名,用于标识各个不同的字典")
@NotEmpty(message = "dictName 字典类别不能为空", groups = ValidGroups.DictReqValid.class) @NotEmpty(message = "dictName {item.not_empty}", groups = ValidGroups.DictReqValid.class)
private String dictName; private String dictName;
@Schema(description = "字典别名,用于显示字典别名") @Schema(description = "字典别名,用于显示字典别名")
@NotNull(message = "dictAlias 字典类别不能为NULL", groups = ValidGroups.DictReqValid.class) @NotNull(message = "dictAlias {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictAlias; private String dictAlias;
@Schema(description = "字典备注信息") @Schema(description = "字典备注信息")
@NotNull(message = "dictRemark 字典类别不能为NULL", groups = ValidGroups.DictReqValid.class) @NotNull(message = "dictRemark {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictRemark; private String dictRemark;
} }

View File

@ -25,7 +25,7 @@ import java.util.List;
@Schema(name = "OperationLogDetailsReq", description = "操作日志详细请求参数") @Schema(name = "OperationLogDetailsReq", description = "操作日志详细请求参数")
public class OperationLogDetailsReq { public class OperationLogDetailsReq {
@Schema(description = "操作日志ID") @Schema(description = "操作日志ID")
@NotEmpty(message = "操作日志ID不能为空", groups = ValidGroups.OperationLogReqValid.class) @NotEmpty(message = "{array.not_empty}", groups = ValidGroups.OperationLogReqValid.class)
@Size(message = "操作日志ID至少需要指定 1 个,最多只能指定 100 个", min = 1, max = 100, groups = ValidGroups.OperationLogReqValid.class) @Size(message = "{array.value_range}", min = 1, max = 100, groups = ValidGroups.OperationLogReqValid.class)
private List<Long> operationIds; private List<Long> operationIds;
} }

View File

@ -30,7 +30,7 @@ public class RegisterResourceReq {
* The Resources. * The Resources.
*/ */
@Schema(description = "需要添加的资源") @Schema(description = "需要添加的资源")
@NotNull(message = "resources 资源不能为NULL", groups = ValidGroups.ResourceReqValid.class) @NotNull(message = "resources {item.not_null}", groups = ValidGroups.ResourceReqValid.class)
@Size(min = 1, max = 100, message = "resources 单次添加资源条数为 [1, 100]", groups = ValidGroups.ResourceReqValid.class) @Size(min = 1, max = 100, message = "resources {array.value_range}", groups = ValidGroups.ResourceReqValid.class)
List<@Valid ResourceInfo> resources; List<@Valid ResourceInfo> resources;
} }

View File

@ -24,26 +24,26 @@ import org.hibernate.validator.constraints.Length;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class RegisterUserReq { public class RegisterUserReq {
@Schema(description = "用户名") @Schema(description = "用户名")
@NotBlank(message = "username 用户名不能为空", groups = ValidGroups.UserReqValid.class) @NotBlank(message = "username {item.not_empty}", groups = ValidGroups.UserReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS, @Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE, flags = Pattern.Flag.CASE_INSENSITIVE,
message = "username 用户名存在非法字符串", message = "username {invalid.character}",
groups = ValidGroups.UserReqValid.class) groups = ValidGroups.UserReqValid.class)
private String username; private String username;
@Schema(description = "密码") @Schema(description = "密码")
@NotBlank(message = "password 密码不能为空", groups = ValidGroups.UserReqValid.class) @NotBlank(message = "password {item.not_empty}", groups = ValidGroups.UserReqValid.class)
@Length(min = 32, max = 64, @Length(min = 32, max = 64,
message = "password 密码长度必须为SHA256编码后的长度", message = "password {password.length}",
groups = ValidGroups.UserReqValid.class) groups = ValidGroups.UserReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS, @Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE, flags = Pattern.Flag.CASE_INSENSITIVE,
message = "password 密码存在非法字符串", message = "password {invalid.character}",
groups = ValidGroups.UserReqValid.class) groups = ValidGroups.UserReqValid.class)
private String password; private String password;
@Schema(description = "用户组ID") @Schema(description = "用户组ID")
@NotNull(message = "roleId 用户组ID不能为空", groups = ValidGroups.UserReqValid.class) @NotNull(message = "roleId {item.not_null}", groups = ValidGroups.UserReqValid.class)
@Min(value = 2, message = "roleId 用户组ID最小取值为2", groups = ValidGroups.UserReqValid.class) @Min(value = 2, message = "roleId {item.value_min}", groups = ValidGroups.UserReqValid.class)
private Long roleId; private Long roleId;
} }

View File

@ -22,6 +22,6 @@ import lombok.NoArgsConstructor;
@Schema(name = "RemoveDictReq", description = "删除用户字典请求参数") @Schema(name = "RemoveDictReq", description = "删除用户字典请求参数")
public class RemoveDictReq { public class RemoveDictReq {
@Schema(description = "字典名,用于标识各个不同的字典") @Schema(description = "字典名,用于标识各个不同的字典")
@NotNull(message = "dictName 字典名不能为NULL", groups = ValidGroups.DictReqValid.class) @NotNull(message = "dictName {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictName; private String dictName;
} }

View File

@ -20,7 +20,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class UserIdReq { public class UserIdReq {
@NotNull(message = "userId 用户ID不能为空", groups = ValidGroups.UserIdReqValid.class) @NotNull(message = "userId {item.not_null}", groups = ValidGroups.UserIdReqValid.class)
@UUID(message = "uid 必须为符号UUID规范(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)的字符串", groups = ValidGroups.UserIdReqValid.class) @UUID(message = "uid {uuid.format}", groups = ValidGroups.UserIdReqValid.class)
private String uid; private String uid;
} }

View File

@ -1,5 +1,6 @@
package com.cf.cs.protocol.pojo.po; package com.cf.cs.protocol.pojo.po;
import com.cf.cs.base.common.ErrorCode;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -28,4 +29,10 @@ public class DictContent extends BaseRespStatus {
private String dictAlias; private String dictAlias;
private String dictRemark; private String dictRemark;
private List<DictDetails> children; private List<DictDetails> children;
public DictContent(String dictName, ErrorCode err) {
this.dictName = dictName;
this.setStatus(err.getCode());
this.setMessage(new String[] {err.getDescription()});
}
} }

View File

@ -31,9 +31,9 @@ public class DictDetails {
private String upgradeBy; private String upgradeBy;
private Timestamp upgradeTime; private Timestamp upgradeTime;
@NotBlank(message = "title 字典内容不能为空", groups = ValidGroups.DictReqContentValid.class) @NotBlank(message = "title {item.not_empty}", groups = ValidGroups.DictReqContentValid.class)
private String title; private String title;
@NotNull(message = "value 字典内容值不能为 NULL", groups = ValidGroups.DictReqContentValid.class) @NotNull(message = "value {item.not_null}", groups = ValidGroups.DictReqContentValid.class)
private Integer value; private Integer value;
private Integer sorted; private Integer sorted;
private String cssClass; private String cssClass;

View File

@ -25,22 +25,22 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class ResourceInfo { public class ResourceInfo {
@Schema(description = "资源路径") @Schema(description = "资源路径")
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class) @NotNull(message = "path {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "path 资源 URL 不能为空字符串", groups = ValidGroups.ResourceInfoValid.class) @NotBlank(message = "path {item.not_empty}", groups = ValidGroups.ResourceInfoValid.class)
private String path; private String path;
@Schema(description = "资源名称") @Schema(description = "资源名称")
@NotNull(message = "name 资源名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class) @NotNull(message = "name {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "name 资源名称不能为空字符串", groups = ValidGroups.ResourceInfoValid.class) @NotBlank(message = "name {item.not_empty}", groups = ValidGroups.ResourceInfoValid.class)
private String name; private String name;
@Schema(description = "资源类型名称") @Schema(description = "资源类型名称")
@NotNull(message = "resTypeId 资源名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class) @NotNull(message = "resTypeId {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
private Integer resTypeId; private Integer resTypeId;
@Schema(description = "HTTP 方法") @Schema(description = "HTTP 方法")
@NotNull(message = "HttpMethod 方法名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class) @NotNull(message = "HttpMethod {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@Size(min = 1, max = 8, message = "HttpMethod HTTP 方法名称不能为空", groups = ValidGroups.ResourceInfoValid.class) @Size(min = 1, max = 8, message = "HttpMethod HTTP {array.value_range}", groups = ValidGroups.ResourceInfoValid.class)
@ValidHttpMethod(groups = ValidGroups.ResourceInfoValid.class) @ValidHttpMethod(groups = ValidGroups.ResourceInfoValid.class)
private List<String> httpMethod; private List<String> httpMethod;
} }

View File

@ -28,6 +28,9 @@ public class OptLogSummaryResp {
@Schema(description = "操作说明") @Schema(description = "操作说明")
private String description; private String description;
@Schema(description = "访问用户")
private String accessUser;
@Schema(description = "请求来源 IP 地址") @Schema(description = "请求来源 IP 地址")
private String requestIp; private String requestIp;

View File

@ -1,5 +1,7 @@
package com.cf.cs.protocol.validation.valids.impl; package com.cf.cs.protocol.validation.valids.impl;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.protocol.validation.valids.ValidHttpMethod; import com.cf.cs.protocol.validation.valids.ValidHttpMethod;
import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext; import jakarta.validation.ConstraintValidatorContext;
@ -27,7 +29,8 @@ public class ValidHttpMethodImpl implements ConstraintValidator<ValidHttpMethod,
if (RequestMethod.resolve(k.toUpperCase()) == null) { if (RequestMethod.resolve(k.toUpperCase()) == null) {
errMsg.append("[") errMsg.append("[")
.append(k) .append(k)
.append("]: 不是合法的 HTTP 请求方法"); .append("]: ")
.append(MessageUtil.get("http.request_invalid", ApiContextUtils.getLanguare()));
} }
}); });

View File

@ -2,6 +2,8 @@ package com.cf.cs.protocol.validation.valids.impl;
import com.cf.cs.base.common.ConstValue; import com.cf.cs.base.common.ConstValue;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.protocol.config.ProtocolConfigure; import com.cf.cs.protocol.config.ProtocolConfigure;
import com.cf.cs.protocol.validation.valids.ValidProtocolTimestamp; import com.cf.cs.protocol.validation.valids.ValidProtocolTimestamp;
import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidator;
@ -35,15 +37,16 @@ public class ValidProtocolTimestampImpl implements ConstraintValidator<ValidProt
if (timeStamp > System.currentTimeMillis()) { if (timeStamp > System.currentTimeMillis()) {
String errMsg = String.format("请求时间[%s] 大于当前服务器时间 [%s]", date, current); String errMsg = MessageUtil.get("timeout.current.format", new String[] {date, current}, ApiContextUtils.getLanguare());
//禁用默认的message的值 //禁用默认的message的值
constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.disableDefaultConstraintViolation();
//重新添加错误提示语句 //重新添加错误提示语句
constraintValidatorContext.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation(); constraintValidatorContext.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
return false; return false;
} else if (System.currentTimeMillis() - timeStamp > ProtocolConfigure.TIMEOUT_OF_SECONDS * ConstValue.MS_OF_SECONDS) { } else if (System.currentTimeMillis() - timeStamp > ProtocolConfigure.TIMEOUT_OF_SECONDS * ConstValue.MS_OF_SECONDS) {
String errMsg = String.format("请求时间[%s] 延时超过当前服务器时间[%s] 允许范围 %d(S)", date, current, String errMsg = MessageUtil.get("timeout.current.format",
ProtocolConfigure.TIMEOUT_OF_SECONDS); new String[] {date, current, String.valueOf(ProtocolConfigure.TIMEOUT_OF_SECONDS)},
ApiContextUtils.getLanguare());
//禁用默认的message的值 //禁用默认的message的值
constraintValidatorContext.disableDefaultConstraintViolation(); constraintValidatorContext.disableDefaultConstraintViolation();
//重新添加错误提示语句 //重新添加错误提示语句

View File

@ -36,7 +36,7 @@ public class CommonFrameworkApi {
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@PostMapping("/version") @PostMapping("/version")
@OperationLogAnnotation(OperationModule = "通用模块", OperationType = "读取", OperationDesc = "获取当前系统版本信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_COMMON", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_VERSION")
public ProtocolResp<VersionResp> getVersion() { public ProtocolResp<VersionResp> getVersion() {
return ProtocolResp.result(VersionResp.builder() return ProtocolResp.result(VersionResp.builder()
.version(VersionInfo.builder() .version(VersionInfo.builder()
@ -57,7 +57,7 @@ public class CommonFrameworkApi {
*/ */
@GetMapping("/version") @GetMapping("/version")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "通用模块", OperationType = "读取", OperationDesc = "获取当前系统版本信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_COMMON", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_VERSION")
public ProtocolResp<VersionResp> getVersionV2() { public ProtocolResp<VersionResp> getVersionV2() {
return ProtocolResp.result(VersionResp.builder() return ProtocolResp.result(VersionResp.builder()
.version(VersionInfo.builder() .version(VersionInfo.builder()

View File

@ -3,7 +3,9 @@ package com.cf.cs.restful.controller;
import com.cf.cs.base.annotation.OperationLogAnnotation; import com.cf.cs.base.annotation.OperationLogAnnotation;
import com.cf.cs.base.common.ErrorCode; import com.cf.cs.base.common.ErrorCode;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.HelperUtils; import com.cf.cs.base.misc.HelperUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.crypto.annotation.EncryptionProtocol; import com.cf.cs.crypto.annotation.EncryptionProtocol;
import com.cf.cs.base.pojo.po.PageResults; import com.cf.cs.base.pojo.po.PageResults;
import com.cf.cs.protocol.pojo.dto.OperationLogDetailsReq; import com.cf.cs.protocol.pojo.dto.OperationLogDetailsReq;
@ -49,7 +51,7 @@ public class OperationLogApi {
*/ */
@PostMapping("/summary") @PostMapping("/summary")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "操作日志模块", OperationType = "读取", OperationDesc = "获取操作日志简要信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_SYSLOG", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_SYSLOG_SUMMARY")
public ProtocolResp<? extends BaseRespStatus> getSummary(@RequestBody ProtocolReq<OperationLogReq> mr) { public ProtocolResp<? extends BaseRespStatus> getSummary(@RequestBody ProtocolReq<OperationLogReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class,
ValidGroups.BasePagedReqValid.class, ValidGroups.BasePagedReqValid.class,
@ -61,6 +63,13 @@ public class OperationLogApi {
PageResults<OptLogSummaryResp> ret = operationLogService.getOperationLogSummary(req.getPageNumber(), req.getPageSize(), PageResults<OptLogSummaryResp> ret = operationLogService.getOperationLogSummary(req.getPageNumber(), req.getPageSize(),
req.getTotalSize(), req.getUserName()); req.getTotalSize(), req.getUserName());
ret.getItems().forEach(k -> {
k.setOperationStatus(MessageUtil.get(k.getOperationStatus(), ApiContextUtils.getLanguare()));
k.setModule(MessageUtil.get(k.getModule(), ApiContextUtils.getLanguare()));
k.setOperationType(MessageUtil.get(k.getOperationType(), ApiContextUtils.getLanguare()));
k.setDescription(MessageUtil.get(k.getDescription(), ApiContextUtils.getLanguare()));
});
return ProtocolResp.result(BasePageResultResp.<OptLogSummaryResp>builder() return ProtocolResp.result(BasePageResultResp.<OptLogSummaryResp>builder()
.items(ret) .items(ret)
.build()); .build());
@ -79,7 +88,7 @@ public class OperationLogApi {
*/ */
@PostMapping("/details") @PostMapping("/details")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "操作日志模块", OperationType = "读取", OperationDesc = "获取操作日志详细信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_SYSLOG", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_SYSLOG_DETAIL")
public ProtocolResp<? extends BaseRespStatus> getDetails(@RequestBody ProtocolReq<OperationLogDetailsReq> mr) { public ProtocolResp<? extends BaseRespStatus> getDetails(@RequestBody ProtocolReq<OperationLogDetailsReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class,
ValidGroups.OperationLogReqValid.class); ValidGroups.OperationLogReqValid.class);

View File

@ -62,7 +62,7 @@ public class PermissionManagerApi {
*/ */
@GetMapping("resourcePermission") @GetMapping("resourcePermission")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "权限管理模块", OperationType = "读取", OperationDesc = "获取当前用户资源权限") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_AUTH", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_CUR_USR_RES_RIGHT")
public ProtocolResp<? extends BaseRespStatus> getCurrentUserResourcePermission() { public ProtocolResp<? extends BaseRespStatus> getCurrentUserResourcePermission() {
AuthAccountUser au = authUsersService.getAuthAccountByUserName(ApiContextUtils.get().getUsername()); AuthAccountUser au = authUsersService.getAuthAccountByUserName(ApiContextUtils.get().getUsername());
@ -86,7 +86,7 @@ public class PermissionManagerApi {
@PostMapping("resourcePermission") @PostMapping("resourcePermission")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "权限管理模块", OperationType = "读取", OperationDesc = "获取用户资源权限") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_AUTH", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_USR_RES_RIGHT")
public ProtocolResp<? extends BaseRespStatus> getUserResourcePermission(@RequestBody ProtocolReq<UserIdReq> mr) { public ProtocolResp<? extends BaseRespStatus> getUserResourcePermission(@RequestBody ProtocolReq<UserIdReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.OperationLogReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.OperationLogReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -115,7 +115,7 @@ public class PermissionManagerApi {
*/ */
@GetMapping("/allRoles") @GetMapping("/allRoles")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "权限管理模块", OperationType = "读取", OperationDesc = "获取当前所有用户组") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_AUTH", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_ALL_USR_GROUP")
public ProtocolResp<? extends BaseRespStatus> getAllRoles() { public ProtocolResp<? extends BaseRespStatus> getAllRoles() {
return ProtocolResp.result(GetRoleResp.builder().roles(userPermissionService.getAllUserGroup()).build()); return ProtocolResp.result(GetRoleResp.builder().roles(userPermissionService.getAllUserGroup()).build());
} }
@ -129,7 +129,7 @@ public class PermissionManagerApi {
@PutMapping("/resource") @PutMapping("/resource")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "权限管理模块", OperationType = "创建", OperationDesc = "注册新的资源") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_AUTH", OperationType = "SYSLOG_TYPE_CREATE", OperationDesc = "SYSLOG_DESC_CREATE_RESOURCE")
public ProtocolResp<? extends BaseRespStatus> registerResource(@RequestBody ProtocolReq<RegisterResourceReq> mr) { public ProtocolResp<? extends BaseRespStatus> registerResource(@RequestBody ProtocolReq<RegisterResourceReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.ResourceReqValid.class, List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.ResourceReqValid.class,
ValidGroups.ResourceInfoValid.class); ValidGroups.ResourceInfoValid.class);
@ -155,7 +155,7 @@ public class PermissionManagerApi {
@DeleteMapping("/resource") @DeleteMapping("/resource")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "权限管理模块", OperationType = "删除", OperationDesc = "删除资源") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_AUTH", OperationType = "SYSLOG_TYPE_DEL", OperationDesc = "SYSLOG_DESC_DEL_RESOURCE")
public ProtocolResp<? extends BaseRespStatus> removeResourceById(@RequestBody ProtocolReq<IdArrayReq> mr) { public ProtocolResp<? extends BaseRespStatus> removeResourceById(@RequestBody ProtocolReq<IdArrayReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserIdReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserIdReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项

View File

@ -57,7 +57,7 @@ public class SystemDictController {
*/ */
@GetMapping("/enum/allDict") @GetMapping("/enum/allDict")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取系统所有枚举字典类型信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_ALL_ENUM_DICT")
public ProtocolResp<? extends BaseRespStatus> getEnumDictionary() { public ProtocolResp<? extends BaseRespStatus> getEnumDictionary() {
Set<String> ret = dictionaryService.getAllEnumDictionary(); Set<String> ret = dictionaryService.getAllEnumDictionary();
@ -74,7 +74,7 @@ public class SystemDictController {
*/ */
@PostMapping("/enum/dictContent") @PostMapping("/enum/dictContent")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取系统枚举字典详细内容") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_ENUM_DETAIL")
public ProtocolResp<? extends BaseRespStatus> getEnumDictionaryContent(@RequestBody ProtocolReq<DictContentReq> mr) { public ProtocolResp<? extends BaseRespStatus> getEnumDictionaryContent(@RequestBody ProtocolReq<DictContentReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class,
ValidGroups.DictReqValid.class); ValidGroups.DictReqValid.class);
@ -103,7 +103,7 @@ public class SystemDictController {
@PutMapping("/user/add") @PutMapping("/user/add")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "创建", OperationDesc = "新建用户字典") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_CREATE", OperationDesc = "新建用户字典")
public ProtocolResp<? extends BaseRespStatus> createNewDictionary(@RequestBody ProtocolReq<NewUserDictReq> mr) { public ProtocolResp<? extends BaseRespStatus> createNewDictionary(@RequestBody ProtocolReq<NewUserDictReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -128,7 +128,7 @@ public class SystemDictController {
@DeleteMapping("/user/delete") @DeleteMapping("/user/delete")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "创建", OperationDesc = "新建用户字典") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_CREATE", OperationDesc = "SYSLOG_DESC_CREATE_USER_DICT")
public ProtocolResp<? extends BaseRespStatus> removeDictionary(@RequestBody ProtocolReq<RemoveDictReq> mr) { public ProtocolResp<? extends BaseRespStatus> removeDictionary(@RequestBody ProtocolReq<RemoveDictReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -153,7 +153,7 @@ public class SystemDictController {
@PostMapping("/user/upgrade") @PostMapping("/user/upgrade")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "修改", OperationDesc = "修改用户字典内容") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_MODIFY", OperationDesc = "SYSLOG_DESC_MODIFY_USER_DICT")
public ProtocolResp<? extends BaseRespStatus> upgradeDictionary(@RequestBody ProtocolReq<NewUserDictReq> mr) { public ProtocolResp<? extends BaseRespStatus> upgradeDictionary(@RequestBody ProtocolReq<NewUserDictReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -178,7 +178,7 @@ public class SystemDictController {
@PostMapping("/user/allDict") @PostMapping("/user/allDict")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取所有用户字典") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_ALL_USER_DICT")
public ProtocolResp<? extends BaseRespStatus> getUserDictionary(@RequestBody ProtocolReq<BasePagedReq> mr) { public ProtocolResp<? extends BaseRespStatus> getUserDictionary(@RequestBody ProtocolReq<BasePagedReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -205,7 +205,7 @@ public class SystemDictController {
@PostMapping("/user/getDictContent") @PostMapping("/user/getDictContent")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取用户字典内容项") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_USER_DETAIL")
public ProtocolResp<? extends BaseRespStatus> getUserDictionaryContent(@RequestBody ProtocolReq<DictContentReq> mr) { public ProtocolResp<? extends BaseRespStatus> getUserDictionaryContent(@RequestBody ProtocolReq<DictContentReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -231,7 +231,7 @@ public class SystemDictController {
@PutMapping("/user/addDictContent") @PutMapping("/user/addDictContent")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "字典模块", OperationType = "创建", OperationDesc = "新增用户字典内容项") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_DICT", OperationType = "SYSLOG_TYPE_CREATE", OperationDesc = "SYSLOG_DESC_CREATE_USER_DICT_ITEM")
public ProtocolResp<? extends BaseRespStatus> createNewDictionaryContent(@RequestBody ProtocolReq<AddDictContentReq> mr) { public ProtocolResp<? extends BaseRespStatus> createNewDictionaryContent(@RequestBody ProtocolReq<AddDictContentReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class, List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class,
ValidGroups.DictReqContentValid.class); ValidGroups.DictReqContentValid.class);

View File

@ -36,7 +36,7 @@ public class SystemInfoApi {
*/ */
@GetMapping("/osInfo") @GetMapping("/osInfo")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "系统信息模块", OperationType = "读取", OperationDesc = "获取当前操作系统信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_SYSINFO", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_OS_INFO")
public ProtocolResp<GetOsInfoResp> getOsInfo() { public ProtocolResp<GetOsInfoResp> getOsInfo() {
return ProtocolResp.result(GetOsInfoResp.builder() return ProtocolResp.result(GetOsInfoResp.builder()
.os(systemInfoService.getOsName()) .os(systemInfoService.getOsName())
@ -51,7 +51,7 @@ public class SystemInfoApi {
*/ */
@GetMapping("/processorInfo") @GetMapping("/processorInfo")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "系统信息模块", OperationType = "读取", OperationDesc = "获取当前处理器信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_SYSINFO", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_CPU_INFO")
public ProtocolResp<GetProcessorInfoResp> getProcessorInfo() { public ProtocolResp<GetProcessorInfoResp> getProcessorInfo() {
return ProtocolResp.result(GetProcessorInfoResp.builder().cpuInfo(systemInfoService.getProcessInfo()).build()); return ProtocolResp.result(GetProcessorInfoResp.builder().cpuInfo(systemInfoService.getProcessInfo()).build());
} }
@ -63,7 +63,7 @@ public class SystemInfoApi {
*/ */
@GetMapping("/hwInfo") @GetMapping("/hwInfo")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "系统信息模块", OperationType = "读取", OperationDesc = "获取系统硬件信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_SYSINFO", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_HW_INFO")
public ProtocolResp<GetHwInfoResp> getHwInfo() { public ProtocolResp<GetHwInfoResp> getHwInfo() {
return ProtocolResp.result(GetHwInfoResp.builder().hwInfo(systemInfoService.getHardwareInfo()).build()); return ProtocolResp.result(GetHwInfoResp.builder().hwInfo(systemInfoService.getHardwareInfo()).build());
} }

View File

@ -58,7 +58,7 @@ public class UserManagerApi {
@PostMapping("/userInfo") @PostMapping("/userInfo")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取用户信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_USER_MGR", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_USER")
public ProtocolResp<? extends BaseRespStatus> getUserInfoById(@RequestBody ProtocolReq<UserIdReq> mr) { public ProtocolResp<? extends BaseRespStatus> getUserInfoById(@RequestBody ProtocolReq<UserIdReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.OperationLogReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.OperationLogReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -82,7 +82,7 @@ public class UserManagerApi {
@PostMapping("/userList") @PostMapping("/userList")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取用户列表") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_USER_MGR", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_USER_LIST")
public ProtocolResp<? extends BaseRespStatus> getAllUserInfoPaged(@RequestBody ProtocolReq<BasePagedReq> mr) { public ProtocolResp<? extends BaseRespStatus> getAllUserInfoPaged(@RequestBody ProtocolReq<BasePagedReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -106,7 +106,7 @@ public class UserManagerApi {
*/ */
@GetMapping("/userInfo") @GetMapping("/userInfo")
@EncryptionProtocol @EncryptionProtocol
@OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "读取", OperationDesc = "获取当前用户信息") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_USER_MGR", OperationType = "SYSLOG_TYPE_READ", OperationDesc = "SYSLOG_DESC_GET_CUR_USER")
public ProtocolResp<GetUserInfoResp> getCurrentUserInfo() { public ProtocolResp<GetUserInfoResp> getCurrentUserInfo() {
return ProtocolResp.result(GetUserInfoResp.builder() return ProtocolResp.result(GetUserInfoResp.builder()
.userInfo(userDbService.getCurrentUserInfo()) .userInfo(userDbService.getCurrentUserInfo())
@ -122,7 +122,7 @@ public class UserManagerApi {
@PutMapping("/register") @PutMapping("/register")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "创建", OperationDesc = "创建新用户") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_USER_MGR", OperationType = "SYSLOG_TYPE_CREATE", OperationDesc = "SYSLOG_DESC_CREATE_USER")
public ProtocolResp<? extends BaseRespStatus> createNewUser(@RequestBody ProtocolReq<RegisterUserReq> mr) { public ProtocolResp<? extends BaseRespStatus> createNewUser(@RequestBody ProtocolReq<RegisterUserReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项
@ -148,7 +148,7 @@ public class UserManagerApi {
@DeleteMapping("/remove") @DeleteMapping("/remove")
@EncryptionProtocol @EncryptionProtocol
@DecryptionProtocol @DecryptionProtocol
@OperationLogAnnotation(OperationModule = "用户管理模块", OperationType = "删除", OperationDesc = "删除用户") @OperationLogAnnotation(OperationModule = "SYSLOG_MOD_USER_MGR", OperationType = "SYSLOG_TYPE_DEL", OperationDesc = "SYSLOG_DESC_DEL_USER")
public ProtocolResp<BaseRespStatus> removeUser(@RequestBody ProtocolReq<UserIdReq> mr) { public ProtocolResp<BaseRespStatus> removeUser(@RequestBody ProtocolReq<UserIdReq> mr) {
List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserIdReqValid.class); List<String> validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.UserIdReqValid.class);
// 如果校验通过validate为空否则validate包含未校验通过项 // 如果校验通过validate为空否则validate包含未校验通过项

View File

@ -0,0 +1,129 @@
package com.cf.cs.restful.exception;
import com.cf.cs.base.common.ConstValue;
import com.cf.cs.base.common.ErrorCode;
import com.cf.cs.base.exception.CommonErrorCodeException;
import com.cf.cs.base.misc.HelperUtils;
import com.cf.cs.protocol.exception.SecurityProtocolException;
import com.cf.cs.protocol.pojo.po.BaseRespStatus;
import com.cf.cs.protocol.pojo.vo.ProtocolResp;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.NoHandlerFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The type Controller exception handler.
*
* @author xajhuang @163.com
*/
@ControllerAdvice
@Slf4j
public class ControllerExceptionHandler {
/**
* Controller not found protocol resp.
*
* @param e the e
* @return the protocol resp
*/
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public ProtocolResp<BaseRespStatus> controllerNotFound(NoHandlerFoundException e) {
List<String> errMsg = new ArrayList<>();
errMsg.add(e.getMessage());
return ProtocolResp.result(ErrorCode.ERR_NOSUCHITEM,
HttpStatus.NOT_FOUND.value(),
errMsg.toArray(new String[0]));
}
/**
* Controller global exception protocol resp.
*
* @param e the e
* @return the protocol resp
*/
@ExceptionHandler({MethodArgumentNotValidException.class})
@ResponseBody
public ProtocolResp<BaseRespStatus> controllerGlobalException(MethodArgumentNotValidException e) {
AtomicInteger idx = new AtomicInteger();
List<String> errMsg = e.getBindingResult()
.getFieldErrors()
.stream()
.map(v -> idx.getAndIncrement() + ": " + v.getDefaultMessage())
.toList();
return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION,
ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(),
errMsg.toArray(new String[0]));
}
/**
* Common error exception protocol resp.
*
* @param ex the ex
* @return the protocol resp
*/
@ExceptionHandler({CommonErrorCodeException.class})
@ResponseBody
public ProtocolResp<BaseRespStatus> commonErrorException(Exception ex) {
return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION,
ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(),
new String[] {ex.getMessage()});
}
/**
* Handle exception protocol resp.
*
* @param rsp the rsp
* @param req the req
* @param ex the ex
* @return the protocol resp
*/
@ExceptionHandler(SecurityProtocolException.class)
@ResponseBody
public ProtocolResp<BaseRespStatus> handleException(HttpServletResponse rsp,
HttpServletRequest req,
SecurityProtocolException ex) {
try {
String reqType = req.getMethod();
String reqPath = req.getRequestURI();
String reqIp = req.getRemoteAddr();
String reqToken = req.getHeader("Authorization");
if (reqToken != null && !reqToken.isEmpty()) {
reqToken = reqToken.replace(ConstValue.STRING_HTTP_AUTH_HEAD, "");
}
log.error("""
Interface [{}] request <{}> from {}, token = <{}>
+++ Request: {}
--- Exception information: {}""",
reqType, reqPath, reqIp, reqToken, HelperUtils.inputStream2String(req.getInputStream()),
ex.getMessage());
} catch (Exception ignored) {
// Do nothing...
}
List<String> errMeg = new ArrayList<>();
rsp.setStatus(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode());
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
errMeg.add(ex.getErr().getStringValue() + ": " + ex.getDescription());
}
return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION,
ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(),
errMeg.toArray(new String[0]));
}
}

View File

@ -1,14 +1,17 @@
package com.cf.cs.restful.service.impl; package com.cf.cs.restful.service.impl;
import com.cf.cs.base.common.CommonEnumHandler;
import com.cf.cs.base.common.CommonStatus;
import com.cf.cs.base.common.ErrorCode; import com.cf.cs.base.common.ErrorCode;
import com.cf.cs.base.common.ProtoCryptoType;
import com.cf.cs.base.exception.CommonErrorCodeException; import com.cf.cs.base.exception.CommonErrorCodeException;
import com.cf.cs.base.misc.ApiContextUtils; import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.HelperUtils; import com.cf.cs.base.misc.HelperUtils;
import com.cf.cs.base.pojo.po.PageResults; import com.cf.cs.base.pojo.po.PageResults;
import com.cf.cs.database.mapper.DictDataMapper; import com.cf.cs.database.mapper.DictDataMapper;
import com.cf.cs.database.mapper.DictTypeMapper; import com.cf.cs.database.mapper.DictTypeMapper;
import com.cf.cs.database.pojo.entity.DictType;
import com.cf.cs.database.pojo.entity.DictData; import com.cf.cs.database.pojo.entity.DictData;
import com.cf.cs.database.pojo.entity.DictType;
import com.cf.cs.database.pojo.po.UserDictionary; import com.cf.cs.database.pojo.po.UserDictionary;
import com.cf.cs.protocol.pojo.po.DictContent; import com.cf.cs.protocol.pojo.po.DictContent;
import com.cf.cs.protocol.pojo.po.DictDetails; import com.cf.cs.protocol.pojo.po.DictDetails;
@ -16,6 +19,7 @@ import com.cf.cs.restful.service.DictionaryService;
import com.houkunlin.system.dict.starter.DictUtil; import com.houkunlin.system.dict.starter.DictUtil;
import com.houkunlin.system.dict.starter.SystemDictStarter; import com.houkunlin.system.dict.starter.SystemDictStarter;
import com.houkunlin.system.dict.starter.bean.DictTypeVo; import com.houkunlin.system.dict.starter.bean.DictTypeVo;
import com.houkunlin.system.dict.starter.bean.DictValueVo;
import com.houkunlin.system.dict.starter.notice.RefreshDictTypeEvent; import com.houkunlin.system.dict.starter.notice.RefreshDictTypeEvent;
import com.houkunlin.system.dict.starter.notice.RefreshDictValueEvent; import com.houkunlin.system.dict.starter.notice.RefreshDictValueEvent;
import com.houkunlin.system.dict.starter.provider.SystemDictProvider; import com.houkunlin.system.dict.starter.provider.SystemDictProvider;
@ -65,24 +69,21 @@ public class DictionaryServiceImpl implements DictionaryService {
SystemDictStarter.getBean(SystemDictProvider.class).dictTypeIterator().forEachRemaining(k -> { SystemDictStarter.getBean(SystemDictProvider.class).dictTypeIterator().forEachRemaining(k -> {
if (dictType.contains(k.getType())) { if (dictType.contains(k.getType())) {
List<DictDetails> children = new ArrayList<>(); List<DictDetails> children = new ArrayList<>();
k.getChildren().forEach(m -> children.add(DictDetails.builder() k.getChildren()
.title(m.getTitle()) .forEach(m -> children.add(DictDetails.builder()
.value((Integer) m.getValue()) .title(getLocalEnumMessage(m))
.disabled(m.isDisabled()) .value((Integer) m.getValue())
.build())); .disabled(m.isDisabled())
sysDictList.add(DictContent.builder() .build()));
.dictName(k.getType()) sysDictList.add(DictContent.builder().dictName(k.getType()).children(children).build());
.children(children)
.build());
} }
allSysDict.add(k.getType()); allSysDict.add(k.getType());
}); });
dictType.removeAll(allSysDict); dictType.stream().filter(k -> !allSysDict.contains(k)).forEach(m -> {
DictContent dict = new DictContent(m, ErrorCode.ERR_NOSUCHITEM) ;
dictType.forEach(k -> sysDictList.add(DictContent.builder() sysDictList.add(dict);
.dictName(k) });
.build()));
return sysDictList; return sysDictList;
} }
@ -117,8 +118,7 @@ public class DictionaryServiceImpl implements DictionaryService {
// 找不到对应的字典供修改 // 找不到对应的字典供修改
if (dt == null) { if (dt == null) {
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, type + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
type + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
} }
if (name != null) { if (name != null) {
@ -154,9 +154,7 @@ public class DictionaryServiceImpl implements DictionaryService {
totalSize = -1L; totalSize = -1L;
} }
QueryWrapper wrapper = QueryWrapper.create() QueryWrapper wrapper = QueryWrapper.create().from(DICT_TYPE).select();
.from(DICT_TYPE)
.select();
Page<UserDictionary> dict = dictTypeMapper.paginateAs(pageNumber, pageSize, totalSize, wrapper, UserDictionary.class); Page<UserDictionary> dict = dictTypeMapper.paginateAs(pageNumber, pageSize, totalSize, wrapper, UserDictionary.class);
@ -173,30 +171,28 @@ public class DictionaryServiceImpl implements DictionaryService {
public List<DictContent> getUserDictionaryContent(List<String> dictName) { public List<DictContent> getUserDictionaryContent(List<String> dictName) {
List<DictContent> resp = new ArrayList<>(); List<DictContent> resp = new ArrayList<>();
QueryWrapper wrapper = QueryWrapper.create() QueryWrapper wrapper = QueryWrapper.create().from(DICT_TYPE).select().where(DICT_TYPE.DICT_TYPE_NAME.in(dictName));
.from(DICT_TYPE)
.select()
.where(DICT_TYPE.DICT_TYPE_NAME.in(dictName));
List<DictType> ret = dictTypeMapper.selectListWithRelationsByQuery(wrapper); List<DictType> ret = dictTypeMapper.selectListWithRelationsByQuery(wrapper);
ret.forEach(k -> { ret.forEach(k -> {
List<DictDetails> children = new ArrayList<>(); List<DictDetails> children = new ArrayList<>();
k.getDictDataList().forEach(m -> children.add(DictDetails.builder() k.getDictDataList()
.id(m.getId()) .forEach(m -> children.add(DictDetails.builder()
.title(m.getDictLabel()) .id(m.getId())
.value(m.getDictValue()) .title(m.getDictLabel())
.sorted(m.getDictSort()) .value(m.getDictValue())
.cssClass(HelperUtils.meagreDbStringValue(m.getCssClass())) .sorted(m.getDictSort())
.listClass(HelperUtils.meagreDbStringValue(m.getListClass())) .cssClass(HelperUtils.meagreDbStringValue(m.getCssClass()))
.isDefault("Y".equals(m.getIsDefault())) .listClass(HelperUtils.meagreDbStringValue(m.getListClass()))
.createBy(m.getCreateBy()) .isDefault("Y".equals(m.getIsDefault()))
.createTime(m.getCreateTime()) .createBy(m.getCreateBy())
.upgradeBy(HelperUtils.meagreDbStringValue(m.getUpdateBy())) .createTime(m.getCreateTime())
.upgradeTime(m.getUpdateTime()) .upgradeBy(HelperUtils.meagreDbStringValue(m.getUpdateBy()))
.disabled(false) .upgradeTime(m.getUpdateTime())
.build())); .disabled(false)
.build()));
resp.add(DictContent.builder() resp.add(DictContent.builder()
.dictId(k.getId()) .dictId(k.getId())
@ -207,16 +203,12 @@ public class DictionaryServiceImpl implements DictionaryService {
.build()); .build());
}); });
dictName.stream() dictName.stream().filter(k -> ret.stream().noneMatch(v -> v.getDictTypeName().equals(k))).forEach(m -> {
.filter(k -> ret.stream().noneMatch(v -> v.getDictTypeName().equals(k))) DictContent dt = DictContent.builder().dictName(m).build();
.forEach(m -> { dt.setStatus(ErrorCode.ERR_NOSUCHITEM.getCode());
DictContent dt = DictContent.builder() dt.setMessage(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()});
.dictName(m) resp.add(dt);
.build(); });
dt.setStatus(ErrorCode.ERR_NOSUCHITEM.getCode());
dt.setMessage(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()});
resp.add(dt);
});
return resp; return resp;
} }
@ -227,8 +219,7 @@ public class DictionaryServiceImpl implements DictionaryService {
DictType dt = dictTypeMapper.selectOneWithRelationsByCondition(DICT_TYPE.DICT_TYPE_NAME.eq(dictName)); DictType dt = dictTypeMapper.selectOneWithRelationsByCondition(DICT_TYPE.DICT_TYPE_NAME.eq(dictName));
if (dt == null) { if (dt == null) {
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, dictName + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
dictName + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
} }
List<Long> contentId = dt.getDictDataList().stream().map(DictData::getId).toList(); List<Long> contentId = dt.getDictDataList().stream().map(DictData::getId).toList();
@ -248,4 +239,36 @@ public class DictionaryServiceImpl implements DictionaryService {
dv.getChildren().forEach(v -> v.setDisabled(true)); dv.getChildren().forEach(v -> v.setDisabled(true));
publisher.publishEvent(new RefreshDictValueEvent(dv.getChildren(), true)); publisher.publishEvent(new RefreshDictValueEvent(dv.getChildren(), true));
} }
private String getLocalEnumMessage(DictValueVo m) {
int value = (Integer) m.getValue();
switch (m.getDictType()) {
case "ErrorCode":
ErrorCode err = CommonEnumHandler.codeOf(ErrorCode.class, value);
if (err != null) {
return err.getDescription();
}
break;
case "CommonStatus":
CommonStatus cs = CommonEnumHandler.codeOf(CommonStatus.class, value);
if (cs != null) {
return cs.getDescription();
}
break;
case "ProtoCryptoType":
ProtoCryptoType pt = CommonEnumHandler.codeOf(ProtoCryptoType.class, value);
if (pt != null) {
return pt.getDescription();
}
break;
default:
return m.getTitle();
}
return m.getTitle();
}
} }

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version> <version>3.2.4</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
@ -81,17 +81,17 @@
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId> <artifactId>spring-security-core</artifactId>
<version>6.2.2</version> <version>6.2.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot3-starter</artifactId> <artifactId>mybatis-flex-spring-boot3-starter</artifactId>
<version>1.8.2</version> <version>1.8.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId> <artifactId>mybatis-flex-processor</artifactId>
<version>1.8.2</version> <version>1.8.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jayway.jsonpath</groupId> <groupId>com.jayway.jsonpath</groupId>