Browse Source

解决冲突

james 1 month ago
parent
commit
2dc196badf

+ 70 - 103
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceInfoServiceImpl.java

@@ -92,13 +92,13 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
     private RemoteTransferService remoteTransferService;
 
     @Autowired
+    private RemoteTsdbProxyService remoteTsdbProxyService;
+	
+	@Autowired
     private DmpProductAttributeMapper dmpProductAttributeMapper;
 
     private static final String ALARM_HTTP_URL = "/service-alarm/baseAlarm/alarmInfo";
 
-    private RemoteTsdbProxyService remoteTsdbProxyService;
-
-
     @Override
     public Map<String, Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName) {
         Integer tenantId;
@@ -369,6 +369,8 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
             }
             this.save(dmpDeviceInfo);
 
+            remoteTransferService.deleteDeviceCache(dmpDeviceInfo.getProductCode());
+
             DmpDeviceStatus dmpDeviceStatus = new DmpDeviceStatus();
             dmpDeviceStatus.setDeviceId(dmpDeviceInfo.getDeviceId());
             dmpDeviceStatus.setProductId(dmpDeviceInfo.getProductId());
@@ -421,91 +423,50 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
 
     @Override
     public void deviceStatus(){
-//        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());
-//            }
-//
-//            List<DmpDeviceInfo> devInfoList = new ArrayList<>();
-//            List<BaseAlarm> baseUnAlarmList = new ArrayList<>();
-////            List<BaseAlarm> baseAlarmList = new ArrayList<>();
-//            if(devList.size() > 0) {
-//                devInfoList = baseMapper.getDeviceInfoList(devList);
-//                baseUnAlarmList = baseMapper.getUnDeviceAlarmList(devList);
-////                baseAlarmList = baseMapper.getDeviceAlarmList(devList);
-//            }
-//
-//            if(CollectionUtils.isNotEmpty(devInfoList)){
-//                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++){
-//                                if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(j).getProductCode())){
-//                                    LambdaUpdateWrapper<BaseAlarm> updateWrapper1 = Wrappers.lambdaUpdate();
-//                                    updateWrapper1.set(BaseAlarm::getHandleStatus,1)
-//                                            .set(BaseAlarm::getHandleBy,"YT_admin")
-//                                            .set(BaseAlarm::getHandleTime,LocalDateTime.now())
-//                                            .eq(BaseAlarm::getDeviceId,list.get(i).getDeviceId())
-//                                            .eq(BaseAlarm::getHandleStatus,0)
-//                                            .eq(BaseAlarm::getProductCode,list.get(i).getProductCode());
-//                                    this.update(updateWrapper1);
-//                                    break;
-//                                }
-//                            }
-//                        }
-//
-//                    }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())){
-//                                int count = 0;
-//                                for(int k=0;k<baseUnAlarmList.size();k++){
-//                                    if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(k).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(k).getProductCode())){
-//                                        count++;
-//                                    }
-//                                }
-//                                if(count == 0){
-//                                    BaseAlarm baseAlarm = new BaseAlarm();
-//                                    baseAlarm.setDeviceId(list.get(i).getDeviceId());
-//                                    baseAlarm.setAlarmTime(LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"))+":00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-//                                    baseAlarm.setAlarmType("001");
-//                                    baseAlarm.setAlarmObject(devInfoList.get(j).getDeviceName());
-//                                    baseAlarm.setAlarmData("");
-//                                    baseAlarm.setAlarmAttribute("离线告警");
-//                                    baseAlarm.setAlarmContent("设备离线告警");
-//                                    baseAlarm.setAlarmGrade(1);
-//
-//                                    baseAlarm.setAlarmAddress(devInfoList.get(j).getInstallAddress());
-//                                    baseAlarm.setProductCode(devInfoList.get(j).getProductCode());
-//                                    this.add(baseAlarm);
-//                                }
-//                                break;
-//                            }
-//                        }
-//
-//                    }
-//                    dmpDeviceStatusService.update(updateWrapper);
-//                }
-//            }
-//
-//        }
-//        log.info("定时同步设备状态和设备告警数据 end");
+        log.info("定时同步设备状态数据 start");
+        LastInnerQueryVO queryVO = new LastInnerQueryVO();
+        List<String> deviceuuidList = new ArrayList<>();
+        LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(DmpDeviceInfo::getDeviceUuid)
+                .eq(DmpDeviceInfo::getDeleteFlag,0)
+                .ne(DmpDeviceInfo::getServiceStatus,3)
+                .orderByDesc(DmpDeviceInfo::getId);
+        List<DmpDeviceInfo> devList = this.list(queryWrapper);
+        if(CollectionUtils.isNotEmpty(devList)){
+            int count = devList.size();
+            for (int i = 0; i < devList.size(); i++) {
+                deviceuuidList.add(devList.get(i).getDeviceUuid());
+            }
+        }
+        queryVO.setDeviceuuid(deviceuuidList);
+
+        List<LastInnerResultVO> list = remoteTsdbProxyService.last(queryVO);
+        if(CollectionUtils.isNotEmpty(list)){
+            for(int i=0;i<list.size();i++){
+                if(Objects.nonNull(list.get(i).getMetrics())){
+                    String deviceuuid = list.get(i).getDeviceuuid();
+                    LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
+                    String date =  lTime.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,lTime)
+                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+
+                    }else{
+                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
+                                .set(DmpDeviceStatus::getLastOnlineTime,lTime)
+                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+
+                    }
+                    dmpDeviceStatusService.update(updateWrapper);
+                }
+
+            }
+
+        }
+        log.info("定时同步设备状态数据 end");
     }
 
     @Override
