|
|
@@ -52,23 +52,28 @@ public class DeviceInfoService {
|
|
|
ProjectInfoService projectInfoService;
|
|
|
|
|
|
/**
|
|
|
- * 添加设备
|
|
|
+ * 添加-编辑设备
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
public ResultContent<DeviceInfo> addDeviceInfo(DeviceInfoAddParam param) {
|
|
|
- DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(param.getDeviceId());
|
|
|
- if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
- return ResultContent.buildFail(String.format("设备ID已存在:%s", param.getDeviceId()));
|
|
|
+ DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
+ DeviceInfo temp = deviceInfoDao.findTopByDeviceId(param.getDeviceId());
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ deviceInfo = temp;
|
|
|
+ param.setId(null);
|
|
|
}
|
|
|
- deviceInfo = new DeviceInfo();
|
|
|
- BeanUtils.copyProperties(param, deviceInfo);
|
|
|
+ BeanUtils.copyProperties(param, deviceInfo, "id");
|
|
|
+
|
|
|
+ // 项目
|
|
|
ProjectInfo projectInfo = null;
|
|
|
if (StringUtils.isNotEmpty(param.getProjectInfoOid())) {
|
|
|
projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoOid());
|
|
|
}
|
|
|
deviceInfo.setProjectInfo(projectInfo);
|
|
|
+
|
|
|
+ // 模版
|
|
|
IotTemplate iotTemplate = null;
|
|
|
if (StringUtils.isNotEmpty(param.getIotTemplateId())) {
|
|
|
iotTemplate = iotTemplateDao.findTopById(param.getIotTemplateId());
|
|
|
@@ -156,6 +161,22 @@ public class DeviceInfoService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 改变设备状态
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent updateDeviceState(DeviceInfoUpdateRemark param) {
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ deviceInfo.setState(param.getState());
|
|
|
+ deviceInfoDao.save(deviceInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 测试设备的连接时间
|
|
|
*
|