huangzhen
2023-10-19 1f69ad0de4a0abf9b50599146d8f9b6a22e803a3
src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/DataReceiveServiceImpl.java
@@ -127,7 +127,7 @@
                return gasCategory;
            }).collect(Collectors.toList());
        }
        logger.info("【气体异常map】init完成");
        logger.info("[GasExcMap] init complete");
    }
    @PostConstruct
@@ -143,7 +143,7 @@
                }
            }
        }
        logger.info("【预警阈值】init完成");
        logger.info("[WarningThreshold] init complete");
    }
    @Override
@@ -164,6 +164,7 @@
        GasFlux save = gasFluxService.save(gasFlux);
        if (save == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"气体通量数据保存失败");
        gasFluxDataCacheAndPush();
        return ForeignResult.success();
    }
@@ -193,13 +194,21 @@
            push = true;
            descs.add(GasFluxStateEnum.INVERSION_FAILED_10_MINUTES_NO_DATA.getDesc());
        }
        if (push == true){
            String message = JSON.toJSONString(reqDTO);
            try {
                GasDeviceExcWebsocketServer.sendInfo(message,null);
            } catch (IOException e) {
                logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
            }
        String message = JSON.toJSONString(reqDTO);
        //todo 暂时改为实时推送给前端
        try {
            GasDeviceExcWebsocketServer.sendInfo(message,null);
        } catch (IOException e) {
            logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
        }
        if (push){
            //todo 线上环境还是异常才向前端推送
            //String message = JSON.toJSONString(reqDTO);
            //try {
            //    GasDeviceExcWebsocketServer.sendInfo(message,null);
            //} catch (IOException e) {
            //    logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
            //}
            String execInfo = JSON.toJSONString(descs);
            logger.info("【警告】设备异常,异常原因: "+ execInfo);
            DeviceExceptionLog log = new DeviceExceptionLog();
@@ -212,7 +221,7 @@
        return ForeignResult.success();
    }
    private void gasFluxDataCacheAndPush(GasFlux save){
    private void gasFluxDataCacheAndPush(){
        LocalDateTime time = LocalDateTime.now();
        LocalDateTime startTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
        List<GasFlux> gasFluxes =  gasFluxService.listTodayGasFluxData(startTime,time);
@@ -231,7 +240,7 @@
    @Override
    @Transactional
    public ForeignResult uploadGasConcentration(UploadGasConcentrationReqDTO reqDto) {
        //gasConcentrationParameterVerification(reqDto);
        gasConcentrationParameterVerification(reqDto);
        GasConcentration gasConcentration = new GasConcentration();
        BeanUtils.copyProperties(reqDto,gasConcentration);
        gasConcentration.setDataReceivingTime(LocalDateTime.now());
@@ -279,7 +288,6 @@
                            Integer count= integer + 1;
                            gasExcCountMap.put(i,count);
                            if (yellowWarningThreshold.equals(count)) {
                                System.out.println("超过次数: "+count);
                                warnLogGenerateAndExecPush(WarningThresholdEnum.YELLOW.getCode(), gasCategory.get(i),value);
                            }
                            if (redWarningThreshold.equals(count)) {
@@ -356,13 +364,19 @@
    }
    private void dataCacheAndPush(GasConcentration save){
        LocalDateTime startTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
        LocalDateTime time = LocalDateTime.now();
        String cacheName = time.format(formatter);
        RBucket<String> bucket = redissonClient.getBucket(gasConcentrationCachePrefix+cacheName);
        String cache = bucket.get();
        List<GasConcentration> gasConcentrations = JSON.parseArray(cache,GasConcentration.class);
        if (CollectionUtils.isEmpty(gasConcentrations)){
            gasConcentrations = new ArrayList<>();
            List<GasConcentration> concentrations = gasConcentrationService.listDatabyTimeSlot(startTime, time);
            if (CollectionUtils.isEmpty(concentrations)){
                gasConcentrations = new ArrayList<>();
            }else {
                gasConcentrations = concentrations;
            }
            gasConcentrations.add(save);
        }else {
            gasConcentrations.add(save);