liulin
2025-07-09 512ddb42f73f1560661865225dd03870e021e1d2
src/main/java/com/lunhan/water/service/PaymentRecordsService.java
@@ -80,6 +80,8 @@
    private FacilityAlarmRecordMapperImpl facilityAlarmRecordMapper;
    @Autowired
    private WaterFacilityRecordsMapperImpl waterFacilityRecordsMapper;
    @Autowired
    private AlarmHistoryMapperImpl alarmHistoryMapper;
    public ExecutedResult<Long> create(ReqCreatePaymentRecords request) {
        // 转换po
@@ -310,23 +312,6 @@
            DEBUG_LOGGER.error("设备数据未找到!");
            return;
        }
//        数据上报格式:
//        主题格式:zundong/QS001/data
//        数据格式:{"Data":
//          [
//              {"name":"QS001_state","value":1}, //状态
//              {"name":"QS001_fault","value":0}, //是否故障
//              {"name":"QS001_count","value":10000} //总水量
//          ],"time":"2025-07-02 15:19:17"
//        }
//        心跳上报格式:
//        主题格式:zundong/QS001/state
//        数据格式:{"Data":
//              [
//               {"name":"QS001_heartbeat","value":1} //心跳
//              ],"time":"2025-07-02 15:19:17"
//          }
        //消息解析
        Gson gson = new Gson();
        JsonObject object = gson.fromJson(msg, JsonObject.class);
@@ -350,6 +335,8 @@
        CountVO stateVo = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_state1")).findFirst().orElse(null);
        CountVO heartbeat = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_heartbeat")).findFirst().orElse(null);
        CountVO countVO = listVo.stream().filter(x -> x.getName().equals(facilityPO.getFacilityCode() + "_count1")).findFirst().orElse(null);
        AlarmHistoryPO alarmHistoryPO=new AlarmHistoryPO();
        alarmHistoryPO.setFacilityId(facilityPO.getId());
        switch (stateVo.getValue()) {
            case "0"://取水完成
                BigDecimal divide = new BigDecimal(countVO.getValue()).setScale(2,RoundingMode.DOWN);
@@ -370,11 +357,48 @@
                }
                break;
            case "1"://运行
                facilityPO.setState(1);
                waterFacilityMapper.updateById(facilityPO);
                break;
            case "2"://停止
                facilityPO.setState(2);
                waterFacilityMapper.updateById(facilityPO);
                break;
            case "3"://故障
            case "10"://故障
                alarmHistoryPO.setCode("500");
                alarmHistoryPO.setDescription("管道缺水");
                break;
            case "11"://故障
                alarmHistoryPO.setCode("501");
                alarmHistoryPO.setDescription("流量计故障");
                break;
            case "12"://故障
                alarmHistoryPO.setCode("502");
                alarmHistoryPO.setDescription("阀门故障");
                break;
            case "13"://故障
                alarmHistoryPO.setCode("503");
                alarmHistoryPO.setDescription("柜内温度过低");
                break;
            case "14"://故障
                alarmHistoryPO.setCode("504");
                alarmHistoryPO.setDescription("柜内温度过高");
                break;
        }
        if(StringUtil.isNotNullOrEmpty(alarmHistoryPO.getCode())){
            AlarmHistoryPO historyPO = alarmHistoryMapper.getByCode(facilityPO.getId(), alarmHistoryPO.getCode());
            if(Objects.nonNull(historyPO)){
                historyPO.setLastTime(LocalDateTimeUtil.nowDateTimeStr());
                historyPO.setCount(historyPO.getCount()+1);
                alarmHistoryMapper.updateById(historyPO);
            }else {
                alarmHistoryPO.setLastTime(LocalDateTimeUtil.nowDateTimeStr());
                alarmHistoryPO.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
                alarmHistoryMapper.insert(alarmHistoryPO);
            }
        }else {
            alarmHistoryMapper.deleteByFacilityId(facilityPO.getId());
        }
        HeartbeatDataPO heartbeatDataPO = heartbeatDataMapper.getByKey(facilityPO.getFacilityCode());
        if(Objects.nonNull(heartbeatDataPO)){