浏览代码

[功能修复]优化离线和计费模型检测

liuf 9 月之前
父节点
当前提交
909aa55c54

+ 24 - 1
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
 import com.tmzn.devicelinkykc.entity.BillingModel;
+import com.tmzn.devicelinkykc.entity.DeviceStatus;
 import com.tmzn.devicelinkykc.entity.param.AjaxResult;
 import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
 import com.tmzn.devicelinkykc.frameMsg.DataConversion;
@@ -15,6 +16,7 @@ import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
 import com.tmzn.devicelinkykc.redis.RedisCache;
 import com.tmzn.devicelinkykc.service.BillingModelService;
 import com.tmzn.devicelinkykc.service.DeviceControlerService;
+import com.tmzn.devicelinkykc.service.DeviceStatusService;
 import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
 import com.tmzn.devicelinkykc.msgparser.MessageParseMgr;
 import com.tmzn.devicelinkykc.util.Encrytion;
@@ -74,11 +76,32 @@ public class TestController {
         return "ok";
     }
 
+    @Autowired
+    DeviceStatusService deviceStatusService;
+
     @PostMapping("/parser1")
     public String parser1(@RequestBody String message ) {
 
         try{
-            deviceMsgHandle.deviceMsg(message);
+
+
+            QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+            billWapper.eq("pile_code", "32010600530570");
+            billWapper.eq("device_imei", "863218078065418");
+            BillingModel b = billingModelService.getOne(billWapper);
+            if (b == null) {
+                log.info("{}上报充电中未匹配计费模型", "32010600530570");
+            }
+
+
+
+            QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
+            deviceStatusQueryWrapper.eq("device_imei", "863343064704539");
+            deviceStatusQueryWrapper.last("limit 1");
+            DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
+            System.out.println(statusServiceOne);
+
+//            deviceMsgHandle.deviceMsg(message);
         }catch (Exception e){
             e.printStackTrace();
             System.out.println(e.getMessage());

+ 11 - 0
src/main/java/com/tmzn/devicelinkykc/message/YkcMsgHandle.java

@@ -476,8 +476,19 @@ public class YkcMsgHandle {
                     reason=0x03;
                     logger.info("枪禁用{}",device.getPileCode());
                 }
+
+                QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+                billWapper.eq("pile_code", deviceConnectionMsg.getDeviceId());
+                billWapper.eq("device_imei", deviceConnectionMsg.getImei());
+                BillingModel b = billingModelService.getOne(billWapper);
+                if (b == null) {
+                    temp = true;
+                    reason=0x00;
+                    logger.info("未配置计费模型{}",deviceConnectionMsg.getDeviceId());
+                }
             }
 
+
             if (temp) {
                 logger.info("启动失败{}:reason:{}" ,deviceConnectionMsg.getDeviceId(), reason);
                 charngingPushFrame.startStatus(deviceConnectionMsg, transOrder, guns[0], result, reason);

+ 30 - 15
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/MsgCharngingRunner.java

@@ -104,34 +104,49 @@ public class MsgCharngingRunner {
             return;
         }
 
-        Set<String> devicePileCodes = map.keySet();
-        QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
-        billWapper.in("pile_code", devicePileCodes);
-        List<BillingModel> billingModels = billingModelService.list(billWapper);
-        if (billingModels.size() < 1) {
-            log.info("无计费可上报模型");
-            return;
-        }
-
-        Map<String, BillingModel> billingModelMap = billingModels.stream()
-                .collect(Collectors.toMap(BillingModel::getPileCode, billingModel -> billingModel));
+//        Set<String> devicePileCodes = map.keySet();
+//        QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+//        billWapper.in("pile_code", devicePileCodes);
+//        List<BillingModel> billingModels = billingModelService.list(billWapper);
+//        if (billingModels.size() < 1) {
+//            log.info("无计费可上报模型");
+//            return;
+//        }
+
+//        Map<String, BillingModel> billingModelMap = billingModels.stream()
+//                .collect(Collectors.toMap(BillingModel::getPileCode, billingModel -> billingModel));
 
         //只上传最近的订单
         Map<String, Boolean> dealMap = new HashMap<>();
         list.forEach(item -> {
             try {
-                if(!deviceMsgHandle.checkConnection(item.getPileCode(),item.getDeviceImei())){
-                    log.info("{}重新连接句柄不存在等待下次执行",item.getPileCode());
+                //检查设备是否在线
+                QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
+                deviceStatusQueryWrapper.eq("pile_code", item.getPileCode());
+                deviceStatusQueryWrapper.eq("gun_port", item.getGunsCode());
+//                deviceStatusQueryWrapper.last("limit 1");
+                DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
+                if(statusServiceOne != null && statusServiceOne.getOnlineStatus()==StatusConstant.OFFLINE){
+                    log.info("{}设备已离线不上报",item.getPileCode());
                     return;
                 }
 
-                DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
-                BillingModel b = billingModelMap.get(item.getPileCode());
+                QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+                billWapper.eq("pile_code", item.getPileCode());
+                billWapper.eq("device_imei", item.getDeviceImei());
+                BillingModel b = billingModelService.getOne(billWapper);
                 if (b == null) {
                     log.info("{}上报充电中未匹配计费模型", item.getPileCode());
                     return;
                 }
 
+                if(!deviceMsgHandle.checkConnection(item.getPileCode(),item.getDeviceImei())){
+                    log.info("{}重新连接句柄不存在等待下次执行",item.getPileCode());
+                    return;
+                }
+
+                DeviceConnectionMsg deviceConnectionMsg = map.get(item.getPileCode());
+
                 String k = item.getPileCode() + "_" + item.getGunsCode();
                 if (dealMap.containsKey(k)) {
                     log.info("{}本轮已上报充电中只报最后一个订单", k);