TRX 1 tahun lalu
induk
melakukan
7ce0066750

+ 6 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/IotMainDao.java

@@ -18,6 +18,8 @@ public interface IotMainDao extends IotMainDaoExtend, org.springframework.data.m
 
     IotMain findTopByNameAndIotTemplate(String name, IotTemplate iotTemplate);
 
+    IotMain findTopByIdentifierAndIotTemplate(String identifier, IotTemplate iotTemplate);
+
     IotMain findTopByIotTopicAndIotTemplate(String iotTopic, IotTemplate iotTemplate);
 
     List<IotMain> findByIotTemplateOrderByCreateTimeAsc(IotTemplate iotTemplate);
@@ -28,4 +30,8 @@ public interface IotMainDao extends IotMainDaoExtend, org.springframework.data.m
 
     List<IotMain> findByDeviceIdAndIdentifierAndIotDataType(String deviceId, String identifier, IotDataType iotData);
 
+    List<IotMain> findByDeviceIdAndIdentifierAndIotDataTypeAndFunctionType(String deviceId, String identifier, IotDataType iotDataType, FunctionType functionType);
+
+    void deleteByIotTemplate(IotTemplate iotTemplate);
+
 }

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

@@ -32,7 +32,7 @@ public class IotMain extends SuperEntity {
     // ------------------------iotMain 基础字段 start-----------------------
 
     @Schema(description = "功能类型,属性 事件 服务")
-    FunctionType functionType;
+    private FunctionType functionType;
 
     @Schema(description = "功能名称")
     private String name;

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

@@ -37,7 +37,7 @@ public class IotTemplate extends SuperEntity {
     @Schema(description = "所属分组code")
     private String projectCode;
 
-    @Schema(description = "物模型所属模版ID,就是管理设备时绑定的那个模版")
+    @Schema(description = "物模型所属模版ID,就是管理设备时绑定的模版")
     private String iotTemplateId;
 
     public static IotTemplate build(String id) {

+ 11 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotSendMessageService.java

@@ -2,6 +2,7 @@ package com.zhongshu.iot.server.core.service.iot;
 
 import cn.hutool.json.JSONObject;
 import com.github.microservice.models.iot.IotSendParam;
+import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.OperationType;
 import com.zhongshu.iot.server.core.dao.iot.IotMainDao;
@@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -70,8 +72,15 @@ public class IotSendMessageService extends SuperService {
         if (ObjectUtils.isEmpty(deviceInfo)) {
             return ResultContent.buildFail(String.format("设备不存在:%S", param.getDeviceId()));
         }
-        List<IotMain> list = iotMainDao.findByDeviceIdAndIdentifierAndIotDataType(
-                param.getDeviceId(), param.getIdentifier(), IotDataType.Device);
+        FunctionType functionType = param.getFunctionType();
+        List<IotMain> list = new ArrayList<>();
+        if (functionType != null) {
+            list = iotMainDao.findByDeviceIdAndIdentifierAndIotDataTypeAndFunctionType(
+                    param.getDeviceId(), param.getIdentifier(), IotDataType.Device, functionType);
+        } else {
+            list = iotMainDao.findByDeviceIdAndIdentifierAndIotDataType(
+                    param.getDeviceId(), param.getIdentifier(), IotDataType.Device);
+        }
 
         if (ObjectUtils.isEmpty(list)) {
             log.error("设备没有对应的物模型 {} {}", param.getDeviceId(), param.getIdentifier());

+ 13 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -105,12 +105,17 @@ public class IotServiceImpl extends SuperService {
      * @param id
      * @return
      */
+    @Transactional
     public ResultContent deleteTemplate(String id) {
         IotTemplate template = iotTemplateDao.findTopById(id);
         if (ObjectUtils.isEmpty(template)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
         }
         iotTemplateDao.delete(template);
+
+        // 删除对应的  物模型 数据
+        iotMainDao.deleteByIotTemplate(template);
+
         return ResultContent.buildSuccess();
     }
 
@@ -338,6 +343,8 @@ public class IotServiceImpl extends SuperService {
         // 判断名称是否重复
         IotMain nameTemp = iotMainDao.findTopByNameAndIotTemplate(param.getName(), iotTemplate);
         IotMain topicTemp = iotMainDao.findTopByIotTopicAndIotTemplate(param.getIotTopic(), iotTemplate);
+        IotMain identifierTemp = iotMainDao.findTopByIdentifierAndIotTemplate(param.getIdentifier(), iotTemplate);
+
         if (StringUtils.isNotEmpty(param.getId())) {
             entity = iotMainDao.findTopById(param.getId());
             if (ObjectUtils.isEmpty(entity)) {
@@ -349,6 +356,9 @@ public class IotServiceImpl extends SuperService {
             if (ObjectUtils.isNotEmpty(topicTemp) && !topicTemp.getId().equals(param.getId())) {
                 return ResultContent.buildFail(String.format("iotTopic已存在:%s", param.getIotTopic()));
             }
+            if (ObjectUtils.isNotEmpty(identifierTemp) && !identifierTemp.getId().equals(param.getId())) {
+                return ResultContent.buildFail(String.format("identifier已存在:%s", param.getIdentifier()));
+            }
         } else {
             entity = new IotMain();
             initEntity(entity);
@@ -358,6 +368,9 @@ public class IotServiceImpl extends SuperService {
             if (ObjectUtils.isNotEmpty(topicTemp)) {
                 return ResultContent.buildFail(String.format("iotTopic已存在:%s", param.getIotTopic()));
             }
+            if (ObjectUtils.isNotEmpty(identifierTemp)) {
+                return ResultContent.buildFail(String.format("identifier已存在:%s", param.getIdentifier()));
+            }
         }
 
         BeanUtils.copyProperties(param, entity);