From 200004913ebbb19aa819759ea821543a48b0f083 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Tue, 26 May 2026 10:53:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(device):=20=E6=9B=B4=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=9B=91=E6=B5=8B=E7=82=B9=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 LineInfoParam 参数对象统一接口参数传递 - 移除 DictData 依赖减少不必要的导入 - 修改 getLineInfo 方法调用适配新的参数结构 - 在多个服务类中实现统一的参数封装逻辑 - 优化 Redis 缓存中监测点信息的处理流程 - 提升代码可读性和维护性 --- .../access/handler/MqttMessageHandler.java | 50 ++++++++++--------- .../njcn/access/service/ICsTopicService.java | 2 +- .../service/impl/CsDeviceServiceImpl.java | 2 + .../service/impl/CsTopicServiceImpl.java | 8 ++- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java index 34e8547..b7d6fed 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java @@ -56,7 +56,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.nio.charset.StandardCharsets; -import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; @@ -487,29 +486,34 @@ public class MqttMessageHandler { heartbeatService.receiveHeartbeat(nDid); //有心跳,则将装置改成在线 //csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode()); - //处理心跳 - ReqAndResDto.Res reqAndResParam = new ReqAndResDto.Res(); - reqAndResParam.setMid(res.getMid()); - reqAndResParam.setDid(0); - reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode()); - reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode())); - reqAndResParam.setCode(200); - //fixme 前置处理的时间应该是UTC时间,所以需要加8小时。 - String json = "{Time:"+(System.currentTimeMillis()/1000+8*3600)+"}"; - net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json); - reqAndResParam.setMsg(jsonObject); - publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false); - //处理业务逻辑 - Object object = res.getMsg(); - if (!Objects.isNull(object)){ - List abnormalList = new ArrayList<>(); - if (object instanceof ArrayList){ - abnormalList.addAll((List) object); + //处理心跳 判断设备是否接入,如果设备已经接入则响应,不然忽略 + CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData(); + if (Objects.nonNull(po)) { + if (po.getUsageStatus() == 1 && po.getRunStatus() == 2 && po.getStatus() == 3) { + ReqAndResDto.Res reqAndResParam = new ReqAndResDto.Res(); + reqAndResParam.setMid(res.getMid()); + reqAndResParam.setDid(0); + reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode()); + reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode())); + reqAndResParam.setCode(200); + //fixme 前置处理的时间应该是UTC时间,所以需要加8小时。 + String json = "{Time:"+(System.currentTimeMillis()/1000+8*3600)+"}"; + net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json); + reqAndResParam.setMsg(jsonObject); + publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false); + //处理业务逻辑 + Object object = res.getMsg(); + if (!Objects.isNull(object)){ + List abnormalList = new ArrayList<>(); + if (object instanceof ArrayList){ + abnormalList.addAll((List) object); + } + //todo APF设备不存在逻辑设备掉线的情况,网关下的设备会存在 + abnormalList.forEach(item->{ + System.out.println("异常设备ID:"+item); + }); + } } - //todo APF设备不存在逻辑设备掉线的情况,网关下的设备会存在 - abnormalList.forEach(item->{ - System.out.println("异常设备ID:"+item); - }); } break; case 4866: diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsTopicService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsTopicService.java index d8923e5..912237b 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsTopicService.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsTopicService.java @@ -28,5 +28,5 @@ public interface ICsTopicService extends IService { */ String getVersion(String nDid); - + void deleteByNDid(String nDid); } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java index 5a8ec3a..02d39d8 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java @@ -388,6 +388,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService { appLineTopologyDiagramPOQueryWrapper.in("line_id",collect); appLineTopologyDiagramService.remove(appLineTopologyDiagramPOQueryWrapper); } + //删除topic表 + csTopicService.deleteByNDid(nDid); //清空缓存 redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid); } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsTopicServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsTopicServiceImpl.java index 5178b32..54906ba 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsTopicServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsTopicServiceImpl.java @@ -7,7 +7,6 @@ import com.njcn.access.mapper.CsTopicMapper; import com.njcn.access.pojo.po.CsTopic; import com.njcn.access.service.ICsTopicService; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import java.util.List; @@ -42,4 +41,11 @@ public class CsTopicServiceImpl extends ServiceImpl impl } return version; } + + @Override + public void deleteByNDid(String nDid) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(CsTopic::getNDid,nDid); + this.remove(lambdaQueryWrapper); + } }