|
@@ -12,6 +12,9 @@ import java.util.TimerTask;
|
|
|
|
|
|
|
|
public class WorkTimer {
|
|
public class WorkTimer {
|
|
|
private static final Logger log = LoggerFactory.getLogger(WorkTimer.class);
|
|
private static final Logger log = LoggerFactory.getLogger(WorkTimer.class);
|
|
|
|
|
+ private static final int FINAL_RESULT_REFRESH_DELAY_MS = 500;
|
|
|
|
|
+ private static final int FINAL_RESULT_RETRY_COUNT = 5;
|
|
|
|
|
+ private static final int FINAL_RESULT_RETRY_DELAY_MS = 300;
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Timer stopTimer = null;
|
|
private static Timer stopTimer = null;
|
|
@@ -35,6 +38,41 @@ public class WorkTimer {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static ATEQ.LastResult readCurrentCycleLastResult(boolean expectedPass) {
|
|
|
|
|
+ ATEQ.LastResult latestLastResult = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(FINAL_RESULT_REFRESH_DELAY_MS);
|
|
|
|
|
+ for (int attempt = 1; attempt <= FINAL_RESULT_RETRY_COUNT; attempt++) {
|
|
|
|
|
+ ATEQ.LastResult lastResult = ATEQ.readLastResult();
|
|
|
|
|
+ latestLastResult = lastResult;
|
|
|
|
|
+ if (lastResult.isPass == expectedPass) {
|
|
|
|
|
+ return lastResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.warn("最终结果尚未刷新: 第{}次读取为{},当前周期实时判定为{}",
|
|
|
|
|
+ attempt, lastResult.isPass ? "OK" : "NG", expectedPass ? "OK" : "NG");
|
|
|
|
|
+ if (attempt < FINAL_RESULT_RETRY_COUNT) {
|
|
|
|
|
+ Thread.sleep(FINAL_RESULT_RETRY_DELAY_MS);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ log.warn("等待气密仪最终结果时被中断", e);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("读取气密仪最终结果失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 部分设备在测试结束后实时寄存器与最终结果寄存器的判定位不会同步。
|
|
|
|
|
+ // 已取得最终结果时仍继续流程,避免 NG 工件无法选择漏点或提交无漏点 NG。
|
|
|
|
|
+ if (latestLastResult != null) {
|
|
|
|
|
+ log.warn("最终结果判定位与实时结果不一致,已重试{}次,使用最终结果继续处理: final={}, realtime={}",
|
|
|
|
|
+ FINAL_RESULT_RETRY_COUNT,
|
|
|
|
|
+ latestLastResult.isPass ? "OK" : "NG",
|
|
|
|
|
+ expectedPass ? "OK" : "NG");
|
|
|
|
|
+ }
|
|
|
|
|
+ return latestLastResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 发送禁止运行的定时任务
|
|
// 发送禁止运行的定时任务
|
|
|
private static class StopTimerTask extends TimerTask {
|
|
private static class StopTimerTask extends TimerTask {
|
|
|
@Override
|
|
@Override
|
|
@@ -74,10 +112,16 @@ public class WorkTimer {
|
|
|
|
|
|
|
|
// 如果从实时结果中得到到测试结束,则查询最后结果,并提交结果
|
|
// 如果从实时结果中得到到测试结束,则查询最后结果,并提交结果
|
|
|
if (isEnd && !MesClient.testResultProcessed) {
|
|
if (isEnd && !MesClient.testResultProcessed) {
|
|
|
- // 标记为已处理,防止重复执行
|
|
|
|
|
- MesClient.testResultProcessed = true;
|
|
|
|
|
|
|
+ // ATEQ 会先更新实时结束状态,再刷新最后结果寄存器。
|
|
|
|
|
+ // 读取到的最终判定必须与当前周期实时判定一致,防止使用上一件结果。
|
|
|
|
|
+ ATEQ.LastResult lastResult = readCurrentCycleLastResult(realtimeResult.isPass);
|
|
|
|
|
+ if (lastResult == null) {
|
|
|
|
|
+ MesClient.setMenuStatus("等待气密仪刷新最终结果", 1);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- ATEQ.LastResult lastResult = ATEQ.readLastResult();
|
|
|
|
|
|
|
+ // 只有确认最终结果属于当前周期后才标记已处理。
|
|
|
|
|
+ MesClient.testResultProcessed = true;
|
|
|
log.info(lastResult.toString());
|
|
log.info(lastResult.toString());
|
|
|
MesClient.param1.setText(lastResult.pressureValue+lastResult.pressureUnit);
|
|
MesClient.param1.setText(lastResult.pressureValue+lastResult.pressureUnit);
|
|
|
|
|
|
|
@@ -114,11 +158,6 @@ public class WorkTimer {
|
|
|
|
|
|
|
|
String testDate = DateLocalUtils.getCurrentTime();
|
|
String testDate = DateLocalUtils.getCurrentTime();
|
|
|
testParam.setCreateTime(testDate);
|
|
testParam.setCreateTime(testDate);
|
|
|
- boolean localRecordSaved = JdbcUtils.insertTestRecord(testParam);
|
|
|
|
|
- if (!localRecordSaved) {
|
|
|
|
|
- MesClient.setMenuStatus("本地记录保存失败,请联系管理员", -1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 根据设备判定结果分支处理
|
|
// 根据设备判定结果分支处理
|
|
|
if (lastRet.equals("OK")) {
|
|
if (lastRet.equals("OK")) {
|
|
|
// 设备判OK:启动5秒倒计时,允许人工改判
|
|
// 设备判OK:启动5秒倒计时,允许人工改判
|