TRX 1 год назад
Родитель
Сommit
764938af08

+ 0 - 3
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoAddParam.java

@@ -52,9 +52,6 @@ public class DeviceInfoAddParam extends SuperParam {
     @Schema(description = "连接参数")
     @Schema(description = "连接参数")
     private JSONObject connectParam;
     private JSONObject connectParam;
 
 
-    @Schema(description = "设备类型")
-    private String deviceCate;
-
     @Schema(description = "心跳间隔,单位:秒")
     @Schema(description = "心跳间隔,单位:秒")
     private Long hbInterval = 30l;
     private Long hbInterval = 30l;
 }
 }

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotTemplate.java

@@ -1,9 +1,9 @@
 package com.zhongshu.iot.server.core.domain.iot;
 package com.zhongshu.iot.server.core.domain.iot;
 
 
+import com.github.microservice.types.common.DataState;
 import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.github.microservice.types.deviceUse.DeviceSpecType;
 import com.github.microservice.types.deviceUse.DeviceSpecType;
 import com.github.microservice.types.deviceUse.DeviceType;
 import com.github.microservice.types.deviceUse.DeviceType;
-import com.github.microservice.types.common.DataState;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.media.Schema;

+ 7 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java

@@ -345,7 +345,12 @@ public class OperationMessageService {
             // 业务处理的消息内容
             // 业务处理的消息内容
             JSONObject requestData = (JSONObject) json.get("data");
             JSONObject requestData = (JSONObject) json.get("data");
             requestData.set("mqttDataId", entity.getDataId());
             requestData.set("mqttDataId", entity.getDataId());
-            requestData.set("gateWayId", entity.getGateWayId());
+
+            String gateWayId = requestData.getStr("gateWayId");
+            if (StringUtils.isEmpty(gateWayId)) {
+                gateWayId = entity.getGateWayId();
+                requestData.set("gateWayId", gateWayId);
+            }
             String DeviceId = requestData.getStr("deviceId");
             String DeviceId = requestData.getStr("deviceId");
             if (StringUtils.isEmpty(DeviceId)) {
             if (StringUtils.isEmpty(DeviceId)) {
                 DeviceId = entity.getDeviceId();
                 DeviceId = entity.getDeviceId();
@@ -428,6 +433,7 @@ public class OperationMessageService {
             } else {
             } else {
                 isHandleSuccess = false;
                 isHandleSuccess = false;
                 handleMsg = "消息处理方法未找到";
                 handleMsg = "消息处理方法未找到";
+                log.error("消息处理方法未找到: {}", event);
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();

+ 5 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/base/CommonService.java

@@ -54,7 +54,11 @@ public class CommonService {
         Criteria criteria = new Criteria();
         Criteria criteria = new Criteria();
         if (where != null) {
         if (where != null) {
             where.forEach((key, value) -> {
             where.forEach((key, value) -> {
-                criteria.and(key).is(value);
+                if ("id".equals(key)) {
+                    criteria.and("_id").is(value);
+                } else {
+                    criteria.and(key).is(value);
+                }
             });
             });
         }
         }
         Query query = new Query(criteria);
         Query query = new Query(criteria);

+ 8 - 5
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -1,12 +1,12 @@
 package com.zhongshu.iot.server.core.service.device;
 package com.zhongshu.iot.server.core.service.device;
 
 
+import com.github.microservice.busInfoModel.device.DeviceInfoModel;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.types.deviceUse.DeviceState;
 import com.github.microservice.types.deviceUse.DeviceState;
 import com.github.microservice.types.deviceUse.OnLineState;
 import com.github.microservice.types.deviceUse.OnLineState;
 import com.zhongshu.iot.client.model.iot.IotMainModel;
 import com.zhongshu.iot.client.model.iot.IotMainModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
-import com.github.microservice.busInfoModel.device.DeviceInfoModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoUpdateRemark;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoUpdateRemark;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.IotDataType;
@@ -100,6 +100,8 @@ public class DeviceInfoService {
             // 编辑
             // 编辑
             deviceInfo = temp;
             deviceInfo = temp;
             param.setId(null);
             param.setId(null);
+
+            // 如果已删除的
             if (deviceInfo.getIsDelete() != null && deviceInfo.getIsDelete()) {
             if (deviceInfo.getIsDelete() != null && deviceInfo.getIsDelete()) {
                 deviceInfo.setIsDelete(Boolean.FALSE);
                 deviceInfo.setIsDelete(Boolean.FALSE);
                 deviceInfo.setState(DeviceState.Enable);
                 deviceInfo.setState(DeviceState.Enable);
@@ -111,6 +113,7 @@ public class DeviceInfoService {
         }
         }
         BeanUtils.copyProperties(param, deviceInfo, "id");
         BeanUtils.copyProperties(param, deviceInfo, "id");
 
 
+        // 最近的上线时间
         deviceInfo.setLastOnlineTime(System.currentTimeMillis());
         deviceInfo.setLastOnlineTime(System.currentTimeMillis());
         deviceInfo.setLastOnlineTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         deviceInfo.setLastOnlineTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         deviceInfo.setOnLineState(OnLineState.OnLine);
         deviceInfo.setOnLineState(OnLineState.OnLine);
@@ -141,7 +144,7 @@ public class DeviceInfoService {
             // 日志
             // 日志
             operationLogsService.addLogs(String.format("添加了设备;%s", finalDeviceInfo.getDeviceName()), LogsLevel.Middle, finalDeviceInfo);
             operationLogsService.addLogs(String.format("添加了设备;%s", finalDeviceInfo.getDeviceName()), LogsLevel.Middle, finalDeviceInfo);
 
 
-            // 新账号的绑定设备数量
+            // 新账号的绑定设备数量
             gateWayUserInfoService.updateBindNumber(finalDeviceInfo.getMqttUserName());
             gateWayUserInfoService.updateBindNumber(finalDeviceInfo.getMqttUserName());
 
 
             // 同步设备权限
             // 同步设备权限
@@ -403,7 +406,7 @@ public class DeviceInfoService {
         if (StringUtils.isNotEmpty(deviceId)) {
         if (StringUtils.isNotEmpty(deviceId)) {
             deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
             deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         }
         }
-        return deviceCanUse(deviceInfo);
+        return deviceCanUse(deviceInfo, deviceId);
     }
     }
 
 
     /**
     /**
@@ -412,9 +415,9 @@ public class DeviceInfoService {
      * @param deviceInfo
      * @param deviceInfo
      * @return
      * @return
      */
      */
-    public ResultContent deviceCanUse(DeviceInfo deviceInfo) {
+    public ResultContent deviceCanUse(DeviceInfo deviceInfo, String deviceId) {
         if (ObjectUtils.isEmpty(deviceInfo)) {
         if (ObjectUtils.isEmpty(deviceInfo)) {
-            return ResultContent.buildFail("设备未找到");
+            return ResultContent.buildFail(String.format("设备未找到:%s", deviceId));
         }
         }
         if (deviceInfo.getState() != DeviceState.Enable) {
         if (deviceInfo.getState() != DeviceState.Enable) {
             return ResultContent.buildFail(String.format("设备状态不可用:%s", deviceInfo.getState().getRemark()));
             return ResultContent.buildFail(String.format("设备状态不可用:%s", deviceInfo.getState().getRemark()));

+ 13 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayManagerService.java

@@ -145,7 +145,7 @@ public class GateWayManagerService extends SuperService {
     public ResultContent<DeviceInfo> addDevice(DeviceInfoRegistParam param) {
     public ResultContent<DeviceInfo> addDevice(DeviceInfoRegistParam param) {
         // 产品code
         // 产品code
         if (StringUtils.isEmpty(param.getProductCode())) {
         if (StringUtils.isEmpty(param.getProductCode())) {
-            return ResultContent.buildFail("productCode不能为空");
+            return ResultContent.buildFail("productCode 不能为空");
         }
         }
         // 设备deviceId
         // 设备deviceId
         if (StringUtils.isEmpty(param.getDeviceId())) {
         if (StringUtils.isEmpty(param.getDeviceId())) {
@@ -171,7 +171,17 @@ public class GateWayManagerService extends SuperService {
         // 检查产品是否存在
         // 检查产品是否存在
         IotTemplate iotTemplate = iotTemplateDao.findTopByProductCodeAndIotDataType(param.getProductCode(), IotDataType.IotTemplate);
         IotTemplate iotTemplate = iotTemplateDao.findTopByProductCodeAndIotDataType(param.getProductCode(), IotDataType.IotTemplate);
         if (ObjectUtils.isEmpty(iotTemplate)) {
         if (ObjectUtils.isEmpty(iotTemplate)) {
-            return ResultContent.buildFail(String.format("productCode不存在", param.getProductCode()));
+            return ResultContent.buildFail(String.format("productCode不存在:%s", param.getProductCode()));
+        }
+        if (iotTemplate.getDeviceCategory() == null) {
+            return ResultContent.buildFail(String.format("产品信息不全 deviceCategory"));
+        }
+
+        if (iotTemplate.getDeviceType() == null) {
+            return ResultContent.buildFail(String.format("产品信息不全 deviceType"));
+        }
+        if (iotTemplate.getDeviceCategory() == DeviceCategory.DE && StringUtils.isEmpty(param.getGateWayId())) {
+            return ResultContent.buildFail("gateWayId不能为空");
         }
         }
 
 
         // 检查分组是否存在
         // 检查分组是否存在
@@ -184,7 +194,7 @@ public class GateWayManagerService extends SuperService {
         DeviceInfo gateWayInfo;
         DeviceInfo gateWayInfo;
         if (StringUtils.isNotEmpty(param.getGateWayId())) {
         if (StringUtils.isNotEmpty(param.getGateWayId())) {
             gateWayInfo = deviceInfoDao.findTopByDeviceId(param.getGateWayId());
             gateWayInfo = deviceInfoDao.findTopByDeviceId(param.getGateWayId());
-            ResultContent resultContent = deviceInfoService.deviceCanUse(gateWayInfo);
+            ResultContent resultContent = deviceInfoService.deviceCanUse(gateWayInfo, param.getGateWayId());
             if (resultContent.isFailed()) {
             if (resultContent.isFailed()) {
                 return ResultContent.buildFail(resultContent.getMsg());
                 return ResultContent.buildFail(resultContent.getMsg());
             }
             }

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayUserInfoService.java

@@ -341,6 +341,7 @@ public class GateWayUserInfoService extends SuperService {
      * @return
      * @return
      */
      */
     public ResultContent updateBindNumber(GateWayUserInfo entity) {
     public ResultContent updateBindNumber(GateWayUserInfo entity) {
+        log.info("updateBindNumber: {}", entity.getUserName());
         if (ObjectUtils.isNotEmpty(entity)) {
         if (ObjectUtils.isNotEmpty(entity)) {
             // 网关数量
             // 网关数量
             long gatewayNumber = deviceInfoDao.countByMqttUserNameAndIsDeleteAndDeviceCategory(entity.getUserName(), Boolean.FALSE, DeviceCategory.GW);
             long gatewayNumber = deviceInfoDao.countByMqttUserNameAndIsDeleteAndDeviceCategory(entity.getUserName(), Boolean.FALSE, DeviceCategory.GW);

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotTemplateManagerService.java

@@ -94,7 +94,7 @@ public class IotTemplateManagerService extends SuperService {
             projectInfoCode = iotThing.getProjectCode();
             projectInfoCode = iotThing.getProjectCode();
         }
         }
         // 所属产品信息
         // 所属产品信息
-        IotTemplate iotTemplate = iotTemplateDao.findTopById(iotThing.getIotTemplateId());
+        IotTemplate iotTemplate = iotTemplateDao.findTopByProductCodeAndIotDataType(iotThing.getProductCode(), IotDataType.IotTemplate);
         return deviceBindAutoIotTemplate(iotTemplate, deviceInfo, iotThing.getId(), projectInfoCode);
         return deviceBindAutoIotTemplate(iotTemplate, deviceInfo, iotThing.getId(), projectInfoCode);
     }
     }
 
 

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThingService.java

@@ -124,6 +124,7 @@ public class IotThingService extends SuperService {
             iotThing2DeviceService.bindDevice(iotThing, deviceInfo);
             iotThing2DeviceService.bindDevice(iotThing, deviceInfo);
             // 更新物模型 对应的设备数量
             // 更新物模型 对应的设备数量
             updateThingDeviceCount(iotThing);
             updateThingDeviceCount(iotThing);
+
             // 绑定物模型属性信息
             // 绑定物模型属性信息
             iotTemplateManagerService.deviceBindIotTemplate(iotThing, deviceInfo);
             iotTemplateManagerService.deviceBindIotTemplate(iotThing, deviceInfo);
         }
         }