|
@@ -1,10 +1,20 @@
|
|
|
package com.zhongshu.iot.server.core.service.openApi;
|
|
package com.zhongshu.iot.server.core.service.openApi;
|
|
|
|
|
|
|
|
import com.github.microservice.net.ResultContent;
|
|
import com.github.microservice.net.ResultContent;
|
|
|
-import com.zhongshu.iot.client.model.mqtt.DeviceInfoModel;
|
|
|
|
|
|
|
+import com.github.microservice.types.FunctionType;
|
|
|
|
|
+import com.zhongshu.iot.client.model.iot.IotMainModel;
|
|
|
|
|
+import com.zhongshu.iot.client.model.iot.IotMainSearch;
|
|
|
import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
|
|
import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
|
|
|
|
|
+import com.zhongshu.iot.client.openApi.base.DeviceIdParam;
|
|
|
import com.zhongshu.iot.client.openApi.model.DeviceInfoOpenAPIModel;
|
|
import com.zhongshu.iot.client.openApi.model.DeviceInfoOpenAPIModel;
|
|
|
|
|
+import com.zhongshu.iot.client.openApi.model.IotMainOpenAPIModel;
|
|
|
|
|
+import com.zhongshu.iot.client.openApi.model.IotTemplateOpenAPIModel;
|
|
|
|
|
+import com.zhongshu.iot.client.type.IotDataType;
|
|
|
|
|
+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.mqtt.DeviceInfoDao;
|
|
import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
|
|
|
|
|
+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.mqtt.DeviceInfo;
|
|
import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
|
import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
|
|
import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
|
|
@@ -13,9 +23,14 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
|
* @date 2024/11/11
|
|
* @date 2024/11/11
|
|
@@ -27,22 +42,62 @@ public class DeviceIotOpenApiService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeviceInfoDao deviceInfoDao;
|
|
private DeviceInfoDao deviceInfoDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotTemplateDao iotTemplateDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotMainDao iotMainDao;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设备列表
|
|
* 设备列表
|
|
|
*
|
|
*
|
|
|
- * @param pageable
|
|
|
|
|
* @param param
|
|
* @param param
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public ResultContent<Page<DeviceInfoOpenAPIModel>> pageDevice(Pageable pageable, DeviceInfoSearchParam param) {
|
|
|
|
|
|
|
+ public ResultContent<Page<DeviceInfoOpenAPIModel>> pageDevice(DeviceInfoSearchParam param) {
|
|
|
if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
|
return ResultContent.buildFail("projectInfoCode");
|
|
return ResultContent.buildFail("projectInfoCode");
|
|
|
}
|
|
}
|
|
|
|
|
+ Pageable pageable = PageRequest.of(param.getNumber(), param.getSize());
|
|
|
|
|
+
|
|
|
Page<DeviceInfo> page = deviceInfoDao.page(pageable, param);
|
|
Page<DeviceInfo> page = deviceInfoDao.page(pageable, param);
|
|
|
return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toDeviceModel));
|
|
return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toDeviceModel));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 得到设备管理的物模型
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent<List<IotTemplateOpenAPIModel>> getDeviceTemplateList(DeviceIdParam param) {
|
|
|
|
|
+ if (ObjectUtils.isEmpty(param.getDeviceId())) {
|
|
|
|
|
+ return ResultContent.buildFail("deviceId不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<IotTemplate> list = iotTemplateDao.findByDeviceIdAndIotDataTypeOrderByCreateTimeAsc(param.getDeviceId(), IotDataType.Device);
|
|
|
|
|
+ List<IotTemplateOpenAPIModel> models = new ArrayList<>();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
|
|
+ models = list.stream().map(this::toIotTemplateModel).collect(Collectors.toUnmodifiableList());
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 物模型管理的 标识符分页数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent<Page<IotMainOpenAPIModel>> pageIotMain(IotMainSearch param) {
|
|
|
|
|
+ if (StringUtils.isEmpty(param.getIotTemplateId())) {
|
|
|
|
|
+ return ResultContent.buildFail("iotTemplateId不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ Pageable pageable = PageRequest.of(param.getNumber(), param.getSize());
|
|
|
|
|
+ Page<IotMain> page = iotMainDao.page(pageable, param);
|
|
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toIotMainModel));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //-------------------------模型转换 start--------------------------
|
|
|
private DeviceInfoOpenAPIModel toDeviceModel(DeviceInfo entity) {
|
|
private DeviceInfoOpenAPIModel toDeviceModel(DeviceInfo entity) {
|
|
|
DeviceInfoOpenAPIModel model = new DeviceInfoOpenAPIModel();
|
|
DeviceInfoOpenAPIModel model = new DeviceInfoOpenAPIModel();
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
@@ -50,4 +105,21 @@ public class DeviceIotOpenApiService {
|
|
|
}
|
|
}
|
|
|
return model;
|
|
return model;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private IotTemplateOpenAPIModel toIotTemplateModel(IotTemplate entity) {
|
|
|
|
|
+ IotTemplateOpenAPIModel model = new IotTemplateOpenAPIModel();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
|
|
+ }
|
|
|
|
|
+ return model;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private IotMainOpenAPIModel toIotMainModel(IotMain entity) {
|
|
|
|
|
+ IotMainOpenAPIModel model = new IotMainOpenAPIModel();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
|
|
+ }
|
|
|
|
|
+ return model;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|