Browse Source

Merge branch 'usky-zyj' of uskycloud/usky-modules into master

gez 1 month ago
parent
commit
ca43ae3ebf
16 changed files with 178 additions and 35 deletions
  1. 5 2
      service-iot/service-iot-api/src/main/java/com/usky/iot/RemoteIotTaskService.java
  2. 7 2
      service-iot/service-iot-api/src/main/java/com/usky/iot/factory/RemoteIotTaskFactory.java
  3. 5 0
      service-iot/service-iot-biz/pom.xml
  4. 20 20
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/DeviceStatusApi.java
  5. 7 2
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/ServiceIotTaskApi.java
  6. 2 1
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DeviceHttpController.java
  7. 12 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpDeviceInfoController.java
  8. 2 1
      service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpDeviceTypeController.java
  9. 5 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/DmpDeviceStatus.java
  10. 3 2
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/BaseAlarmService.java
  11. 5 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpDeviceInfoService.java
  12. 1 1
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpDeviceTypeService.java
  13. 7 1
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseAlarmServiceImpl.java
  14. 92 0
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceInfoServiceImpl.java
  15. 3 2
      service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceTypeServiceImpl.java
  16. 2 1
      service-meeting/service-meeting-biz/src/main/java/com/usky/meeting/service/impl/MeetingInfoServiceImpl.java

+ 5 - 2
service-iot/service-iot-api/src/main/java/com/usky/iot/RemoteIotTaskService.java

@@ -14,8 +14,11 @@ public interface RemoteIotTaskService {
     @GetMapping("/dataOverviewJobData")
     void dataOverviewJobData();
 
-    @GetMapping("/baseAlarmStatus")
-    void baseAlarmStatus();
+    @GetMapping("/deviceStatus")
+    void deviceStatus();
+
+    @GetMapping("/deviceOffLineAlarm")
+    void deviceOffLineAlarm();
 
     @GetMapping("/customInfoStatus")
     void customInfoStatus();

+ 7 - 2
service-iot/service-iot-api/src/main/java/com/usky/iot/factory/RemoteIotTaskFactory.java

@@ -32,8 +32,13 @@ public class RemoteIotTaskFactory implements FallbackFactory<RemoteIotTaskServic
             }
 
             @Override
