|
@@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -31,18 +32,6 @@ public class CommSendService {
|
|
|
interface Const {
|
|
|
|
|
|
/**
|
|
|
- * 123.112.16.165
|
|
|
- */
|
|
|
- String ROUTER_IP = "123.112.16.165";
|
|
|
- /**
|
|
|
- * 123.112.16.165
|
|
|
- */
|
|
|
- String IP = "123.112.16.165";
|
|
|
- /**
|
|
|
- * 8899
|
|
|
- */
|
|
|
- int PORT = 8899;
|
|
|
- /**
|
|
|
* 报文长度
|
|
|
*/
|
|
|
int MSG_LENGTH = 20;
|
|
@@ -102,7 +91,7 @@ public class CommSendService {
|
|
|
@Autowired
|
|
|
private RealExamFaultService realExamFaultService;
|
|
|
@Autowired
|
|
|
- private SimConfig sConfig;
|
|
|
+ private SimConfig config;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -133,7 +122,7 @@ public class CommSendService {
|
|
|
Fault.TYPE_3.equals(f.getFaultType()) &&
|
|
|
Fault.State.ENABLE.equals(f.getFaultState())
|
|
|
) {
|
|
|
- readOneFaultResistance(s, ref, f);
|
|
|
+ readOneFaultResistance(s, ref, f, RealExamFault.State.LOOP_READ);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
@@ -148,42 +137,26 @@ public class CommSendService {
|
|
|
}
|
|
|
|
|
|
public void readOneExamAtLast(RealExam re) {
|
|
|
+ l.info("readOneExamAtLast");
|
|
|
List<RealExamFault> listREF = realExamFaultService.listAllType2LoopReadStateByExamId(re.getExamId());
|
|
|
listREF.forEach(ref -> {
|
|
|
Sim s = simService.selectSimBySimId(re.getSimId());
|
|
|
Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
|
|
|
- readOneFaultResistance(s, ref, f);
|
|
|
+ readOneFaultResistance(s, ref, f, RealExamFault.State.FINISH);
|
|
|
});
|
|
|
-
|
|
|
- submit(re.getExamId());
|
|
|
+ // 计算扣分。
|
|
|
+ // 最后都读取到,才算扣分。
|
|
|
{
|
|
|
- calculateScoreAsync(re.getExamId());
|
|
|
+ calculateScore(re.getExamId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param examId
|
|
|
- */
|
|
|
- @Transactional
|
|
|
- public void submit(long examId) {
|
|
|
- l.info("submit");
|
|
|
- RealExam re1 = realExamService.selectRealExamByExamId(examId);
|
|
|
- re1.setExamStatus(RealExam.State.SUBMITTED);
|
|
|
- re1.setEndTime(DateUtils.getNowDate());
|
|
|
- realExamService.updateRealExam(re1);
|
|
|
- }
|
|
|
-
|
|
|
@Async("tp-comm")
|
|
|
public void readOneExamAtLastAsync(RealExam re) {
|
|
|
+ l.info("readOneExamAtLastAsync");
|
|
|
readOneExamAtLast(re);
|
|
|
}
|
|
|
|
|
|
- // todo:
|
|
|
- // @Async
|
|
|
- public void calculateScoreAsync(Long realExamId) {
|
|
|
- calculateScore(realExamId);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 计算减分(不包括超时)。汇总到deduction_total_score字段。
|
|
|
*
|
|
@@ -221,12 +194,12 @@ public class CommSendService {
|
|
|
public void scheduledConnect() {
|
|
|
l.info("scheduledConnect");
|
|
|
try {
|
|
|
- if (!isReachable(ROUTER_IP)) {
|
|
|
+ if (!isReachable(config.getRouterIp())) {
|
|
|
// ping 不通。
|
|
|
l.warn("ping not ok");
|
|
|
simService.updateAllEnableState(Sim.State.GATEWAY_OFFLINE);
|
|
|
}
|
|
|
- if (!isReachable(IP)) {
|
|
|
+ if (!isReachable(config.getRs485Ip())) {
|
|
|
// todo:ping 不通。
|
|
|
l.warn("ping not ok");
|
|
|
simService.updateAllEnableState(Sim.State.GATEWAY_OFFLINE);
|
|
@@ -418,7 +391,7 @@ public class CommSendService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void readOneFaultResistance(Sim s, RealExamFault reF, Fault f) {
|
|
|
+ public void readOneFaultResistance(Sim s, RealExamFault reF, Fault f, String refState) {
|
|
|
l.info("readOneFaultResistance");
|
|
|
try {
|
|
|
SimMsg sm = new SimMsg();
|
|
@@ -426,12 +399,18 @@ public class CommSendService {
|
|
|
sm.setSendMsg(sendMsg);
|
|
|
String receiveMsg = send(sendMsg, s);
|
|
|
sm.setReceiveMsg(receiveMsg);
|
|
|
- simReceiveService.setFaultAnswerValue(sm, s, reF, f);
|
|
|
+ simReceiveService.setFaultAnswerValue(sm, s, reF, f, refState);
|
|
|
} catch (IOException e) {
|
|
|
catchException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Async("tp-comm")
|
|
|
+ public void readOneFaultResistanceAsync(Sim s, RealExamFault reF, Fault f, String refState) {
|
|
|
+ l.info("readOneFaultResistanceAsync");
|
|
|
+ readOneFaultResistance(s, reF, f, refState);
|
|
|
+ }
|
|
|
+
|
|
|
public void test() {
|
|
|
try {
|
|
|
{
|
|
@@ -533,6 +512,10 @@ public class CommSendService {
|
|
|
* @return
|
|
|
*/
|
|
|
public synchronized String send(final String sendMsg, final Sim s) throws IOException {
|
|
|
+ if (!config.isCommGlobal()) {
|
|
|
+ l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
l.info("********sendMsg == [{}]", sendMsg);
|
|
|
//
|
|
|
{
|
|
@@ -575,10 +558,15 @@ public class CommSendService {
|
|
|
}
|
|
|
|
|
|
public void openSocket() throws IOException {
|
|
|
+ l.info(config.toString());
|
|
|
+ if (!config.isCommGlobal()) {
|
|
|
+ l.warn("isCommGlobal == false [模拟器通信被禁用!]");
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!isSocketOk()) {
|
|
|
simService.updateAllEnableState(Sim.State.GATEWAY_OFFLINE);
|
|
|
l.info("openSocket cachedSocket is null");
|
|
|
- cachedSocket = new Socket(IP, PORT);
|
|
|
+ cachedSocket = new Socket(config.getRs485Ip(), config.getRs485Port());
|
|
|
// setSoTimeout todo:????
|
|
|
// cachedSocket.setSoTimeout(2000);
|
|
|
} else {
|
|
@@ -632,7 +620,7 @@ public class CommSendService {
|
|
|
*/
|
|
|
public boolean isReachable(String ipV4) throws IOException {
|
|
|
InetAddress ia = InetAddress.getByName(ipV4);
|
|
|
- return ia.isReachable(sConfig.getGatewayReachableTimeout());
|
|
|
+ return ia.isReachable(2000);
|
|
|
}
|
|
|
|
|
|
/**
|