Compare commits

...

2 Commits

Author SHA1 Message Date
黄昕 e654fc3fe5 1. 枚举字典支持国际化 2024-03-24 11:25:36 +08:00
黄昕 76df3543e1 1. 错误码支持国际化 2024-03-24 09:56:49 +08:00
15 changed files with 310 additions and 163 deletions

View File

@ -1,5 +1,6 @@
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.HelperUtils;
import com.cf.cs.protocol.misc.ProtocolJsonUtils;
@ -74,6 +75,8 @@ public class RequestBodyCacheWrapper extends HttpServletRequestWrapper {
} catch (Exception e) {
body = "";
} finally {
String language = request.getHeader(ConstValue.LANGUAGE_HEAD);
ApiContextUtils.setRequestLocal(language);
ApiContextUtils.setRequestInfo(body, reqTimeStamp);
}
}

View File

@ -1,5 +1,7 @@
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.json.DictType;
@ -35,6 +37,15 @@ public enum CommonStatus implements BaseEnum, DictEnum<Integer> {
this.readme = readme;
}
/**
* Gets string value.
*
* @return the string value
*/
public String getStringValue() {
return this.name();
}
@Override
public Integer getValue() {
return this.code;
@ -47,6 +58,6 @@ public enum CommonStatus implements BaseEnum, DictEnum<Integer> {
@Override
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.
*/
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 SECOND_OF_MINUTE = 60;
/**
* The constant MAX_IPV4_LEN.
*/
public static final int MAX_IPV4_LEN = 15;
/**

View File

@ -1,5 +1,7 @@
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.json.DictType;
import jakarta.servlet.http.HttpServletResponse;
@ -292,6 +294,6 @@ public enum ErrorCode implements BaseEnum, DictEnum<Integer> {
@Override
public String getDescription() {
return this.errMsg;
return MessageUtil.get(getStringValue(), ApiContextUtils.getLanguare());
}
}

View File

@ -1,5 +1,7 @@
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.json.DictType;
@ -61,6 +63,6 @@ public enum ProtoCryptoType implements BaseEnum, DictEnum<Integer> {
@Override
public String getDescription() {
return this.readme;
return MessageUtil.get(getStringValue(), ApiContextUtils.getLanguare());
}
}

View File

@ -23,7 +23,7 @@ public class LocaleConfig {
Locale.setDefault(Locale.CHINA);
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
//设置国际化文件存储路径和名称 i18n目录messages文件名
source.setBasenames("i18n/messages");
source.setBasenames("i18n/message", "i18n/errorMessage", "i18n/enumMessage");
//设置根据key如果没有获取到对应的文本信息,则返回key作为信息
source.setUseCodeAsDefaultMessage(true);
//设置字符编码

View File

@ -0,0 +1,69 @@
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 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 == 2) {
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 == 2) {
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) {
return getInstance().getMessage(key, params, language);
}
private static MessageSource getInstance() {
return Lazy.MESSAGE_SOURCE;
}
private static class Lazy {
private static final MessageSource MESSAGE_SOURCE = SpringBootBeanUtils.getBean(MessageSource.class);
}
}

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,54 @@
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

View File

@ -0,0 +1,55 @@
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

View File

@ -1,54 +0,0 @@
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

View File

@ -1,55 +0,0 @@
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

View File

@ -1,5 +1,6 @@
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.JsonPropertyOrder;
import lombok.AllArgsConstructor;
@ -28,4 +29,10 @@ public class DictContent extends BaseRespStatus {
private String dictAlias;
private String dictRemark;
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

@ -1,14 +1,17 @@
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.ProtoCryptoType;
import com.cf.cs.base.exception.CommonErrorCodeException;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.HelperUtils;
import com.cf.cs.base.pojo.po.PageResults;
import com.cf.cs.database.mapper.DictDataMapper;
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.DictType;
import com.cf.cs.database.pojo.po.UserDictionary;
import com.cf.cs.protocol.pojo.po.DictContent;
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.SystemDictStarter;
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.RefreshDictValueEvent;
import com.houkunlin.system.dict.starter.provider.SystemDictProvider;
@ -65,24 +69,21 @@ public class DictionaryServiceImpl implements DictionaryService {
SystemDictStarter.getBean(SystemDictProvider.class).dictTypeIterator().forEachRemaining(k -> {
if (dictType.contains(k.getType())) {
List<DictDetails> children = new ArrayList<>();
k.getChildren().forEach(m -> children.add(DictDetails.builder()
.title(m.getTitle())
.value((Integer) m.getValue())
.disabled(m.isDisabled())
.build()));
sysDictList.add(DictContent.builder()
.dictName(k.getType())
.children(children)
.build());
k.getChildren()
.forEach(m -> children.add(DictDetails.builder()
.title(getLocalEnumMessage(m))
.value((Integer) m.getValue())
.disabled(m.isDisabled())
.build()));
sysDictList.add(DictContent.builder().dictName(k.getType()).children(children).build());
}
allSysDict.add(k.getType());
});
dictType.removeAll(allSysDict);
dictType.forEach(k -> sysDictList.add(DictContent.builder()
.dictName(k)
.build()));
dictType.stream().filter(k -> !allSysDict.contains(k)).forEach(m -> {
DictContent dict = new DictContent(m, ErrorCode.ERR_NOSUCHITEM) ;
sysDictList.add(dict);
});
return sysDictList;
}
@ -117,8 +118,7 @@ public class DictionaryServiceImpl implements DictionaryService {
// 找不到对应的字典供修改
if (dt == null) {
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM,
type + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, type + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
}
if (name != null) {
@ -154,9 +154,7 @@ public class DictionaryServiceImpl implements DictionaryService {
totalSize = -1L;
}
QueryWrapper wrapper = QueryWrapper.create()
.from(DICT_TYPE)
.select();
QueryWrapper wrapper = QueryWrapper.create().from(DICT_TYPE).select();
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) {
List<DictContent> resp = new ArrayList<>();
QueryWrapper wrapper = QueryWrapper.create()
.from(DICT_TYPE)
.select()
.where(DICT_TYPE.DICT_TYPE_NAME.in(dictName));
QueryWrapper wrapper = QueryWrapper.create().from(DICT_TYPE).select().where(DICT_TYPE.DICT_TYPE_NAME.in(dictName));
List<DictType> ret = dictTypeMapper.selectListWithRelationsByQuery(wrapper);
ret.forEach(k -> {
List<DictDetails> children = new ArrayList<>();
k.getDictDataList().forEach(m -> children.add(DictDetails.builder()
.id(m.getId())
.title(m.getDictLabel())
.value(m.getDictValue())
.sorted(m.getDictSort())
.cssClass(HelperUtils.meagreDbStringValue(m.getCssClass()))
.listClass(HelperUtils.meagreDbStringValue(m.getListClass()))
.isDefault("Y".equals(m.getIsDefault()))
.createBy(m.getCreateBy())
.createTime(m.getCreateTime())
.upgradeBy(HelperUtils.meagreDbStringValue(m.getUpdateBy()))
.upgradeTime(m.getUpdateTime())
.disabled(false)
.build()));
k.getDictDataList()
.forEach(m -> children.add(DictDetails.builder()
.id(m.getId())
.title(m.getDictLabel())
.value(m.getDictValue())
.sorted(m.getDictSort())
.cssClass(HelperUtils.meagreDbStringValue(m.getCssClass()))
.listClass(HelperUtils.meagreDbStringValue(m.getListClass()))
.isDefault("Y".equals(m.getIsDefault()))
.createBy(m.getCreateBy())
.createTime(m.getCreateTime())
.upgradeBy(HelperUtils.meagreDbStringValue(m.getUpdateBy()))
.upgradeTime(m.getUpdateTime())
.disabled(false)
.build()));
resp.add(DictContent.builder()
.dictId(k.getId())
@ -207,16 +203,12 @@ public class DictionaryServiceImpl implements DictionaryService {
.build());
});
dictName.stream()
.filter(k -> ret.stream().noneMatch(v -> v.getDictTypeName().equals(k)))
.forEach(m -> {
DictContent dt = DictContent.builder()
.dictName(m)
.build();
dt.setStatus(ErrorCode.ERR_NOSUCHITEM.getCode());
dt.setMessage(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()});
resp.add(dt);
});
dictName.stream().filter(k -> ret.stream().noneMatch(v -> v.getDictTypeName().equals(k))).forEach(m -> {
DictContent dt = DictContent.builder().dictName(m).build();
dt.setStatus(ErrorCode.ERR_NOSUCHITEM.getCode());
dt.setMessage(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()});
resp.add(dt);
});
return resp;
}
@ -227,8 +219,7 @@ public class DictionaryServiceImpl implements DictionaryService {
DictType dt = dictTypeMapper.selectOneWithRelationsByCondition(DICT_TYPE.DICT_TYPE_NAME.eq(dictName));
if (dt == null) {
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM,
dictName + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
throw new CommonErrorCodeException(ErrorCode.ERR_NOSUCHITEM, dictName + ": " + ErrorCode.ERR_NOSUCHITEM.getDescription());
}
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));
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();
}
}