-            public void baseAlarmStatus() {
-                throw new FeignBadRequestException(500,"定时同步设备状态和设备告警数据异常"+throwable.getMessage());
+            public void deviceStatus() {
+                throw new FeignBadRequestException(500,"定时同步设备状态异常"+throwable.getMessage());
+            }
+
+            @Override
+            public void deviceOffLineAlarm() {
+                throw new FeignBadRequestException(500,"定时同步设备离线告警数据异常"+throwable.getMessage());
             }
 
             @Override

+ 5 - 0
service-iot/service-iot-biz/pom.xml

@@ -19,6 +19,11 @@
             <artifactId>service-backend-api</artifactId>
             <version>0.0.1</version>
         </dependency>
+        <dependency>
+            <groupId>com.usky</groupId>
+            <artifactId>data-tsdb-proxy-api</artifactId>
+            <version>0.0.1</version>
+        </dependency>
         <dependency>
             <groupId>com.usky</groupId>
             <artifactId>data-transfer-api</artifactId>

+ 20 - 20
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/DeviceStatusApi.java

@@ -1,20 +1,20 @@
-package com.usky.iot.controller.api;
-
-import com.usky.iot.client.DeviceStatusClient;
-import com.usky.iot.service.BaseAlarmService;
-import io.swagger.annotations.Api;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@Api(tags = "数据统一查询RPC")
-public class DeviceStatusApi implements DeviceStatusClient {
-
-    @Autowired
-    private BaseAlarmService baseAlarmService;
-
-    public void status(){
-        baseAlarmService.status();
-    }
-
-}
+//package com.usky.iot.controller.api;
+//
+//import com.usky.iot.client.DeviceStatusClient;
+//import com.usky.iot.service.DmpDeviceInfoService;
+//import io.swagger.annotations.Api;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.web.bind.annotation.RestController;
+//
+//@RestController
+//@Api(tags = "数据统一查询RPC")
+//public class DeviceStatusApi implements DeviceStatusClient {
+//
+//    @Autowired
+//    private DmpDeviceInfoService dmpDeviceInfoService;
+//
+//    public void status(){
+//        dmpDeviceInfoService.deviceStatus();
+//    }
+//
+//}

+ 7 - 2
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/api/ServiceIotTaskApi.java

@@ -34,8 +34,13 @@ public class ServiceIotTaskApi implements RemoteIotTaskService {
     }
 
     @Override
-    public void baseAlarmStatus() {
-        baseAlarmService.status();
+    public void deviceStatus() {
+        dmpDeviceInfoService.deviceStatus();
+    }
+
+    @Override
+    public void deviceOffLineAlarm() {
+        baseAlarmService.deviceOffLineAlarm();
     }
 
     @Override

+ 2 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DeviceHttpController.java

@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -42,7 +43,7 @@ public class DeviceHttpController {
 
     @GetMapping(value = "/status")
     public ApiResult<Void> status(){
-        baseAlarmService.status();
+        dmpDeviceInfoService.deviceStatus();
         return ApiResult.success();
     }
 

+ 12 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpDeviceInfoController.java

@@ -4,6 +4,8 @@ import com.usky.backend.domain.*;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.common.core.utils.poi.ExcelUtil;
+<<<<<<< HEAD
+import com.usky.demo.domain.LastInnerQueryVO;
 import com.usky.iot.domain.DmpDeviceInfo;
 import com.usky.iot.service.DmpDeviceInfoService;
 import com.usky.iot.service.vo.*;
@@ -52,6 +54,16 @@ public class DmpDeviceInfoController {
         return ApiResult.success();
     }
 
+    /**
+     * 更新设备列表状态
+     * @param queryVO
+     * @return
+     */
+    @PostMapping("updateDeviceStatus")
+    public ApiResult<Void> updateDeviceStatus(@RequestBody LastInnerQueryVO queryVO){
+        dmpDeviceInfoService.updateDeviceStatus(queryVO);
+        return ApiResult.success();
+    }
 
     /**
      * 分页

+ 2 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpDeviceTypeController.java

@@ -71,9 +71,10 @@ public class DmpDeviceTypeController {
     @GetMapping("getDeviceTypeList")
     public ApiResult<CommonPage<DmpDeviceType>> getDeviceTypeList(@RequestParam(value = "typeCode",required = false) String typeCode,
                                                                   @RequestParam(value = "typeName",required = false) String typeName,
+                                                                  @RequestParam(value = "typeDomain",required = false) Integer typeDomain,
                                                                   @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize){
-        return ApiResult.success(dmpDeviceTypeService.getDeviceTypeList(typeCode,typeName,pageNum,pageSize));
+        return ApiResult.success(dmpDeviceTypeService.getDeviceTypeList(typeCode,typeName,typeDomain,pageNum,pageSize));
     }
 
     /**

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/DmpDeviceStatus.java

@@ -56,4 +56,9 @@ public class DmpDeviceStatus implements Serializable {
      * 产品编码
      */
     private String productCode;
+
+    /**
+     * 设备uuid
+     */
+    private String deviceUuid;
 }

+ 3 - 2
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/BaseAlarmService.java

@@ -8,6 +8,7 @@ import com.usky.iot.service.vo.BaseAlarmListVO;
 import com.usky.iot.service.vo.BaseAlarmRequestVO;
 import com.usky.iot.service.vo.BaseAlarmResponeVO;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
 import java.util.Map;
@@ -26,6 +27,8 @@ public interface BaseAlarmService extends CrudService<BaseAlarm> {
 
     CommonPage<BaseAlarm> page(BaseAlarmListVO baseAlarmListVO);
 
+    void deviceOffLineAlarm();
+
     CommonPage<BaseAlarmResponeVO> statistic_notoken(BaseAlarmRequestVO baseAlarmRequestVO);
 
     CommonPage<BaseAlarm> page_notoken(BaseAlarmListVO baseAlarmListVO);
@@ -36,8 +39,6 @@ public interface BaseAlarmService extends CrudService<BaseAlarm> {
 
     boolean add(BaseAlarm baseAlarm);
 
-    void status();
-
     /**
      * 综合云图-告警统计
      * @return

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpDeviceInfoService.java

@@ -3,6 +3,7 @@ package com.usky.iot.service;
 import com.usky.backend.domain.*;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.common.mybatis.core.CrudService;
+import com.usky.demo.domain.LastInnerQueryVO;
 import com.usky.iot.domain.DmpDeviceInfo;
 import com.usky.iot.service.vo.*;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -32,6 +33,10 @@ public interface DmpDeviceInfoService extends CrudService<DmpDeviceInfo> {
 
     boolean checkNameUnique1(DmpDeviceInfo dmpDeviceInfo,Integer tenantId);
 
+    void deviceStatus();
+
+    void updateDeviceStatus(LastInnerQueryVO queryVO);
+
     CommonPage<DmpDeviceInfo> page(DmpDeviceInfoRequest dmpDeviceInfoRequest);
 
     CommonPage<DmpDeviceInfo> pageWhite(DmpDeviceInfoRequest dmpDeviceInfoRequest);

+ 1 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpDeviceTypeService.java

@@ -24,7 +24,7 @@ public interface DmpDeviceTypeService extends CrudService<DmpDeviceType> {
 
     void remove(Integer id);
 
-    CommonPage<DmpDeviceType> getDeviceTypeList(String typeCode, String typeName, Integer pageNum, Integer pageSize);
+    CommonPage<DmpDeviceType> getDeviceTypeList(String typeCode, String typeName, Integer typeDomain, Integer pageNum, Integer pageSize);
 
     List<DmpDeviceType> tenantIdDeviceTypeList();
 

+ 7 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/BaseAlarmServiceImpl.java

@@ -14,6 +14,9 @@ import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
+import com.usky.demo.RemoteTsdbProxyService;
+import com.usky.demo.domain.LastInnerQueryVO;
+import com.usky.demo.domain.LastInnerResultVO;
 import com.usky.iot.domain.*;
 import com.usky.iot.mapper.BaseAlarmMapper;
 import com.usky.iot.mapper.DmpDeviceTypeMapper;
@@ -69,6 +72,9 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
     @Autowired
     private DataQueryClient dataQueryClient;
 
+    @Autowired
+    private RemoteTsdbProxyService remoteTsdbProxyService;
+
     @Autowired
     private DmpDeviceStatusService dmpDeviceStatusService;
 
@@ -619,7 +625,7 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
     }
 
     @Override
-    public void status(){
+    public void deviceOffLineAlarm(){
         log.info("定时同步设备状态和设备告警数据 start");
         ApiResult<List<StatusVO>> resultList = dataQueryClient.status();
         List<StatusVO> list = resultList.getData();

+ 92 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceInfoServiceImpl.java

@@ -6,6 +6,7 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateTime;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -28,6 +29,9 @@ import com.usky.common.core.exception.BusinessException;
 import com.usky.common.core.util.BeanMapperUtils;
 import com.usky.common.core.util.UUIDUtils;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.demo.RemoteTsdbProxyService;
+import com.usky.demo.domain.LastInnerQueryVO;
+import com.usky.demo.domain.LastInnerResultVO;
 import com.usky.iot.domain.*;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.iot.mapper.DmpDeviceInfoMapper;
@@ -39,6 +43,7 @@ import com.usky.iot.service.DmpProductAttributeService;
 import com.usky.iot.service.enums.TopicInfo;
 import com.usky.iot.service.vo.*;
 import com.usky.transfer.RemoteTransferService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -50,7 +55,9 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.text.DecimalFormat;
+import java.time.Instant;
 import java.time.LocalDateTime;
+import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -63,6 +70,7 @@ import java.util.stream.Collectors;
  * @author ya
  * @since 2022-10-08
  */
+@Slf4j
 @Service
 public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoMapper, DmpDeviceInfo> implements DmpDeviceInfoService {
     @Autowired
@@ -84,10 +92,14 @@ 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";
 
+
     @Override
     public Map<String, Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName) {
         Integer tenantId;
@@ -364,6 +376,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
             dmpDeviceStatus.setDeviceStatus(2);
             dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
             dmpDeviceStatus.setProductCode(dmpDeviceInfo.getProductCode());
+            dmpDeviceStatus.setDeviceUuid(dmpDeviceInfo.getDeviceUuid());
             dmpDeviceStatusService.save(dmpDeviceStatus);
         } else {
             throw new BusinessException("新增设备信息'" + dmpDeviceInfo.getDeviceId() + "'失败,无对应产品信息");
@@ -407,6 +420,84 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         return null != one && !Objects.equals(one.getId(), id);
     }
 
+    @Override
+    public void deviceStatus(){
+        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
+    public void updateDeviceStatus(LastInnerQueryVO queryVO){
+        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);
+                }
+
+            }
+
+        }
+    }
+
     @Override
     public CommonPage<DmpDeviceInfo> page(DmpDeviceInfoRequest diRequest) {
         List<DmpDeviceInfo> list = new ArrayList<>();
@@ -868,6 +959,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                 dmpDeviceStatus.setDeviceStatus(2);
                 dmpDeviceStatus.setLastOfflineTime(LocalDateTime.now());
                 dmpDeviceStatus.setProductCode(devList.get(i).getProductCode());
+                dmpDeviceStatus.setDeviceUuid(devList.get(i).getDeviceUuid());
                 dmpDeviceStatusList.add(dmpDeviceStatus);
             } else {
                 throw new BusinessException("新增设备信息'" + devList.get(i).getDeviceId() + "'失败,无对应产品信息");

+ 3 - 2
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceTypeServiceImpl.java

@@ -84,11 +84,12 @@ public class DmpDeviceTypeServiceImpl extends AbstractCrudService<DmpDeviceTypeM
     }
 
     @Override
-    public CommonPage<DmpDeviceType> getDeviceTypeList(String typeCode, String typeName, Integer pageNum, Integer pageSize) {
+    public CommonPage<DmpDeviceType> getDeviceTypeList(String typeCode, String typeName, Integer typeDomain, Integer pageNum, Integer pageSize) {
         IPage<DmpDeviceType> page = new Page<>(pageNum, pageSize);
         LambdaQueryWrapper<DmpDeviceType> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.like(StringUtils.isNotBlank(typeCode), DmpDeviceType::getTypeCode, typeCode)
-                .like(StringUtils.isNotBlank(typeName), DmpDeviceType::getTypeName, typeName);
+                .like(StringUtils.isNotBlank(typeName), DmpDeviceType::getTypeName, typeName)
+                .eq(typeDomain != null,DmpDeviceType::getTypeDomain,typeDomain);
         page = this.page(page, queryWrapper);
         return new CommonPage<>(page.getRecords(), page.getTotal(), pageSize, pageNum);
     }

+ 2 - 1
service-meeting/service-meeting-biz/src/main/java/com/usky/meeting/service/impl/MeetingInfoServiceImpl.java

@@ -604,7 +604,8 @@ public class MeetingInfoServiceImpl extends AbstractCrudService<MeetingInfoMappe
                             if(code.getCode() != null && code.getCode().equals("OK")) {
                                 //请求成功
                             }else {
-                                throw new BusinessException("发送短信失败");
+//                                throw new BusinessException("发送短信失败");
+                                log.info(dmUser.getPhonenumber()+"发送短信失败");
                             }
                         }