Selaa lähdekoodia

开发定时同步设备告警数据方法,并提供API接口

james 1 kuukausi sitten
vanhempi
commit
c879bf666a

+ 17 - 18
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseAlarmServiceImpl.java

@@ -626,15 +626,24 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
 
     @Override
     public void deviceOffLineAlarm(){
-        log.info("定时同步设备状态和设备告警数据 start");
-        ApiResult<List<StatusVO>> resultList = dataQueryClient.status();
-        List<StatusVO> list = resultList.getData();
-        if(CollectionUtils.isNotEmpty(list)){
-            List<String> devList = new ArrayList<>();
-            for(int i=0;i<list.size();i++){
-                devList.add(list.get(i).getDeviceId());
+        log.info("定时同步设备告警数据 start");
+        List<StatusVO> list = new ArrayList<>();
+        List<String> devList = new ArrayList<>();
+        LambdaQueryWrapper<DmpDeviceStatus> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(DmpDeviceStatus::getProductCode,DmpDeviceStatus::getDeviceId,DmpDeviceStatus::getLastOnlineTime);
+        List<DmpDeviceStatus> dmpDeviceStatusList = dmpDeviceStatusService.list(queryWrapper);
+        if(CollectionUtils.isNotEmpty(dmpDeviceStatusList)){
+            for (int i = 0; i < dmpDeviceStatusList.size(); i++) {
+                StatusVO statusVO = new StatusVO();
+                statusVO.setProductCode(dmpDeviceStatusList.get(i).getProductCode());
+                statusVO.setDeviceId(dmpDeviceStatusList.get(i).getDeviceId());
+                statusVO.setTime(dmpDeviceStatusList.get(i).getLastOnlineTime());
+                list.add(statusVO);
+                devList.add(dmpDeviceStatusList.get(i).getDeviceId());
             }
+        }
 
+        if(CollectionUtils.isNotEmpty(list)){
             List<DmpDeviceInfo> devInfoList = new ArrayList<>();
             List<BaseAlarm> baseUnAlarmList = new ArrayList<>();
 //            List<BaseAlarm> baseAlarmList = new ArrayList<>();
@@ -648,12 +657,7 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
                 for(int i=0;i<list.size();i++){
                     String date =  list.get(i).getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                     String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-                    LambdaUpdateWrapper<DmpDeviceStatus> updateWrapper = Wrappers.lambdaUpdate();
                     if(date.equals(currentDate)){
-                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,1)  //设备在线
-                                .set(DmpDeviceStatus::getLastOnlineTime,list.get(i).getTime())
-                                .eq(DmpDeviceStatus::getDeviceId,list.get(i).getDeviceId())
-                                .eq(DmpDeviceStatus::getProductCode,list.get(i).getProductCode());
                         //设备离线告警恢复在线自动默认处理
                         if(CollectionUtils.isNotEmpty(baseUnAlarmList)){
                             for(int j=0;j<baseUnAlarmList.size();j++){
@@ -672,10 +676,6 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
                         }
 
                     }else{
-                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
-                                .set(DmpDeviceStatus::getLastOfflineTime,list.get(i).getTime())
-                                .eq(DmpDeviceStatus::getDeviceId,list.get(i).getDeviceId())
-                                .eq(DmpDeviceStatus::getProductCode,list.get(i).getProductCode());
 
                         for(int j=0;j<devInfoList.size();j++){
                             if(list.get(i).getDeviceId().equals(devInfoList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(devInfoList.get(j).getProductCode())){
@@ -705,12 +705,11 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
                         }
 
                     }
-                    dmpDeviceStatusService.update(updateWrapper);
                 }
             }
 
         }
-        log.info("定时同步设备状态和设备告警数据 end");
+        log.info("定时同步设备告警数据 end");
     }
 
     @Override

+ 8 - 3
service-job/src/main/java/com/ruoyi/job/task/RyTask.java

@@ -54,9 +54,14 @@ public class RyTask {
         remoteIotTaskService.dataOverviewJobData();
     }
 
-    public void baseAlarmStatus(){
-        System.out.println("baseAlarmStatus start......");
-        remoteIotTaskService.baseAlarmStatus();
+    public void deviceStatus(){
+        System.out.println("deviceStatus start......");
+        remoteIotTaskService.deviceStatus();
+    }
+
+    public void deviceOffLineAlarm(){
+        System.out.println("deviceOffLineAlarm start......");
+        remoteIotTaskService.deviceOffLineAlarm();
     }
 
     public void customInfoStatus(){