|
|
@@ -2,6 +2,7 @@ package com.zhongshu.iot.server.core.service.iot;
|
|
|
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.types.FunctionType;
|
|
|
+import com.github.microservice.types.deviceUse.DeviceSpecType;
|
|
|
import com.zhongshu.iot.client.model.baseParam.NameModel;
|
|
|
import com.zhongshu.iot.client.model.iot.*;
|
|
|
import com.zhongshu.iot.client.type.IotDataType;
|
|
|
@@ -21,6 +22,7 @@ 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;
|
|
|
import com.zhongshu.iot.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.iot.server.core.util.CommonUtil;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
|
import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -85,6 +87,18 @@ public class IotServiceImpl extends SuperService {
|
|
|
public ResultContent addIotTemplate(IotTemplateParam param) {
|
|
|
IotTemplate template = null;
|
|
|
initDefaultUser(param);
|
|
|
+ if (StringUtils.isEmpty(param.getName())) {
|
|
|
+ return ResultContent.buildFail("name is empty");
|
|
|
+ }
|
|
|
+ if (param.getDeviceCategory() == null) {
|
|
|
+ return ResultContent.buildFail("deviceCategory is empty");
|
|
|
+ }
|
|
|
+ if (param.getDeviceType() == null) {
|
|
|
+ return ResultContent.buildFail("deviceType is empty");
|
|
|
+ }
|
|
|
+ if (param.getSpecType() == null) {
|
|
|
+ param.setSpecType(DeviceSpecType.Common);
|
|
|
+ }
|
|
|
|
|
|
IotTemplate temp = iotTemplateDao.findTopByNameAndIotDataType(param.getName(), IotDataType.IotTemplate);
|
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
@@ -103,6 +117,11 @@ public class IotServiceImpl extends SuperService {
|
|
|
template.setIotDataType(IotDataType.IotTemplate);
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, template);
|
|
|
+ String productCode = template.getProductCode();
|
|
|
+ if (StringUtils.isEmpty(productCode)) {
|
|
|
+ productCode = String.format("%s%s", template.getDeviceCategory().name(), CommonUtil.randomStr(10));
|
|
|
+ }
|
|
|
+ template.setProductCode(productCode);
|
|
|
iotTemplateDao.save(template);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|