|
@@ -1,8 +1,9 @@
|
|
|
package com.zhongshu.iot.server.core.service.iot;
|
|
package com.zhongshu.iot.server.core.service.iot;
|
|
|
|
|
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
|
|
+import com.github.microservice.types.FunctionType;
|
|
|
import com.zhongshu.iot.client.model.baseParam.NameModel;
|
|
import com.zhongshu.iot.client.model.baseParam.NameModel;
|
|
|
import com.zhongshu.iot.client.model.iot.*;
|
|
import com.zhongshu.iot.client.model.iot.*;
|
|
|
-import com.github.microservice.types.FunctionType;
|
|
|
|
|
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.IotDeviceDataDao;
|
|
import com.zhongshu.iot.server.core.dao.iot.IotDeviceDataDao;
|
|
@@ -22,7 +23,6 @@ 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.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;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -36,7 +36,6 @@ import org.springframework.util.Assert;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -58,19 +57,22 @@ public class IotServiceImpl extends SuperService {
|
|
|
private IotTopicDao iotTopicDao;
|
|
private IotTopicDao iotTopicDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- UserDao userDao;
|
|
|
|
|
|
|
+ private UserDao userDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- DeviceInfoDao deviceInfoDao;
|
|
|
|
|
|
|
+ private DeviceInfoDao deviceInfoDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private GateWay2DeviceDao gateWay2DeviceDao;
|
|
private GateWay2DeviceDao gateWay2DeviceDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- IotDeviceDataDao iotDeviceDataDao;
|
|
|
|
|
|
|
+ private IotDeviceDataDao iotDeviceDataDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- CommonService commonService;
|
|
|
|
|
|
|
+ private CommonService commonService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotTemplate2DeviceService iotTemplate2DeviceService;
|
|
|
|
|
|
|
|
//----------------------------- 模版 start----------------------------
|
|
//----------------------------- 模版 start----------------------------
|
|
|
|
|
|
|
@@ -190,10 +192,7 @@ public class IotServiceImpl extends SuperService {
|
|
|
}
|
|
}
|
|
|
} else if (template.getIotDataType() == IotDataType.Device) {
|
|
} else if (template.getIotDataType() == IotDataType.Device) {
|
|
|
// 物模型
|
|
// 物模型
|
|
|
- IotTemplate temp = iotTemplateDao.findTopByNameAndDeviceIdAndIotDataType(
|
|
|
|
|
- param.getName(),
|
|
|
|
|
- template.getDeviceId(),
|
|
|
|
|
- IotDataType.Device);
|
|
|
|
|
|
|
+ IotTemplate temp = iotTemplateDao.findTopByNameAndDeviceIdAndIotDataType(param.getName(), template.getDeviceId(), IotDataType.Device);
|
|
|
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()));
|
|
|
}
|
|
}
|
|
@@ -288,15 +287,20 @@ public class IotServiceImpl extends SuperService {
|
|
|
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)) {
|
|
|
|
|
+// return ResultContent.buildFail(String.format("设备【%s】已绑定模版%s", deviceInfo.getDeviceName(), iotTemplate.getName()));
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ IotTemplate newIotTemplate = null;
|
|
|
if (ObjectUtils.isNotEmpty(temp)) {
|
|
if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
- return ResultContent.buildFail(String.format("设备【%s】已绑定模版%s", deviceInfo.getDeviceName(), iotTemplate.getName()));
|
|
|
|
|
|
|
+ newIotTemplate = temp;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ newIotTemplate = new IotTemplate();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- IotTemplate newIotTemplate = new IotTemplate();
|
|
|
|
|
BeanUtils.copyProperties(iotTemplate, newIotTemplate, "id", "createTime", "updateTime");
|
|
BeanUtils.copyProperties(iotTemplate, newIotTemplate, "id", "createTime", "updateTime");
|
|
|
newIotTemplate.setIotDataType(IotDataType.Device);
|
|
newIotTemplate.setIotDataType(IotDataType.Device);
|
|
|
newIotTemplate.setIotTemplateId(param.getTemplateId());
|
|
newIotTemplate.setIotTemplateId(param.getTemplateId());
|
|
@@ -304,14 +308,34 @@ public class IotServiceImpl extends SuperService {
|
|
|
newIotTemplate.setProjectCode(deviceInfo.getProjectInfoCode());
|
|
newIotTemplate.setProjectCode(deviceInfo.getProjectInfoCode());
|
|
|
iotTemplateDao.save(newIotTemplate);
|
|
iotTemplateDao.save(newIotTemplate);
|
|
|
|
|
|
|
|
|
|
+ // 绑定 物模型 和 设备的关系
|
|
|
|
|
+ iotTemplate2DeviceService.bind(iotTemplate, deviceInfo);
|
|
|
|
|
+
|
|
|
// 属性等数据
|
|
// 属性等数据
|
|
|
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);
|
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(oldList)) {
|
|
|
|
|
+ oldList.stream().forEach(it -> {
|
|
|
|
|
+ map.put(it.getIotMainTemplateId(), it.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
if (list != null) {
|
|
if (list != null) {
|
|
|
|
|
+ IotTemplate finalNewIotTemplate = newIotTemplate;
|
|
|
list.stream().forEach(it -> {
|
|
list.stream().forEach(it -> {
|
|
|
IotMain main = new IotMain();
|
|
IotMain main = new IotMain();
|
|
|
BeanUtils.copyProperties(it, main, "id", "createTime", "updateTime");
|
|
BeanUtils.copyProperties(it, main, "id", "createTime", "updateTime");
|
|
|
- main.setIotTemplate(newIotTemplate);
|
|
|
|
|
|
|
+ if (oldList.contains(it.getId())) {
|
|
|
|
|
+ main.setId(map.get(it.getId()));
|
|
|
|
|
+ map.remove(it.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ main.setIotTemplate(finalNewIotTemplate);
|
|
|
|
|
+ // 所属模版内容数据ID
|
|
|
|
|
+ main.setIotMainTemplateId(it.getId());
|
|
|
|
|
+
|
|
|
main.setIotDataType(IotDataType.Device);
|
|
main.setIotDataType(IotDataType.Device);
|
|
|
main.setDeviceId(deviceInfo.getDeviceId());
|
|
main.setDeviceId(deviceInfo.getDeviceId());
|
|
|
main.setProjectCode(deviceInfo.getProjectInfoCode());
|
|
main.setProjectCode(deviceInfo.getProjectInfoCode());
|
|
@@ -321,6 +345,11 @@ public class IotServiceImpl extends SuperService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
iotMainDao.saveAll(saveList);
|
|
iotMainDao.saveAll(saveList);
|
|
|
|
|
+ if (!map.isEmpty()) {
|
|
|
|
|
+ List<String> ids = new ArrayList<>(map.keySet());
|
|
|
|
|
+ iotMainDao.deleteAllById(ids);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更新权限数据
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|