|
@@ -14,6 +14,8 @@ import com.zswl.dataservice.model.mqtt.DeviceInfoModel;
|
|
|
import com.zswl.dataservice.model.mqtt.DeviceInfoSearchParam;
|
|
import com.zswl.dataservice.model.mqtt.DeviceInfoSearchParam;
|
|
|
import com.zswl.dataservice.service.base.SuperService;
|
|
import com.zswl.dataservice.service.base.SuperService;
|
|
|
import com.zswl.dataservice.type.FunctionType;
|
|
import com.zswl.dataservice.type.FunctionType;
|
|
|
|
|
+import com.zswl.dataservice.type.IotDataType;
|
|
|
|
|
+import com.zswl.dataservice.type.ResultState;
|
|
|
import com.zswl.dataservice.utils.bean.BeanUtil;
|
|
import com.zswl.dataservice.utils.bean.BeanUtil;
|
|
|
import com.zswl.dataservice.utils.bean.BeanUtils;
|
|
import com.zswl.dataservice.utils.bean.BeanUtils;
|
|
|
import com.zswl.dataservice.utils.page.PageEntityUtil;
|
|
import com.zswl.dataservice.utils.page.PageEntityUtil;
|
|
@@ -150,6 +152,7 @@ public class IotServiceImpl extends SuperService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 分页查询 模版的Topic管理数据
|
|
* 分页查询 模版的Topic管理数据
|
|
|
|
|
+ *
|
|
|
* @param pageable
|
|
* @param pageable
|
|
|
* @param param
|
|
* @param param
|
|
|
* @return
|
|
* @return
|
|
@@ -162,8 +165,16 @@ public class IotServiceImpl extends SuperService {
|
|
|
//----------------------------- Topic end------------------------------
|
|
//----------------------------- Topic end------------------------------
|
|
|
|
|
|
|
|
//----------------------------- 物模型 start----------------------------
|
|
//----------------------------- 物模型 start----------------------------
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 添加属性 事件
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
public ResultContent addIotMain(IotMainParam param) {
|
|
public ResultContent addIotMain(IotMainParam param) {
|
|
|
initDefaultUser(param);
|
|
initDefaultUser(param);
|
|
|
|
|
+
|
|
|
String iotTemplateId = param.getIotTemplateId();
|
|
String iotTemplateId = param.getIotTemplateId();
|
|
|
IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
|
|
IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
|
|
|
if (ObjectUtils.isEmpty(iotTemplate)) {
|
|
if (ObjectUtils.isEmpty(iotTemplate)) {
|
|
@@ -171,24 +182,35 @@ public class IotServiceImpl extends SuperService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
IotMain entity = null;
|
|
IotMain entity = null;
|
|
|
|
|
+ // 判断名称是否重复
|
|
|
|
|
+ IotTopic nameTemp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
|
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
entity = iotMainDao.findTopById(param.getId());
|
|
entity = iotMainDao.findTopById(param.getId());
|
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
}
|
|
}
|
|
|
- IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
|
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(nameTemp) && !nameTemp.getId().equals(param.getId())) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
entity = new IotMain();
|
|
entity = new IotMain();
|
|
|
- IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(nameTemp)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setIotTemplate(iotTemplate);
|
|
entity.setIotTemplate(iotTemplate);
|
|
|
|
|
+ if (iotTemplate.getIotDataType() == IotDataType.Device) {
|
|
|
|
|
+ // 把 topic有占位符的换为具体的值
|
|
|
|
|
+ String deviceId = iotTemplate.getDeviceId();
|
|
|
|
|
+ String iotTopic = entity.getIotTopic();
|
|
|
|
|
+ String realIotTopic = "";
|
|
|
|
|
+ if (StringUtils.isNotEmpty(iotTopic)) {
|
|
|
|
|
+ realIotTopic = iotTopic.replaceAll("$\\{deviceId\\}", deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+ entity.setRealIotTopic(realIotTopic);
|
|
|
|
|
+ }
|
|
|
iotMainDao.save(entity);
|
|
iotMainDao.save(entity);
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|