@@ -513,23 +474,26 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         List<LastInnerResultVO> list = remoteTsdbProxyService.last(queryVO);
         if(CollectionUtils.isNotEmpty(list)){
             for(int i=0;i<list.size();i++){
-                String deviceuuid = list.get(i).getDeviceuuid();
-                LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
-                String date =  lTime.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,lTime)
-                            .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
-
-                }else{
-                    updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
-                            .set(DmpDeviceStatus::getLastOnlineTime,lTime)
-                            .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+                if(Objects.nonNull(list.get(i).getMetrics())){
+                    String deviceuuid = list.get(i).getDeviceuuid();
+                    LocalDateTime lTime = Instant.ofEpochMilli(Long.valueOf(list.get(i).getMetrics().get("time").toString())).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
+                    String date =  lTime.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,lTime)
+                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
+
+                    }else{
+                        updateWrapper.set(DmpDeviceStatus::getDeviceStatus,2)  //设备离线
+                                .set(DmpDeviceStatus::getLastOnlineTime,lTime)
+                                .eq(DmpDeviceStatus::getDeviceUuid,deviceuuid);
 
+                    }
+                    dmpDeviceStatusService.update(updateWrapper);
                 }
-                dmpDeviceStatusService.update(updateWrapper);
+
             }
 
         }
@@ -910,6 +874,9 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         }
 
         dmpDeviceInfo.setDeleteFlag(1);
+
+        remoteTransferService.deleteDeviceCache(dmpDeviceInfo.getProductCode());
+
         return this.updateById(dmpDeviceInfo);
     }
 

+ 10 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpProductInfoServiceImpl.java

@@ -21,6 +21,7 @@ import com.usky.iot.mapper.DmpProductInfoMapper;
 import com.usky.iot.service.*;
 import com.usky.iot.service.config.IntegerUtils;
 import com.usky.iot.service.vo.DmpProductInfoRequest;
+import com.usky.transfer.RemoteTransferService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -54,6 +55,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
     @Autowired
     private DmpProductAttributeService dmpProductAttributeService;
 
+    @Autowired
+    private RemoteTransferService remoteTransferService;
+
     @Override
     public void add(DmpProductInfo dmpProductInfo) {
         if (checkNameUnique(dmpProductInfo)){
@@ -81,6 +85,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
         dmpProductInfo.setDeleteFlag(0);
         dmpProductInfo.setTenantId(SecurityUtils.getTenantId());
         this.save(dmpProductInfo);
+
+        remoteTransferService.deleteProductCache();
+
         int productId = dmpProductInfo.getId();
         if(null != one){
             String dataField = one.getDataField();
@@ -253,6 +260,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
         }
 
         dmpProductInfo.setDeleteFlag(1);
+
+        remoteTransferService.deleteProductCache();
+
         return this.updateById(dmpProductInfo);
     }
 

+ 1 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/PmTimeConfServiceImpl.java

@@ -87,6 +87,7 @@ public class PmTimeConfServiceImpl extends AbstractCrudService<PmTimeConfMapper,
         responseVO.setSubmitOnTime(submitOnTime);
         responseVO.setSubmitLate(submitLate);
         responseVO.setNotSubmitted(notSubmitted);
+        responseVO.setStatisticalDate(countDate);
         return responseVO;
     }
 

+ 15 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/PmSubmitCountResponseVO.java

@@ -1,5 +1,7 @@
 package com.usky.iot.service.vo;
 
+import java.time.LocalDate;
+
 /**
  *
  * @author fyc
@@ -23,6 +25,11 @@ public class PmSubmitCountResponseVO {
      **/
     private Integer notSubmitted;
 
+    /**
+     * 统计日期
+     **/
+    private LocalDate statisticalDate;
+
     public Integer getSubmitOnTime() {
         return submitOnTime;
     }
@@ -47,4 +54,12 @@ public class PmSubmitCountResponseVO {
         this.notSubmitted = notSubmitted;
     }
 
+    public LocalDate getStatisticalDate() {
+        return statisticalDate;
+    }
+
+    public void setStatisticalDate(LocalDate statisticalDate) {
+        this.statisticalDate = statisticalDate;
+    }
+
 }