|
@@ -3,21 +3,21 @@ package com.ruoyi.sim.service.impl;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.sim.config.SimConfig;
|
|
import com.ruoyi.sim.config.SimConfig;
|
|
-import com.ruoyi.sim.config.SimDebugConfig;
|
|
|
|
|
|
+import com.ruoyi.sim.constant.CommConst;
|
|
import com.ruoyi.sim.domain.*;
|
|
import com.ruoyi.sim.domain.*;
|
|
|
|
+import com.ruoyi.sim.domain.vo.SimSocketVo;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
-import java.net.InetAddress;
|
|
|
|
import java.net.Socket;
|
|
import java.net.Socket;
|
|
-import java.net.UnknownHostException;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static com.ruoyi.sim.constant.CommConst.*;
|
|
import static com.ruoyi.sim.constant.CommConst.*;
|
|
@@ -35,6 +35,8 @@ public class CommSendService {
|
|
@Autowired
|
|
@Autowired
|
|
private CommReceiveService simReceiveService;
|
|
private CommReceiveService simReceiveService;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private SeatService seatService;
|
|
|
|
+ @Autowired
|
|
private SimService simService;
|
|
private SimService simService;
|
|
@Autowired
|
|
@Autowired
|
|
private FaultService faultService;
|
|
private FaultService faultService;
|
|
@@ -48,8 +50,13 @@ public class CommSendService {
|
|
private CommBuildService commBuildService;
|
|
private CommBuildService commBuildService;
|
|
@Autowired
|
|
@Autowired
|
|
private DebugFaultService debugFaultService;
|
|
private DebugFaultService debugFaultService;
|
|
|
|
+ // private SocketOldService socketOldService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SocketService socketService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FailedCountService failedCountService;
|
|
@Autowired
|
|
@Autowired
|
|
- private SocketOldService socketOldService;
|
|
|
|
|
|
+ private CommCheckService commCheckService;
|
|
@Autowired
|
|
@Autowired
|
|
CommReceiveService commReceiveService;
|
|
CommReceiveService commReceiveService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -71,13 +78,12 @@ public class CommSendService {
|
|
}
|
|
}
|
|
List<RealExamFault> listRef = realExamFaultService.listAllType2State2and3ByExamId(e.getExamId());
|
|
List<RealExamFault> listRef = realExamFaultService.listAllType2State2and3ByExamId(e.getExamId());
|
|
listRef.forEach(ref -> {
|
|
listRef.forEach(ref -> {
|
|
- Sim s = simService.selectSimBySimId(e.getSimId());
|
|
|
|
|
|
+ RealExam re = realExamService.selectRealExamByExamId(ref.getExamId());
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
|
+ Sim sim = simService.selectSimBySimId(e.getSimId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
- if (f != null &&
|
|
|
|
- Fault.Type.REAL_GZBW.equals(f.getFaultType()) &&
|
|
|
|
- Fault.State.ENABLE.equals(f.getFaultState())
|
|
|
|
- ) {
|
|
|
|
- readOneSimOneFaultResistance(s, ref, f, null);
|
|
|
|
|
|
+ if (f != null && Fault.Type.REAL_GZBW.equals(f.getFaultType()) && Fault.State.ENABLE.equals(f.getFaultState())) {
|
|
|
|
+ readOneSimOneFaultResistance(seat, sim, ref, f, null);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -95,9 +101,10 @@ public class CommSendService {
|
|
l.info("readOneExamAtLast");
|
|
l.info("readOneExamAtLast");
|
|
List<RealExamFault> list = realExamFaultService.listAllType2State2and3ByExamId(re.getExamId());
|
|
List<RealExamFault> list = realExamFaultService.listAllType2State2and3ByExamId(re.getExamId());
|
|
for (RealExamFault ref : list) {
|
|
for (RealExamFault ref : list) {
|
|
- Sim s = simService.selectSimBySimId(re.getSimId());
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
|
+ Sim sim = simService.selectSimBySimId(re.getSimId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
- readOneSimOneFaultResistance(s, ref, f, RealExamFault.State.FINISH);
|
|
|
|
|
|
+ readOneSimOneFaultResistance(seat, sim, ref, f, RealExamFault.State.FINISH);
|
|
}
|
|
}
|
|
// 计算扣分。
|
|
// 计算扣分。
|
|
// 最后都读取到,才算扣分。
|
|
// 最后都读取到,才算扣分。
|
|
@@ -107,36 +114,34 @@ public class CommSendService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void readOneSimAtLastByDebug(Sim s) {
|
|
|
|
|
|
+ public void readOneSimAtLastByDebug(Seat seat, Sim sim) {
|
|
l.info("readOneSimAtLastByDebug");
|
|
l.info("readOneSimAtLastByDebug");
|
|
- List<Fault> list = faultService.listType3(s.getSimType());
|
|
|
|
|
|
+ List<Fault> list = faultService.listType3(sim.getSimType());
|
|
for (Fault f : list) {
|
|
for (Fault f : list) {
|
|
- readOneSimOneFaultResistance(s, null, f, null);
|
|
|
|
|
|
+ readOneSimOneFaultResistance(seat, sim, null, f, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public AjaxResult debugReadAllFaultResistanceBySimNum(String simNum) {
|
|
|
|
|
|
+ public AjaxResult debugReadAllFaultResistanceBySimNum(final Long seatId) {
|
|
// check
|
|
// check
|
|
|
|
|
|
//
|
|
//
|
|
// 打开socket
|
|
// 打开socket
|
|
{
|
|
{
|
|
- AjaxResult ar1 = socketOldService.openSocket();
|
|
|
|
- if (ar1.isError()) {
|
|
|
|
- return ar1;
|
|
|
|
- }
|
|
|
|
|
|
+ socketService.tryOpenAll();
|
|
}
|
|
}
|
|
//
|
|
//
|
|
- Sim s = simService.uniqueBySimNum(simNum);
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
{
|
|
{
|
|
- AjaxResult arE3 = checkOneSimStateActive(s);
|
|
|
|
|
|
+ AjaxResult arE3 = checkOneSimStateActive(seat);
|
|
if (arE3.isError()) {
|
|
if (arE3.isError()) {
|
|
return arE3;
|
|
return arE3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- s = simService.uniqueBySimNum(simNum);
|
|
|
|
|
|
+ sim = simService.uniqueBySimNum(sim.getSimNum());
|
|
// todo: aj改造
|
|
// todo: aj改造
|
|
- readOneSimAtLastByDebug(s);
|
|
|
|
|
|
+ readOneSimAtLastByDebug(seat, sim);
|
|
return AjaxResult.success("成功读取!");
|
|
return AjaxResult.success("成功读取!");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -168,7 +173,7 @@ public class CommSendService {
|
|
*/
|
|
*/
|
|
public void scheduledReadSim() {
|
|
public void scheduledReadSim() {
|
|
l.info("scheduledReadSim");
|
|
l.info("scheduledReadSim");
|
|
- if (!realExamCollectionService.existOpened()) {
|
|
|
|
|
|
+ if (!realExamCollectionService.existAtLeastOneOpened()) {
|
|
l.info("没有open的考试集合");
|
|
l.info("没有open的考试集合");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -197,15 +202,6 @@ public class CommSendService {
|
|
// debugReadSimType(simNum);
|
|
// debugReadSimType(simNum);
|
|
// l.info("bRea:" + bRea);
|
|
// l.info("bRea:" + bRea);
|
|
|
|
|
|
- {
|
|
|
|
- Socket s = socketOldService.getCachedSocket();
|
|
|
|
- l.info("cachedSocket.isConnected():" + s.isConnected());
|
|
|
|
- l.info("cachedSocket.isBound():" + s.isBound());
|
|
|
|
- l.info("cachedSocket.isClosed():" + s.isClosed());
|
|
|
|
- l.info("cachedSocket.isInputShutdown():" + s.isInputShutdown());
|
|
|
|
- l.info("cachedSocket.isOutputShutdown():" + s.isOutputShutdown());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// debugReadAllFaultResistance(simNum, simType);
|
|
// debugReadAllFaultResistance(simNum, simType);
|
|
|
|
|
|
// debugWriteAllFault(simNum, simType);
|
|
// debugWriteAllFault(simNum, simType);
|
|
@@ -223,121 +219,78 @@ public class CommSendService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 连接情况 的 定时任务。
|
|
* 连接情况 的 定时任务。
|
|
- * 执行频率: 3min
|
|
|
|
|
|
+ * 执行频率: 5min
|
|
*/
|
|
*/
|
|
public void scheduledConnect() {
|
|
public void scheduledConnect() {
|
|
l.info("scheduled####Connect 连接情况 的 定时任务");
|
|
l.info("scheduled####Connect 连接情况 的 定时任务");
|
|
- if (!SimDebugConfig.SCHEDULED_CONNECT) {
|
|
|
|
|
|
+// if (!SimDebugConfig.SCHEDULED_CONNECT) {
|
|
|
|
+ if (true) {
|
|
l.info("连接情况 的 定时任务被禁用!");
|
|
l.info("连接情况 的 定时任务被禁用!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (!realExamCollectionService.existOpened()) {
|
|
|
|
- l.info("没有open的考试集合");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (!isReachable(config.getRouterIp())) {
|
|
|
|
- l.warn("ping RouterIp not ok");
|
|
|
|
- simService.updateAllEnableState(Sim.State.GATEWAY_OFFLINE);
|
|
|
|
- return;
|
|
|
|
|
|
+
|
|
|
|
+ // 暂时注释
|
|
|
|
+// if (!realExamCollectionService.existAtLeastOneOpened()) {
|
|
|
|
+// l.info("没有open的任何集合");
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ {
|
|
|
|
+ AjaxResult ar01 = commCheckService.checkRouterState(config.getRouterIp());
|
|
|
|
+ if (ar01.isError()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (!isReachable(config.getRs485Ip())) {
|
|
|
|
- l.warn("ping Rs485Ip not ok");
|
|
|
|
- simService.updateAllEnableState(Sim.State.GATEWAY_OFFLINE);
|
|
|
|
- return;
|
|
|
|
|
|
+ //
|
|
|
|
+ {
|
|
|
|
+ seatService.listAllRs485Ip().forEach(rs485Ip -> {
|
|
|
|
+ commCheckService.checkPingRs485State(rs485Ip);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+ // socketOldService.openSocket();
|
|
|
|
|
|
- socketOldService.openSocket();
|
|
|
|
- if (socketOldService.isCachedSocketOk()) {
|
|
|
|
- checkAllSimState();
|
|
|
|
- }
|
|
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+// if (socketOldService.isCachedSocketOk()) {
|
|
|
|
+// checkAllSeatAndSimState();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ socketService.tryOpenAll();
|
|
|
|
+ commCheckService.checkAllSeatAndSimState();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 主动更新模拟器状态。
|
|
* 主动更新模拟器状态。
|
|
|
|
+ * <p>
|
|
|
|
+ * <p>
|
|
|
|
+ * 主动查询一次模拟器状态。更新模拟器在线/离线状态;否则返回对应错误。
|
|
|
|
+ * todo:需要重新考虑
|
|
*
|
|
*
|
|
- * @param s
|
|
|
|
|
|
+ * @param seat
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult checkOneSimStateActive(Sim s) {
|
|
|
|
- final long simId = s.getSimId();
|
|
|
|
|
|
+ @Deprecated
|
|
|
|
+ public AjaxResult checkOneSimStateActive(Seat seat) {
|
|
// 这句可能会调整模拟器状态,后面需要重新查询。
|
|
// 这句可能会调整模拟器状态,后面需要重新查询。
|
|
- {
|
|
|
|
- AjaxResult ar1 = checkOneSimState(s, true);
|
|
|
|
- if (ar1.isError()) {
|
|
|
|
- return ar1;
|
|
|
|
- }
|
|
|
|
|
|
+ commCheckService.checkOneSeatState(seat, true);
|
|
|
|
+ AjaxResult ar1 = commCheckService.checkOneSimOnlineState(seat, true);
|
|
|
|
+ if (ar1.isError()) {
|
|
|
|
+ return ar1;
|
|
}
|
|
}
|
|
// 重新最新模拟器。
|
|
// 重新最新模拟器。
|
|
- s = simService.selectSimBySimId(simId);
|
|
|
|
|
|
+ Sim sim = gggSimBySeatId(seat.getSeatId());
|
|
// 如果模拟器离线
|
|
// 如果模拟器离线
|
|
- if (s != null && Sim.State.ONLINE.equals(s.getSimState())) {
|
|
|
|
|
|
+ if (sim != null && Sim.State.ONLINE.equals(sim.getSimState())) {
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
} else {
|
|
} else {
|
|
return AjaxResult.error("未连接模拟器,请检查连接!");
|
|
return AjaxResult.error("未连接模拟器,请检查连接!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @param s
|
|
|
|
- * @param important true 重试次数不同,也会进行序列号检查。
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public AjaxResult checkOneSimState(final Sim s, final boolean important) {
|
|
|
|
- // check
|
|
|
|
- if (s == null) {
|
|
|
|
- return AjaxResult.error("sim is null");
|
|
|
|
- }
|
|
|
|
- if (Sim.State.DISABLE.equals(s.getSimState())) {
|
|
|
|
- l.warn("sim DISABLE,模拟器被禁用,sim = {}", s);
|
|
|
|
- return AjaxResult.error("模拟器被禁用");
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isBlank(s.getSimType()) || StringUtils.isBlank(s.getSimNum())) {
|
|
|
|
- l.warn("sim error data {}", s);
|
|
|
|
- return AjaxResult.error("模拟器数据错误。");
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- SimMsg smS = commBuildService.buildSendMsgReadSimType(s.getSimNum());
|
|
|
|
- int retryCount = RETRY_COUNT_0;
|
|
|
|
- long sleep = SLEEP_SHORT;
|
|
|
|
- if (important) {
|
|
|
|
- retryCount = RETRY_COUNT_QUERY_SN_IMPORTANT;
|
|
|
|
- }
|
|
|
|
- SimMsg smR = send(smS, s, retryCount, sleep);
|
|
|
|
- if (StringUtils.isNotBlank(smR.getReceiveMsg())) {
|
|
|
|
- l.info("isNotBlank");
|
|
|
|
- socketOldService.commFailCountClearOne(s.getSimId());
|
|
|
|
- }
|
|
|
|
- simReceiveService.checkOneSimState(smR, s);
|
|
|
|
- {
|
|
|
|
- if (important) {
|
|
|
|
- AjaxResult ar1 = simReceiveService.checkOneSimSn(smR, s);
|
|
|
|
- if (ar1.isError()) {
|
|
|
|
- return ar1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return AjaxResult.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查找所有没有被手动禁用,并order by sim_num的模拟器列表。检查所有模拟器状态。
|
|
|
|
- */
|
|
|
|
- public void checkAllSimState() {
|
|
|
|
- // RealExamCollection ecF = realExamCollectionService.selectRealExamCollectionOpened();
|
|
|
|
- // l.info("ecF.getSimType() = {}", ecF.getSimType());
|
|
|
|
- // if (ecF != null) {
|
|
|
|
-
|
|
|
|
- // }
|
|
|
|
- List<Sim> list = simService.listAllEnable(); // ecF.getSimType()
|
|
|
|
- l.info("checkAllSimState list.size() = {}", list.size());
|
|
|
|
- list.forEach(s -> {
|
|
|
|
- checkOneSimState(s, false);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Async("tp-comm")
|
|
@Async("tp-comm")
|
|
public void checkAllSimStateAsync() {
|
|
public void checkAllSimStateAsync() {
|
|
- checkAllSimState();
|
|
|
|
|
|
+ commCheckService.checkAllSeatAndSimState();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -359,27 +312,26 @@ public class CommSendService {
|
|
l.info("清除exam list = {}", list.size());
|
|
l.info("清除exam list = {}", list.size());
|
|
}
|
|
}
|
|
assert list != null;
|
|
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
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
|
+ list.forEach(ref -> {
|
|
|
|
+ Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
|
|
+ if (faultService.isDisable(f.getFaultId())) {
|
|
|
|
+ l.warn("故障 {} -被禁用", f.getName());
|
|
|
|
+ throw new IllegalArgumentException("故障被禁用");
|
|
|
|
+ }
|
|
|
|
+ Sim sim = simService.selectSimBySimId(re.getSimId());
|
|
|
|
+ // check
|
|
|
|
|
|
- //
|
|
|
|
- clearOneSimOneFault(s, ref, f);
|
|
|
|
- });
|
|
|
|
|
|
+ //
|
|
|
|
+ clearOneSimOneFault(seat, sim, ref, f);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
- public void clearOneSimAllFaultBySim(Sim s) {
|
|
|
|
- l.info("clearOneSimAllFaultBySim = {}", s);
|
|
|
|
- faultService.listType3EnableBySimType(s.getSimType())
|
|
|
|
- .forEach(f -> {
|
|
|
|
- clearOneSimOneFault(s, null, f);
|
|
|
|
- });
|
|
|
|
|
|
+ public void clearOneSimAllFaultBySim(Seat seat, Sim sim) {
|
|
|
|
+ l.info("clearOneSimAllFaultBySim = {}", sim);
|
|
|
|
+ faultService.listType3EnableBySimType(sim.getSimType()).forEach(f -> {
|
|
|
|
+ clearOneSimOneFault(seat, sim, null, f);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -394,11 +346,13 @@ public class CommSendService {
|
|
|
|
|
|
public void clearAll() {
|
|
public void clearAll() {
|
|
// todo:
|
|
// todo:
|
|
- simService.listAllEnable().forEach(s -> {
|
|
|
|
- String simType = s.getSimType();
|
|
|
|
|
|
+ // 根据Seat数据遍历
|
|
|
|
+ seatService.listAllEnable().forEach(seat -> {
|
|
|
|
+ Sim sim = gggSimBySeatId(seat.getSeatId());
|
|
|
|
+ String simType = sim.getSimType();
|
|
List<Fault> listF = faultService.listType3EnableBySimType(simType);
|
|
List<Fault> listF = faultService.listType3EnableBySimType(simType);
|
|
listF.forEach(f -> {
|
|
listF.forEach(f -> {
|
|
- clearOneSimOneFault(s, null, f);
|
|
|
|
|
|
+ clearOneSimOneFault(seat, sim, null, f);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -406,82 +360,89 @@ public class CommSendService {
|
|
/**
|
|
/**
|
|
* debug读取模拟器类型序列号
|
|
* debug读取模拟器类型序列号
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public SimMsg debugReadSimType(final String simNum) {
|
|
|
|
- SimMsg sm = commBuildService.buildSendMsgReadSimType(simNum);
|
|
|
|
- return send(sm, null, RETRY_COUNT_0, SLEEP_SHORT);
|
|
|
|
|
|
+ public SimMsg debugReadSimType(final Long seatId) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ SimMsg sm = commBuildService.buildSendMsgReadSimType(sim.getSimNum());
|
|
|
|
+ return send(sm, seat, sim, CommConst.RETRY_COUNT_0, CommConst.SLEEP_SHORT);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* debug清除一个故障
|
|
* debug清除一个故障
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @param bindHardwareMsg
|
|
* @param bindHardwareMsg
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public SimMsg debugClearOneFault(final String simNum, final String bindHardwareMsg) {
|
|
|
|
- SimMsg sm = commBuildService.buildSendMsgClearFault(simNum, bindHardwareMsg);
|
|
|
|
- Sim s = simService.uniqueBySimNum(simNum);
|
|
|
|
- return send(sm, s, RETRY_COUNT_CLEAR_ONE_FAULT, SLEEP_LONG);
|
|
|
|
|
|
+ public SimMsg debugClearOneFault(final Long seatId, final String bindHardwareMsg) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ SimMsg sm = commBuildService.buildSendMsgClearFault(sim.getSimNum(), bindHardwareMsg);
|
|
|
|
+ return send(sm, seat, sim, RETRY_COUNT_CLEAR_ONE_FAULT, SLEEP_LONG);
|
|
}
|
|
}
|
|
|
|
|
|
public AjaxResult debugClearAllOnlineSimAllFault() {
|
|
public AjaxResult debugClearAllOnlineSimAllFault() {
|
|
l.info("debugClearAllOnlineSimAllFault");
|
|
l.info("debugClearAllOnlineSimAllFault");
|
|
simService.listAllOnline().forEach(s -> {
|
|
simService.listAllOnline().forEach(s -> {
|
|
- AjaxResult ar = debugClearAllFaultBySimNum(s.getSimNum());
|
|
|
|
|
|
+ // AjaxResult ar = debugClearAllFaultBySeatId(0);// todo:尚未实现
|
|
});
|
|
});
|
|
|
|
+ debugFaultService.deleteAll();
|
|
return AjaxResult.success("清除成功,清除所有在线模拟器所有故障!");
|
|
return AjaxResult.success("清除成功,清除所有在线模拟器所有故障!");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* debug清除所有故障
|
|
* debug清除所有故障
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult debugClearAllFaultBySimNum(final String simNum) {
|
|
|
|
- Sim s1 = simService.uniqueBySimNum(simNum);
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ public AjaxResult debugClearAllFaultBySeatId(final Long seatId) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ // todo:
|
|
{
|
|
{
|
|
- AjaxResult arE3 = checkOneSimStateActive(s1);
|
|
|
|
|
|
+ AjaxResult arE3 = checkOneSimStateActive(seat);
|
|
if (arE3.isError()) {
|
|
if (arE3.isError()) {
|
|
return arE3;
|
|
return arE3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- s1 = simService.uniqueBySimNum(simNum);
|
|
|
|
- if (s1 == null) {
|
|
|
|
|
|
+ sim = simService.uniqueBySimNum(sim.getSimNum());
|
|
|
|
+ if (sim == null) {
|
|
return AjaxResult.error("清除失败,对应simNum模拟器不存在!");
|
|
return AjaxResult.error("清除失败,对应simNum模拟器不存在!");
|
|
}
|
|
}
|
|
- if (!Sim.State.ONLINE.equals(s1.getSimState())) {
|
|
|
|
|
|
+ if (!Sim.State.ONLINE.equals(sim.getSimState())) {
|
|
return AjaxResult.error("清除失败,模拟器尚未在线!");
|
|
return AjaxResult.error("清除失败,模拟器尚未在线!");
|
|
}
|
|
}
|
|
List<SimMsg> list = new ArrayList<>();
|
|
List<SimMsg> list = new ArrayList<>();
|
|
- for (String b : getGZBWBySimType(s1.getSimType())) {
|
|
|
|
- SimMsg sm = debugClearOneFault(simNum, b);
|
|
|
|
|
|
+ for (String b : getGZBWBySimType(sim.getSimType())) {
|
|
|
|
+ SimMsg sm = debugClearOneFault(seatId, b);
|
|
list.add(sm);
|
|
list.add(sm);
|
|
- if (sm != null && !sm.getOk()) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+// if (sm != null && !sm.isOk()) {
|
|
|
|
+//
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
+ debugFaultService.deleteAll();
|
|
return AjaxResult.success("清除成功,清除当前模拟器所有故障!");
|
|
return AjaxResult.success("清除成功,清除当前模拟器所有故障!");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @param reF 可以为空,表示不关联考试的,单独执行的。调试模式下为空。
|
|
* @param reF 可以为空,表示不关联考试的,单独执行的。调试模式下为空。
|
|
* @param f
|
|
* @param f
|
|
*/
|
|
*/
|
|
- public void clearOneSimOneFault(Sim s, RealExamFault reF, Fault f) {
|
|
|
|
- l.info("clearOneSimOneFault 清除One故障:getSimNum = {},getBindHardwareMsg = {},fault.getName = {}",
|
|
|
|
- s.getSimNum(), f.getBindHardwareMsg(), f.getName());
|
|
|
|
|
|
+ public void clearOneSimOneFault(Seat seat, Sim sim, RealExamFault reF, Fault f) {
|
|
|
|
+ l.info("clearOneSimOneFault 清除One故障:getSimNum = {},getBindHardwareMsg = {},fault.getName = {}", sim.getSimNum(), f.getBindHardwareMsg(), f.getName());
|
|
// check todo:
|
|
// check todo:
|
|
|
|
|
|
// step1
|
|
// step1
|
|
- SimMsg smS = commBuildService.buildSendMsgClearFault(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
- SimMsg smR = send(smS, s, RETRY_COUNT_CLEAR_ONE_FAULT, SLEEP_LONG);
|
|
|
|
|
|
+ SimMsg smS = commBuildService.buildSendMsgClearFault(sim.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
+ SimMsg smR = send(smS, seat, sim, RETRY_COUNT_CLEAR_ONE_FAULT, SLEEP_LONG);
|
|
if (reF != null) {
|
|
if (reF != null) {
|
|
- simReceiveService.clearOneFault(smR, s, reF, f);
|
|
|
|
|
|
+ simReceiveService.clearOneFault(smR, sim, reF, f);
|
|
} else {
|
|
} else {
|
|
l.info("reF == null");
|
|
l.info("reF == null");
|
|
}
|
|
}
|
|
@@ -504,29 +465,31 @@ public class CommSendService {
|
|
/**
|
|
/**
|
|
* debug下发一个故障
|
|
* debug下发一个故障
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @param bindHardwareMsg
|
|
* @param bindHardwareMsg
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public SimMsg debugWriteOneFault(final String simNum, final String bindHardwareMsg) {
|
|
|
|
- SimMsg sm = commBuildService.buildSendMsgWriteFault(simNum, bindHardwareMsg);
|
|
|
|
- return send(sm, null, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
|
|
|
+ public SimMsg debugWriteOneFault(final Long seatId, final String bindHardwareMsg) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ SimMsg sm = commBuildService.buildSendMsgWriteFault(sim.getSimNum(), bindHardwareMsg);
|
|
|
|
+ return send(sm, seat, sim, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* debug下发所有故障
|
|
* debug下发所有故障
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public List<SimMsg> debugWriteAllFault(final String simNum) {
|
|
|
|
|
|
+ public List<SimMsg> debugWriteAllFault(final Long seatId) {
|
|
List<SimMsg> list = new ArrayList<>();
|
|
List<SimMsg> list = new ArrayList<>();
|
|
- Sim s = simService.uniqueBySimNum(simNum);
|
|
|
|
- String simType = s.getSimType();
|
|
|
|
- for (String b : getGZBWBySimType(simType)) {
|
|
|
|
- list.add(debugWriteOneFault(simNum, b));
|
|
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ String simType = sim.getSimType();
|
|
|
|
+ for (String bind : getGZBWBySimType(simType)) {
|
|
|
|
+ list.add(debugWriteOneFault(seatId, bind));
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
@@ -535,14 +498,13 @@ public class CommSendService {
|
|
* todo:尚未实现
|
|
* todo:尚未实现
|
|
* 实现方式类似 studentStartRealExam方法。
|
|
* 实现方式类似 studentStartRealExam方法。
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @param faultIds
|
|
* @param faultIds
|
|
* @param checkReplace 是否进行可换件检查
|
|
* @param checkReplace 是否进行可换件检查
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult debugWriteSelectedFaultBySimNum(final String simNum,
|
|
|
|
- final String[] faultIds,
|
|
|
|
- final Boolean checkReplace) {
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ public AjaxResult debugWriteSelectedFaultBySimNum(final Long seatId, final String[] faultIds, final Boolean checkReplace) {
|
|
//
|
|
//
|
|
l.info("faultIds.length = {}", faultIds.length);
|
|
l.info("faultIds.length = {}", faultIds.length);
|
|
{
|
|
{
|
|
@@ -552,29 +514,26 @@ public class CommSendService {
|
|
// check faultIds 有效性
|
|
// check faultIds 有效性
|
|
|
|
|
|
//
|
|
//
|
|
- Sim s = simService.uniqueBySimNum(simNum);
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
// check sim
|
|
// check sim
|
|
// 打开socket
|
|
// 打开socket
|
|
{
|
|
{
|
|
- AjaxResult ar1 = socketOldService.openSocket();
|
|
|
|
- l.info("ar1 = {}", ar1);
|
|
|
|
- if (ar1.isError()) {
|
|
|
|
- return ar1;
|
|
|
|
- }
|
|
|
|
|
|
+ socketService.tryOpenAll();
|
|
}
|
|
}
|
|
// Step 1 主动查询一次模拟器状态。
|
|
// Step 1 主动查询一次模拟器状态。
|
|
{
|
|
{
|
|
- AjaxResult arE3 = checkOneSimStateActive(s);
|
|
|
|
|
|
+ AjaxResult arE3 = checkOneSimStateActive(seat);
|
|
if (arE3.isError()) {
|
|
if (arE3.isError()) {
|
|
return arE3;
|
|
return arE3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- s = simService.uniqueBySimNum(simNum);
|
|
|
|
|
|
+ sim = simService.uniqueBySimNum(sim.getSimNum());
|
|
// Step 2
|
|
// Step 2
|
|
// msg判断,是否含有"故障部位"字符串
|
|
// msg判断,是否含有"故障部位"字符串
|
|
{
|
|
{
|
|
if (checkReplace) {
|
|
if (checkReplace) {
|
|
- AjaxResult arE2 = readOneSimAllFaultCheck(s);
|
|
|
|
|
|
+ AjaxResult arE2 = readOneSimAllFaultCheck(seat, sim);
|
|
if (arE2.isError()) {
|
|
if (arE2.isError()) {
|
|
return arE2;
|
|
return arE2;
|
|
}
|
|
}
|
|
@@ -582,7 +541,7 @@ public class CommSendService {
|
|
}
|
|
}
|
|
// Step 3 清除对应一台模拟器 所有故障部位故障。
|
|
// Step 3 清除对应一台模拟器 所有故障部位故障。
|
|
{
|
|
{
|
|
- clearOneSimAllFaultBySim(s);
|
|
|
|
|
|
+ clearOneSimAllFaultBySim(seat, sim);
|
|
}
|
|
}
|
|
// Step 4 下发对应一台模拟器 出题选中的 故障位置故障。
|
|
// Step 4 下发对应一台模拟器 出题选中的 故障位置故障。
|
|
{
|
|
{
|
|
@@ -590,11 +549,11 @@ public class CommSendService {
|
|
for (int i = 0; i < faultIds.length; i++) {
|
|
for (int i = 0; i < faultIds.length; i++) {
|
|
faults[i] = faultService.selectFaultByFaultId(faultIds[i]);
|
|
faults[i] = faultService.selectFaultByFaultId(faultIds[i]);
|
|
}
|
|
}
|
|
- writeOneSimAllSelectFaultByDebug(s, faults);
|
|
|
|
|
|
+ writeOneSimAllSelectFaultByDebug(seat, sim, faults);
|
|
}
|
|
}
|
|
// Step 5 读取
|
|
// Step 5 读取
|
|
{
|
|
{
|
|
- readOneSimAllFaultFirstTimeBySim(s, faultIds);
|
|
|
|
|
|
+ readOneSimAllFaultFirstTimeBySim(seat, sim, faultIds);
|
|
}
|
|
}
|
|
return AjaxResult.success("下发故障流程执行成功!");
|
|
return AjaxResult.success("下发故障流程执行成功!");
|
|
}
|
|
}
|
|
@@ -629,41 +588,42 @@ public class CommSendService {
|
|
realExamService.updateOneState(re.getExamId(), RealExam.State.SIM_WRITING);
|
|
realExamService.updateOneState(re.getExamId(), RealExam.State.SIM_WRITING);
|
|
List<RealExamFault> list = realExamFaultService.listAllType2FlagYesClearedStateByExamId(re.getExamId());
|
|
List<RealExamFault> list = realExamFaultService.listAllType2FlagYesClearedStateByExamId(re.getExamId());
|
|
for (RealExamFault ref : list) {
|
|
for (RealExamFault ref : list) {
|
|
- Sim s = simService.selectSimBySimId(re.getSimId());
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
|
+ Sim sim = simService.selectSimBySimId(re.getSimId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
// 选中的才下发。
|
|
// 选中的才下发。
|
|
- writeOneSimOneFault(s, ref, f);
|
|
|
|
|
|
+ writeOneSimOneFault(seat, sim, ref, f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeOneSimAllSelectFaultByDebug(Sim s, Fault[] faults) {
|
|
|
|
|
|
+ public void writeOneSimAllSelectFaultByDebug(Seat seat, Sim sim, Fault[] faults) {
|
|
for (Fault f : faults) {
|
|
for (Fault f : faults) {
|
|
- writeOneSimOneFault(s, null, f);
|
|
|
|
|
|
+ writeOneSimOneFault(seat, sim, null, f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeOneSimOneFault(Sim s, RealExamFault ref, Fault f) {
|
|
|
|
- l.info("下发故障:getSimId = {},fault.getName = {}", s.getSimId(), f.getName());
|
|
|
|
|
|
+ public void writeOneSimOneFault(Seat seat, Sim sim, RealExamFault ref, Fault f) {
|
|
|
|
+ l.info("下发故障:getSimId = {},fault.getName = {}", sim.getSimId(), f.getName());
|
|
// todo:ref is null.
|
|
// todo:ref is null.
|
|
// 下发故障
|
|
// 下发故障
|
|
- SimMsg smA1 = commBuildService.buildSendMsgWriteFault(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
- SimMsg smA2 = send(smA1, s, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
|
|
|
+ SimMsg smA1 = commBuildService.buildSendMsgWriteFault(sim.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
+ SimMsg smA2 = send(smA1, seat, sim, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 开始考试前检查读取。
|
|
* 开始考试前检查读取。
|
|
*
|
|
*
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult readOneSimAllFaultCheck(Sim s) {
|
|
|
|
|
|
+ public AjaxResult readOneSimAllFaultCheck(Seat seat, Sim sim) {
|
|
Fault q = new Fault();
|
|
Fault q = new Fault();
|
|
q.setFaultType(Fault.Type.REAL_GZBW);
|
|
q.setFaultType(Fault.Type.REAL_GZBW);
|
|
- q.setSimType(s.getSimType());
|
|
|
|
|
|
+ q.setSimType(sim.getSimType());
|
|
List<Fault> list = faultService.selectFaultList(q);
|
|
List<Fault> list = faultService.selectFaultList(q);
|
|
List<Fault> listNG = new ArrayList<>();
|
|
List<Fault> listNG = new ArrayList<>();
|
|
for (Fault f : list) {
|
|
for (Fault f : list) {
|
|
- AjaxResult ar = readOneSimOneFaultCheck(s, f);
|
|
|
|
|
|
+ AjaxResult ar = readOneSimOneFaultCheck(seat, sim, f);
|
|
if (ar.isError()) {
|
|
if (ar.isError()) {
|
|
listNG.add(f);
|
|
listNG.add(f);
|
|
l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
|
|
l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
|
|
@@ -686,15 +646,15 @@ public class CommSendService {
|
|
/**
|
|
/**
|
|
* 检查读取。
|
|
* 检查读取。
|
|
*
|
|
*
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @param f
|
|
* @param f
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult readOneSimOneFaultCheck(Sim s, Fault f) {
|
|
|
|
- l.info("readOneSimOneFaultCheck s = {},f = {}", s, f);
|
|
|
|
- SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
- SimMsg sm2 = send(sm1, s, RETRY_COUNT_CHECK_ONE_FAULT, SLEEP_LONG);
|
|
|
|
- return simReceiveService.getOneFaultCheck(sm2, s, f);
|
|
|
|
|
|
+ public AjaxResult readOneSimOneFaultCheck(Seat seat, Sim sim, Fault f) {
|
|
|
|
+ l.info("readOneSimOneFaultCheck sim = {},f = {}", sim, f);
|
|
|
|
+ SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(sim.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
+ SimMsg sm2 = send(sm1, seat, sim, RETRY_COUNT_CHECK_ONE_FAULT, SLEEP_LONG);
|
|
|
|
+ return simReceiveService.getOneFaultCheck(sm2, sim, f);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -706,91 +666,93 @@ public class CommSendService {
|
|
l.info("readOneSimAllFaultFirstTimeByExam re = {}", re);
|
|
l.info("readOneSimAllFaultFirstTimeByExam re = {}", re);
|
|
List<RealExamFault> list = realExamFaultService.listAllType2(re.getExamId());
|
|
List<RealExamFault> list = realExamFaultService.listAllType2(re.getExamId());
|
|
for (RealExamFault ref : list) {
|
|
for (RealExamFault ref : list) {
|
|
- Sim s = simService.selectSimBySimId(re.getSimId());
|
|
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
|
+ Sim sim = simService.selectSimBySimId(re.getSimId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
- readOneSimOneFaultFirstTime(s, ref, f, null);
|
|
|
|
|
|
+ readOneSimOneFaultFirstTime(seat, sim, ref, f, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 第一次读取,作为出题值。debug模式。
|
|
* 第一次读取,作为出题值。debug模式。
|
|
*
|
|
*
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @param faultIds
|
|
* @param faultIds
|
|
*/
|
|
*/
|
|
- public void readOneSimAllFaultFirstTimeBySim(Sim s, final String[] faultIds) {
|
|
|
|
- l.info("readOneSimAllFaultFirstTimeBySim s = {}", s);
|
|
|
|
- List<Fault> list = faultService.listType3(s.getSimType());
|
|
|
|
|
|
+ public void readOneSimAllFaultFirstTimeBySim(Seat seat, Sim sim, final String[] faultIds) {
|
|
|
|
+ l.info("readOneSimAllFaultFirstTimeBySim s = {}", sim);
|
|
|
|
+ List<Fault> list = faultService.listType3(sim.getSimType());
|
|
for (Fault f : list) {
|
|
for (Fault f : list) {
|
|
- readOneSimOneFaultFirstTime(s, null, f, faultIds);
|
|
|
|
|
|
+ readOneSimOneFaultFirstTime(seat, sim, null, f, faultIds);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 第一次读取,作为出题值。
|
|
* 第一次读取,作为出题值。
|
|
*
|
|
*
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @param ref debug调试模式为空。可以为空。
|
|
* @param ref debug调试模式为空。可以为空。
|
|
* @param f
|
|
* @param f
|
|
* @param faultIds debug调试模式为空。
|
|
* @param faultIds debug调试模式为空。
|
|
*/
|
|
*/
|
|
- public void readOneSimOneFaultFirstTime(Sim s, RealExamFault ref, Fault f, String[] faultIds) {
|
|
|
|
|
|
+ public void readOneSimOneFaultFirstTime(Seat seat, Sim sim, RealExamFault ref, Fault f, String[] faultIds) {
|
|
l.info("readOneSimOneFaultFirstTime");
|
|
l.info("readOneSimOneFaultFirstTime");
|
|
// 读取一次当前电阻代表值作为出题值。
|
|
// 读取一次当前电阻代表值作为出题值。
|
|
- SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
- SimMsg sm2 = send(sm1, s, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
|
- simReceiveService.setFaultQuestionValue(sm2, s, ref, f, faultIds);
|
|
|
|
|
|
+ SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(sim.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
+ SimMsg sm2 = send(sm1, seat, sim, RETRY_COUNT_WRITE_ONE_FAULT, SLEEP_LONG);
|
|
|
|
+ simReceiveService.setFaultQuestionValue(sm2, sim, ref, f, faultIds);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* debug读取一个故障位置数据
|
|
* debug读取一个故障位置数据
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @param bindHardwareMsg
|
|
* @param bindHardwareMsg
|
|
* @return
|
|
* @return
|
|
- * @throws IOException
|
|
|
|
*/
|
|
*/
|
|
- public SimMsg debugReadOneFaultResistance(final String simNum, final String bindHardwareMsg) {
|
|
|
|
- SimMsg sm = commBuildService.buildSendMsgReadFaultResistance(simNum, bindHardwareMsg);
|
|
|
|
- return send(sm, null, RETRY_COUNT_0, SLEEP_SHORT);
|
|
|
|
|
|
+ public SimMsg debugReadOneFaultResistance(final Long seatId, final String bindHardwareMsg) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
|
|
+ SimMsg sm = commBuildService.buildSendMsgReadFaultResistance(sim.getSimNum(), bindHardwareMsg);
|
|
|
|
+ return send(sm, seat, null, RETRY_COUNT_0, SLEEP_SHORT);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* debug读取全部故障位置数据
|
|
* debug读取全部故障位置数据
|
|
*
|
|
*
|
|
- * @param simNum
|
|
|
|
|
|
+ * @param seatId
|
|
* @return
|
|
* @return
|
|
- * @throws IOException
|
|
|
|
*/
|
|
*/
|
|
- public List<SimMsg> debugReadAllFaultResistance(final String simNum) {
|
|
|
|
|
|
+ public List<SimMsg> debugReadAllFaultResistance(final Long seatId) {
|
|
|
|
+ Sim sim = gggSimBySeatId(seatId);
|
|
List<SimMsg> list = new ArrayList<>();
|
|
List<SimMsg> list = new ArrayList<>();
|
|
- String simType = simService.uniqueBySimNum(simNum).getSimType();
|
|
|
|
|
|
+ String simType = simService.uniqueBySimNum(sim.getSimNum()).getSimType();
|
|
for (String b : getGZBWBySimType(simType)) {
|
|
for (String b : getGZBWBySimType(simType)) {
|
|
- list.add(debugReadOneFaultResistance(simNum, b));
|
|
|
|
|
|
+ list.add(debugReadOneFaultResistance(seatId, b));
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param s
|
|
|
|
|
|
+ * @param sim
|
|
* @param reF
|
|
* @param reF
|
|
* @param f
|
|
* @param f
|
|
* @param refState 中间轮询是null,交卷最后一次读取为finish状态。用来修改状态的。debug模式下执行为null。
|
|
* @param refState 中间轮询是null,交卷最后一次读取为finish状态。用来修改状态的。debug模式下执行为null。
|
|
*/
|
|
*/
|
|
- public void readOneSimOneFaultResistance(Sim s, RealExamFault reF, Fault f, String refState) {
|
|
|
|
|
|
+ public void readOneSimOneFaultResistance(Seat seat, Sim sim, RealExamFault reF, Fault f, String refState) {
|
|
l.info("readOneSimOneFaultResistance");
|
|
l.info("readOneSimOneFaultResistance");
|
|
- SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(s.getSimNum(), f.getBindHardwareMsg());
|
|
|
|
|
|
+ SimMsg sm1 = commBuildService.buildSendMsgReadFaultResistance(sim.getSimNum(), f.getBindHardwareMsg());
|
|
SimMsg sm2 = null;
|
|
SimMsg sm2 = null;
|
|
if (reF != null && refState != null) {
|
|
if (reF != null && refState != null) {
|
|
if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
|
|
if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
|
|
- sm2 = send(sm1, s, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
|
|
|
|
|
|
+ sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
|
|
} else {
|
|
} else {
|
|
- sm2 = send(sm1, s, RETRY_COUNT_0, SLEEP_SHORT);
|
|
|
|
|
|
+ sm2 = send(sm1, seat, sim, RETRY_COUNT_0, SLEEP_SHORT);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- sm2 = send(sm1, s, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
|
|
|
|
|
|
+ sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE, SLEEP_SHORT);
|
|
}
|
|
}
|
|
- simReceiveService.setFaultAnswerValue(sm2, s, reF, f, refState);
|
|
|
|
|
|
+ simReceiveService.setFaultAnswerValue(sm2, sim, reF, f, refState);
|
|
}
|
|
}
|
|
|
|
|
|
private long previousSendSleep = 0;
|
|
private long previousSendSleep = 0;
|
|
@@ -799,12 +761,13 @@ public class CommSendService {
|
|
* send hex message
|
|
* send hex message
|
|
*
|
|
*
|
|
* @param sm 发送
|
|
* @param sm 发送
|
|
- * @param s 可以为空,更新最后发送/接收时间 用。
|
|
|
|
|
|
+ * @param seat 不能为空
|
|
|
|
+ * @param sim 可以为空!更新最后发送/接收时间 用。
|
|
* @param retryTotalCount 重试次数
|
|
* @param retryTotalCount 重试次数
|
|
* @param sleep 不使用传入0,不进行挂起。
|
|
* @param sleep 不使用传入0,不进行挂起。
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public synchronized SimMsg send(final SimMsg sm, final Sim s, final int retryTotalCount, final long sleep) {
|
|
|
|
|
|
+ public synchronized SimMsg send(final SimMsg sm, final Seat seat, final Sim sim, final int retryTotalCount, final long sleep) {
|
|
try {
|
|
try {
|
|
if (!config.isCommGlobal()) {
|
|
if (!config.isCommGlobal()) {
|
|
l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
@@ -813,28 +776,37 @@ public class CommSendService {
|
|
if (sm == null || sm.getSendMsg() == null || StringUtils.isBlank(sm.getSendMsg())) {
|
|
if (sm == null || sm.getSendMsg() == null || StringUtils.isBlank(sm.getSendMsg())) {
|
|
throw new IllegalArgumentException("SimMsg IllegalArgument");
|
|
throw new IllegalArgumentException("SimMsg IllegalArgument");
|
|
}
|
|
}
|
|
|
|
+ // sim
|
|
|
|
+ if (seat == null) {
|
|
|
|
+ throw new IllegalArgumentException("seat is null");
|
|
|
|
+ }
|
|
if (sleep < 0) {
|
|
if (sleep < 0) {
|
|
throw new IllegalArgumentException("SimMsg sleep");
|
|
throw new IllegalArgumentException("SimMsg sleep");
|
|
}
|
|
}
|
|
// log.
|
|
// log.
|
|
{
|
|
{
|
|
- l.info("####SendMsg#### == [{}]", sm);
|
|
|
|
|
|
+ l.info("####发送#### == Seat[{}],SimMsg[{}]", seat, sm);
|
|
}
|
|
}
|
|
// 如果没有打开socket,顺道打开。正好后面要sleep
|
|
// 如果没有打开socket,顺道打开。正好后面要sleep
|
|
- socketOldService.openSocket();
|
|
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+ // socketOldService.openSocket();
|
|
|
|
+ socketService.openOne(seat.toSimSocketVo());
|
|
{
|
|
{
|
|
- // sleep ,追求顺序请求。
|
|
|
|
|
|
+ // sleep挂起线程,追求顺序请求。
|
|
if (sleep > 0 && previousSendSleep != 0L) {
|
|
if (sleep > 0 && previousSendSleep != 0L) {
|
|
Thread.sleep(previousSendSleep);
|
|
Thread.sleep(previousSendSleep);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
previousSendSleep = sleep;
|
|
previousSendSleep = sleep;
|
|
- InputStream is = socketOldService.getCachedSocket().getInputStream();
|
|
|
|
- OutputStream os = socketOldService.getCachedSocket().getOutputStream();
|
|
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+ // Socket socket = socketOldService.getCachedSocket();
|
|
|
|
+ Socket socket = socketService.get(seat);
|
|
|
|
+ InputStream is = socket.getInputStream();
|
|
|
|
+ OutputStream os = socket.getOutputStream();
|
|
os.write(hexStrToByteArrs(sm.getSendMsg()));
|
|
os.write(hexStrToByteArrs(sm.getSendMsg()));
|
|
sm.setSendTime(DateUtils.getNowDate());
|
|
sm.setSendTime(DateUtils.getNowDate());
|
|
- if (s != null) {
|
|
|
|
- simService.updateLastSentTime(s);
|
|
|
|
|
|
+ if (sim != null) {
|
|
|
|
+ simService.updateLastSentTime(sim);
|
|
}
|
|
}
|
|
byte[] buffer = new byte[LENGTH_24];
|
|
byte[] buffer = new byte[LENGTH_24];
|
|
int length = is.read(buffer);
|
|
int length = is.read(buffer);
|
|
@@ -842,31 +814,49 @@ public class CommSendService {
|
|
for (int i = 0; i < length; i++) {
|
|
for (int i = 0; i < length; i++) {
|
|
sbHex.append(String.format("%02X", buffer[i]));
|
|
sbHex.append(String.format("%02X", buffer[i]));
|
|
}
|
|
}
|
|
- sm.setReceiveMsg(sbHex.toString());
|
|
|
|
|
|
+ String receiveWith0 = sbHex.toString();
|
|
|
|
+ // 原始带0的收到报文。
|
|
|
|
+ sm.setReceiveOriginalMsg(receiveWith0);
|
|
|
|
+ sm.setReceiveMsg(commReceiveService.removeRrefix0(receiveWith0));
|
|
sm.setReceiveTime(DateUtils.getNowDate());
|
|
sm.setReceiveTime(DateUtils.getNowDate());
|
|
// log.
|
|
// log.
|
|
{
|
|
{
|
|
- l.info("####ReceiveMsg#### = [{}]", sm);
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
- AjaxResult ar = commReceiveService.checkReceiveMsg(sm.getReceiveMsg());
|
|
|
|
|
|
+ AjaxResult ar = commReceiveService.checkReceiveMsg(sm.getReceiveMsg());
|
|
if (ar.isError()) {
|
|
if (ar.isError()) {
|
|
// todo:
|
|
// todo:
|
|
- l.warn("####Fail#### = {}", sm);
|
|
|
|
|
|
+ l.warn("####接收错误#### = {}", sm);
|
|
|
|
+ sm.setResult(SimMsg.Result.RECEIVE_CHECK_FAIL);
|
|
return sm;
|
|
return sm;
|
|
|
|
+ } else {
|
|
|
|
+ l.info("####接收成功#### = {}", sm);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (s != null) {
|
|
|
|
- simService.updateLastReceivedTime(s);
|
|
|
|
|
|
+ if (sim != null) {
|
|
|
|
+ simService.updateLastReceivedTime(sim);
|
|
}
|
|
}
|
|
- } catch (InterruptedException | IOException e) { // SocketTimeoutException
|
|
|
|
|
|
+ sm.setResult(SimMsg.Result.SUCCESS);
|
|
|
|
+ // 最后返回报文实体。
|
|
|
|
+ return sm;
|
|
|
|
+ } catch (InterruptedException | IOException e) {
|
|
|
|
+ l.error("SocketTimeoutException");// SocketTimeoutException
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ sm.setResult(SimMsg.Result.SOCKET_EXCEPTION);
|
|
|
|
+ if (sim != null) {
|
|
|
|
+ l.info("fail sim.getSimId() = {}", sim.getSimId());
|
|
|
|
+ }
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+ // boolean limit = socketOldService.commFailCountAdd1(Objects.requireNonNull(sim).getSimId());
|
|
|
|
+ SimSocketVo ssv = seat.toSimSocketVo();
|
|
// 失败计数
|
|
// 失败计数
|
|
- l.info("fail sim data = {}", s);
|
|
|
|
- boolean limit = socketOldService.commFailCountAdd1(Objects.requireNonNull(s).getSimId());
|
|
|
|
- if (limit) {
|
|
|
|
- simService.updateSimStateBySimId(s.getSimId(), Sim.State.OFFLINE);
|
|
|
|
- socketOldService.commFailCountClearOne(s.getSimId());
|
|
|
|
|
|
+ failedCountService.plus1(ssv);
|
|
|
|
+ if (failedCountService.isReachedMax(ssv, retryTotalCount)) {
|
|
|
|
+ // 达到重试次数上限,认为模拟器离线
|
|
|
|
+ if (sim != null) {
|
|
|
|
+ simService.updateSimStateBySimId(sim.getSimId(), Sim.State.OFFLINE);
|
|
|
|
+ }
|
|
|
|
+ // SocketOldService实现
|
|
|
|
+ // socketOldService.commFailCountClearOne(sim.getSimId());
|
|
|
|
+ failedCountService.reset0(ssv);
|
|
}
|
|
}
|
|
// 先考虑一台模拟器演示。
|
|
// 先考虑一台模拟器演示。
|
|
// 进行重试 start
|
|
// 进行重试 start
|
|
@@ -876,14 +866,15 @@ public class CommSendService {
|
|
}
|
|
}
|
|
if (sm.getRetryCount() < retryTotalCount) {
|
|
if (sm.getRetryCount() < retryTotalCount) {
|
|
sm.retryCountPlus1();
|
|
sm.retryCountPlus1();
|
|
- send(sm, s, retryTotalCount, sleep);
|
|
|
|
|
|
+ send(sm, seat, sim, retryTotalCount, sleep);
|
|
l.warn("####RetryTotalCount重试#### = {}", sm);
|
|
l.warn("####RetryTotalCount重试#### = {}", sm);
|
|
} else {
|
|
} else {
|
|
l.warn("####RetryTotalCount达到重试上限#### = {}", sm);
|
|
l.warn("####RetryTotalCount达到重试上限#### = {}", sm);
|
|
}
|
|
}
|
|
// 进行重试 end
|
|
// 进行重试 end
|
|
|
|
+ // 最后返回报文实体。
|
|
|
|
+ return sm;
|
|
}
|
|
}
|
|
- return sm;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -899,28 +890,6 @@ public class CommSendService {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 等同于ping命令。
|
|
|
|
- *
|
|
|
|
- * @param ipV4
|
|
|
|
- * @return
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- public boolean isReachable(String ipV4) {
|
|
|
|
- InetAddress ia = null;
|
|
|
|
- try {
|
|
|
|
- ia = InetAddress.getByName(ipV4);
|
|
|
|
- return ia.isReachable(2048);
|
|
|
|
- } catch (UnknownHostException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return false;
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* https://mvnrepository.com/artifact/com.infiniteautomation/modbus4j/3.0.3
|
|
* https://mvnrepository.com/artifact/com.infiniteautomation/modbus4j/3.0.3
|
|
*/
|
|
*/
|
|
@@ -972,4 +941,21 @@ public class CommSendService {
|
|
}
|
|
}
|
|
return hexString.toString();
|
|
return hexString.toString();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * todo:不存在部分数据
|
|
|
|
+ *
|
|
|
|
+ * @param seatId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Sim gggSimBySeatId(Long seatId) {
|
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(seatId);
|
|
|
|
+ AjaxResult ar01 = commCheckService.checkOneSeatState(seat, true);
|
|
|
|
+ if (ar01.isSuccess()) {
|
|
|
|
+ Long simId = seatService.selectSeatBySeatId(seatId).getCurrentSimId();
|
|
|
|
+ return simService.selectSimBySimId(simId);
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalArgumentException("error gggSimBySeatId");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|