Browse Source

更新!

TRX 1 năm trước cách đây
mục cha
commit
84120fdb2c
21 tập tin đã thay đổi với 310 bổ sung140 xóa
  1. 0 9
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/baseParam/SuperParam.java
  2. 2 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainAttributeModel.java
  3. 7 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainModel.java
  4. 13 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainParam.java
  5. 4 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainSearch.java
  6. 1 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotTemplateParam.java
  7. 4 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/thing/IotThingSearch.java
  8. 3 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoSearchParam.java
  9. 24 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/DeviceController.java
  10. 57 54
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotController.java
  11. 1 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotTemplate2DeviceController.java
  12. 3 3
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/IotMainDao.java
  13. 5 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/impl/IotMainDaoImpl.java
  14. 9 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/impl/IotThingDaoImpl.java
  15. 3 2
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/DeviceInfoDaoImpl.java
  16. 9 5
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotMain.java
  17. 0 6
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/base/SuperService.java
  18. 91 53
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java
  19. 9 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotTemplateManagerService.java
  20. 10 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThingService.java
  21. 55 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThingSyncService.java

+ 0 - 9
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/baseParam/SuperParam.java

@@ -23,13 +23,4 @@ public class SuperParam implements Serializable {
 
     @Schema(description = "备注")
     private String remark;
-
-    @Schema(description = "创建用户ID", hidden = true)
-    private String createUserId;
-
-    @Schema(description = "添加用户名称", hidden = true)
-    private String createUserName;
-
-    @Schema(description = "添加用户电话", hidden = true)
-    private String createPhone;
 }

+ 2 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainAttributeModel.java

@@ -17,5 +17,6 @@ import lombok.NoArgsConstructor;
 public class IotMainAttributeModel extends IotMainModel {
 
     @Schema(description = "属性的值")
-    IotDeviceDataModel deviceData;
+    private IotDeviceDataModel deviceData;
+
 }

+ 7 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainModel.java

