123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package com.ruoyi.sim.service.impl;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.sim.domain.Fault;
- import com.ruoyi.sim.domain.RealExamFault;
- import com.ruoyi.sim.domain.Sim;
- import com.ruoyi.sim.domain.SimMsg;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import static com.ruoyi.sim.service.impl.CommConst.*;
- @Service
- // 多实例
- // 异步调用
- // @Scope("prototype")
- public class CommReceiveService {
- private static final Logger l = LoggerFactory.getLogger(CommReceiveService.class);
- @Autowired
- private RealExamFaultService realExamFaultService;
- @Autowired
- private SimService simService;
- /**
- * 只要返回信息,即认为在线。
- *
- * @param sm
- * @param s
- */
- public void checkOneSimState(SimMsg sm, Sim s) {
- if (s == null) {
- l.warn("s is null");
- return;
- }
- if (StringUtils.isNotBlank(sm.getReceiveMsg())) {
- simService.updateSimStateBySimId(s.getSimId(), Sim.State.ONLINE);
- }
- }
- public void clearOneFault(SimMsg sm, Sim s, RealExamFault reF, Fault f) {
- // check
- //
- //
- if (reF != null) {
- realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.CLEARED);
- }
- }
- /**
- * 设置出题值。
- *
- * @param sm
- * @param s
- * @param reF
- * @param f
- */
- public void setFaultQuestionValue(SimMsg sm, Sim s, RealExamFault reF, Fault f) {
- // check
- //
- String faultQuestionValue = parseGetData(sm.getReceiveMsg());
- // todo:
- if (StringUtils.isBlank(faultQuestionValue)) {
- l.warn("faultQuestionValue is empty!");
- return;
- }
- l.info("faultQuestionValue = {}", faultQuestionValue);
- // 修改关联状态。
- reF.setSimFaultQuestionValue(faultQuestionValue);
- realExamFaultService.updateRealExamFault(reF);
- if (RealExamFault.Flag.YES.equals(reF.getFlag())) {
- realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.WRITTEN);
- } else if (RealExamFault.Flag.NO.equals(reF.getFlag())) {
- realExamFaultService.updateRefStateByRefId(reF.getRefId(), RealExamFault.State.LOOP_READ);
- }
- }
- /**
- * 设置答题值。
- *
- * @param sm
- * @param s
- * @param reF
- * @param f
- * @param refState 轮询时候为null
- */
- public void setFaultAnswerValue(SimMsg sm, Sim s, RealExamFault reF, Fault f, String refState) {
- // check
- if (reF == null) {
- l.info("reF null!");
- return;
- }
- //
- String faultAnswerValue = parseGetData(sm.getReceiveMsg());
- // todo:
- if (StringUtils.isBlank(faultAnswerValue)) {
- l.warn("faultAnswerValue is empty!");
- return;
- }
- l.info("faultAnswerValue = {}", faultAnswerValue);
- if (StringUtils.isNotBlank(refState)) {
- reF.setRefState(refState);
- }
- reF.setSimFaultAnswerValue(faultAnswerValue);
- realExamFaultService.updateRealExamFault(reF);
- }
- /**
- * 截取
- *
- * @param receiveMsg
- * @return
- */
- public String parseGetData(String receiveMsg) {
- if (StringUtils.isEmpty(receiveMsg)) {
- return "";
- }
- return StringUtils.substring(receiveMsg, 10, 18);
- }
- /**
- * 0002型 01故障部位进行特殊处理。
- */
- public String FAULT_0002_GZBW_01 = "0002GZBW0001";
- public AjaxResult getOneFaultCheck(SimMsg sm, Sim s, Fault f) {
- String checkValue = parseGetData(sm.getReceiveMsg());
- if (s != null &&
- s.getSimType().equals(Sim.TYPE_0002) &&
- f.getFaultId().equals(FAULT_0002_GZBW_01)) {
- return AjaxResult.success(f);
- }
- if (BLANK_CONTENT.equals(checkValue)) {
- l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
- return AjaxResult.error(
- "故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;"
- , f);
- } else {
- return AjaxResult.success(f);
- }
- }
- }
|