From ecd98bd977775d8c2846dc47ee2529b1a57422c7 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Tue, 18 Jun 2024 20:43:01 +0800 Subject: [PATCH] 1. 111 --- .../iot/receive/ReceiveController.java | 12 +++++---- .../service/impl/AsDeviceServiceImpl.java | 26 ++++++++++++++++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index 0c0388e..3d0d7f4 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -324,11 +324,13 @@ public class ReceiveController { AsDevice device = asDeviceService.selectAsDeviceByMac(mac); //开异步线程保存回调参数 scheduledExecutorService.schedule(() -> { - log.info("【接收onenet推送】异步更新在线状态"+JSON.toJSONString(device)); - device.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_ONLINE); - int i = asDeviceService.updateAsDevice(device); - if(i>0){ - log.info("【接收onenet推送】异步保存在线状态成功"); + if(device.getOnlineStatus().equals(ServiceConstants.VEHICLE_STATUS_OFFLINE)){ + log.info("【接收onenet推送】异步更新在线状态"+JSON.toJSONString(device)); + device.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_ONLINE); + int i = asDeviceService.updateAsDevice(device); + if(i>0){ + log.info("【接收onenet推送】异步保存在线状态成功"); + } } }, 0, TimeUnit.SECONDS); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index f771e62..265ed4a 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -242,6 +242,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(ObjectUtil.isNotNull(status)){ String typeName = sysDictDataService.selectDictLabel("as_device_status", status); asDevice1.setStatusStr(typeName); + if(status.equals(ServiceConstants.VEHICLE_STATUS_NOT_BAND) && ObjectUtil.isNotNull(asDevice1.getAreaId())){ + asDevice1.setStatus(ServiceConstants.VEHICLE_STATUS_IN_OFFLINE); + } } if(ObjectUtil.isNotNull(areaId)){ SysDept sysDept = wxPayService.getDeptObjByAreaId(areaId); @@ -468,6 +471,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** 2.发送命令*/ ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁"); if(responseVo.getCode() != 0){ + asynchronousUpdateOnlineStatus(asDevice.getMac()); throw new ServiceException("【扫码/编号开锁骑行】更新车辆状态失败"); } /** 3.更新车辆状态*/ @@ -665,10 +669,28 @@ public class AsDeviceServiceImpl extends ServiceImpl i //记录命令 if (!HttpStatus.IOT_SUCCESS.equals(code)) { + // 异步更新在线状态 + asynchronousUpdateOnlineStatus(mac); throw new ServiceException(code+"-----"+ IotUtil.formatMsg(code)); } } + private void asynchronousUpdateOnlineStatus(String mac) { + AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac); + //异步更新在线状态 + scheduledExecutorService.schedule(() -> { + if(device.getOnlineStatus().equals(ServiceConstants.VEHICLE_STATUS_ONLINE)){ + log.info("【接收onenet推送】异步更新在线状态"+JSON.toJSONString(device)); + device.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE); + int i = asDeviceMapper.updateAsDevice(device); + if(i>0){ + log.info("【接收onenet推送】异步保存在线状态成功"); + } + } + + }, 0, TimeUnit.SECONDS); + } + @Override /** 发送命令*/ public ResponseVo sendCommandWithResp(String mac, String token,String command,String type) { @@ -1403,10 +1425,12 @@ public class AsDeviceServiceImpl extends ServiceImpl i @SneakyThrows @Override public boolean isOnline(String sn) { - ResponseVo responseVo = sendCommandWithResp(asDeviceMapper.selectAsDeviceBySn(sn).getMac(), Token.getToken(), "111", "是否在线"); + AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn); + ResponseVo responseVo = sendCommandWithResp(device.getMac(), Token.getToken(), "111", "是否在线"); if(responseVo.getCode() == 0){ return true; } + asynchronousUpdateOnlineStatus(device.getMac()); return false; }