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