puzhibing
2026-09-08 3b8b9508a015daae960d0b4f4a25e62949f983c5
修改充电枪状态更新时效问题
6个文件已修改
120 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/ChargingPileFallbackFactory.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/feignClient/ChargingPileClient.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/vo/UpdateChargingPileStatusVo.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingPileController.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/ChargingMessageUtil.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/ChargingPileFallbackFactory.java
@@ -69,6 +69,11 @@
            }
            @Override
            public void realTimeUpdateChargingPileStatus(UpdateChargingPileStatusVo vo) {
                log.error("实时修改充电桩状态失败:" + throwable.getMessage());
            }
            @Override
            public R<List<TChargingPile>> getAllPile() {
                return R.fail("查询所有充电桩信息失败:"+throwable.getMessage());
            }
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/feignClient/ChargingPileClient.java
@@ -61,6 +61,15 @@
    @PostMapping("/t-charging-pile/updateChargingPileStatus")
    void updateChargingPileStatus(@RequestBody UpdateChargingPileStatusVo vo);
    /**
     * 实时修改充电桩状态
     * @param vo
     */
    @PostMapping("/realTimeUpdateChargingPileStatus")
    void realTimeUpdateChargingPileStatus(@RequestBody UpdateChargingPileStatusVo vo);
    /**
     * 获取所有桩
     */
ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/vo/UpdateChargingPileStatusVo.java
@@ -12,4 +12,6 @@
    private String pile_code;
    private String gun_code;
    private Integer status;
    /*是否插枪(0:否,1:是)*/
    private Integer insertionStatus;
}
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingPileController.java
@@ -275,15 +275,10 @@
        String gun_code = vo.getGun_code();
        //0:正常,1:故障,2=插枪
        Integer status = vo.getStatus();
        Long time = (Long) redisTemplate.opsForHash().get("charging_gun_online", (pile_code + gun_code));
        //小于3秒才处理数据,防止频繁查询数据
//        if(null != time && (System.currentTimeMillis() - time) < 3000){
//            return;
//        }
        TChargingGun tChargingGun = chargingGunService.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getFullNumber, (pile_code + gun_code)).eq(TChargingGun::getDelFlag, 0));
        if(null != tChargingGun){
            //写入缓存数据,用于充电桩对接服务中限制频率
            redisTemplate.opsForHash().put("charging_gun_online", tChargingGun.getFullNumber(), System.currentTimeMillis());
            TChargingPile chargingPile = chargingPileService.getById(tChargingGun.getChargingPileId());
            //枪处于离线或者故障,返回状态为正常,则修改其状态
@@ -416,6 +411,66 @@
    @ResponseBody
    @PostMapping("/realTimeUpdateChargingPileStatus")
    public void realTimeUpdateChargingPileStatus(@RequestBody UpdateChargingPileStatusVo vo){
        String pile_code = vo.getPile_code();
        String gun_code = vo.getGun_code();
        //0:离线,1:故障,2:空闲,3:充电
        Integer status = vo.getStatus();
        TChargingGun tChargingGun = chargingGunService.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getFullNumber, (pile_code + gun_code)).eq(TChargingGun::getDelFlag, 0));
        if(null != tChargingGun){
            TChargingPile chargingPile = chargingPileService.getById(tChargingGun.getChargingPileId());
            Site site = siteService.getById(tChargingGun.getSiteId());
            TChargingGun tChargingGun1 = new TChargingGun();
            tChargingGun1.setId(tChargingGun.getId());
            tChargingGun1.setStatus(getStatus(status, vo.getInsertionStatus()));
            chargingGunService.updateById(tChargingGun1);
            tChargingGun.setStatus(tChargingGun1.getStatus());
            threadPoolExecutor.execute(()->{
                //上传成都监管
                chengDuJianGuanClient.notificationStationStatus(tChargingGun.getId());
            });
            if(site.getIsOpenSynchronization() == 1){
                threadPoolExecutor.execute(()->{
                    //推送状态给三方平台
                    tcecClient.pushChargingGunStatus(tChargingGun.getFullNumber(), tChargingGun1.getStatus());
                    pushConnectorStatus(tChargingGun);
                });
            }
            if(tChargingGun1.getStatus() == 7){
                TFaultMessage faultMessage = new TFaultMessage();
                faultMessage.setSiteId(chargingPile.getSiteId());
                faultMessage.setChargingPileId(chargingPile.getId());
                faultMessage.setChargingGunId(tChargingGun.getId());
                faultMessage.setStatus(2);
                faultMessage.setDownTime(LocalDateTime.now());
                faultMessage.setCreateTime(LocalDateTime.now());
                faultMessage.setDelFlag(false);
                faultMessage.setContent("设备故障");
                faultMessageService.save(faultMessage);
            }
        }
    }
    private Integer getStatus(Integer status, Integer insertionStatus){
        switch (status){
            case 0:
                return 1;
            case 1:
                return 7;
            case 2:
                return 0 == insertionStatus ? 2 : 3;
            case 3:
                return 0 == insertionStatus ? 2 : 4;
            default:
                return 7;
        }
    }
    @ResponseBody
    @PostMapping("/getAllPile")
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
@@ -117,13 +117,6 @@
                long PING = System.currentTimeMillis();
                PingMessage pingMessage = JSON.parseObject(content.toJSONString(),PingMessage.class);
                String fullName = pingMessage.getCharging_pile_code() + pingMessage.getCharging_gun_code();
                //主动丢弃一次心跳数据,用于降低调华为接口评率,防止被限流
                boolean heartRate = redisTemplate.hasKey("HeartRate:" + fullName);
                if(heartRate){
                    redisTemplate.delete("HeartRate:" + fullName);
                    break;
                }
                redisTemplate.opsForValue().set("HeartRate:" + fullName, System.currentTimeMillis());
                // 响应硬件
                Pong pong = new Pong();
                pong.setCharging_pile_code(pingMessage.getCharging_pile_code());
