From 340eb42dde017aea8b9547c17f1a0a00b1a01b15 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 24 Sep 2024 17:56:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.db | Bin 225280 -> 225280 bytes src/main/java/a8k/type/appret/AppRet.java | 43 ++++++----- src/main/java/a8k/type/ecode/AppRetEcodeInfo.java | 85 ---------------------- src/main/java/a8k/type/ecode/ErrorContext.java | 31 ++++++++ 4 files changed, 52 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/a8k/type/ecode/AppRetEcodeInfo.java create mode 100644 src/main/java/a8k/type/ecode/ErrorContext.java diff --git a/app.db b/app.db index ec8d3c3f967ba2ca99f11456e09707f480ca1b82..8a699331bfbdbb3938d7e01505d10c9f66f78661 100644 GIT binary patch delta 613 zcma)&Jx&8L5Jq>i2_i(x(gz7p3TQ_1&)6P|28lDIM2hWQUjm5@1=Mg7kRn9MB~no4 z78Fq6Y$QsO!jdI_Z|3uxugdwVd>ZG==i}>qc|UuY*>qjBGHNj>~;*8cRkZD9tROGYm*E1GTI@V}>iFFd-8$5&e!})JV&X zfF?Es*f0q$J%dob^@wSp*EESSpyjOS5YK{l5(!wk0NR95V-28BU5P0XQ!Uall4iZl z67GYuoP(BL0Y>N3mym%A(V_I(812%IL~xdO1V`a6y)^`ZT2xJH^f zAtXp1WLdUXjk4;cx~V>^QH9mx;_US6u)Qdz`7RRoHo@)g2J7HI%KnV?*THrdQ$;s& f2SL5_Vme%V*`}pTKC+{97Q?IWllT5>@8{ze79g3? delta 613 zcma)&yGjE=6o&Vb1Y=m&K7z^?+8mgfGgoW`pCP4?*}1%g;Ko9$6#66zK`ea@%e;k! z7S5)y)E$`a`#3+}YFn+g)#E&0KOJ4=>$~OsGJjnbH@BU&o*)JX!YK!wItGR~4-Qef z5S5G^8$%6^k&MTSd9~MCVHHvVq@@~on_S~V1Ve?2=mQd|8?7Qw#%O0SB|M9a0}>>_ zgN&eiH&W8^pj&5@5>1Sb8%oNZqPcGq$iNB8fO{3ddX#`ngtXUj)?%Y&j9QXnXHf10 zQbj;YW`WxvLF+aEmy)FYNlvq3dYY1aX9!`%g<-}+P%Q1D4#DVjNiz`zYGOlRNzqK> zewJmEdY0AC^>zJGKh(3DZ%$7>54!Vmkq?PD>A@lG#y$8)vfpB(9_)scDtmHBpyI4t aO#3eXWvNn+>@fY!^z!TYZS+!nzyAQoW|rRo 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; + } +}