diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java deleted file mode 100644 index a113151..0000000 --- a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ErrorContext.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.electromagnetic.industry.software.common.resp; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ErrorContext implements Serializable { - - /** - * 序列ID - */ - private static final long serialVersionUID = 3939009139641299179L; - - /** - * 默认分隔符 - */ - private static final String SPLIT = "|"; - - /** - * 错误堆栈集合 - */ - private List errorStack = new ArrayList(); - - /** - * 第三方错误原始信息 - */ - private String thirdPartyError; - - /** - * 错误变量映射 - */ - private Map errorVariableMap = new HashMap(); - - /** - * 默认构造方法。 - */ - public ErrorContext() { - // 默认构造方法 - } - - /** - * 获取当前错误对象。 - * - * @return 当前错误码对象 - */ - public ResultCode fetchCurrentError() { - if (errorStack != null && errorStack.size() > 0) { - return errorStack.get(errorStack.size() - 1); - } - - return null; - } - - /** - * 向堆栈中添加错误对象。 - * - * @param error 错误码 - */ - public void addError(ResultCode error) { - if (errorStack == null) { - errorStack = new ArrayList(); - } - - errorStack.add(error); - } - - /** - * 获取字符串形式的错误码堆栈 - * - * @return 错误码堆栈 - */ - @Deprecated - public String fetchErrorCodeStack() { - StringBuffer sb = new StringBuffer(); - for (int i = errorStack.size(); i > 0; i--) { - if (i == errorStack.size()) { - sb.append(errorStack.get(i - 1)); - } else { - sb.append(SPLIT).append(errorStack.get(i - 1)); - } - } - - return sb.toString(); - } - - /** - * 获取字符串形式的错误码堆栈digest - * - * @return 错误码堆栈 - */ - public String fetchErrorCodeStackDigest() { - StringBuffer sb = new StringBuffer(); - for (int i = errorStack.size(); i > 0; i--) { - if (i == errorStack.size()) { - sb.append(errorStack.get(i - 1)); - } else { - sb.append(SPLIT).append(errorStack.get(i - 1)); - } - } - - return sb.toString(); - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - - //错误堆栈 - sb.append("errorStack=["); - sb.append(fetchErrorCodeStackDigest()); - sb.append("],"); - - //第三方错误 - sb.append("thirdPartyError=["); - sb.append(thirdPartyError); - sb.append("]"); - - return sb.toString(); - } -} diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java deleted file mode 100644 index 42378a3..0000000 --- a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/resp/ResultCode.java +++ /dev/null @@ -1,414 +0,0 @@ -package com.electromagnetic.industry.software.common.resp; - -import java.io.Serializable; - -public class ResultCode implements Serializable { - - /** - * 结果码固定前缀 - */ - protected static final String PREFIX = "CE"; - /** - * 序列ID - */ - private static final long serialVersionUID = 3951948353107763580L; - /** - * 结果码版本 - */ - private String version; - - /** - * 结果码级别[第9位],INFO-1,WARN-3,ERROR-5,FATAL-7,参见ResultCodeLevel定义 - */ - private String codeLevel; - - /** - * 结果码类型[第10位],SUCCESS-0,BIZ_ERROR-1,SYS_ERROR-2,THIRD_ERROR-3,参见ResultCodeType定义 - */ - private String codeType; - - /** - * 系统编号[第11-13位],见SystemCode定义 - */ - private String systemCode; - - /** - * 系统名称 - */ - private String systemName; - - /** - * 具体结果码[第14-17位] - */ - private String errorSpecific; - - /** - * 错误英文简称 - */ - private String errorName; - - /** - * 结果码信息描述,可空 - */ - private String description; - - // ~~~ 构造方法 - - /** - * 默认构造方法。 - */ - public ResultCode() { - // 默认构造方法。 - } - - /** - * 构造方法。 - * - * @param resultCode 结果码字符串 - */ - public ResultCode(String resultCode) { - - //结果码长度检查 - checkStringLength(resultCode, 16); - - //拆分结果码 - spliteResultCode(resultCode); - } - - /** - * 构造方法。 - * - * @param resultCode 结果码字符串 - * @param errorName 错误码英文简称 - */ - public ResultCode(String resultCode, String errorName) { - this(resultCode); - this.errorName = errorName; - } - - /** - * 构造方法。 - * - * @param resultCode 结果码字符串 - * @param errorName 错误码英文简称 - * @param description 结果码信息描述 - */ - public ResultCode(String resultCode, String errorName, String description) { - this(resultCode); - this.errorName = errorName; - this.description = description; - } - - /** - * 构造方法。 - * - * @param version 版本 - * @param codeLevel 结果码级别 - * @param codeType 结果码类型 - * @param systemCode 系统编号 - * @param errorSpecific 具体错误码 - */ - public ResultCode(String version, String codeLevel, String codeType, String systemCode, String errorSpecific) { - this.version = version; - this.codeLevel = codeLevel; - this.codeType = codeType; - this.systemCode = systemCode; - this.errorSpecific = errorSpecific; - } - - /** - * 构造方法。 - * - * @param version 版本 - * @param codeLevel 结果码级别 - * @param codeType 结果码类型 - * @param systemCode 系统编号 - * @param errorSpecific 具体错误码 - * @param errorName 错误码英文简称 - */ - public ResultCode(String version, String codeLevel, String codeType, String systemCode, String errorSpecific, - String errorName) { - this(version, codeLevel, codeType, systemCode, errorSpecific); - this.errorName = errorName; - } - - // ~~~ 公有方法 - - /** - * 组装返回码字符串。 - * - * @return 返回码字符串 - */ - public String fetchResultCode() { - StringBuffer sb = new StringBuffer(); - - sb.append(PREFIX); - sb.append(version); - sb.append(codeLevel); - sb.append(codeType); - sb.append(systemCode); - sb.append(errorSpecific); - - return sb.toString(); - } - - /** - * 组装返回码字符串。 解决enum 单利线程安全问题 - * - * @param eventCode - * @return 返回码字符串 - */ - public String fetchResultCode(String eventCode) { - StringBuffer sb = new StringBuffer(); - - sb.append(PREFIX); - sb.append(version); - sb.append(codeLevel); - sb.append(codeType); - sb.append(eventCode); - sb.append(errorSpecific); - - return sb.toString(); - } - - /** - * 构建错误对象digest - * - * @return 错误码摘要日志 - */ -// public String toDigest() { -// -// //组装结果码字符串 -// String resultCode = fetchResultCode(); -// -// if (StringUtils.isNotBlank(errorName)) { -// resultCode = resultCode + "@" + errorName; -// } else { -// resultCode = resultCode + "@"; -// } -// -// if (StringUtils.isNotBlank(systemName)) { -// resultCode = resultCode + "@" + systemName; -// } else { -// resultCode = resultCode + "@"; -// } -// -// return resultCode; -// } - - // ~~~ 重写方法 - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - //错误完整性检查 - checkStringLength(this.version, 1); - checkStringLength(this.codeLevel, 1); - checkStringLength(this.codeType, 1); - checkStringLength(this.systemCode, 8); - checkStringLength(this.errorSpecific, 3); - - //组装结果码字符串 - String resultCode = fetchResultCode(); - -// if (StringUtils.isNotBlank(errorName)) { -// resultCode = resultCode + "@" + errorName; -// } - - return resultCode; - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return this.fetchResultCode().hashCode(); - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - - if (obj == this) { - return true; - } - - if (obj == null) { - return false; - } - return false; - -// return StringUtils.equals(this.fetchResultCode(), (((ResultCode) obj).fetchResultCode())); - } - - // ~~~ 内部方法 - - /** - * 解析和拆分结果码。 - * - * @param resultCode 结果码字符串 - */ - private void spliteResultCode(String resultCode) { - if (!resultCode.startsWith(PREFIX)) { - throw new IllegalArgumentException(); - } - - char[] chars = resultCode.toCharArray(); - - // 旧:CIC_RS_100000200 - // 新:CE15112000201001 - - this.version = "" + chars[2]; - this.codeLevel = "" + chars[3]; - this.codeType = "" + chars[4]; - this.systemCode = "" + chars[5] + chars[6] + chars[7] + chars[8] + chars[9] + chars[10] + chars[11] + chars[12]; - this.errorSpecific = "" + chars[13] + chars[14] + chars[15]; - } - - /** - * 字符串长度检查。 - * - * @param resultCode 结果码字符串 - * @param length 长度 - */ - private void checkStringLength(String resultCode, int length) { - if (resultCode == null || resultCode.length() != length) { - throw new IllegalArgumentException(); - } - } - - // ~~~ bean方法 - - /** - * Getter method for property codeLevel. - * - * @return property value of codeLevel - */ - public String getCodeLevel() { - return codeLevel; - } - - /** - * Setter method for property codeLevel. - * - * @param codeLevel value to be assigned to property codeLevel - */ - public void setCodeLevel(String codeLevel) { - this.codeLevel = codeLevel; - } - - /** - * Getter method for property codeType. - * - * @return property value of codeType - */ - public String getCodeType() { - return codeType; - } - - /** - * Setter method for property codeType. - * - * @param codeType value to be assigned to property codeType - */ - public void setCodeType(String codeType) { - this.codeType = codeType; - } - - /** - * Getter method for property systemCode. - * - * @return property value of systemCode - */ - public String getSystemCode() { - return systemCode; - } - - /** - * Setter method for property systemCode. - * - * @param systemCode value to be assigned to property systemCode - */ - public void setSystemCode(String systemCode) { - this.systemCode = systemCode; - } - - /** - * Getter method for property errorSpecific. - * - * @return property value of errorSpecific - */ - public String getErrorSpecific() { - return errorSpecific; - } - - /** - * Setter method for property errorSpecific. - * - * @param errorSpecific value to be assigned to property errorSpecific - */ - public void setErrorSpecific(String errorSpecific) { - this.errorSpecific = errorSpecific; - } - - /** - * Getter method for property description. - * - * @return property value of description - */ - public String getDescription() { - return description; - } - - /** - * Setter method for property description. - * - * @param description value to be assigned to property description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Getter method for property systemName. - * - * @return property value of systemName - */ - public String getSystemName() { - return systemName; - } - - /** - * Setter method for property systemName. - * - * @param systemName value to be assigned to property systemName - */ - public void setSystemName(String systemName) { - this.systemName = systemName; - } - - /** - * Getter method for property errorName. - * - * @return property value of errorName - */ - public String getErrorName() { - return errorName; - } - - /** - * Setter method for property errorName. - * - * @param errorName value to be assigned to property errorName - */ - public void setErrorName(String errorName) { - this.errorName = errorName; - } - -} \ No newline at end of file