|
|
@@ -2,7 +2,9 @@ package com.zhongshu.iot.server.core.service.iot;
|
|
|
|
|
|
import com.github.microservice.models.iotDeviceData.IotDeviceDataModel;
|
|
|
import com.github.microservice.models.iotDeviceData.IotDeviceDataSearch;
|
|
|
+import com.github.microservice.models.iotDeviceData.IotDeviceDataSimpleModel;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
import com.github.microservice.types.deviceUse.IotDeviceDataType;
|
|
|
import com.zhongshu.iot.client.type.IotDataType;
|
|
|
import com.zhongshu.iot.server.core.dao.iot.IotDeviceDataDao;
|
|
|
@@ -71,7 +73,7 @@ public class IotDeviceDataService {
|
|
|
temp.setDeviceId(deviceId);
|
|
|
temp.setProjectCode(iotMain.getProjectCode());
|
|
|
temp.setProperty(property);
|
|
|
- temp.setData(value);
|
|
|
+ temp.setValue(value);
|
|
|
temp.setDataType(IotDeviceDataType.Current);
|
|
|
temp.setTimes();
|
|
|
temp.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
@@ -79,7 +81,7 @@ public class IotDeviceDataService {
|
|
|
iotDeviceDataDao.save(temp);
|
|
|
|
|
|
// 发送刷新信息
|
|
|
- iotFreshService.sendPageFreshMessage(iotMain);
|
|
|
+ iotFreshService.sendPageFreshMessage(temp);
|
|
|
return ResultContent.buildSuccess();
|
|
|
} else {
|
|
|
return ResultContent.buildFail("没找到对应属性");
|
|
|
@@ -96,7 +98,7 @@ public class IotDeviceDataService {
|
|
|
public Object getDevicePropertyValue(String deviceId, String property) {
|
|
|
IotDeviceData entity = getDevicePropertyObject(deviceId, property);
|
|
|
if (entity != null) {
|
|
|
- return entity.getData();
|
|
|
+ return entity.getValue();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -135,6 +137,26 @@ public class IotDeviceDataService {
|
|
|
return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
}
|
|
|
|
|
|
+ public ResultContent<IotDeviceDataModel> detail(String id) {
|
|
|
+ IotDeviceData entity = iotDeviceDataDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent delete(String id) {
|
|
|
+ IotDeviceData entity = iotDeviceDataDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ if (entity.getDataType() == IotDeviceDataType.Current) {
|
|
|
+ return ResultContent.buildFail("当前最新数据无法删除");
|
|
|
+ }
|
|
|
+ iotDeviceDataDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
public IotDeviceDataModel toModel(IotDeviceData entity) {
|
|
|
IotDeviceDataModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
@@ -144,4 +166,13 @@ public class IotDeviceDataService {
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ public IotDeviceDataSimpleModel toSimpleModel(IotDeviceData entity) {
|
|
|
+ IotDeviceDataSimpleModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new IotDeviceDataSimpleModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
}
|