Przeglądaj źródła

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

gez 4 tygodni temu
rodzic
commit
ea9db7ebe9

+ 4 - 2
service-eg/service-eg-biz/src/main/java/com/usky/eg/controller/web/EgDeviceController.java

@@ -92,8 +92,10 @@ public class EgDeviceController {
                                                  @RequestParam("commandValue") String commandValue,
                                                  @RequestParam(value = "domain",required = false) String domain,
                                                  @RequestParam(value = "userId",required = false) Long userId,
-                                                 @RequestParam(value = "userName",required = false) String userName){
-        return ApiResult.success(egDeviceService.control(productCode,deviceUuid,commandCode,commandValue,domain,userId,userName));
+                                                 @RequestParam(value = "userName",required = false) String userName,
+                                                 @RequestParam(value = "categoryType") Integer categoryType,
+                                                 @RequestParam(value = "gatewayUuid",required = false) String gatewayUuid){
+        return ApiResult.success(egDeviceService.control(productCode,deviceUuid,commandCode,commandValue,domain,userId,userName,categoryType,gatewayUuid));
     }
 
 }

+ 1 - 1
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/EgDeviceService.java

@@ -33,5 +33,5 @@ public interface EgDeviceService extends CrudService<EgDevice> {
 
     boolean checkDeviceNameUnique(EgDevice egDevice);
 
-    Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName);
+    Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName, Integer categoryType, String gatewayUuid);
 }

+ 7 - 2
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/impl/EgDeviceServiceImpl.java

@@ -250,7 +250,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
     }
 
     @Override
-    public Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName){
+    public Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName, Integer categoryType, String gatewayUuid){
         Integer tenantId;
         long commandUserId;
         String commandUserName;
@@ -290,11 +290,16 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
 
         Map<String,Object> map = new HashMap<>();
         map.put("method","control");
+        map.put("deviceUuid", deviceUuid);
         Map<String,Object> map1 = new HashMap<>();
         map1.put("commandCode",commandCode);
         map1.put("commandValue",commandValue);
         map.put("params",map1);
 
-        return remoteTransferService.deviceControl(productCode,deviceUuid, JSON.toJSONString(map),tenantId,commandUserId,commandUserName);
+        if(categoryType == 3){
+            return remoteTransferService.deviceControl(productCode, gatewayUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
+        }else{
+            return remoteTransferService.deviceControl(productCode, deviceUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
+        }
     }
 }

+ 7 - 0
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/impl/EgRecordServiceImpl.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.datascope.annotation.DataScope;
+import com.ruoyi.common.datascope.context.DataScopeContextHolder;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
@@ -61,11 +63,13 @@ public class EgRecordServiceImpl extends AbstractCrudService<EgRecordMapper, EgR
 
         egRecord.setCreateTime(LocalDateTime.now());
         egRecord.setTenantId(tenantId);
+        egRecord.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue());
 
         this.save(egRecord);
     }
 
     @Override
+    @DataScope
     public CommonPage<EgRecord> page(EgRecordRequestVO requestVO){
         IPage<EgRecord> page = new Page<>(requestVO.getCurrent(),requestVO.getSize());
         String deviceName = requestVO.getDeviceName();
@@ -86,11 +90,14 @@ public class EgRecordServiceImpl extends AbstractCrudService<EgRecordMapper, EgR
             egDeviceList = egDeviceMapper.selectList(egDeviceQuery);
         }
 
+        String dataScopeSql = DataScopeContextHolder.getDataScopeSql();
+
         LambdaQueryWrapper<EgRecord> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.like(StringUtils.isNotBlank(requestVO.getUserName()),EgRecord::getUserName,requestVO.getUserName())
                 .eq(null != requestVO.getPassType(),EgRecord::getPassType,requestVO.getPassType())
                 .in(CollectionUtils.isNotEmpty(egDeviceIdList),EgRecord::getEgDeviceId,egDeviceIdList)
                 .between(StringUtils.isNotBlank(requestVO.getStartTime())&&StringUtils.isNotBlank(requestVO.getEndTime()),EgRecord::getPassTime,requestVO.getStartTime(),requestVO.getEndTime())
