| | |
| | | import com.gkhy.fourierSpecialGasMonitor.repository.GasConcentrationRepository; |
| | | import com.gkhy.fourierSpecialGasMonitor.service.*; |
| | | import com.gkhy.fourierSpecialGasMonitor.utils.SendMessageUtil; |
| | | import com.gkhy.fourierSpecialGasMonitor.utils.SummaryUtils; |
| | | import com.gkhy.fourierSpecialGasMonitor.websocket.GasConcentrationExcWebsocketServer; |
| | | import com.gkhy.fourierSpecialGasMonitor.websocket.GasConcentrationWebsocketServer; |
| | | import com.gkhy.fourierSpecialGasMonitor.websocket.GasDeviceExcWebsocketServer; |
| | |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Field; |
| | | import java.text.MessageFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | |
| | | @Autowired |
| | | private GasFluxWebsocketServer gasFluxWebsocketServer; |
| | | |
| | | @Autowired |
| | | private SummaryStatsService summaryStatsService; |
| | | |
| | | private static final ReentrantLock lock = new ReentrantLock(); |
| | | |
| | |
| | | log.setContent(content); |
| | | log.setTime(now); |
| | | log.setExecDesc(execInfo); |
| | | log.setDelFlag(0); |
| | | log.setDelFlag(1); |
| | | DeviceExceptionLog save = deviceExceptionLogService.save(log); |
| | | if (save == null) { |
| | | logger.info("【警告】设备异常日志保存>>>>>>>>>>>>>>>>>>失败"); |
| | |
| | | GasConcentration save = gasConcentrationService.save(gasConcentration); |
| | | if (save == null) |
| | | throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"气体实时数据保存失败"); |
| | | //计算平局值,最大值,最小值 |
| | | computeAndSaveDailySummaryStats(save); |
| | | dataCacheAndPush(save); |
| | | execDataCountAndPush(reqDto); |
| | | return ForeignResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 计算并保存当天的气体浓度统计数据(若统计为空则初始化,否则更新) |
| | | * @param newData 新插入的气体浓度数据 |
| | | */ |
| | | private void computeAndSaveDailySummaryStats(GasConcentration newData) { |
| | | // 定义当天时间范围(00:00:00 至当前时间) |
| | | LocalDateTime todayStart = LocalDate.now().atStartOfDay(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 查询当天已有的统计数据 |
| | | SummaryStats dailyStats = gasConcentrationService.findStats(todayStart, now); |
| | | |
| | | // 若统计数据为空,创建新对象并初始化(用新数据作为初始值) |
| | | if (dailyStats == null || dailyStats.isEmpty()) { |
| | | dailyStats = new SummaryStats(); |
| | | SummaryUtils.initSummaryStats(dailyStats, newData); |
| | | } else { |
| | | // 若统计数据已存在,更新统计值(根据新数据重新计算 min/max/avg) |
| | | SummaryUtils.updateSummaryStats(dailyStats, newData); |
| | | } |
| | | |
| | | |
| | | dailyStats.setTemp(newData.getTemp()); |
| | | dailyStats.setHumidity(newData.getHumidity()); |
| | | dailyStats.setWindSpeed(newData.getWindSpeed()); |
| | | dailyStats.setWindDirection(newData.getWindDirection()); |
| | | dailyStats.setPressure(newData.getPressure()); |
| | | // 补充通用字段(时间取最新数据的时间) |
| | | dailyStats.setTime(newData.getTime()); |
| | | |
| | | // 保存统计结果 |
| | | summaryStatsService.save(dailyStats); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | private void execDataCountAndPush(UploadGasConcentrationReqDTO reqDto){ |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket(SystemCacheKeyEnum.KEY_GAS_CATEGORY.getKey()); |