From 0eb673e59446a09ca045596875991cb4dbd3bfc2 Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Fri, 29 Dec 2023 18:39:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=A8=E5=86=85=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ljsd/jieling/exception/ErrorCode.java | 4 ++ .../jieling/exception/ErrorCodeException.java | 4 +- .../exception/ErrorTableException.java | 72 +++++++++++++++++++ .../java/config/SErrorCodeEerverConfig.java | 15 ++-- 4 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java index d71c13ead..c586086cb 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCode.java @@ -226,6 +226,10 @@ public enum ErrorCode implements IErrorCode { this.errMsg = errMsg; } + public void setCodeId(int codeId) { + this.codeId = codeId; + } + @Override public int code() { return codeId; diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java index 7c2576314..e7d32eab6 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorCodeException.java @@ -67,7 +67,7 @@ public class ErrorCodeException extends Exception { } public String toString() { - return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&¶ms.size()!=0)?params.toString():"")+"] "; + return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] "; } public List getParams() { @@ -75,6 +75,6 @@ public class ErrorCodeException extends Exception { } public String getMessage() { - return "" + super.getMessage(); + return super.getMessage(); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java new file mode 100644 index 000000000..ee3a8d793 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/exception/ErrorTableException.java @@ -0,0 +1,72 @@ +package com.ljsd.jieling.exception; + +import config.SErrorCodeEerverConfig; +import util.StringUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * Description: 逻辑异常包装类 + * Author: zsx + * CreateDate: 2019/10/21 11:44 + */ +public class ErrorTableException extends Exception { + private int id; + private String msg; + private List params; + + public ErrorTableException(int id, String msg) { + this.id = id; + this.msg = msg; + } + + public ErrorTableException(int id, String msg, List params) { + this.id = id; + this.msg = msg; + this.params = params; + } + + public ErrorTableException(int id) { + String message = SErrorCodeEerverConfig.errorTableMap.get(id); + if (StringUtil.isEmpty(message)){ + this.id = -1; + this.msg = "操作失败,并未找到错误码:{"+id+"},请联系管理员"; + }else { + this.id = id; + this.msg = message; + } + } + + public void setId(int id) { + this.id = id; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setParams(List params) { + this.params = params; + } + + public int getCode() { + return this.id; + } + + public String getMsg() { + return msg; + } + + public String getMessage() { + return super.getMessage(); + } + + public List getParams() { + return null == params ? new ArrayList<>() : params; + } + + public String toString() { + return "[CODE: " + this.getCode() + "][" + this.getMsg() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&& !params.isEmpty())?params.toString():"")+"] "; + } +} diff --git a/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java b/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java index e22321e01..70ca694bf 100644 --- a/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java +++ b/tablemanager/src/main/java/config/SErrorCodeEerverConfig.java @@ -4,13 +4,16 @@ import manager.STableManager; import manager.Table; import java.text.MessageFormat; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Table(name ="ErrorCodeEerverConfig") public class SErrorCodeEerverConfig implements BaseConfig { - private static Map errorCodeMap; + private static Map errorCodeMap; public static Map errorMap; + public static Map errorTableMap = new HashMap<>(); + private int id; private String key; @@ -26,13 +29,15 @@ public class SErrorCodeEerverConfig implements BaseConfig { Map config = STableManager.getConfig(SErrorCodeEerverConfig.class); Map errorCodeEerverConfigMap = new ConcurrentHashMap<>(); Map tempErrorMap = new ConcurrentHashMap<>(); - for (Map.Entry entry :config.entrySet()){ - SErrorCodeEerverConfig sErrorCodeEerverConfig = entry.getValue(); - errorCodeEerverConfigMap.put(sErrorCodeEerverConfig.getkey(),sErrorCodeEerverConfig); - tempErrorMap.put(sErrorCodeEerverConfig.getid(),sErrorCodeEerverConfig); + Map tableErrorMap = new HashMap<>(); + for (SErrorCodeEerverConfig errorConfig : config.values()) { + errorCodeEerverConfigMap.put(errorConfig.getkey(),errorConfig); + tempErrorMap.put(errorConfig.getid(),errorConfig); + tableErrorMap.put(errorConfig.getid(), errorConfig.getvalue()); } errorCodeMap = errorCodeEerverConfigMap; errorMap = tempErrorMap; + errorTableMap = tableErrorMap; }