|
@@ -7,6 +7,7 @@ import com.ruoyi.sim.constant.CommConst;
|
|
|
import com.ruoyi.sim.domain.*;
|
|
|
import com.ruoyi.sim.domain.vo.ScanSeatVo;
|
|
|
import com.ruoyi.sim.domain.vo.SimSocketParamVo;
|
|
|
+import com.ruoyi.sim.util.SimDateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.slf4j.Logger;
|
|
@@ -61,6 +62,8 @@ public class CommSendService {
|
|
|
private SimConfig config;
|
|
|
@Autowired
|
|
|
private CommStrategy commStrategy;
|
|
|
+ @Autowired
|
|
|
+ private CmdService cmdService;
|
|
|
|
|
|
/**
|
|
|
* 定时任务。
|
|
@@ -97,8 +100,39 @@ public class CommSendService {
|
|
|
readAll();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 开始考试以后,交卷之前,定时任务中间读取值,作为答题值。有优先级高的任务可能跳过执行。
|
|
|
+ *
|
|
|
+ * @param re
|
|
|
+ */
|
|
|
+ public void readOneExamAtMiddle(RealExam re) {
|
|
|
+ l.info("readOneExamAtMiddle getExamId = {}", re.getExamId());
|
|
|
+ List<RealExamFault> list = realExamFaultService.listAllType2State2and3ByExamId(re.getExamId());
|
|
|
+ for (RealExamFault ref : list) {
|
|
|
+ {
|
|
|
+ RealExamFault refQ = realExamFaultService.selectRealExamFaultByRefId(ref.getRefId());
|
|
|
+ if (refQ == null || refQ.getExamId() == 0L) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!RealExamFault.State.WRITTEN.equals(ref.getRefState()) &&
|
|
|
+ !RealExamFault.State.LOOP_READ.equals(ref.getRefState())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
|
+ Sim sim = simService.selectSimBySimId(re.getSimId());
|
|
|
+ Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
|
+ readOneSimOneFaultResistance(seat, sim, ref, f, RealExamFault.State.LOOP_READ);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 交卷最后读取值,作为答题值。
|
|
|
+ *
|
|
|
+ * @param re
|
|
|
+ */
|
|
|
public void readOneExamAtLast(RealExam re) {
|
|
|
- l.info("readOneExamAtLast");
|
|
|
+ l.info("readOneExamAtLast getExamId = {}", re.getExamId());
|
|
|
List<RealExamFault> list = realExamFaultService.listAllType2State2and3ByExamId(re.getExamId());
|
|
|
for (RealExamFault ref : list) {
|
|
|
Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
|
|
@@ -265,11 +299,36 @@ public class CommSendService {
|
|
|
* 每天06:00/12:00/18:00/00:00执行
|
|
|
*/
|
|
|
public void scheduledCloseAllSocket() {
|
|
|
+ l.info("scheduledCloseAllSocket");
|
|
|
AjaxResult ar = socketService.closeAll();
|
|
|
l.info("AjaxResult = {}", ar);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 每10min运行一次。
|
|
|
+ */
|
|
|
+ public void scheduledExamMiddleRead() {
|
|
|
+ l.info("scheduledExamMiddleRead");
|
|
|
+ realExamService.studentMiddleReadRealExam();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每30min运行一次。
|
|
|
+ */
|
|
|
+ public void scheduledSystemAutoCleanExam() {
|
|
|
+ l.info("scheduledSystemAutoCleanExam");
|
|
|
+ realExamService.systemAutoCleanExam();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每6hour运行一次。
|
|
|
+ */
|
|
|
+ public void scheduledProjectRestart() {
|
|
|
+ l.info("scheduledProjectRestart");
|
|
|
+ cmdService.restart();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 主动更新模拟器状态。
|
|
|
* <p>
|
|
|
* <p>
|
|
@@ -421,7 +480,7 @@ public class CommSendService {
|
|
|
return ar;
|
|
|
}
|
|
|
}
|
|
|
- return AjaxResult.success("清除成功,清除所有座次正确连接的模拟器的,所有的故障!");
|
|
|
+ return AjaxResult.success("清除成功,清除所有座次正确连接的模拟器的,所有的故障!" + SimDateUtil.getNow());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -455,7 +514,7 @@ public class CommSendService {
|
|
|
}
|
|
|
list.add(sm);
|
|
|
}
|
|
|
- return AjaxResult.success("清除成功,清除当前模拟器所有的故障!");
|
|
|
+ return AjaxResult.success("清除成功,清除当前模拟器所有的故障!" + SimDateUtil.getNow());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -592,7 +651,7 @@ public class CommSendService {
|
|
|
{
|
|
|
readOneSimAllFaultFirstTimeBySim(seat, sim, faultIds);
|
|
|
}
|
|
|
- return AjaxResult.success("下发故障流程执行成功!");
|
|
|
+ return AjaxResult.success("下发故障流程执行成功!" + SimDateUtil.getNow());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -703,9 +762,9 @@ public class CommSendService {
|
|
|
AjaxResult ar = readOneSimOneFaultCheck(seat, sim, f);
|
|
|
if (!StringUtils.isBlank((String) ar.get(AjaxResult.MSG_TAG))) {
|
|
|
listNG.add(f);
|
|
|
- l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
|
|
|
+ l.info("log 故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
|
|
|
} else {
|
|
|
- l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]安装ok;");
|
|
|
+ l.info("log 故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]安装ok;");
|
|
|
}
|
|
|
if (ar.isError()) {
|
|
|
return ar;
|
|
@@ -716,7 +775,11 @@ public class CommSendService {
|
|
|
} else {
|
|
|
StringBuilder sbNG = new StringBuilder();
|
|
|
for (Fault f : listNG) {
|
|
|
- sbNG.append("[" + f.getReplaceName() + "]可换件异常;<br>");
|
|
|
+ if (StringUtils.equals(f.getFaultId(), "0001GZBW0009")) {
|
|
|
+ sbNG.append("[" + f.getReplaceName() + "]可换件异常;电池仓门被关闭,请确保电池舱门打开!<br>");
|
|
|
+ } else {
|
|
|
+ sbNG.append("[" + f.getReplaceName() + "]可换件异常;<br>");
|
|
|
+ }
|
|
|
}
|
|
|
sbNG.append("请正确安装可换件,检查后重新开始考试!");
|
|
|
return AjaxResult.error(sbNG.toString());
|
|
@@ -822,7 +885,7 @@ public class CommSendService {
|
|
|
* @param sim
|
|
|
* @param reF
|
|
|
* @param f
|
|
|
- * @param refState 中间轮询是null,交卷最后一次读取为finish状态。用来修改状态的。debug模式下执行为null。
|
|
|
+ * @param refState 修改的目标状态。debug模式下执行为null。
|
|
|
*/
|
|
|
public void readOneSimOneFaultResistance(Seat seat, Sim sim, RealExamFault reF, Fault f, String refState) {
|
|
|
l.info("readOneSimOneFaultResistance");
|
|
@@ -830,16 +893,26 @@ public class CommSendService {
|
|
|
SimMsg sm2 = null;
|
|
|
if (reF != null && refState != null) {
|
|
|
if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
|
|
|
- sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE, commStrategy.getSleepShort());
|
|
|
+ sm2 = send(sm1, seat, sim,
|
|
|
+ RETRY_COUNT_READ_ONE_RESISTANCE_FINAL, commStrategy.getSleepShort());
|
|
|
+ } else if (RealExamFault.State.LOOP_READ.equals(refState)) { // 是否是中间读取
|
|
|
+ sm2 = send(sm1, seat, sim,
|
|
|
+ RETRY_COUNT_READ_ONE_RESISTANCE_MIDDLE, commStrategy.getSleepShort(), false);
|
|
|
} else {
|
|
|
- sm2 = send(sm1, seat, sim, RETRY_COUNT_0, commStrategy.getSleepShort());
|
|
|
+ sm2 = send(sm1, seat, sim,
|
|
|
+ RETRY_COUNT_0, commStrategy.getSleepShort());
|
|
|
}
|
|
|
} else {
|
|
|
- sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE, commStrategy.getSleepShort());
|
|
|
+ sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE_FINAL, commStrategy.getSleepShort());
|
|
|
}
|
|
|
simReceiveService.setFaultAnswerValue(sm2, sim, reF, f, refState);
|
|
|
}
|
|
|
|
|
|
+ public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim,
|
|
|
+ final int retryTotalCount, final long sleep) {
|
|
|
+ return send(sm, seat, sim, retryTotalCount, sleep, true);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 最基本的通信方法。
|
|
|
* send hex message
|
|
@@ -851,51 +924,66 @@ public class CommSendService {
|
|
|
* @param sim 可以为空!更新最后发送/接收时间 用。
|
|
|
* @param retryTotalCount 重试次数
|
|
|
* @param sleep 不使用传入0,不进行挂起。
|
|
|
+ * @param importantTask
|
|
|
* @return
|
|
|
*/
|
|
|
- public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim, final int retryTotalCount, final long sleep) {
|
|
|
+ public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim,
|
|
|
+ final int retryTotalCount, final long sleep, final boolean importantTask) {
|
|
|
+ if (!config.isCommGlobal()) {
|
|
|
+ l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
|
+ return sm;
|
|
|
+ }
|
|
|
+ if (sm == null || sm.getSendMsg() == null || StringUtils.isBlank(sm.getSendMsg())) {
|
|
|
+ throw new IllegalArgumentException("SimMsg IllegalArgument");
|
|
|
+ }
|
|
|
+ // sim
|
|
|
+ if (seat == null) {
|
|
|
+ throw new IllegalArgumentException("seat is null");
|
|
|
+ }
|
|
|
+ if (sleep < 0) {
|
|
|
+ throw new IllegalArgumentException("SimMsg sleep");
|
|
|
+ }
|
|
|
+ // log.
|
|
|
+ {
|
|
|
+ l.info("####发送#### == Seat[{}],SimMsg[{}]", seat, sm);
|
|
|
+ }
|
|
|
+ SimSocketParamVo sspv = seat.toSimSocketParamVo();
|
|
|
try {
|
|
|
- if (!config.isCommGlobal()) {
|
|
|
- l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
|
- return sm;
|
|
|
- }
|
|
|
- if (sm == null || sm.getSendMsg() == null || StringUtils.isBlank(sm.getSendMsg())) {
|
|
|
- throw new IllegalArgumentException("SimMsg IllegalArgument");
|
|
|
- }
|
|
|
- // sim
|
|
|
- if (seat == null) {
|
|
|
- throw new IllegalArgumentException("seat is null");
|
|
|
- }
|
|
|
- if (sleep < 0) {
|
|
|
- throw new IllegalArgumentException("SimMsg sleep");
|
|
|
- }
|
|
|
- // log.
|
|
|
- {
|
|
|
- l.info("####发送#### == Seat[{}],SimMsg[{}]", seat, sm);
|
|
|
- }
|
|
|
// 如果没有打开socket,顺道打开。正好后面要sleep。
|
|
|
// 不强制重开Socket。
|
|
|
// 先进行Socket相关处理。
|
|
|
- SimSocketParamVo sspv = seat.toSimSocketParamVo();
|
|
|
+
|
|
|
+ // 优先级高的在运行,跳过
|
|
|
+ if (importantTask == false && socketService.getImportantTaskRunning(sspv)) {
|
|
|
+ sm.setResult(SimMsg.Result.SKIP);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
+ l.warn("####跳过运行#### sm = {}", sm);
|
|
|
+ return sm;
|
|
|
+ }
|
|
|
+ if (importantTask) {
|
|
|
+ socketService.setImportantTaskRunning(sspv, true);
|
|
|
+ }
|
|
|
socketService.openOne(sspv);
|
|
|
// Socket情况不正确,直接返回。
|
|
|
if (socketService.isNotOk(sspv)) {
|
|
|
sm.setResult(SimMsg.Result.SOCKET_CONNECT_EXCEPTION);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
return sm;
|
|
|
}
|
|
|
{
|
|
|
// sleep挂起线程,追求顺序请求。
|
|
|
// 大于0才挂起。
|
|
|
- if (sleep > 0 && socketService.get(sspv).getPreviousSendSleep() > 0L) {
|
|
|
+ if (sleep > 0 && socketService.getVo(sspv).getPreviousSendSleep() > 0L) {
|
|
|
// 时间间隔挂起。
|
|
|
- Thread.sleep(socketService.get(sspv).getPreviousSendSleep());
|
|
|
+ Thread.sleep(socketService.getVo(sspv).getPreviousSendSleep());
|
|
|
}
|
|
|
}
|
|
|
- socketService.get(sspv).setPreviousSendSleep(sleep);
|
|
|
- Socket socket = socketService.get(sspv).getSocket();
|
|
|
+ socketService.getVo(sspv).setPreviousSendSleep(sleep);
|
|
|
+ Socket socket = socketService.getVo(sspv).getSocket();
|
|
|
InputStream is = socket.getInputStream();
|
|
|
OutputStream os = socket.getOutputStream();
|
|
|
- socket.setSoTimeout(commStrategy.getSoTimeout());
|
|
|
+ Sim simSeat = simService.selectSimBySimId(seat.getCurrentSimId());
|
|
|
+ socket.setSoTimeout(commStrategy.getSoTimeout(simSeat));
|
|
|
os.write(hexStrToByteArrs(sm.getSendMsg()));
|
|
|
sm.setSendTime(DateUtils.getNowDate());
|
|
|
if (sim != null) {
|
|
@@ -919,6 +1007,7 @@ public class CommSendService {
|
|
|
// todo:
|
|
|
l.warn("####接收错误@格式错误#### = sm = {},ar = {}", sm, ar);
|
|
|
sm.setResult(SimMsg.Result.RECEIVE_CHECK_FAIL);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
return sm;
|
|
|
}
|
|
|
}
|
|
@@ -927,6 +1016,7 @@ public class CommSendService {
|
|
|
if (ar.isError()) {
|
|
|
l.warn("####接收错误@匹配错误#### sm = {},ar = {}", sm, ar);
|
|
|
sm.setResult(SimMsg.Result.RECEIVE_NOT_MATCH);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
return sm;
|
|
|
}
|
|
|
}
|
|
@@ -935,6 +1025,7 @@ public class CommSendService {
|
|
|
simService.updateLastReceivedTime(sim);
|
|
|
}
|
|
|
sm.setResult(SimMsg.Result.SUCCESS);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
// 最后返回报文实体。
|
|
|
return sm;
|
|
|
} catch (InterruptedException | IOException e) {
|
|
@@ -942,10 +1033,10 @@ public class CommSendService {
|
|
|
l.error("SocketTimeoutException");
|
|
|
e.printStackTrace();
|
|
|
sm.setResult(SimMsg.Result.READ_TIMEOUT_EXCEPTION);
|
|
|
+ socketService.setImportantTaskRunning(sspv, false);
|
|
|
if (sim != null) {
|
|
|
l.info("fail sim.getSimId() = {}", sim.getSimId());
|
|
|
}
|
|
|
- SimSocketParamVo sspv = seat.toSimSocketParamVo();
|
|
|
// Socket失败计数
|
|
|
socketService.failedPlus1(sspv);
|
|
|
if (socketService.failedIsReachedMax(sspv, SocketService.SOCKET_CONNECT_RETRY_COUNT_LIMIT)) {
|
|
@@ -1083,6 +1174,6 @@ public class CommSendService {
|
|
|
|
|
|
// 删除debug表中所有数据。
|
|
|
debugFaultService.deleteAll();
|
|
|
- return AjaxResult.success("全部重置成功。");
|
|
|
+ return AjaxResult.success("全部重置成功。" + SimDateUtil.getNow());
|
|
|
}
|
|
|
}
|