@@ -131,27 +124,8 @@
                pong.setCharging_gun_status(0);
                iotMessageProduce.sendMessage(pong.getCharging_pile_code(), ServiceIdMenu.PONG.getKey(), messageUtil.pong(pong));
                //缓解高并发调华为接口触发限流
//                threadPoolExecutor.execute(()->{
//                    long longValue = Double.valueOf(Math.random() * 1000).longValue();
//                    System.err.println("随机等待" + longValue + "毫秒:" + fullName);
//                    try {
//                        Thread.sleep(longValue);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//
//                    // 响应硬件
//                    Pong pong = new Pong();
//                    pong.setCharging_pile_code(pingMessage.getCharging_pile_code());
//                    pong.setCharging_gun_code(pingMessage.getCharging_gun_code());
//                    pong.setCharging_gun_status(0);
//                    iotMessageProduce.sendMessage(pong.getCharging_pile_code(), ServiceIdMenu.PONG.getKey(), messageUtil.pong(pong));
//                });
                Long time = (Long) redisTemplate.opsForHash().get("charging_gun_online", fullName);
                //小于1分钟才处理数据,防止频繁查询数据
                if(null != time && (System.currentTimeMillis() - time) < 60000){
                if(null != time && (System.currentTimeMillis() - time) < 10000){
                    break;
                }
                
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/tools/ChargingMessageUtil.java
@@ -167,6 +167,15 @@
            case SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA:
                //限制数据处理频率,60秒一次
                UploadRealTimeMonitoringDataMessage uploadRealTimeMonitoringDataMessage = message.getUploadRealTimeMonitoringDataMessage();
                //先更新充电枪状态
                UpdateChargingPileStatusVo vo2 = new UpdateChargingPileStatusVo();
                vo2.setGun_code(uploadRealTimeMonitoringDataMessage.getCharging_gun_code());
                vo2.setPile_code(uploadRealTimeMonitoringDataMessage.getCharging_pile_code());
                vo2.setStatus(uploadRealTimeMonitoringDataMessage.getCharging_gun_status());
                vo2.setInsertionStatus(uploadRealTimeMonitoringDataMessage.getInsertion_status());
                chargingPileClient.realTimeUpdateChargingPileStatus(vo2);
                //再存储充电实时监控数据
                String transaction_serial_number = uploadRealTimeMonitoringDataMessage.getTransaction_serial_number();
                Object o = redisTemplate.opsForValue().get("upload_real_time_monitoring_data:" + transaction_serial_number);
                if(null != o){