CommReceiveService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.ruoyi.sim.service.impl;
  2. import com.ruoyi.common.core.domain.AjaxResult;
  3. import com.ruoyi.sim.domain.Fault;
  4. import com.ruoyi.sim.domain.RealExamFault;
  5. import com.ruoyi.sim.domain.Sim;
  6. import com.ruoyi.sim.domain.SimMsg;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import static com.ruoyi.sim.service.impl.CommConst.*;
  13. @Service
  14. // 多实例
  15. // 异步调用
  16. // @Scope("prototype")
  17. public class CommReceiveService {
  18. private static final Logger l = LoggerFactory.getLogger(CommReceiveService.class);
  19. @Autowired
  20. private RealExamFaultService realExamFaultService;
  21. @Autowired
  22. private SimService simService;
  23. /**
  24. * 只要返回信息,即认为在线。
  25. *
  26. * @param sm
  27. * @param s
  28. */
  29. public void checkOneSimState(SimMsg sm, Sim s) {
  30. if (s == null) {
  31. l.warn("s is null");
  32. return;
  33. }
  34. if (StringUtils.isNotBlank(sm.getReceiveMsg())) {
  35. simService.updateSimStateBySimId(s.getSimId(), Sim.State.ONLINE);
  36. }
  37. }
  38. public void clearOneFault(SimMsg sm, Sim s, RealExamFault reF, Fault f) {
  39. // check
  40. //
  41. //
  42. if (reF != null) {
  43. realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.CLEARED);
  44. }
  45. }
  46. /**
  47. * 设置出题值。
  48. *
  49. * @param sm
  50. * @param s
  51. * @param reF
  52. * @param f
  53. */
  54. public void setFaultQuestionValue(SimMsg sm, Sim s, RealExamFault reF, Fault f) {
  55. // check
  56. //
  57. String faultQuestionValue = parseGetData(sm.getReceiveMsg());
  58. // todo:
  59. if (StringUtils.isBlank(faultQuestionValue)) {
  60. l.warn("faultQuestionValue is empty!");
  61. return;
  62. }
  63. l.info("faultQuestionValue = {}", faultQuestionValue);
  64. // 修改关联状态。
  65. reF.setSimFaultQuestionValue(faultQuestionValue);
  66. realExamFaultService.updateRealExamFault(reF);
  67. if (RealExamFault.Flag.YES.equals(reF.getFlag())) {
  68. realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.WRITTEN);
  69. } else if (RealExamFault.Flag.NO.equals(reF.getFlag())) {
  70. realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.LOOP_READ);
  71. }
  72. }
  73. /**
  74. * 设置答题值。
  75. *
  76. * @param sm
  77. * @param s
  78. * @param reF
  79. * @param f
  80. * @param refState 轮询时候为null
  81. */
  82. public void setFaultAnswerValue(SimMsg sm, Sim s, RealExamFault reF, Fault f, String refState) {
  83. // check
  84. if (reF == null) {
  85. l.info("reF null!");
  86. return;
  87. }
  88. //
  89. String faultAnswerValue = parseGetData(sm.getReceiveMsg());
  90. // todo:
  91. if (StringUtils.isBlank(faultAnswerValue)) {
  92. l.warn("faultAnswerValue is empty!");
  93. return;
  94. }
  95. l.info("faultAnswerValue = {}", faultAnswerValue);
  96. if (StringUtils.isNotBlank(refState)) {
  97. reF.setRefState(refState);
  98. }
  99. reF.setSimFaultAnswerValue(faultAnswerValue);
  100. realExamFaultService.updateRealExamFault(reF);
  101. }
  102. /**
  103. * 截取
  104. *
  105. * @param receiveMsg
  106. * @return
  107. */
  108. public String parseGetData(String receiveMsg) {
  109. if (StringUtils.isEmpty(receiveMsg)) {
  110. return "";
  111. }
  112. return StringUtils.substring(receiveMsg, 10, 18);
  113. }
  114. /**
  115. * 0002型 01故障部位进行特殊处理。
  116. */
  117. public String FAULT_0002_GZBW_01 = "0002GZBW0001";
  118. public AjaxResult getOneFaultCheck(SimMsg sm, Sim s, Fault f) {
  119. String checkValue = parseGetData(sm.getReceiveMsg());
  120. if (s != null &&
  121. s.getSimType().equals(Sim.TYPE_0002) &&
  122. f.getFaultId().equals(FAULT_0002_GZBW_01)) {
  123. return AjaxResult.success(f);
  124. }
  125. if (BLANK_CONTENT.equals(checkValue)) {
  126. l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
  127. return AjaxResult.error(
  128. "故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;"
  129. , f);
  130. } else {
  131. return AjaxResult.success(f);
  132. }
  133. }
  134. }