getRealTimeDataByDevicerId接口数据第一版

This commit is contained in:
wyw 2024-08-13 19:19:18 +08:00
parent 47a00e60e8
commit c4a03a4d44
3 changed files with 114 additions and 54 deletions

View File

@ -54,7 +54,9 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
@Override @Override
public GisDeviceListVo totalAndList(Device device) { public GisDeviceListVo totalAndList(Device device) {
List<Product> productEntities = productMapper.selectProductList(new Product()); Product product = new Product();
product.setProductId(136L);
List<Product> productEntities = productMapper.selectProductList(product);
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
List<TreeItemVo> productContainDeviceListVos = new ArrayList<>(); List<TreeItemVo> productContainDeviceListVos = new ArrayList<>();
int count = 0; int count = 0;
@ -99,8 +101,7 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
@Override @Override
public Object getRealTimeDataByDevicerId(Long deviceId) { public Object getRealTimeDataByDevicerId(Long deviceId) {
HashMap<String, Object> rMap = new HashMap<String, Object>() { HashMap<String, Object> rMap = new HashMap<String, Object>() {};
};
if (deviceId == null) { if (deviceId == null) {
throw new RuntimeException("请上传devicerId"); throw new RuntimeException("请上传devicerId");
} }
@ -108,62 +109,104 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
if (device == null) { if (device == null) {
throw new RuntimeException("未查到该设备"); throw new RuntimeException("未查到该设备");
} }
ThingsModel thingsModel1 = new ThingsModel();
thingsModel1.setProductId(device.getProductId());
List<ThingsModel> thingsModelEntities = thingsModelService.selectThingsModelList(thingsModel1);
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getDeviceInfoCache(device.getDeviceId());
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getCacheDeviceStatus(device.getProductId(),
// device.getSerialNumber());
DateTime dateTime = DateUtil.date(new Date()); DateTime dateTime = DateUtil.date(new Date());
List<DeviceLog> deviceLogsAll = new ArrayList<>(); Map<String, Object> devParams = getDevParams(device);
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{ //太阳能设备
setSerialNumber(device.getSerialNumber()); String taiyangnengIds = devParams.get("taiyangnIds").toString();
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString()); ThingsModel thingsModel1 = new ThingsModel();
setEndTime(DateUtil.endOfDay(dateTime).toString()); thingsModel1.setProductId(138L);
}}); List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
if (deviceLogs != null) { // HashMap<String, Object> taiyangnengMap = new HashMap<String, Object>() {};
deviceLogsAll.addAll(deviceLogs); if (StringUtils.isNotEmpty(taiyangnengIds)) {
} Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
Map<String, List<DeviceLog>> collect = deviceLogsAll.stream().sorted(Comparator setSerialNumber(taiyangnengDevice.getSerialNumber());
.comparing(DeviceLog::getCreateTime, Comparator setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity())); setEndTime(DateUtil.endOfDay(dateTime).toString());
for (ThingsModel thingsModel : thingsModelEntities) { }});
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{ Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
put("upType", 0); .comparing(DeviceLog::getCreateTime, Comparator
put("identifier", thingsModel.getIdentifier()); .nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
put("unit", ""); for (ThingsModel thingsModel : taiyangnengModels) {
put("value", 0); HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("name", thingsModel.getModelName()); put("upType", 0);
}}; put("identifier", thingsModel.getIdentifier());
// {"max": 100, "min": 0, "step": 1, "type": "decimal", "unit": "m/s"} put("unit", "");
if(StringUtils.isNotEmpty(thingsModel.getSpecs())){ put("value", 0);
String specs = thingsModel.getSpecs(); put("name", thingsModel.getModelName());
JSONObject parse = (JSONObject) JSON.parse(specs); }};
if(parse.containsKey("unit")){ if(StringUtils.isNotEmpty(thingsModel.getSpecs())){
hashMap.put("unit", parse.get("unit")); String specs = thingsModel.getSpecs();
} JSONObject parse = (JSONObject) JSON.parse(specs);
} if(parse.containsKey("unit")){
hashMap.put("unit", parse.get("unit"));
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = collect.get(thingsModel.getIdentifier());
if (deviceLogs1 != null) {
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
{
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
} }
hashMap.put("value", deviceLogs1.get(0).getLogValue());
} }
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = collect.get(thingsModel.getIdentifier()); if (hashMap.size() > 1) {
if (deviceLogs2 != null) { List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
hashMap.put("value", deviceLogs2.get(0).getLogValue()); if (deviceLogs1 != null) {
if(StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())){
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
{
hashMap.put("upType", 1);
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
hashMap.put("upType", -1);
}
hashMap.put("value", deviceLogs1.get(0).getLogValue());
}else{
hashMap.put("value", "--");
hashMap.put("upType", 0);
}
}
} else if (hashMap.size() > 0) {
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
if (deviceLogs2 != null) {
hashMap.put("value", deviceLogs2.get(0).getLogValue());
}
} }
rMap.put(thingsModel.getIdentifier(), hashMap);
}
}else{
for (ThingsModel thingsModel : taiyangnengModels){
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
rMap.put(thingsModel.getIdentifier(), hashMap);
} }
rMap.put(thingsModel.getIdentifier(), hashMap);
} }
//安防信息
String anfangIds = devParams.get("anfangIds").toString();
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", "xiangmen");
put("unit", "");
put("value", 0);//0=正常1=箱门振动2=箱门打开
put("name", "箱门状态");
}};
rMap.put("xiangmen",hashMap);
//机井信息
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", "sumFlow");
put("unit", "");
put("value", 0);
put("name", "累计用水量");
}};
rMap.put("sumFlow",hashMap1);
HashMap<Object, Object> hashMap2 = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", "sumEle");
put("unit", "");
put("value", 0);
put("name", "累计用电量");
}};
rMap.put("sumEle",hashMap2);
return rMap; return rMap;
} }
@ -257,4 +300,20 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
} }
public Map<String, Object> getDevParams(Device device) {
Map<String, Object> devData = new HashMap<>();
try{
Object devParams = com.alibaba.fastjson.JSON.parse(device.getDevParams()); //先转换成Object
List<Map<String, Object>> Params = (List<Map<String, Object>>) devParams;
if (Params != null) {
for (Map<String, Object> param : Params) {
devData.put(param.get("key").toString(), param.get("value").toString());
}
}
}catch (Exception exception){
}
return devData;
}
} }

View File

@ -1600,6 +1600,7 @@ public class DeviceServiceImpl implements IDeviceService {
@Override @Override
public List<Map<String, Object>> devicePointInfo(Device devices) { public List<Map<String, Object>> devicePointInfo(Device devices) {
ArrayList<Map<String, Object>> resultList = new ArrayList<>(); ArrayList<Map<String, Object>> resultList = new ArrayList<>();
devices.setProductId(136L);
List<Device> deviceList = selectDeviceList(devices); List<Device> deviceList = selectDeviceList(devices);
for (Device device : deviceList) { for (Device device : deviceList) {

View File

@ -88,7 +88,7 @@ public class ThingsModelServiceImpl implements IThingsModelService {
*/ */
@Override @Override
public ThingsModel selectSingleThingsModel(ThingsModel model) { public ThingsModel selectSingleThingsModel(ThingsModel model) {
model.setLanguage(SecurityUtils.getLanguage()); // model.setLanguage(SecurityUtils.getLanguage());
return thingsModelMapper.selectSingleThingsModel(model); return thingsModelMapper.selectSingleThingsModel(model);
} }