@@ -23,6 +23,12 @@ import java.util.List;
 @NoArgsConstructor
 public class IotMainModel extends SuperModel {
 
+    @Schema(description = "所属物模型id")
+    private String iotThingId;
+
+    @Schema(description = "关联code,产品code")
+    private String productCode;
+
     @Schema(description = "功能名称")
     private String name;
 
@@ -30,7 +36,7 @@ public class IotMainModel extends SuperModel {
     private String identifier;
 
     @Schema(description = "功能类型,属性 事件 服务")
-    FunctionType functionType;
+    private FunctionType functionType;
 
     @Schema(description = "物模型Topic")
     private String iotTopic;

+ 13 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainParam.java

@@ -4,6 +4,7 @@ import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.model.baseParam.SuperParam;
 import com.zhongshu.iot.client.type.DataType;
 import com.zhongshu.iot.client.type.EventType;
+import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.RemoteUrlType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -22,9 +23,20 @@ import java.util.List;
 @NoArgsConstructor
 public class IotMainParam extends SuperParam {
 
-    @Schema(description = "模版或无模型ID")
+    @Schema(description = "产品ID或副本id")
     private String iotTemplateId;
 
+    @Schema(description = "物模型id")
+    private String iotThingId;
+
+    @Schema(description = "区分是模版还是设备关联的物模型")
+    private IotDataType iotDataType;
+
+    @Schema(description = "设备id")
+    private String deviceId;
+
+    //---------------------------正式业务属性 start--------------
+
     @Schema(description = "功能名称", required = true)
     private String name;
 

+ 4 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainSearch.java

@@ -43,6 +43,9 @@ public class IotMainSearch extends SuperSearchParam {
     @Schema(description = "模版ID")
     private String iotTemplateId;
 
+    @Schema(description = "物模型")
+    private String iotThingId;
+
     @Schema(description = "搜索关键字")
     private String keyWord;
 
@@ -51,4 +54,5 @@ public class IotMainSearch extends SuperSearchParam {
 
     @Schema(description = "业务地址类型")
     private RemoteUrlType remoteUrlType;
+
 }

+ 1 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotTemplateParam.java

@@ -19,7 +19,7 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 public class IotTemplateParam extends SuperParam {
 
-    @Schema(description = "模版名称")
+    @Schema(description = "产品名称")
     private String name;
 
     @Schema(description = "产品品类,直连设备、网关子设备、网关设备")

+ 4 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/thing/IotThingSearch.java

@@ -38,4 +38,8 @@ public class IotThingSearch extends SuperSearchParam {
     @Schema(description = "修改时间")
     private List<Long> updateTimes;
 
+    private Long startUpdateTime;
+
+    private Long endUpdateTime;
+
 }

+ 3 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoSearchParam.java

@@ -8,6 +8,8 @@ import com.zhongshu.iot.client.model.baseParam.SuperSearchParam;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.util.List;
+
 /**
  * @author TRX
  * @date 2024/5/16
@@ -34,5 +36,5 @@ public class DeviceInfoSearchParam extends SuperSearchParam {
     private OnLineState onLineState;
 
     @Schema(description = "区分是网关还是设备")
-    private DeviceCategory deviceCategory = DeviceCategory.DE;
+    private List<DeviceCategory> deviceCategorys = List.of(DeviceCategory.DE);
 }

+ 24 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/DeviceController.java

@@ -4,6 +4,7 @@ import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
+import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.zhongshu.iot.client.model.iot.IotMainModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoModel;
@@ -48,10 +49,32 @@ public class DeviceController {
         return deviceInfoService.addDeviceInfo(param);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "设备列表(所有的)-分页查询")
+    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceInfoModel>> page(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceInfoSearchParam param) {
+        return deviceInfoService.pageDevice(pageable, param);
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "设备列表-分页查询")
     @RequestMapping(value = {"pageActivity"}, method = {RequestMethod.POST})
-    public ResultContent<Page<DeviceInfoModel>> pageActivity(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceInfoSearchParam param) {
+    public ResultContent<Page<DeviceInfoModel>> pageActivity(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceInfoSearchParam param) {
+        param.setDeviceCategorys(List.of(DeviceCategory.DE));
+        return deviceInfoService.pageDevice(pageable, param);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "网关列表-分页查询")
+    @RequestMapping(value = {"pageGateWay"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceInfoModel>> pageGateWay(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceInfoSearchParam param) {
+        param.setDeviceCategorys(List.of(DeviceCategory.GW));
         return deviceInfoService.pageDevice(pageable, param);
     }
 

+ 57 - 54
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotController.java

@@ -6,6 +6,7 @@ import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.client.model.baseParam.NameModel;
 import com.zhongshu.iot.client.model.iot.*;
 import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
+import com.zhongshu.iot.server.core.service.iot.IotTemplateManagerService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -32,11 +33,14 @@ import java.util.List;
 public class IotController {
 
     @Autowired
-    IotServiceImpl iotService;
+    private IotServiceImpl iotService;
 
-    //-------------------------- 模版 start------------------------------
+    @Autowired
+    private IotTemplateManagerService iotTemplateManagerService;
+
+    //-------------------------- 产品 start------------------------------
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "添加-编辑模版")
+    @Operation(summary = "添加-编辑产品")
     @RequestMapping(value = "addIotTemplate", method = {RequestMethod.POST})
     public ResultContent addIotTemplate(@RequestBody IotTemplateParam param) {
         Assert.hasText(param.getName(), "name不能为空");
@@ -44,7 +48,7 @@ public class IotController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "模版列表-分页查询")
+    @Operation(summary = "产品列表-分页查询")
     @RequestMapping(value = {"pageTemplate"}, method = {RequestMethod.POST})
     public ResultContent<Page<IotTemplateModel>> pageTemplate(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
             @Parameter(required = false) IotTemplateSearch param) {
@@ -52,7 +56,7 @@ public class IotController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除模版")
+    @Operation(summary = "删除产品")
     @RequestMapping(value = "deleteTemplate", method = {RequestMethod.GET})
     public ResultContent deleteTemplate(
             @RequestParam(name = "id") @Parameter(name = "id", description = "数据id") String id) {
@@ -60,7 +64,7 @@ public class IotController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "查询模版详情")
+    @Operation(summary = "查询产品详情")
     @RequestMapping(value = "getIotTemplate", method = {RequestMethod.GET})
     public ResultContent<IotTemplateModel> getIotTemplate(
             @RequestParam(name = "id")
@@ -83,23 +87,16 @@ public class IotController {
         return iotService.updateIotTemplateName(param);
     }
 
-    //-------------------------- 模版 end--------------------------------
-
-    //-------------------------- 产品 start------------------------------
+    //-------------------------- 产品 end--------------------------------
 
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "设备引用模版")
-    @RequestMapping(value = "deviceBindIotTemplate", method = {RequestMethod.POST})
-    public ResultContent deviceBindIotTemplate(@RequestBody DeviceBindIotTemplate param) {
-        return iotService.deviceBindIotTemplate(param);
-    }
+    //-------------------------- 属性 start------------------------------
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑物属性等")
     @RequestMapping(value = "addIotMain", method = {RequestMethod.POST})
     public ResultContent addIotMain(@RequestBody IotMainParam param) {
         Assert.hasText(param.getName(), "name不能为空");
-        return iotService.addIotMain(param);
+        return iotService.saveIotMain(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
@@ -111,7 +108,7 @@ public class IotController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除产品")
+    @Operation(summary = "删除属性")
     @RequestMapping(value = "deleteIotMain", method = {RequestMethod.GET})
     public ResultContent deleteIotMain(
             @RequestParam(name = "id")
@@ -120,7 +117,7 @@ public class IotController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "查询产品")
+    @Operation(summary = "查询属性详情")
     @RequestMapping(value = "getIotMain", method = {RequestMethod.GET})
     public ResultContent<IotMainModel> getIotMain(
             @RequestParam(name = "id")
@@ -128,44 +125,50 @@ public class IotController {
         return iotService.getIotMain(id);
     }
 
-    //-------------------------- 产品 end--------------------------------
-
-
-    //-------------------------- Topic start------------------------------
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "添加-编辑Topic", hidden = true)
-    @RequestMapping(value = "addIotTopic", method = {RequestMethod.POST})
-    public ResultContent addIotTopic(@RequestBody IotTopicParam param) {
-        Assert.hasText(param.getTopic(), "topic不能为空");
-        return iotService.addIotTopic(param);
-    }
-
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "Topic列表-分页查询", hidden = true)
-    @RequestMapping(value = {"pageIotTopic"}, method = {RequestMethod.POST})
-    public ResultContent<Page<IotTopicModel>> pageIotTopic(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
-            @Parameter(required = false) IotTopicSearch param) {
-        return iotService.pageIotTopic(pageable, param);
-    }
-
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除Topic", hidden = true)
-    @RequestMapping(value = "deleteIotTopic", method = {RequestMethod.GET})
-    public ResultContent deleteIotTopic(
-            @RequestParam(name = "id")
-            @Parameter(name = "id", description = "数据id") String id) {
-        return iotService.deleteIotTopic(id);
-    }
+    //-------------------------- 属性 end--------------------------------
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "查询Topic", hidden = true)
-    @RequestMapping(value = "getIotTopic", method = {RequestMethod.GET})
-    public ResultContent<IotTopicModel> getIotTopic(
-            @RequestParam(name = "id")
-            @Parameter(name = "id", description = "数据id") String id) {
-        return iotService.getIotTopic(id);
+    @Operation(summary = "设备引用产品")
+    @RequestMapping(value = "deviceBindIotTemplate", method = {RequestMethod.POST})
+    public ResultContent deviceBindIotTemplate(@RequestBody DeviceBindIotTemplate param) {
+        return iotService.deviceBindIotTemplate(param);
     }
-
-    //-------------------------- Topic end--------------------------------
+//
+//    //-------------------------- Topic start------------------------------
+//    @ResourceAuth(value = "user", type = AuthType.User)
+//    @Operation(summary = "添加-编辑Topic", hidden = true)
+//    @RequestMapping(value = "addIotTopic", method = {RequestMethod.POST})
+//    public ResultContent addIotTopic(@RequestBody IotTopicParam param) {
+//        Assert.hasText(param.getTopic(), "topic不能为空");
+//        return iotService.addIotTopic(param);
+//    }
+//
+//    @ResourceAuth(value = "user", type = AuthType.User)
+//    @Operation(summary = "Topic列表-分页查询", hidden = true)
+//    @RequestMapping(value = {"pageIotTopic"}, method = {RequestMethod.POST})
+//    public ResultContent<Page<IotTopicModel>> pageIotTopic(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+//            @Parameter(required = false) IotTopicSearch param) {
+//        return iotService.pageIotTopic(pageable, param);
+//    }
+//
+//    @ResourceAuth(value = "user", type = AuthType.User)
+//    @Operation(summary = "删除Topic", hidden = true)
+//    @RequestMapping(value = "deleteIotTopic", method = {RequestMethod.GET})
+//    public ResultContent deleteIotTopic(
+//            @RequestParam(name = "id")
+//            @Parameter(name = "id", description = "数据id") String id) {
+//        return iotService.deleteIotTopic(id);
+//    }
+//
+//    @ResourceAuth(value = "user", type = AuthType.User)
+//    @Operation(summary = "查询Topic", hidden = true)
+//    @RequestMapping(value = "getIotTopic", method = {RequestMethod.GET})
+//    public ResultContent<IotTopicModel> getIotTopic(
+//            @RequestParam(name = "id")
+//            @Parameter(name = "id", description = "数据id") String id) {
+//        return iotService.getIotTopic(id);
+//    }
+//
+//    //-------------------------- Topic end--------------------------------
 
 }

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotTemplate2DeviceController.java

@@ -9,6 +9,7 @@ import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceModel;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceParam;
 import com.zhongshu.iot.client.model.iot.IotTemplate2DeviceSearch;
 import com.zhongshu.iot.server.core.service.iot.IotTemplate2DeviceService;
+import com.zhongshu.iot.server.core.service.iot.IotTemplateManagerService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;

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

@@ -16,11 +16,11 @@ public interface IotMainDao extends IotMainDaoExtend, org.springframework.data.m
 
     IotMain findTopById(String id);
 
-    IotMain findTopByNameAndIotTemplate(String name, IotTemplate iotTemplate);
+    IotMain findTopByNameAndAboutDataId(String name, String aboutDataId);
 
-    IotMain findTopByIdentifierAndIotTemplate(String identifier, IotTemplate iotTemplate);
+    IotMain findTopByIdentifierAndAboutDataId(String identifier, String aboutDataId);
 
-    IotMain findTopByIotTopicAndIotTemplate(String iotTopic, IotTemplate iotTemplate);
+    IotMain findTopByIotTopicAndAboutDataId(String iotTopic, String aboutDataId);
 
     List<IotMain> findByIotTemplateOrderByCreateTimeAsc(IotTemplate iotTemplate);
 

+ 5 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/impl/IotMainDaoImpl.java

@@ -47,6 +47,11 @@ public class IotMainDaoImpl extends BaseImpl implements IotMainDaoExtend {
             criteria.and("iotTemplate").is(IotTemplate.build(param.getIotTemplateId()));
         }
 
+        // 所属所属物模型id
+        if (StringUtils.isNotEmpty(param.getIotThingId())) {
+            criteria.and("iotThingId").is(param.getIotThingId());
+        }
+
         if (param.getFunctionType() != null) {
             criteria.and("functionType").is(param.getFunctionType());
         }

+ 9 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/impl/IotThingDaoImpl.java

@@ -5,6 +5,7 @@ import com.zhongshu.iot.client.model.iot.thing.IotThingSearch;
 import com.zhongshu.iot.server.core.dao.base.BaseImpl;
 import com.zhongshu.iot.server.core.dao.iot.extend.IotThingDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.IotThing;
+import com.zhongshu.iot.server.core.util.CommonUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -57,6 +58,14 @@ public class IotThingDaoImpl extends BaseImpl implements IotThingDaoExtend {
             criteria.and("iotTemplateId").is(param.getIotTemplateId());
         }
 
+        if (!CommonUtil.longIsEmpty(param.getStartUpdateTime()) && !CommonUtil.longIsEmpty(param.getEndUpdateTime())) {
+            criteria.and("updateTime").gte(param.getStartUpdateTime()).lt(param.getEndUpdateTime());
+        } else if (!CommonUtil.longIsEmpty(param.getStartUpdateTime()) && CommonUtil.longIsEmpty(param.getEndUpdateTime())) {
+            criteria.and("updateTime").gte(param.getStartUpdateTime());
+        } else if (CommonUtil.longIsEmpty(param.getStartUpdateTime()) && !CommonUtil.longIsEmpty(param.getEndUpdateTime())) {
+            criteria.and("updateTime").lt(param.getEndUpdateTime());
+        }
+
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
         if (StringUtils.isNotEmpty(param.getName())) {

+ 3 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/DeviceInfoDaoImpl.java

@@ -5,6 +5,7 @@ import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
 import com.zhongshu.iot.server.core.dao.base.BaseImpl;
 import com.zhongshu.iot.server.core.dao.mqtt.extend.DeviceInfoDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -36,8 +37,8 @@ public class DeviceInfoDaoImpl extends BaseImpl implements DeviceInfoDaoExtend {
     public Page<DeviceInfo> page(Pageable pageable, DeviceInfoSearchParam param) {
         Criteria criteria = new Criteria();
 
-        if (param.getDeviceCategory() != null) {
-            criteria.and("deviceCategory").is(param.getDeviceCategory());
+        if (ObjectUtils.isNotEmpty(param.getDeviceCategorys())) {
+            criteria.and("deviceCategory").in(param.getDeviceCategorys());
         }
 
         if (StringUtils.isNotEmpty(param.getDeviceId())) {

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

@@ -33,18 +33,24 @@ public class IotMain extends SuperEntity {
     @Schema(description = "模版id")
     private String iotMainTemplateId;
 
-    @Schema(description = "所属模版、物模型")
+    @Schema(description = "所属产品或产品副本")
     @DBRef(lazy = true)
     private IotTemplate iotTemplate;
 
+    @Schema(description = "关联code,产品code")
+    private String productCode;
+
     @Schema(description = "所属物模型id")
     private String iotThingId;
 
     @Schema(description = "绑定的设备id")
     private String bindDeviceId;
 
-    @Schema(description = "关联code,产品code")
-    private String productCode;
+    @Schema(description = "区分是模版还是设备关联的物模型")
+    private IotDataType iotDataType;
+
+    @Schema(description = "产品ID或物模型id")
+    private String aboutDataId;
 
     // ------------------------iotMain 基础字段 start-----------------------
 
@@ -124,8 +130,6 @@ public class IotMain extends SuperEntity {
     private List<IotAttribute> outChilds;
 
     //--------------------------------关联设备时特有的属性 start------------------
-    @Schema(description = "区分是模版还是设备关联的物模型")
-    private IotDataType iotDataType;
 
     @Schema(description = "关联的设备")
     private String deviceId;

+ 0 - 6
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/base/SuperService.java

@@ -75,12 +75,6 @@ public abstract class SuperService {
         if (param.getId() != null && param.getId().trim().equals("")) {
             param.setId(null);
         }
-        UserCountModel user = getCrrentUser();
-        if (user != null && StringUtils.isEmpty(param.getCreateUserId())) {
-            param.setCreateUserId(user.getUserId());
-            param.setCreateUserName(user.getName());
-            param.setCreatePhone(user.getPhone());
-        }
     }
 
     public void initEntity(SuperEntity param) {

+ 91 - 53
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -4,21 +4,16 @@ import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.github.microservice.types.deviceUse.DeviceSpecType;
+import com.github.microservice.types.deviceUse.ThingType;
 import com.zhongshu.iot.client.model.baseParam.NameModel;
 import com.zhongshu.iot.client.model.iot.*;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.server.core.dao.UserDao;
-import com.zhongshu.iot.server.core.dao.iot.IotDeviceDataDao;
-import com.zhongshu.iot.server.core.dao.iot.IotMainDao;
-import com.zhongshu.iot.server.core.dao.iot.IotTemplateDao;
-import com.zhongshu.iot.server.core.dao.iot.IotTopicDao;
+import com.zhongshu.iot.server.core.dao.iot.*;
 import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.GateWay2DeviceDao;
 import com.zhongshu.iot.server.core.dataConfig.ResultMessage;
-import com.zhongshu.iot.server.core.domain.iot.IotDeviceData;
-import com.zhongshu.iot.server.core.domain.iot.IotMain;
-import com.zhongshu.iot.server.core.domain.iot.IotTemplate;
-import com.zhongshu.iot.server.core.domain.iot.IotTopic;
+import com.zhongshu.iot.server.core.domain.iot.*;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWay2Device;
 import com.zhongshu.iot.server.core.service.base.CommonService;
@@ -81,6 +76,12 @@ public class IotServiceImpl extends SuperService {
     @Autowired
     private DeviceInfoService deviceInfoService;
 
+    @Autowired
+    private IotThingDao iotThingDao;
+
+    @Autowired
+    private IotThingSyncService iotThingSyncService;
+
     //----------------------------- 模版 start----------------------------
 
     /**
@@ -110,6 +111,7 @@ public class IotServiceImpl extends SuperService {
 
         IotTemplate temp = iotTemplateDao.findTopByNameAndIotDataType(param.getName(), IotDataType.IotTemplate);
         if (StringUtils.isNotEmpty(param.getId())) {
+            // 编辑
             template = iotTemplateDao.findTopById(param.getId());
             if (ObjectUtils.isEmpty(template)) {
                 return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
@@ -117,14 +119,18 @@ public class IotServiceImpl extends SuperService {
             if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
+            template.setName(param.getName());
+            template.setRemark(param.getRemark());
         } else {
+            // 新增加
             template = new IotTemplate();
             if (ObjectUtils.isNotEmpty(temp)) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
             template.setIotDataType(IotDataType.IotTemplate);
+            BeanUtils.copyProperties(param, template);
         }
-        BeanUtils.copyProperties(param, template);
+
         String productCode = template.getProductCode();
         if (StringUtils.isEmpty(productCode)) {
             productCode = String.format("%s%s", template.getDeviceCategory().name(), CommonUtil.randomStr(10));
@@ -381,12 +387,12 @@ public class IotServiceImpl extends SuperService {
     }
 
     /**
-     * 添加属性  事件
+     * 添加-编辑 属性 服务 事件
      *
      * @param param
      * @return
      */
-    public ResultContent addIotMain(IotMainParam param) {
+    public ResultContent saveIotMain(IotMainParam param) {
         initDefaultUser(param);
         if (param.getFunctionType() == null) {
             return ResultContent.buildFail("functionType 不能为空");
@@ -394,24 +400,63 @@ public class IotServiceImpl extends SuperService {
         Assert.hasText(param.getName(), "name不能为空");
         Assert.hasText(param.getIdentifier(), "identifier不能为空");
         Assert.hasText(param.getIotTopic(), "iotTopic不能为空");
+        IotDataType iotDataType = param.getIotDataType();
+        if (iotDataType == null) {
+            return ResultContent.buildFail("iotDataType 不能为空");
+        }
 
-        String iotTemplateId = param.getIotTemplateId();
-        IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
-        if (ObjectUtils.isEmpty(iotTemplate)) {
-            return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
+        String aboutDataId = "";
+        // 产品信息
+        IotTemplate iotTemplate = null;
+        if (iotDataType == IotDataType.IotTemplate) {
+            if (StringUtils.isEmpty(param.getIotTemplateId())) {
+                return ResultContent.buildFail("产品id不能为空");
+            }
+            String iotTemplateId = param.getIotTemplateId();
+            iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
+            if (ObjectUtils.isEmpty(iotTemplate)) {
+                return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
+            }
+            aboutDataId = param.getIotTemplateId();
+        }
+
+        IotThing iotThing = null;
+        DeviceInfo deviceInfo = null;
+        if (iotDataType == IotDataType.Device) {
+            if (StringUtils.isEmpty(param.getIotThingId())) {
+                return ResultContent.buildFail("物模型id不能为空");
+            }
+            iotThing = iotThingDao.findTopById(param.getIotThingId());
+            if (iotThing == null) {
+                return ResultContent.buildFail(String.format("物模型不存在:%s", param.getIotThingId()));
+            }
+            aboutDataId = param.getIotThingId();
+            if (iotThing.getThingType() == ThingType.Auto) {
+                deviceInfo = deviceInfoDao.findTopByDeviceId(iotThing.getDeviceId());
+            } else if (iotThing.getThingType() == ThingType.Manual) {
+                if (StringUtils.isEmpty(param.getDeviceId())) {
+                    return ResultContent.buildFail("手动创建的物模型deviceId不能为空");
+                }
+                deviceInfo = deviceInfoDao.findTopByDeviceId(param.getDeviceId());
+            }
+            if (deviceInfo == null) {
+                return ResultContent.buildFail("物模型管理的设备信息未找到");
+            }
         }
 
         IotMain entity = null;
         // 判断名称是否重复
-        IotMain nameTemp = iotMainDao.findTopByNameAndIotTemplate(param.getName(), iotTemplate);
-        IotMain topicTemp = iotMainDao.findTopByIotTopicAndIotTemplate(param.getIotTopic(), iotTemplate);
-        IotMain identifierTemp = iotMainDao.findTopByIdentifierAndIotTemplate(param.getIdentifier(), iotTemplate);
+        IotMain nameTemp = iotMainDao.findTopByNameAndAboutDataId(param.getName(), aboutDataId);
+        IotMain topicTemp = iotMainDao.findTopByIdentifierAndAboutDataId(param.getIotTopic(), aboutDataId);
+        IotMain identifierTemp = iotMainDao.findTopByIotTopicAndAboutDataId(param.getIdentifier(), aboutDataId);
 
         if (StringUtils.isNotEmpty(param.getId())) {
+            // 编辑
             entity = iotMainDao.findTopById(param.getId());
             if (ObjectUtils.isEmpty(entity)) {
                 return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
             }
+
             if (ObjectUtils.isNotEmpty(nameTemp) && !nameTemp.getId().equals(param.getId())) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
@@ -422,6 +467,7 @@ public class IotServiceImpl extends SuperService {
                 return ResultContent.buildFail(String.format("identifier已存在:%s", param.getIdentifier()));
             }
         } else {
+            // 添加
             entity = new IotMain();
             initEntity(entity);
             if (ObjectUtils.isNotEmpty(nameTemp)) {
@@ -436,15 +482,23 @@ public class IotServiceImpl extends SuperService {
         }
 
         BeanUtils.copyProperties(param, entity);
-        // 设备所属模型
-        entity.setIotTemplate(iotTemplate);
-        entity.setIotDataType(iotTemplate.getIotDataType());
-        if (iotTemplate.getIotDataType() == IotDataType.Device) {
-            entity.setDeviceId(iotTemplate.getDeviceId());
+
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            entity.setDeviceId(deviceInfo.getDeviceId());
+        }
+        if (iotDataType == IotDataType.IotTemplate) {
+            // 产品
+            entity.setIotTemplate(iotTemplate);
+            entity.setProductCode(iotTemplate.getProductCode());
             entity.setProjectCode(iotTemplate.getProjectCode());
+        } else if (iotDataType == IotDataType.Device) {
+            // 物模型
+            entity.setProductCode(iotThing.getProductCode());
+            entity.setProjectCode(iotThing.getProjectCode());
             initRealTopic(entity);
         }
         iotMainDao.save(entity);
+        iotThingSyncService.asyncIotThing(iotThing);
         return ResultContent.buildSuccess();
     }
 
@@ -530,7 +584,7 @@ public class IotServiceImpl extends SuperService {
         if (ObjectUtils.isEmpty(entity)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
         }
-        return ResultContent.buildSuccess(toModel(entity));
+        return ResultContent.buildSuccess(toAttributeModel(entity));
     }
 
     /**
@@ -542,15 +596,12 @@ public class IotServiceImpl extends SuperService {
      */
     public ResultContent<Page<IotMainModel>> pageIotMain(Pageable pageable, IotMainSearch param) {
         initSearchParam(param);
-        if (StringUtils.isEmpty(param.getIotTemplateId())) {
-            return ResultContent.buildFail("iotTemplateId不能为空");
+        // 从物模型查看  或 从产品查看
+        if (StringUtils.isEmpty(param.getIotTemplateId()) && StringUtils.isEmpty(param.getIotThingId())) {
+            return ResultContent.buildFail("iotTemplateId和iotThingId不能同时为空");
         }
         Page<IotMain> page = iotMainDao.page(pageable, param);
-        if (param.getFunctionType() != null && param.getFunctionType() == FunctionType.Attribute) {
-            return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toAttributeModel));
-        } else {
-            return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
-        }
+        return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toAttributeModel));
     }
 
     /**
@@ -563,7 +614,7 @@ public class IotServiceImpl extends SuperService {
         List<IotMain> list = iotMainDao.findByIotTemplateAndFunctionTypeOrderByCreateTimeAsc(IotTemplate.build(templateId), functionType);
         List<IotMainModel> models = new ArrayList<>();
         if (ObjectUtils.isNotEmpty(list)) {
-            models = list.stream().map(this::toModel).collect(Collectors.toList());
+            models = list.stream().map(this::toAttributeModel).collect(Collectors.toList());
         }
         return ResultContent.buildSuccess(models);
     }
@@ -575,7 +626,7 @@ public class IotServiceImpl extends SuperService {
         if (ObjectUtils.isNotEmpty(entity)) {
             model = new IotTemplateModel();
             BeanUtils.copyProperties(entity, model);
-            // 设备数量
+            // (统计)设备数量
             model.setDeviceCount(deviceInfoService.countByProductCode(entity.getProductCode()));
         }
         return model;
@@ -590,21 +641,6 @@ public class IotServiceImpl extends SuperService {
         return model;
     }
 
-    /**
-     * IOTMain模型
-     *
-     * @param entity
-     * @return
-     */
-    public IotMainModel toModel(IotMain entity) {
-        IotMainModel model = null;
-        if (ObjectUtils.isNotEmpty(entity)) {
-            model = new IotMainModel();
-            BeanUtils.copyProperties(entity, model);
-        }
-        return model;
-    }
-
     /**
      * 属性 类型的model,包含值
      *
@@ -616,11 +652,13 @@ public class IotServiceImpl extends SuperService {
         if (ObjectUtils.isNotEmpty(entity)) {
             model = new IotMainAttributeModel();
             BeanUtils.copyProperties(entity, model);
-            IotDeviceData iotDeviceData = iotDeviceDataDao.findTopByIotMain(entity);
-            if (ObjectUtils.isNotEmpty(iotDeviceData)) {
-                IotDeviceDataModel deviceData = new IotDeviceDataModel();
-                BeanUtils.copyProperties(iotDeviceData, deviceData);
-                model.setDeviceData(deviceData);
+            if (entity.getFunctionType() != FunctionType.Attribute) {
+                IotDeviceData iotDeviceData = iotDeviceDataDao.findTopByIotMain(entity);
+                if (ObjectUtils.isNotEmpty(iotDeviceData)) {
+                    IotDeviceDataModel deviceData = new IotDeviceDataModel();
+                    BeanUtils.copyProperties(iotDeviceData, deviceData);
+                    model.setDeviceData(deviceData);
+                }
             }
         }
         return model;

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

@@ -99,6 +99,13 @@ public class IotTemplateManagerService extends SuperService {
         return deviceBindAutoIotTemplate(iotTemplate, deviceInfo, iotThing.getId(), projectInfoCode);
     }
 
+    /**
+     * @param iotTemplate     产品信息
+     * @param deviceInfo      设备信息
+     * @param iotThingId      所属物模型id
+     * @param projectInfoCode 分组code
+     * @return
+     */
     public ResultContent deviceBindAutoIotTemplate(IotTemplate iotTemplate, DeviceInfo deviceInfo,
             String iotThingId, String projectInfoCode) {
         if (ObjectUtils.isEmpty(iotTemplate)) {
@@ -151,7 +158,8 @@ public class IotTemplateManagerService extends SuperService {
                     map.remove(it.getId());
                 }
                 main.setIotThingId(iotThingId);
-                // 所属
+
+                // 所属产品副本
                 main.setIotTemplate(finalNewIotTemplate);
                 // 所属产品code
                 main.setProductCode(finalNewIotTemplate.getProductCode());

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

@@ -22,6 +22,7 @@ import com.zhongshu.iot.server.core.service.base.SuperService;
 import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.service.device.ProjectInfoService;
 import com.zhongshu.iot.server.core.util.CommonUtil;
+import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -176,12 +177,20 @@ public class IotThingService extends SuperService {
 
     /**
      * 物模型分页查询
-     *
+     * 
      * @param pageable
      * @param param
      * @return
      */
     public ResultContent<Page<IotThingModel>> page(Pageable pageable, IotThingSearch param) {
+        if (ObjectUtils.isNotEmpty(param.getUpdateTimes()) && param.getUpdateTimes().size() == 2) {
+            Long startUpdateTime = param.getUpdateTimes().get(0);
+            Long endUpdateTime = param.getUpdateTimes().get(1);
+            startUpdateTime = DateUtils.getDayStartTime(startUpdateTime);
+            endUpdateTime = DateUtils.getDayEndTime(endUpdateTime);
+            param.setStartUpdateTime(startUpdateTime);
+            param.setEndUpdateTime(endUpdateTime);
+        }
         Page<IotThing> page = iotThingDao.page(pageable, param);
         return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
     }

+ 55 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThingSyncService.java

@@ -0,0 +1,55 @@
+package com.zhongshu.iot.server.core.service.iot;
+
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.iot.server.core.domain.iot.IotThing;
+import com.zhongshu.iot.server.core.service.base.SuperService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * 物模型同步 服务
+ *
+ * @author TRX
+ * @date 2025/2/26
+ */
+@Slf4j
+@Service
+public class IotThingSyncService extends SuperService {
+
+    /**
+     * 异步 同步物模型数据
+     *
+     * @param iotThing
+     * @return
+     */
+    public ResultContent asyncIotThing(IotThing iotThing) {
+        if (ObjectUtils.isNotEmpty(iotThing)) {
+            CompletableFuture.runAsync(() -> {
+                try {
+                    syncIotThing(iotThing);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            });
+        }
+        return ResultContent.buildSuccess();
+    }
+
+    /**
+     * 同步 同步物模型数据
+     *
+     * @param iotThing
+     * @return
+     */
+    public ResultContent syncIotThing(IotThing iotThing) {
+        if (ObjectUtils.isNotEmpty(iotThing)) {
+
+        }
+        return ResultContent.buildSuccess();
+    }
+
+
+}