| | |
| | | private final TestWarningExceptionService warningExceptions; |
| | | private final Clock clock; |
| | | private final Map<String, Instant> lastSnapshotAt = new java.util.concurrent.ConcurrentHashMap<>(); |
| | | private final Map<Long, Instant> lastOfflineCheckAt = new java.util.concurrent.ConcurrentHashMap<>(); |
| | | |
| | | @Autowired |
| | | public TestDataReceptionServiceImpl(TTestMapper mapper, ITTestService tests, @Nullable TestDataObservationAdapter adapter, |
| | |
| | | TestWarningExceptionService warningExceptions, Clock clock) |
| | | { this.mapper = mapper; this.tests = tests; this.adapter = adapter; this.warningExceptions = warningExceptions; this.clock = clock; } |
| | | |
| | | /** 轮询接收中测试,只保存本次成功观测的实时槽位及设备直接返回汇总。 */ |
| | | /** 轮询接收中测试,记录绑定来源离线异常,并保存成功观测的实时槽位及设备汇总。 */ |
| | | @Override @Transactional(rollbackFor = Exception.class) |
| | | public void captureReceivedData() |
| | | { |
| | | for (TTest test : receivingTests()) for (TTestBattery battery : batteries(test)) { saveRealtime(test, battery); saveDeviceAggregates(test, battery); } |
| | | for (TTest test : receivingTests()) { |
| | | Instant now = clock.instant(); |
| | | Instant previous = lastOfflineCheckAt.get(test.getTestId()); |
| | | // 离线检查独立于测量采样槽位,并与暂停、停止和删除共享测试事务锁。 |
| | | if (previous == null || !now.isBefore(previous.plusSeconds(5))) { |
| | | warningExceptions.recordOfflineSources(test, Date.from(now)); |
| | | lastOfflineCheckAt.put(test.getTestId(), now); |
| | | } |
| | | for (TTestBattery battery : batteries(test)) { saveRealtime(test, battery); saveDeviceAggregates(test, battery); } |
| | | } |
| | | } |
| | | |
| | | private List<TTest> receivingTests() |