TRX 1 年間 前
コミット
059c294be5

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

@@ -1,5 +1,6 @@
 package com.zhongshu.iot.client.model.iot;
 
+import com.github.microservice.models.iotDeviceData.IotDeviceDataModel;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -17,5 +18,5 @@ import lombok.NoArgsConstructor;
 public class IotMainAttributeModel extends IotMainModel {
 
     @Schema(description = "属性对应的最新值")
-    private Object value;
+    private IotDeviceDataModel value;
 }

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

@@ -2,6 +2,7 @@ package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.busInfoModel.device.DeviceInfoMoreModel;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.types.deviceUse.DeviceCategory;
@@ -112,6 +113,15 @@ public class DeviceController {
         return deviceInfoService.getDeviceById(deviceId);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "查询设备详情")
+    @RequestMapping(value = "getDeviceMoreById", method = {RequestMethod.GET})
+    public ResultContent<DeviceInfoMoreModel> getDeviceMoreById(
+            @Parameter(name = "deviceId", description = "数据ID", example = "")
+            @RequestParam("deviceId") String deviceId) {
+        return deviceInfoService.getDeviceMoreById(deviceId);
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "编辑备注")
     @RequestMapping(value = "updateRemark", method = {RequestMethod.POST})

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

@@ -37,7 +37,7 @@ public class IotMainDaoImpl extends BaseImpl implements IotMainDaoExtend {
 
     @Override
     public Page<IotMain> page(Pageable pageable, IotMainSearch param) {
-        Criteria criteria = new Criteria();
+        Criteria criteria = buildCriteriaAboutTime(param);
 
         if (StringUtils.isNotEmpty(param.getId())) {
             criteria.and("_id").is(param.getId());
@@ -108,7 +108,6 @@ public class IotMainDaoImpl extends BaseImpl implements IotMainDaoExtend {
             );
         }
 
-        criteria.and("isDelete").is(Boolean.FALSE);
         Sort sort = buildSort(param);
         Query query = Query.query(criteria);
         query.with(sort);

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

@@ -37,7 +37,7 @@ public class IotDeviceData extends SuperEntity {
     @Schema(description = "所属分组code")
     private String projectCode;
 
-    @Schema(description = "属性")
+    @Schema(description = "属性名称,如:name、age、temperature")
     private String property;
 
     @Schema(description = "对应的值")

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

@@ -42,10 +42,7 @@ public class IotMain extends SuperEntity {
 
     @Schema(description = "所属物模型id")
     private String iotThingId;
-
-    @Schema(description = "绑定的设备id")
-    private String bindDeviceId;
-
+    
     @Schema(description = "区分是模版还是设备关联的物模型")
     private IotDataType iotDataType;
 

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.busInfoModel.device.DeviceInfoModel;
+import com.github.microservice.busInfoModel.device.DeviceInfoMoreModel;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.types.deviceUse.DeviceState;
@@ -395,6 +396,15 @@ public class DeviceInfoService {
         return ResultContent.buildSuccess(model);
     }
 
+    public ResultContent<DeviceInfoMoreModel> getDeviceMoreById(String deviceId) {
+        DeviceInfoMoreModel model = null;
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            model = toMoreModel(deviceInfo);
+        }
+        return ResultContent.buildSuccess(model);
+    }
+
     /**
      * 判断设备是否可用(本身)
      *
@@ -436,11 +446,19 @@ public class DeviceInfoService {
             BeanUtils.copyProperties(deviceInfo, deviceInfoModel);
             // 分组信息
             deviceInfoModel.setProjectInfo(projectInfoService.toModel(deviceInfo.getProjectInfo()));
-
             // 产品信息
             deviceInfoModel.setIotTemplate(iotService.toSimpleModel(deviceInfo.getProductCode()));
         }
         return deviceInfoModel;
     }
 
+    public DeviceInfoMoreModel toMoreModel(DeviceInfo deviceInfo) {
+        DeviceInfoMoreModel deviceInfoModel = new DeviceInfoMoreModel();
+        if (ObjectUtils.isNotEmpty(deviceInfo)) {
+            DeviceInfoModel _model = toModel(deviceInfo);
+            BeanUtils.copyProperties(_model, deviceInfoModel);
+            deviceInfoModel.setIotTemplate(iotService.toSimpleModel(deviceInfo.getProductCode()));
+        }
+        return deviceInfoModel;
+    }
 }

+ 10 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotDeviceDataService.java

@@ -98,6 +98,16 @@ public class IotDeviceDataService {
         return null;
     }
 
+    public IotDeviceDataModel getDevicePropertyModel(String deviceId, String property) {
+        if (StringUtils.isNotEmpty(deviceId) && StringUtils.isNotEmpty(property)) {
+            IotDeviceData entity = getDevicePropertyObject(deviceId, property);
+            if (entity != null) {
+                return toModel(entity);
+            }
+        }
+        return null;
+    }
+
     /**
      * 查询值
      *

+ 35 - 92
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -10,7 +10,10 @@ import com.github.microservice.types.deviceUse.ThingType;
 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.*;
+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.IotThingDao;
+import com.zhongshu.iot.server.core.dao.iot.IotTopicDao;
 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;
@@ -20,7 +23,6 @@ import com.zhongshu.iot.server.core.domain.iot.IotThing;
 import com.zhongshu.iot.server.core.domain.iot.IotTopic;
 import com.zhongshu.iot.server.core.domain.iot.device.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.device.GateWay2Device;
-import com.zhongshu.iot.server.core.service.base.CommonService;
 import com.zhongshu.iot.server.core.service.base.SuperService;
 import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.util.CommonUtil;
@@ -68,12 +70,6 @@ public class IotServiceImpl extends SuperService {
     @Autowired
     private GateWay2DeviceDao gateWay2DeviceDao;
 
-    @Autowired
-    private IotDeviceDataDao iotDeviceDataDao;
-
-    @Autowired
-    private CommonService commonService;
-
     @Autowired
     private IotTemplate2DeviceService iotTemplate2DeviceService;
 
@@ -89,10 +85,10 @@ public class IotServiceImpl extends SuperService {
     @Autowired
     private IotDeviceDataService iotDeviceDataService;
 
-    //----------------------------- 模版 start----------------------------
+    //----------------------------- 产品 start----------------------------
 
     /**
-     * 添加模版
+     * 添加产品
      *
      * @param param
      * @return
@@ -148,7 +144,7 @@ public class IotServiceImpl extends SuperService {
     }
 
     /**
-     * 删除模版
+     * 删除产品
      *
      * @param id
      * @return
@@ -168,7 +164,7 @@ public class IotServiceImpl extends SuperService {
     }
 
     /**
-     * 查询模版详情
+     * 查询产品详情
      *
      * @param id
      * @return
@@ -181,8 +177,13 @@ public class IotServiceImpl extends SuperService {
         return ResultContent.buildSuccess(toModel(template));
     }
 
+    public IotTemplateModel getIotTemplateByCode(String productCode) {
+        IotTemplate template = iotTemplateDao.findTopByProductCodeAndIotDataType(productCode, IotDataType.IotTemplate);
+        return toModel(template);
+    }
+
     /**
-     * 模版分页
+     * 产品分页
      *
      * @param pageable
      * @param param
@@ -225,7 +226,7 @@ public class IotServiceImpl extends SuperService {
 
         // 检查名称是否重复
         if (template.getIotDataType() == IotDataType.IotTemplate) {
-            // 模版
+            // 产品
             IotTemplate temp = iotTemplateDao.findTopByNameAndIotDataType(param.getName(), IotDataType.IotTemplate);
             if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(template.getId())) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
@@ -242,76 +243,12 @@ public class IotServiceImpl extends SuperService {
         return ResultContent.buildSuccess();
     }
 
-    //----------------------------- 模版 end------------------------------
-
-
-    //----------------------------- Topic start----------------------------
-    public ResultContent addIotTopic(IotTopicParam param) {
-        initDefaultUser(param);
-        String iotTemplateId = param.getIotTemplateId();
-        IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
-        if (ObjectUtils.isEmpty(iotTemplate)) {
-            return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
-        }
-
-        IotTopic entity = null;
-        if (StringUtils.isNotEmpty(param.getId())) {
-            entity = iotTopicDao.findTopById(param.getId());
-            if (ObjectUtils.isEmpty(entity)) {
-                return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
-            }
-            IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getTopic(), iotTemplate);
-            if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
-                return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getTopic()));
-            }
-        } else {
-            entity = new IotTopic();
-            IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getTopic(), iotTemplate);
-            if (ObjectUtils.isNotEmpty(temp)) {
-                return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getTopic()));
-            }
-        }
-        BeanUtils.copyProperties(param, entity);
-        entity.setIotTemplate(iotTemplate);
-        iotTopicDao.save(entity);
-        return ResultContent.buildSuccess();
-    }
-
-    public ResultContent deleteIotTopic(String id) {
-        IotTopic entity = iotTopicDao.findTopById(id);
-        if (ObjectUtils.isEmpty(entity)) {
-            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
-        }
-        iotTopicDao.delete(entity);
-        return ResultContent.buildSuccess();
-    }
-
-    public ResultContent<IotTopicModel> getIotTopic(String id) {
-        IotTopic entity = iotTopicDao.findTopById(id);
-        if (ObjectUtils.isEmpty(entity)) {
-            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
-        }
-        return ResultContent.buildSuccess(toModel(entity));
-    }
-
-    /**
-     * 分页查询 模版的Topic管理数据
-     *
-     * @param pageable
-     * @param param
-     * @return
-     */
-    public ResultContent<Page<IotTopicModel>> pageIotTopic(Pageable pageable, IotTopicSearch param) {
-        initSearchParam(param);
-        Page<IotTopic> page = iotTopicDao.page(pageable, param);
-        return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
-    }
-    //----------------------------- Topic end------------------------------
+    //----------------------------- 产品 end------------------------------
 
     //----------------------------- 物模型 start----------------------------
 
     /**
-     * 设备绑定模版
+     * 设备绑定产品
      *
      * @param param
      * @return
@@ -322,16 +259,16 @@ public class IotServiceImpl extends SuperService {
         if (ObjectUtils.isEmpty(deviceInfo)) {
             return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getDeviceId()));
         }
-        // 模版信息
+        // 产品信息
         IotTemplate iotTemplate = iotTemplateDao.findTopById(param.getTemplateId());
         if (ObjectUtils.isEmpty(iotTemplate)) {
-            return ResultContent.buildFail(String.format("模版ID不存在", param.getTemplateId()));
+            return ResultContent.buildFail(String.format("产品ID不存在", param.getTemplateId()));
         }
 
-        // 判断该设备是否已绑定该模版
+        // 判断该设备是否已绑定该产品
         IotTemplate temp = iotTemplateDao.findTopByDeviceIdAndIotTemplateIdAndIotDataType(param.getDeviceId(), iotTemplate.getId(), IotDataType.Device);
 //        if (ObjectUtils.isNotEmpty(temp)) {
-//            return ResultContent.buildFail(String.format("设备【%s】已绑定模版%s", deviceInfo.getDeviceName(), iotTemplate.getName()));
+//            return ResultContent.buildFail(String.format("设备【%s】已绑定产品%s", deviceInfo.getDeviceName(), iotTemplate.getName()));
 //        }
 
         IotTemplate newIotTemplate = null;
@@ -353,7 +290,7 @@ public class IotServiceImpl extends SuperService {
 
         // 属性等数据
         List<IotMain> saveList = new ArrayList<>();
-        // 模版对应的数据
+        // 产品对应的数据
         List<IotMain> list = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(iotTemplate);
         // 以前绑定的数据
         List<IotMain> oldList = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(newIotTemplate);
@@ -373,7 +310,7 @@ public class IotServiceImpl extends SuperService {
                     map.remove(it.getId());
                 }
                 main.setIotTemplate(finalNewIotTemplate);
-                // 所属模版内容数据ID
+                // 所属产品内容数据ID
                 main.setIotMainTemplateId(it.getId());
 
                 main.setIotDataType(IotDataType.Device);
@@ -415,6 +352,7 @@ public class IotServiceImpl extends SuperService {
         String aboutDataId = "";
         // 产品信息
         IotTemplate iotTemplate = null;
+        // 如果是产品
         if (iotDataType == IotDataType.IotTemplate) {
             if (StringUtils.isEmpty(param.getIotTemplateId())) {
                 return ResultContent.buildFail("产品id不能为空");
@@ -422,13 +360,14 @@ public class IotServiceImpl extends SuperService {
             String iotTemplateId = param.getIotTemplateId();
             iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
             if (ObjectUtils.isEmpty(iotTemplate)) {
-                return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
+                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不能为空");
@@ -502,12 +441,13 @@ public class IotServiceImpl extends SuperService {
             // 物模型
             entity.setProductCode(iotThing.getProductCode());
             entity.setProjectCode(iotThing.getProjectCode());
+            entity.setIotThingId(iotThing.getId());
             initRealTopic(entity);
         }
         entity.setAboutDataId(aboutDataId);
         iotMainDao.save(entity);
 
-        //
+        // 同步物模型
         iotThingSyncService.asyncIotThing(iotThing);
         return ResultContent.buildSuccess();
     }
@@ -607,15 +547,18 @@ public class IotServiceImpl extends SuperService {
     public ResultContent<Page<IotMainModel>> pageIotMain(Pageable pageable, IotMainSearch param) {
         initSearchParam(param);
         // 从物模型查看  或 从产品查看
-        if (StringUtils.isEmpty(param.getIotTemplateId()) && StringUtils.isEmpty(param.getIotThingId())) {
-            return ResultContent.buildFail("iotTemplateId和iotThingId不能同时为空");
+        if (StringUtils.isEmpty(param.getIotTemplateId())
+                && StringUtils.isEmpty(param.getIotThingId())
+                && StringUtils.isEmpty(param.getDeviceId())) {
+            return ResultContent.buildFail("iotTemplateId和iotThingId和deviceId不能同时为空");
         }
         Page<IotMain> page = iotMainDao.page(pageable, param);
         return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toAttributeModel));
     }
 
+
     /**
-     * 得到模版物模型的顶用数据
+     * 得到产品物模型的顶用数据
      *
      * @param templateId
      * @return
@@ -685,7 +628,7 @@ public class IotServiceImpl extends SuperService {
 
             // 属性值
             if (entity.getFunctionType() == FunctionType.Attribute && entity.getIotDataType() == IotDataType.Device) {
-                model.setValue(iotDeviceDataService.getDevicePropertyValue(entity.getDeviceId(), entity.getIdentifier()));
+                model.setValue(iotDeviceDataService.getDevicePropertyModel(entity.getDeviceId(), entity.getIdentifier()));
             }
         }
         return model;

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

@@ -179,6 +179,8 @@ public class IotTemplateManagerService extends SuperService {
                 if (ObjectUtils.isNotEmpty(gateWayInfo)) {
                     main.setGateWayId(gateWayInfo.getDeviceId());
                 }
+                main.setAboutDataId(iotThingId);
+
                 iotService.initRealTopic(main);
                 saveList.add(main);
             });