+                .apply(Objects.nonNull(dataScopeSql), dataScopeSql)
                 .orderByDesc(EgRecord::getId);
         page = this.page(page,queryWrapper);
         if((page.getRecords().size() > 0) && (egDeviceList.size() > 0)){

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

@@ -68,8 +68,10 @@ public class DeviceHttpController {
                                                  @RequestParam("commandValue") String commandValue,
                                                  @RequestParam(value = "domain",required = false) String domain,
                                                  @RequestParam(value = "userId",required = false) Long userId,
-                                                 @RequestParam(value = "userName",required = false) String userName){
-        return ApiResult.success(dmpDeviceInfoService.control(productCode,deviceUuid,commandCode,commandValue,domain,userId,userName));
+                                                 @RequestParam(value = "userName",required = false) String userName,
+                                                 @RequestParam(value = "categoryType") Integer categoryType,
+                                                 @RequestParam(value = "gatewayUuid",required = false) String gatewayUuid){
+        return ApiResult.success(dmpDeviceInfoService.control(productCode,deviceUuid,commandCode,commandValue,domain,userId,userName,categoryType,gatewayUuid));
     }
 
 

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

@@ -85,6 +85,15 @@ public class DmpDeviceInfoController {
         return ApiResult.success(dmpDeviceInfoService.pageWhite(dmpDeviceInfoRequest));
     }
 
+    /**
+     * 网关设备信息下拉接口
+     * @return
+     */
+    @GetMapping("gatewayDeviceList")
+    public ApiResult<List<DmpDeviceInfo>> gatewayDeviceList() {
+        return ApiResult.success(dmpDeviceInfoService.gatewayDeviceList());
+    }
+
     /**
      * 删除记录
      */

+ 10 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/DmpDeviceInfo.java

@@ -142,6 +142,16 @@ public class DmpDeviceInfo implements Serializable {
      */
     private String latitude;
 
+    /**
+     * 设备所属类型(1、普通设备  2、网关设备  3、网关子设备)
+     */
+    private Integer categoryType;
+
+    /**
+     * 所属网关
+     */
+    private String gatewayUuid;
+
     /**
      * 设备状态;1:在线,2:离线
      */

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

@@ -111,6 +111,11 @@ public class DmpProductAttribute implements Serializable {
      */
     private String attributeDescribe;
 
+    /**
+     * 属性字典
+     */
+    private String attributeDict;
+
     /**
      * 创建人
      */

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

@@ -41,6 +41,8 @@ public interface DmpDeviceInfoService extends CrudService<DmpDeviceInfo> {
 
     CommonPage<DmpDeviceInfo> pageWhite(DmpDeviceInfoRequest dmpDeviceInfoRequest);
 
+    List<DmpDeviceInfo> gatewayDeviceList();
+
     boolean remove(Integer id);
 
     /**
@@ -76,7 +78,7 @@ public interface DmpDeviceInfoService extends CrudService<DmpDeviceInfo> {
     List<DataAverageResponseVO> deviceDataAverage(DataAverageRequestVO requestVO);
     List<DataAverageExportVO> DataAverageExport(DataAverageRequestVO requestVO);
 
-    Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName);
+    Map<String,Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName, Integer categoryType, String gatewayUuid);
 
     /**
      * @description: 获取设备topic列表

+ 255 - 69
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDeviceInfoServiceImpl.java

@@ -105,7 +105,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
 
 
     @Override
-    public Map<String, Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName) {
+    public Map<String, Object> control(String productCode, String deviceUuid, String commandCode, String commandValue, String domain, Long userId, String userName, Integer categoryType, String gatewayUuid) {
         Integer tenantId;
         long commandUserId;
         String commandUserName;
@@ -146,12 +146,18 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
 
         Map<String, Object> map = new HashMap<>();
         map.put("method", "control");
+        map.put("deviceUuid", deviceUuid);
         Map<String, Object> map1 = new HashMap<>();
         map1.put("commandCode", commandCode);
         map1.put("commandValue", commandValue);
         map.put("params", map1);
 
-        return remoteTransferService.deviceControl(productCode, deviceUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
+        if(categoryType == 3){
+            return remoteTransferService.deviceControl(productCode, gatewayUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
+        }else{
+            return remoteTransferService.deviceControl(productCode, deviceUuid, JSON.toJSONString(map), tenantId, commandUserId, commandUserName);
+        }
+
     }
 
     @Override
@@ -166,6 +172,8 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         Integer productId = requestVO.getProductId();
         Integer pageNum = requestVO.getPageNum();
         Integer pageSize = requestVO.getPageSize();
+        Integer categoryType = requestVO.getCategoryType();
+
 
         pageNum = (pageNum != null) ? pageNum : 1;
         pageSize = (pageSize != null) ? pageSize : 10;
@@ -182,37 +190,101 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                 throw new BusinessException("设备uuid“deviceUuid“不能为空!");
             }
 
-            DmpTopicResponseVO add = new DmpTopicResponseVO();
-            add.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.ADD_REMARKS.getLetter());
-            add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
-            add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
-            add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
-            responseVOList.add(add);
-
-            DmpTopicResponseVO info = new DmpTopicResponseVO();
-            info.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.INFO_REMARKS.getLetter());
-            info.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
-            info.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
-            info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
-            responseVOList.add(info);
-
-            DmpTopicResponseVO control = new DmpTopicResponseVO();
-            control.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
-            control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
-            control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
-            control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
-            responseVOList.add(control);
-
-            DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
-            controlResponse.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_RESPONSE_REMARKS.getLetter());
-            controlResponse.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
-            controlResponse.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
-            controlResponse.setRemarks(TopicInfo.CONTROL_RESPONSE_REMARKS.getValue());
-            responseVOList.add(controlResponse);
+            if(categoryType == 1){
+                DmpTopicResponseVO add = new DmpTopicResponseVO();
+                add.setTopic("/usky/devices/" + deviceUuid + "/add");
+                add.setPublisher("普通设备");
+                add.setSubscriber("物联网平台");
+                add.setRemarks("添加普通设备");
+                responseVOList.add(add);
+
+                DmpTopicResponseVO info = new DmpTopicResponseVO();
+                info.setTopic("/usky/devices/" + deviceUuid + "/info");
+                info.setPublisher("普通设备");
+                info.setSubscriber("物联网平台");
+                info.setRemarks("普通设备上报数据");
+                responseVOList.add(info);
+
+                DmpTopicResponseVO control = new DmpTopicResponseVO();
+                control.setTopic("/usky/devices/" + deviceUuid + "/control");
+                control.setPublisher("物联网平台");
+                control.setSubscriber("普通设备");
+                control.setRemarks("物联网平台给普通设备下发命令");
+                responseVOList.add(control);
+
+                DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
+                controlResponse.setTopic("/usky/devices/" + deviceUuid + "/controlResponse");
+                controlResponse.setPublisher("普通设备");
+                controlResponse.setSubscriber("物联网平台");
+                controlResponse.setRemarks("普通设备返回给物联网平台的命令响应");
+                responseVOList.add(controlResponse);
+            }else{
+                String gatewayUuid = requestVO.getGatewayUuid();
+                if(categoryType == 2){
+                    gatewayUuid = requestVO.getDeviceUuid();
+                }
+
+                DmpTopicResponseVO add = new DmpTopicResponseVO();
+                add.setTopic("/usky/devices/" + gatewayUuid + "/add");
+                add.setPublisher("网关设备");
+                add.setSubscriber("物联网平台");
+                add.setRemarks("网关设备添加子设备");
+                responseVOList.add(add);
+
+                DmpTopicResponseVO info = new DmpTopicResponseVO();
+                info.setTopic("/usky/devices/" + gatewayUuid + "/info");
+                info.setPublisher("网关设备");
+                info.setSubscriber("物联网平台");
+                info.setRemarks("网关设备上报数据");
+                responseVOList.add(info);
+
+                DmpTopicResponseVO control = new DmpTopicResponseVO();
+                control.setTopic("/usky/devices/" + gatewayUuid + "/control");
+                control.setPublisher("物联网平台");
+                control.setSubscriber("网关设备");
+                control.setRemarks("物联网平台给网关设备下发命令");
+                responseVOList.add(control);
+
+                DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
+                controlResponse.setTopic("/usky/devices/" + gatewayUuid + "/controlResponse");
+                controlResponse.setPublisher("网关设备");
+                controlResponse.setSubscriber("物联网平台");
+                controlResponse.setRemarks("网关设备返回给物联网平台的命令响应");
+                responseVOList.add(controlResponse);
+            }
+
+//            DmpTopicResponseVO add = new DmpTopicResponseVO();
+//            add.setTopic("/usky/devices/" + deviceUuid + "/" + TopicInfo.ADD_REMARKS.getLetter());
+//            add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
+//            add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
+//            add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
+//            responseVOList.add(add);
+//
+//            DmpTopicResponseVO info = new DmpTopicResponseVO();
+//            info.setTopic("/usky/devices/" + deviceUuid + "/" + TopicInfo.INFO_REMARKS.getLetter());
+//            info.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
+//            info.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
+//            info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
+//            responseVOList.add(info);
+//
+//            DmpTopicResponseVO control = new DmpTopicResponseVO();
+//            control.setTopic("/usky/devices/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
+//            control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
+//            control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
+//            control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
+//            responseVOList.add(control);
+//
+//            DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
+//            controlResponse.setTopic("/usky/devices/" + deviceUuid + "/" + TopicInfo.CONTROL_RESPONSE_REMARKS.getLetter());
+//            controlResponse.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
+//            controlResponse.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
+//            controlResponse.setRemarks(TopicInfo.CONTROL_RESPONSE_REMARKS.getValue());
+//            responseVOList.add(controlResponse);
 
         } else {
-            switch (topicType) {
-                case "add":
+            if(categoryType == 1){
+                switch (topicType) {
+                    case "add":
                     /*if (StringUtils.isBlank(productCode)) {
                         throw new BusinessException("产品编码“productCode”不能为空!");
                     } else if (StringUtils.isBlank(deviceId)) {
@@ -241,44 +313,141 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                     String topicPayload = topicPayloadJson.toString();
                     add.setTopicPayload(topicPayload);
                     responseVOList.add(add);*/
-                    break;
-                case "info":
-                    if (StringUtils.isBlank(productCode)) {
+                        break;
+                    case "info":
+                        if (StringUtils.isBlank(productCode)) {
+                            throw new BusinessException("产品编码“productCode”不能为空!");
+                        } else if (productId == null) {
+                            throw new BusinessException("产品ID“productId“不能为空!");
+                        } else if (StringUtils.isBlank(deviceId)) {
+                            throw new BusinessException("设备编号“deviceId”不能为空!");
+                        }
+
+                        DmpTopicResponseVO info = new DmpTopicResponseVO();
+                        info.setTopic("/usky/devices/" + deviceUuid + "/info");
+                        info.setPublisher("普通设备");
+                        info.setSubscriber("物联网平台");
+                        info.setRemarks("普通设备上报数据");
+
+                        // 组装topicPayload
+                        JSONObject infoPayloadJson = new JSONObject();
+                        infoPayloadJson.put("productCode", productCode);
+                        infoPayloadJson.put("deviceUuid", deviceUuid);
+                        Long timestamp = System.currentTimeMillis();
+                        infoPayloadJson.put("timestamp", timestamp);
+
+                        JSONObject metricsJson = new JSONObject();
+                        List<DmpProductAttribute> productAttributeList = getProductAttributeList(productId);
+                        for (DmpProductAttribute productAttribute : productAttributeList) {
+                            metricsJson.put(productAttribute.getAttributeCode(), productAttribute.getMaximum());
+                        }
+                        infoPayloadJson.put("metrics", metricsJson);
+
+                        JSONObject tagsJson = new JSONObject();
+                        tagsJson.put("device_id", deviceId);
+                        infoPayloadJson.put("tags", tagsJson);
+                        String infoPayload = infoPayloadJson.toString();
+                        info.setTopicPayload(infoPayload);
+                        info.setProductAttributeList(productAttributeList);
+                        responseVOList.add(info);
+                        break;
+                    case "control":
+                    /*if (StringUtils.isBlank(deviceUuid)) {
+                        throw new BusinessException("设备uuid“deviceUuid“不能为空!");
+                    }else if (StringUtils.isBlank(productCode)){
+                        throw new BusinessException("产品编码“productCode”不能为空!");
+                    }
+
+                    DmpTopicResponseVO control = new DmpTopicResponseVO();
+                    control.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
+                    control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
+                    control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
+                    control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
+
+                    // 组装topicPayload
+                    JSONObject controlPayloadJson = new JSONObject();
+
+                    responseVOList.add(control);*/
+                        break;
+                    case "controlResponse":
+                        break;
+                    default:
+                        throw new BusinessException("topicType参数错误!");
+                }
+            }else{
+                String gatewayUuid = requestVO.getGatewayUuid();
+                if(categoryType == 2){
+                    gatewayUuid = requestVO.getDeviceUuid();
+                }
+                switch (topicType) {
+                    case "add":
+                    /*if (StringUtils.isBlank(productCode)) {
                         throw new BusinessException("产品编码“productCode”不能为空!");
-                    } else if (productId == null) {
-                        throw new BusinessException("产品ID“productId“不能为空!");
                     } else if (StringUtils.isBlank(deviceId)) {
                         throw new BusinessException("设备编号“deviceId”不能为空!");
+                    } else if (StringUtils.isBlank(deviceName)) {
+                        throw new BusinessException("设备名“deviceName“不能为空!");
                     }
 
-                    DmpTopicResponseVO info = new DmpTopicResponseVO();
-                    info.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.INFO_REMARKS.getLetter());
-                    info.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
-                    info.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
-                    info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
+                    DmpTopicResponseVO add = new DmpTopicResponseVO();
+                    add.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.ADD_REMARKS.getLetter());
+                    add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
+                    add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
+                    add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
 
                     // 组装topicPayload
-                    JSONObject infoPayloadJson = new JSONObject();
-                    infoPayloadJson.put("productCode", productCode);
-                    Long timestamp = System.currentTimeMillis();
-                    infoPayloadJson.put("timestamp", timestamp);
-
-                    JSONObject metricsJson = new JSONObject();
-                    List<DmpProductAttribute> productAttributeList = getProductAttributeList(productId);
-                    for (DmpProductAttribute productAttribute : productAttributeList) {
-                        metricsJson.put(productAttribute.getAttributeCode(), productAttribute.getMaximum());
+                    JSONObject topicPayloadJson = new JSONObject();
+                    topicPayloadJson.put("productCode", productCode);
+                    topicPayloadJson.put("deviceId", deviceId);
+                    topicPayloadJson.put("deviceName", deviceName);
+                    if (!StringUtils.isBlank(simCode)) {
+                        topicPayloadJson.put("simCode", simCode);
+                    }
+                    if (!StringUtils.isBlank(installAddress)) {
+                        topicPayloadJson.put("installAddress", installAddress);
                     }
-                    infoPayloadJson.put("metrics", metricsJson);
-
-                    JSONObject tagsJson = new JSONObject();
-                    tagsJson.put("device_id", deviceId);
-                    infoPayloadJson.put("tags", tagsJson);
-                    String infoPayload = infoPayloadJson.toString();
-                    info.setTopicPayload(infoPayload);
-                    info.setProductAttributeList(productAttributeList);
-                    responseVOList.add(info);
-                    break;
-                case "control":
+                    String topicPayload = topicPayloadJson.toString();
+                    add.setTopicPayload(topicPayload);
+                    responseVOList.add(add);*/
+                        break;
+                    case "info":
+                        if (StringUtils.isBlank(productCode)) {
+                            throw new BusinessException("产品编码“productCode”不能为空!");
+                        } else if (productId == null) {
+                            throw new BusinessException("产品ID“productId“不能为空!");
+                        } else if (StringUtils.isBlank(deviceId)) {
+                            throw new BusinessException("设备编号“deviceId”不能为空!");
+                        }
+
+                        DmpTopicResponseVO info = new DmpTopicResponseVO();
+                        info.setTopic("/usky/devices/" + gatewayUuid + "/info");
+                        info.setPublisher("网关设备");
+                        info.setSubscriber("物联网平台");
+                        info.setRemarks("网关设备上报数据");
+
+                        // 组装topicPayload
+                        JSONObject infoPayloadJson = new JSONObject();
+                        infoPayloadJson.put("productCode", productCode);
+                        infoPayloadJson.put("deviceUuid", deviceUuid);
+                        Long timestamp = System.currentTimeMillis();
+                        infoPayloadJson.put("timestamp", timestamp);
+
+                        JSONObject metricsJson = new JSONObject();
+                        List<DmpProductAttribute> productAttributeList = getProductAttributeList(productId);
+                        for (DmpProductAttribute productAttribute : productAttributeList) {
+                            metricsJson.put(productAttribute.getAttributeCode(), productAttribute.getMaximum());
+                        }
+                        infoPayloadJson.put("metrics", metricsJson);
+
+                        JSONObject tagsJson = new JSONObject();
+                        tagsJson.put("device_id", deviceId);
+                        infoPayloadJson.put("tags", tagsJson);
+                        String infoPayload = infoPayloadJson.toString();
+                        info.setTopicPayload(infoPayload);
+                        info.setProductAttributeList(productAttributeList);
+                        responseVOList.add(info);
+                        break;
+                    case "control":
                     /*if (StringUtils.isBlank(deviceUuid)) {
                         throw new BusinessException("设备uuid“deviceUuid“不能为空!");
                     }else if (StringUtils.isBlank(productCode)){
@@ -295,11 +464,12 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                     JSONObject controlPayloadJson = new JSONObject();
 
                     responseVOList.add(control);*/
-                    break;
-                case "controlResponse":
-                    break;
-                default:
-                    throw new BusinessException("topicType参数错误!");
+                        break;
+                    case "controlResponse":
+                        break;
+                    default:
+                        throw new BusinessException("topicType参数错误!");
+                }
             }
         }
 
@@ -369,7 +539,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
             dmpDeviceInfo.setCreatedBy(SecurityUtils.getUsername());
             dmpDeviceInfo.setCreatedTime(LocalDateTime.now());
             dmpDeviceInfo.setTenantId(SecurityUtils.getTenantId());
-//            dmpDeviceInfo.setServiceStatus(1);
+            dmpDeviceInfo.setServiceStatus(1);
             if (StringUtils.isBlank(dmpDeviceInfo.getDeviceUuid())) {
                 dmpDeviceInfo.setDeviceUuid(UUIDUtils.uuid());
             }
@@ -473,7 +643,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         IPage<DmpDeviceInfo> page = new Page<>(pageCurrent, pageSize);
 
         if (diRequest.getDeviceStatus() != null) {
-            if (StringUtils.isNotBlank(diRequest.getDeviceId()) || StringUtils.isNotBlank(diRequest.getDeviceUuid()) || StringUtils.isNotBlank(diRequest.getDeviceName()) || diRequest.getProductId() != null || StringUtils.isNotBlank(diRequest.getProductCode()) || diRequest.getServiceStatus() != null) {
+            if (StringUtils.isNotBlank(diRequest.getDeviceId()) || StringUtils.isNotBlank(diRequest.getDeviceUuid()) || StringUtils.isNotBlank(diRequest.getDeviceName()) || diRequest.getProductId() != null || StringUtils.isNotBlank(diRequest.getProductCode()) || diRequest.getServiceStatus() != null || diRequest.getCategoryType() != null) {
                 LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
                 queryWrapper.eq(StringUtils.isNotBlank(diRequest.getDeviceId()), DmpDeviceInfo::getDeviceId, diRequest.getDeviceId())
                         .eq(StringUtils.isNotBlank(diRequest.getDeviceUuid()), DmpDeviceInfo::getDeviceUuid, diRequest.getDeviceUuid())
@@ -481,6 +651,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                         .eq(diRequest.getProductId() != null, DmpDeviceInfo::getProductId, diRequest.getProductId())
                         .like(StringUtils.isNotBlank(diRequest.getProductCode()), DmpDeviceInfo::getProductCode, diRequest.getProductCode())
                         .eq(diRequest.getServiceStatus() != null, DmpDeviceInfo::getServiceStatus, diRequest.getServiceStatus())
+                        .eq(diRequest.getCategoryType() != null, DmpDeviceInfo::getCategoryType, diRequest.getCategoryType())
                         .eq(DmpDeviceInfo::getDeleteFlag, 0)
                         .eq(DmpDeviceInfo::getTenantId, SecurityUtils.getTenantId())
                         .orderByDesc(DmpDeviceInfo::getId);
@@ -591,6 +762,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                     .eq(diRequest.getProductId() != null, DmpDeviceInfo::getProductId, diRequest.getProductId())
                     .like(StringUtils.isNotBlank(diRequest.getProductCode()), DmpDeviceInfo::getProductCode, diRequest.getProductCode())
                     .eq(diRequest.getServiceStatus() != null, DmpDeviceInfo::getServiceStatus, diRequest.getServiceStatus())
+                    .eq(diRequest.getCategoryType() != null, DmpDeviceInfo::getCategoryType, diRequest.getCategoryType())
                     .eq(DmpDeviceInfo::getDeleteFlag, 0)
                     .eq(DmpDeviceInfo::getTenantId, SecurityUtils.getTenantId());
 
@@ -668,13 +840,14 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         }
 
         if (diRequest.getDeviceStatus() != null) {
-            if (StringUtils.isNotBlank(diRequest.getDeviceId()) || StringUtils.isNotBlank(diRequest.getDeviceName()) || diRequest.getProductId() != null || StringUtils.isNotBlank(diRequest.getProductCode()) || diRequest.getServiceStatus() != null) {
+            if (StringUtils.isNotBlank(diRequest.getDeviceId()) || StringUtils.isNotBlank(diRequest.getDeviceName()) || diRequest.getProductId() != null || StringUtils.isNotBlank(diRequest.getProductCode()) || diRequest.getServiceStatus() != null || diRequest.getCategoryType() != null) {
                 LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
                 queryWrapper.eq(StringUtils.isNotBlank(diRequest.getDeviceId()), DmpDeviceInfo::getDeviceId, diRequest.getDeviceId())
                         .like(StringUtils.isNotBlank(diRequest.getDeviceName()), DmpDeviceInfo::getDeviceName, diRequest.getDeviceName())
                         .eq(diRequest.getProductId() != null, DmpDeviceInfo::getProductId, diRequest.getProductId())
                         .like(StringUtils.isNotBlank(diRequest.getProductCode()), DmpDeviceInfo::getProductCode, diRequest.getProductCode())
                         .eq(diRequest.getServiceStatus() != null, DmpDeviceInfo::getServiceStatus, diRequest.getServiceStatus())
+                        .eq(diRequest.getCategoryType() != null, DmpDeviceInfo::getCategoryType, diRequest.getCategoryType())
                         .eq(DmpDeviceInfo::getDeleteFlag, 0)
                         .eq(DmpDeviceInfo::getTenantId, tenantId)
                         .orderByDesc(DmpDeviceInfo::getId);
@@ -784,6 +957,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
                     .eq(diRequest.getProductId() != null, DmpDeviceInfo::getProductId, diRequest.getProductId())
                     .like(StringUtils.isNotBlank(diRequest.getProductCode()), DmpDeviceInfo::getProductCode, diRequest.getProductCode())
                     .eq(diRequest.getServiceStatus() != null, DmpDeviceInfo::getServiceStatus, diRequest.getServiceStatus())
+                    .eq(diRequest.getCategoryType() != null, DmpDeviceInfo::getCategoryType, diRequest.getCategoryType())
                     .eq(DmpDeviceInfo::getDeleteFlag, 0)
                     .eq(DmpDeviceInfo::getTenantId, tenantId)
                     .orderByDesc(DmpDeviceInfo::getId);
@@ -825,6 +999,18 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
         return new CommonPage<>(page.getRecords(), page.getTotal(), pageSize, pageCurrent);
     }
 
+    @Override
+    public List<DmpDeviceInfo> gatewayDeviceList(){
+        LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(DmpDeviceInfo::getCategoryType,2)
+                .eq(DmpDeviceInfo::getDeleteFlag, 0)
+                .eq(DmpDeviceInfo::getTenantId, SecurityUtils.getTenantId())
+                .orderByDesc(DmpDeviceInfo::getId);
+        List<DmpDeviceInfo> list1 = this.list(queryWrapper);
+
+        return list1;
+    }
+
     @Override
     public boolean remove(Integer id) {
         DmpDeviceInfo dmpDeviceInfo = this.getById(id);

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

@@ -125,6 +125,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
                             dmpProductAttribute.setAttributeUnit(attribute_unit);
                             dmpProductAttribute.setMaximum(BigDecimal.valueOf(maximum));
                             dmpProductAttribute.setMinimum(BigDecimal.valueOf(minimum));
+                            if(!(obj.getString("attribute_dict")).equals("")){
+                                dmpProductAttribute.setAttributeDict(obj.getString("attribute_dict"));
+                            }
                             dmpProductAttribute.setDeleteFlag(0);
                             dmpProductAttribute.setCreatedBy(SecurityUtils.getUsername());
                             dmpProductAttribute.setCreatedTime(new Date());

+ 20 - 2
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/DeviceImportVo.java

@@ -1,8 +1,12 @@
 package com.usky.iot.service.vo;
 
-import cn.afterturn.easypoi.excel.annotation.Excel;
 
+import cn.afterturn.easypoi.excel.annotation.Excel;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
 
 /**
  * <p>
@@ -13,7 +17,9 @@ import lombok.Data;
  * @since 2023-07-27
  */
 @Data
-public class DeviceImportVo{
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class DeviceImportVo implements Serializable {
     /**
      * 系统编号(必填)
      */
@@ -43,4 +49,16 @@ public class DeviceImportVo{
     @Excel(name = "安装位置描述(必填)")
     private String installAddress;
 
+    /**
+     * 设备所属类型(1、普通设备  2、网关设备  3、网关子设备)
+     */
+    @Excel(name = "设备所属类型(必填)",replace = {"普通设备_1", "网关设备_2", "网关子设备_3"})
+    private Integer categoryType;
+
+    /**
+     * 所属网关
+     */
+    @Excel(name = "所属网关")
+    private String gatewayUuid;
+
 }

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

@@ -56,4 +56,9 @@ public class DmpDeviceInfoRequest {
      */
     private String deviceUuid;
 
+    /**
+     * 设备所属类型(1、普通设备  2、网关设备  3、网关子设备)
+     */
+    private Integer categoryType;
+
 }

+ 10 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/DmpTopicRequestVO.java

@@ -76,4 +76,14 @@ public class DmpTopicRequestVO {
      **/
     private Integer pageSize;
 
+    /**
+     * 设备所属类型(1、普通设备  2、网关设备  3、网关子设备)
+     */
+    private Integer categoryType;
+
+    /**
+     * 所属网关
+     */
+    private String gatewayUuid;
+
 }