diff --git a/app.db b/app.db index ec8d3c3..8a69933 100644 Binary files a/app.db and b/app.db differ diff --git a/src/main/java/a8k/type/appret/AppRet.java b/src/main/java/a8k/type/appret/AppRet.java index 661c4da..c942c6f 100644 --- a/src/main/java/a8k/type/appret/AppRet.java +++ b/src/main/java/a8k/type/appret/AppRet.java @@ -1,6 +1,6 @@ package a8k.type.appret; -import a8k.type.ecode.AppRetEcodeInfo; +import a8k.type.ecode.ErrorContext; import a8k.hardware.type.a8kcanprotocol.CmdId; import a8k.hardware.type.a8kcanprotocol.MId; import a8k.hardware.type.a8kcanprotocol.A8kEcode; @@ -11,24 +11,27 @@ public class AppRet { public AppRetType appRetType = AppRetType.NORMAL; - //错误信息 + // 错误信息 @Getter - AppRetEcodeInfo ecode = null; + ErrorContext ecode = null; + + // 显示给用户的内容 + @Getter + String message = null; + + //异常触发上下文 @Getter String traceInfo = null; - //携带的对象 + // 携带的对象 @Getter String dataType; @Getter - T data; + T data; - //显示给用户的内容 - @Getter - String message = null; + // 接口请求时间 @Getter - long timestamp;//接口请求时间 - + long timestamp; public AppRet() { this.timestamp = System.currentTimeMillis(); @@ -38,7 +41,6 @@ public class AppRet { return !AppRetType.FAILURE.equals(appRetType); } - public static AppRet message(String message, T data) { AppRet r = new AppRet<>(); r.appRetType = AppRetType.MESSAGE; @@ -55,18 +57,16 @@ public class AppRet { return r; } - public static AppRet success() { AppRet r = new AppRet<>(); r.appRetType = AppRetType.NORMAL; return r; } - public static AppRet fail(Integer errorCode, MId mid, CmdId cmd) { AppRet r = new AppRet<>(); r.appRetType = AppRetType.FAILURE; - r.ecode = new AppRetEcodeInfo(errorCode, mid, cmd); + r.ecode = new ErrorContext(errorCode, mid, cmd); r.message = r.ecode.toDisPlayString(); return r; } @@ -75,7 +75,7 @@ public class AppRet { AppRet r = new AppRet<>(); r.appRetType = AppRetType.FAILURE; - r.ecode = new AppRetEcodeInfo(errorCode, mid, null); + r.ecode = new ErrorContext(errorCode, mid, null); r.message = r.ecode.toDisPlayString(); return r; } @@ -84,7 +84,7 @@ public class AppRet { AppRet r = new AppRet<>(); r.appRetType = AppRetType.FAILURE; - r.ecode = new AppRetEcodeInfo(errorCode, null, null); + r.ecode = new ErrorContext(errorCode, null, null); r.message = r.ecode.toDisPlayString(); return r; } @@ -93,7 +93,7 @@ public class AppRet { AppRet r = new AppRet<>(); r.appRetType = AppRetType.FAILURE; - r.ecode = new AppRetEcodeInfo(ret.getEcode().errorCode, ret.getEcode().mid, ret.getEcode().cmd); + r.ecode = new ErrorContext(ret.getEcode().code, ret.getEcode().relateMid, ret.getEcode().relateCmd); r.data = null; r.message = r.ecode.toDisPlayString(); return r; @@ -109,20 +109,19 @@ public class AppRet { r.appRetType = AppRetType.FAILURE; if (e instanceof HardwareException hexcep) { - r.ecode = new AppRetEcodeInfo(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); + r.ecode = new ErrorContext(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); r.traceInfo = trace; r.message = r.ecode.toDisPlayString(); if (hexcep.getExtMessage() != null) { - r.message = r.message + "\n 额外信息:"+hexcep.getExtMessage(); + r.message = r.message + "\n 额外信息:" + hexcep.getExtMessage(); } } else { - r.ecode = new AppRetEcodeInfo(A8kEcode.CodeException.index, null, null); + r.ecode = new ErrorContext(A8kEcode.CodeException.index, null, null); r.traceInfo = trace; - r.message = e.getMessage(); + r.message = e.getMessage(); } return r; } - } diff --git a/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java b/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java deleted file mode 100644 index 996c43a..0000000 --- a/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java +++ /dev/null @@ -1,85 +0,0 @@ -package a8k.type.ecode; - -import a8k.hardware.type.a8kcanprotocol.A8kEcode; -import a8k.hardware.type.a8kcanprotocol.CmdId; -import a8k.hardware.type.a8kcanprotocol.MId; - -public class AppRetEcodeInfo { - public Integer errorCode; - public MId mid; - public CmdId cmd; - - public AppRetEcodeInfo(Integer errorCode, MId mid, CmdId cmd) { - this.errorCode = errorCode; - this.mid = mid; - this.cmd = cmd; - } - - // code - - public Integer getCode() { - return errorCode; - } - - public String getCodeName() { - return errorCode.toString(); - } - - // mid code - - public Integer getMidCode() { - if (mid == null) { - return null; - } - return mid.toInt(); - } - - public String getMidChName() { - if (mid == null) { - return null; - } - return mid.chname; - } - - public String getMidCodeName() { - if (mid == null) { - return null; - } - return mid.toString(); - } - - // cmd code - - public Integer getCmdCode() { - if (cmd == null) { - return null; - } - return cmd.toInt(); - } - - public String getCmdChName() { - if (cmd == null) { - return null; - } - return cmd.chName; - } - - public String getCmdCodeName() { - if (cmd == null) { - return null; - } - return cmd.toString(); - } - - public String toDisPlayString() { - String info; - info = String.format("错误: (%s)%d", A8kEcode.toDisPlayString(errorCode), errorCode); - if (mid != null) { - info += String.format("\n 相关模块: %s", mid.chname); - } - if (cmd != null) { - info += String.format("\n 相关指令: %s", cmd.chName); - } - return info; - } -} diff --git a/src/main/java/a8k/type/ecode/ErrorContext.java b/src/main/java/a8k/type/ecode/ErrorContext.java new file mode 100644 index 0000000..8958d6e --- /dev/null +++ b/src/main/java/a8k/type/ecode/ErrorContext.java @@ -0,0 +1,31 @@ +package a8k.type.ecode; + +import a8k.hardware.type.a8kcanprotocol.A8kEcode; +import a8k.hardware.type.a8kcanprotocol.CmdId; +import a8k.hardware.type.a8kcanprotocol.MId; + +public class ErrorContext { + public Integer code; + public String codeName; + public MId relateMid; + public CmdId relateCmd; + + public ErrorContext(Integer errorCode, MId mid, CmdId cmd) { + this.code = errorCode; + this.codeName = A8kEcode.toDisPlayString(errorCode); + this.relateMid = mid; + this.relateCmd = cmd; + } + + public String toDisPlayString() { + String info; + info = String.format("错误: (%s)%d", A8kEcode.toDisPlayString(code), code); + if (relateMid != null) { + info += String.format("\n 相关模块: %s", relateMid.chname); + } + if (relateCmd != null) { + info += String.format("\n 相关指令: %s", relateCmd.chName); + } + return info; + } +}