SimMsg.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. package com.ruoyi.sim.domain;
  2. import java.util.Date;
  3. import java.util.Objects;
  4. import com.fasterxml.jackson.annotation.JsonFormat;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.sim.service.impl.CommParseUtils;
  7. import org.apache.commons.lang3.builder.ToStringBuilder;
  8. import org.apache.commons.lang3.builder.ToStringStyle;
  9. import com.ruoyi.common.annotation.Excel;
  10. import com.ruoyi.common.core.domain.BaseEntity;
  11. /**
  12. * 模拟器报文对象 sim_sim_msg
  13. *
  14. * @author tom
  15. * @date 2024-12-18
  16. */
  17. public class SimMsg extends BaseEntity {
  18. private static final long serialVersionUID = 1L;
  19. /**
  20. * 模拟器报文ID
  21. */
  22. private Long simMsgId;
  23. /**
  24. * 模拟器ID
  25. */
  26. @Excel(name = "模拟器ID")
  27. private Long simId;
  28. /**
  29. * 关联ID
  30. */
  31. @Excel(name = "关联ID")
  32. private Long examFaultRefId;
  33. /**
  34. * 考试类型
  35. * 1:练习
  36. * 2:自主练习
  37. * 3:考试
  38. */
  39. @Excel(name = "考试类型")
  40. private String examCollectionType;
  41. /**
  42. * 状态 0初始值 1成功 2失败
  43. */
  44. @Excel(name = "状态 0初始值 1成功 2失败")
  45. private String sendMsgState;
  46. /**
  47. * 优先级
  48. */
  49. @Excel(name = "优先级")
  50. private Integer priority;
  51. /**
  52. * 发送报文类型 cmd+cmdId
  53. */
  54. @Excel(name = "发送报文类型 cmd+cmdId")
  55. private String sendMsgType;
  56. /**
  57. * 发送报文
  58. */
  59. @Excel(name = "发送报文")
  60. private String sendMsg;
  61. /**
  62. * 发送时间
  63. */
  64. @JsonFormat(pattern = "yyyy-MM-dd")
  65. @Excel(name = "发送时间", width = 30, dateFormat = "yyyy-MM-dd")
  66. private Date sendTime;
  67. /**
  68. * 接收报文
  69. */
  70. @Excel(name = "接收报文")
  71. private String receiveMsg;
  72. private String receiveOriginalMsg;
  73. /**
  74. * 接收时间
  75. */
  76. @JsonFormat(pattern = "yyyy-MM-dd")
  77. @Excel(name = "接收时间", width = 30, dateFormat = "yyyy-MM-dd")
  78. private Date receiveTime;
  79. /**
  80. * 重试次数
  81. */
  82. @Excel(name = "重试次数")
  83. private Integer retryCount = 0;
  84. /**
  85. * default.
  86. */
  87. private Integer result = Result.DEFAULT_VALUE;
  88. /**
  89. * default ""
  90. */
  91. private String errorMsg = "";
  92. public void setSimMsgId(Long simMsgId) {
  93. this.simMsgId = simMsgId;
  94. }
  95. public Long getSimMsgId() {
  96. return simMsgId;
  97. }
  98. public void setSimId(Long simId) {
  99. this.simId = simId;
  100. }
  101. public Long getSimId() {
  102. return simId;
  103. }
  104. public void setExamFaultRefId(Long examFaultRefId) {
  105. this.examFaultRefId = examFaultRefId;
  106. }
  107. public Long getExamFaultRefId() {
  108. return examFaultRefId;
  109. }
  110. public void setExamCollectionType(String examCollectionType) {
  111. this.examCollectionType = examCollectionType;
  112. }
  113. public String getExamCollectionType() {
  114. return examCollectionType;
  115. }
  116. public void setSendMsgState(String sendMsgState) {
  117. this.sendMsgState = sendMsgState;
  118. }
  119. public String getSendMsgState() {
  120. return sendMsgState;
  121. }
  122. public void setPriority(Integer priority) {
  123. this.priority = priority;
  124. }
  125. public Integer getPriority() {
  126. return priority;
  127. }
  128. public void setSendMsgType(String sendMsgType) {
  129. this.sendMsgType = sendMsgType;
  130. }
  131. public String getSendMsgType() {
  132. return sendMsgType;
  133. }
  134. public void setSendMsg(String sendMsg) {
  135. this.sendMsg = sendMsg;
  136. }
  137. public String getSendMsg() {
  138. return sendMsg;
  139. }
  140. public void setSendTime(Date sendTime) {
  141. this.sendTime = sendTime;
  142. }
  143. public Date getSendTime() {
  144. return sendTime;
  145. }
  146. public void setReceiveMsg(String receiveMsg) {
  147. this.receiveMsg = receiveMsg;
  148. }
  149. public String getReceiveMsg() {
  150. return receiveMsg;
  151. }
  152. public String getReceiveOriginalMsg() {
  153. return receiveOriginalMsg;
  154. }
  155. public void setReceiveOriginalMsg(String receiveOriginalMsg) {
  156. this.receiveOriginalMsg = receiveOriginalMsg;
  157. }
  158. public void setReceiveTime(Date receiveTime) {
  159. this.receiveTime = receiveTime;
  160. }
  161. public Date getReceiveTime() {
  162. return receiveTime;
  163. }
  164. public void setRetryCount(Integer retryCount) {
  165. this.retryCount = retryCount;
  166. }
  167. public Integer getRetryCount() {
  168. return retryCount;
  169. }
  170. public Integer getResult() {
  171. return result;
  172. }
  173. public void setResult(Integer result) {
  174. this.result = result;
  175. }
  176. public String getErrorMsg() {
  177. return errorMsg;
  178. }
  179. public void setErrorMsg(String errorMsg) {
  180. this.errorMsg = errorMsg;
  181. }
  182. @Override
  183. public String toString() {
  184. return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
  185. .append("simMsgId", simMsgId)
  186. .append("simId", simId)
  187. .append("examFaultRefId", examFaultRefId)
  188. .append("examCollectionType", examCollectionType)
  189. .append("sendMsgState", sendMsgState)
  190. .append("priority", priority)
  191. .append("sendMsgType", sendMsgType)
  192. .append("sendMsg", sendMsg)
  193. .append("sendTime", sendTime)
  194. .append("receiveMsg", receiveMsg)
  195. .append("receiveOriginalMsg", receiveOriginalMsg)
  196. .append("receiveTime", receiveTime)
  197. .append("retryCount", retryCount)
  198. .append("result", result)
  199. .append("errorMsg", errorMsg)
  200. .toString();
  201. }
  202. // -------------------------------- tom add --------------------------------
  203. public boolean isResultOk() {
  204. if (Objects.equals(this.result, Result.SUCCESS)) {
  205. return true;
  206. }
  207. return false;
  208. }
  209. public boolean isResultNotOk() {
  210. return !isResultOk();
  211. }
  212. public AjaxResult getDefaultErrorAR() {
  213. if (Objects.equals(this.result, Result.SUCCESS)) {
  214. // throw new IllegalArgumentException("错误执行!先判断消息对错!");
  215. return AjaxResult.success("");
  216. } else if (Objects.equals(this.result, Result.SOCKET_CONNECT_EXCEPTION)) {
  217. return AjaxResult.error("模拟器通信连接失败!");
  218. } else if (Objects.equals(this.result, Result.READ_TIMEOUT_EXCEPTION)) {
  219. return AjaxResult.error("模拟器通信超时!");
  220. } else if (Objects.equals(this.result, Result.RECEIVE_CHECK_FAIL)) {
  221. return AjaxResult.error("回复报文格式错误!<br/>系统自动尝试重新连接,请3秒后重新尝试开始考试!");
  222. } else if (Objects.equals(this.result, Result.RECEIVE_NOT_MATCH)) {
  223. return AjaxResult.error("回复报文不匹配!<br/>系统自动尝试重新连接,请3秒后重新尝试开始考试!");
  224. } else {
  225. // throw new IllegalArgumentException("参数错误!");
  226. }
  227. return null;
  228. }
  229. public String getReceiveSubContentData() {
  230. return CommParseUtils.receiveSubContentData(this);
  231. }
  232. public boolean isReceiveContentDataBlank() {
  233. return CommParseUtils.isReceiveContentDataBlank(this);
  234. }
  235. public interface Result {
  236. /**
  237. * 默认空值。
  238. */
  239. Integer DEFAULT_VALUE = 0;
  240. /**
  241. * 成功。
  242. */
  243. Integer SUCCESS = 200;
  244. /**
  245. * Socket连接问题。
  246. */
  247. Integer SOCKET_CONNECT_EXCEPTION = 501;
  248. /**
  249. * SocketTimeoutException。
  250. */
  251. Integer READ_TIMEOUT_EXCEPTION = 502;
  252. /**
  253. * 接收报文格式不正确。
  254. */
  255. Integer RECEIVE_CHECK_FAIL = 520;
  256. /**
  257. * 接收报文格式不匹配。
  258. */
  259. Integer RECEIVE_NOT_MATCH = 530;
  260. /**
  261. * 报文校验码错误。
  262. * todo:没有启用。
  263. */
  264. Integer CRC_ERROR = 540;
  265. /**
  266. * 重要报文在运行,低优先级的跳过
  267. */
  268. Integer SKIP = 600;
  269. }
  270. public SimMsg() {
  271. }
  272. public SimMsg(Long simMsgId, String sendMsg) {
  273. this.simMsgId = simMsgId;
  274. this.sendMsg = sendMsg;
  275. }
  276. public void retryCountPlus1() {
  277. setRetryCount(getRetryCount() + 1);
  278. }
  279. }