|  | @@ -107,6 +107,35 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void readOneSimAtLastByDebug(Sim s) {
 | 
	
		
			
				|  |  | +        l.info("readOneSimAtLastByDebug");
 | 
	
		
			
				|  |  | +        List<Fault> list = faultService.listType3(s.getSimType());
 | 
	
		
			
				|  |  | +        for (Fault f : list) {
 | 
	
		
			
				|  |  | +            readOneSimOneFaultResistance(s, null, f, null);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public AjaxResult debugReadAllFaultResistanceBySimNum(String simNum) {
 | 
	
		
			
				|  |  | +        // check
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //
 | 
	
		
			
				|  |  | +        // 打开socket
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            AjaxResult ar1 = openSocket();
 | 
	
		
			
				|  |  | +            if (ar1.isError()) {
 | 
	
		
			
				|  |  | +                return ar1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //
 | 
	
		
			
				|  |  | +        Sim s = simService.uniqueBySimNum(simNum);
 | 
	
		
			
				|  |  | +        if (s == null || !Sim.State.ONLINE.equals(s.getSimState())) {
 | 
	
		
			
				|  |  | +            return AjaxResult.error("未连接维修模拟器,请检查连接!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // todo: aj改造
 | 
	
		
			
				|  |  | +        readOneSimAtLastByDebug(s);
 | 
	
		
			
				|  |  | +        return AjaxResult.success("成功读取!");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Async("tp-comm")
 | 
	
		
			
				|  |  |      public void readOneExamAtLastAsync(RealExam re) {
 | 
	
		
			
				|  |  |          l.info("readOneExamAtLastAsync");
 | 
	
	
		
			
				|  | @@ -277,18 +306,28 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          if (list != null) {
 | 
	
		
			
				|  |  |              l.info("清除exam list = {}", list.size());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        list.forEach(ref -> {
 | 
	
		
			
				|  |  | -            Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
 | 
	
		
			
				|  |  | -            if (faultService.isDisable(f.getFaultId())) {
 | 
	
		
			
				|  |  | -                l.warn("故障 {} -被禁用", f.getName());
 | 
	
		
			
				|  |  | -                throw new IllegalArgumentException("故障被禁用");
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            Sim s = simService.selectSimBySimId(re.getSimId());
 | 
	
		
			
				|  |  | -            // check
 | 
	
		
			
				|  |  | +        assert list != null;
 | 
	
		
			
				|  |  | +        list
 | 
	
		
			
				|  |  | +                .forEach(ref -> {
 | 
	
		
			
				|  |  | +                    Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
 | 
	
		
			
				|  |  | +                    if (faultService.isDisable(f.getFaultId())) {
 | 
	
		
			
				|  |  | +                        l.warn("故障 {} -被禁用", f.getName());
 | 
	
		
			
				|  |  | +                        throw new IllegalArgumentException("故障被禁用");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    Sim s = simService.selectSimBySimId(re.getSimId());
 | 
	
		
			
				|  |  | +                    // check
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            //
 | 
	
		
			
				|  |  | -            clearOneSimOneFault(s, ref, f);
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  | +                    //
 | 
	
		
			
				|  |  | +                    clearOneSimOneFault(s, ref, f);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void clearOneSimAllFaultBySim(Sim s) {
 | 
	
		
			
				|  |  | +        l.info("clearOneSimAllFaultBySim = {}", s);
 | 
	
		
			
				|  |  | +        faultService.listType3EnableBySimType(s.getSimType())
 | 
	
		
			
				|  |  | +                .forEach(f -> {
 | 
	
		
			
				|  |  | +                    clearOneSimOneFault(s, null, f);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -369,7 +408,7 @@ public class CommSendService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * @param s
 | 
	
		
			
				|  |  | -     * @param reF 可以为空,表示不关联考试的,单独执行的。
 | 
	
		
			
				|  |  | +     * @param reF 可以为空,表示不关联考试的,单独执行的。调试模式下为空。
 | 
	
		
			
				|  |  |       * @param f
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public void clearOneSimOneFault(Sim s, RealExamFault reF, Fault f) {
 | 
	
	
		
			
				|  | @@ -380,7 +419,12 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          // step1
 | 
	
		
			
				|  |  |          SimMsg smS = commBuildService.buildSendMsgClearFault(s.getSimNum(), f.getBindHardwareMsg());
 | 
	
		
			
				|  |  |          SimMsg smR = send(smS, s, RETRY_COUNT_CLEAR_ONE_FAULT, SLEEP_LONG);
 | 
	
		
			
				|  |  | -        simReceiveService.clearOneFault(smR, s, reF, f);
 | 
	
		
			
				|  |  | +        if (reF != null) {
 | 
	
		
			
				|  |  | +            simReceiveService.clearOneFault(smR, s, reF, f);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            l.info("reF == null");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          // step2
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 下发故障独立运行。下面屏蔽。
 | 
	
	
		
			
				|  | @@ -427,16 +471,56 @@ public class CommSendService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * todo:尚未实现
 | 
	
		
			
				|  |  | +     * 实现方式类似 studentStartRealExam方法。
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param simNum
 | 
	
		
			
				|  |  |       * @param faultIds
 | 
	
		
			
				|  |  | +     * @param checkReplace 是否进行可换件检查
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public AjaxResult debugWriteSelectedFaultBySimNum(final String simNum,
 | 
	
		
			
				|  |  |                                                        final String[] faultIds,
 | 
	
		
			
				|  |  |                                                        final Boolean checkReplace) {
 | 
	
		
			
				|  |  | +        // check faultIds 有效性
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        return null;
 | 
	
		
			
				|  |  | +        //
 | 
	
		
			
				|  |  | +        Sim s = simService.uniqueBySimNum(simNum);
 | 
	
		
			
				|  |  | +        // check sim
 | 
	
		
			
				|  |  | +        // 打开socket
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            AjaxResult ar1 = openSocket();
 | 
	
		
			
				|  |  | +            if (ar1.isError()) {
 | 
	
		
			
				|  |  | +                return ar1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // Step 2
 | 
	
		
			
				|  |  | +        // msg判断,是否含有"故障部位"字符串
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            if (checkReplace) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                AjaxResult arE2 = readOneSimAllFaultCheck(s);
 | 
	
		
			
				|  |  | +                if (arE2.isError()) {
 | 
	
		
			
				|  |  | +                    return arE2;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // Step 3 清除对应一台模拟器 所有故障部位故障。
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            clearOneSimAllFaultBySim(s);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // Step 4 下发对应一台模拟器 出题选中的 故障位置故障。
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            Fault[] faults = new Fault[faultIds.length];
 | 
	
		
			
				|  |  | +            for (int i = 0; i < faultIds.length; i++) {
 | 
	
		
			
				|  |  | +                faults[i] = faultService.selectFaultByFaultId(faultIds[i]);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            writeOneSimAllSelectFaultByDebug(s, faults);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // Step 5 读取
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            readOneSimAllFaultFirstTimeBySim(s);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return AjaxResult.success("下发故障流程执行成功!");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private String[] getGZBWBySimType(String simType) {
 | 
	
	
		
			
				|  | @@ -464,7 +548,7 @@ public class CommSendService {
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param re
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public void writeOneSimAllSelectFault(RealExam re) {
 | 
	
		
			
				|  |  | +    public void writeOneSimAllSelectFaultByExam(RealExam re) {
 | 
	
		
			
				|  |  |          // 更新Exam状态。
 | 
	
		
			
				|  |  |          realExamService.updateOneState(re.getExamId(), RealExam.State.SIM_WRITING);
 | 
	
		
			
				|  |  |          List<RealExamFault> list = realExamFaultService.listAllType2FlagYesClearedStateByExamId(re.getExamId());
 | 
	
	
		
			
				|  | @@ -476,6 +560,12 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void writeOneSimAllSelectFaultByDebug(Sim s, Fault[] faults) {
 | 
	
		
			
				|  |  | +        for (Fault f : faults) {
 | 
	
		
			
				|  |  | +            writeOneSimOneFault(s, null, f);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      public void writeOneSimOneFault(Sim s, RealExamFault ref, Fault f) {
 | 
	
		
			
				|  |  |          l.info("下发故障:getSimId = {},fault.getName = {}", s.getSimId(), f.getName());
 | 
	
		
			
				|  |  |          // todo:ref is null.
 | 
	
	
		
			
				|  | @@ -485,7 +575,7 @@ public class CommSendService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | -     * 检查读取。
 | 
	
		
			
				|  |  | +     * 开始考试前检查读取。
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param s
 | 
	
		
			
				|  |  |       * @return
 | 
	
	
		
			
				|  | @@ -535,7 +625,7 @@ public class CommSendService {
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param re
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public void readOneSimAllFaultFirstTime(RealExam re) {
 | 
	
		
			
				|  |  | +    public void readOneSimAllFaultFirstTimeByExam(RealExam re) {
 | 
	
		
			
				|  |  |          List<RealExamFault> list = realExamFaultService.listAllType2(re.getExamId());
 | 
	
		
			
				|  |  |          for (RealExamFault ref : list) {
 | 
	
		
			
				|  |  |              Sim s = simService.selectSimBySimId(re.getSimId());
 | 
	
	
		
			
				|  | @@ -544,11 +634,18 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void readOneSimAllFaultFirstTimeBySim(Sim s) {
 | 
	
		
			
				|  |  | +        List<Fault> list = faultService.listType3(s.getSimType());
 | 
	
		
			
				|  |  | +        for (Fault f : list) {
 | 
	
		
			
				|  |  | +            readOneSimOneFaultFirstTime(s, null, f);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 第一次读取,作为出题值。
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param s
 | 
	
		
			
				|  |  | -     * @param ref
 | 
	
		
			
				|  |  | +     * @param ref debug调试模式为空。
 | 
	
		
			
				|  |  |       * @param f
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public void readOneSimOneFaultFirstTime(Sim s, RealExamFault ref, Fault f) {
 | 
	
	
		
			
				|  | @@ -601,10 +698,14 @@ public class CommSendService {
 | 
	
		
			
				|  |  |          l.info("readOneFaultResistance");
 | 
	
		
			
				|  |  |          SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
 | 
	
		
			
				|  |  |          SimMsg sm2 = null;
 | 
	
		
			
				|  |  | -        if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
 | 
	
		
			
				|  |  | -            sm2 = send(sm1, s, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
 | 
	
		
			
				|  |  | +        if (reF != null && refState != null) {
 | 
	
		
			
				|  |  | +            if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
 | 
	
		
			
				|  |  | +                sm2 = send(sm1, s, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                sm2 = send(sm1, s, RETRY_COUNT_0, SLEEP_SHORT);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | -            sm2 = send(sm1, s, RETRY_COUNT_0, SLEEP_SHORT);
 | 
	
		
			
				|  |  | +            sm2 = send(sm1, s, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          simReceiveService.setFaultAnswerValue(sm2, s, reF, f, refState);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -680,7 +781,7 @@ public class CommSendService {
 | 
	
		
			
				|  |  |              // 先考虑一台模拟器演示。
 | 
	
		
			
				|  |  |              // 进行重试 start
 | 
	
		
			
				|  |  |              if (sm.getRetryCount() == RETRY_COUNT_0) {
 | 
	
		
			
				|  |  | -                l.warn("####RetryTotalCount不重试RETRY_COUNT_0#### = {}", sm);
 | 
	
		
			
				|  |  | +                l.warn("####RetryTotalCount不重试RETRY_COUNT_0#### = getSimMsgId = {}", sm.getSimMsgId());
 | 
	
		
			
				|  |  |                  return sm;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (sm.getRetryCount() < retryTotalCount) {
 | 
	
	
		
			
				|  | @@ -742,11 +843,11 @@ public class CommSendService {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } catch (IOException e) {
 | 
	
		
			
				|  |  |              e.printStackTrace();
 | 
	
		
			
				|  |  | -            return AjaxResult.error("openSocket IOException");
 | 
	
		
			
				|  |  | +            return AjaxResult.error("开启连接失败!请检查物联网网关连接或配置。");
 | 
	
		
			
				|  |  |          } finally {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return AjaxResult.success();
 | 
	
		
			
				|  |  | +        return AjaxResult.success("开启连接成功!");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -770,12 +871,12 @@ public class CommSendService {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } catch (IOException e) {
 | 
	
		
			
				|  |  |              e.printStackTrace();
 | 
	
		
			
				|  |  | -            return AjaxResult.success("closeSocket IOException");
 | 
	
		
			
				|  |  | +            return AjaxResult.success("关闭连接失败!请检查物联网网关连接或配置。");
 | 
	
		
			
				|  |  |          } finally {
 | 
	
		
			
				|  |  |              cachedSocket = null;
 | 
	
		
			
				|  |  |              commFailCountClearAll();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return AjaxResult.success();
 | 
	
		
			
				|  |  | +        return AjaxResult.success("关闭连接成功!");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 |