供电和供水实时数据

This commit is contained in:
wuyw 2024-08-19 23:39:31 +08:00
parent 5ffeb9891c
commit 25f745c2d3

View File

@ -248,68 +248,96 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
taiyangnengModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<HashMap<Object, Object>> list = new ArrayList<>();
if (StringUtils.isNotEmpty(taiyangnengIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
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());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.parseLong(taiyangnengIds));
if(cache != null){
HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
if(checkedData != null){
List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_kaixian")){
continue;
}
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", haiWeiPropertyVo.getNameEn());
put("unit", haiWeiPropertyVo.getUnit());
put("value", haiWeiPropertyVo.getValue());
put("name", haiWeiPropertyVo.getNameCn());
}};
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_MpptDown")){
hashMap.put("value", Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?
"异常":"正常");
}
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_市电状态")){
hashMap.put("value", Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?
"市电":"太阳能");
}
list.add(hashMap);
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
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());
}
}
list.add(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());
}};
list.add(hashMap);
}
}
// if (StringUtils.isNotEmpty(taiyangnengIds)) {
// Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
// List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
// setSerialNumber(taiyangnengDevice.getSerialNumber());
// setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
// setEndTime(DateUtil.endOfDay(dateTime).toString());
// }});
// Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
// .comparing(DeviceLog::getCreateTime, Comparator
// .nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
// 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());
// }};
// if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
// 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 = taiyangnengCollect.get(thingsModel.getIdentifier());
// 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());
// }
// }
// list.add(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());
// }};
// list.add(hashMap);
// }
// }
return list;
}
@ -332,68 +360,100 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService {
List<ThingsModel> liuliangModels = thingsModelService.selectThingsModelList(thingsModel1);
liuliangModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
List<HashMap<Object, Object>> list = new ArrayList<>();
if (StringUtils.isNotEmpty(liuliangIds)) {
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
setSerialNumber(taiyangnengDevice.getSerialNumber());
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
setEndTime(DateUtil.endOfDay(dateTime).toString());
}});
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
.comparing(DeviceLog::getCreateTime, Comparator
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
String specs = thingsModel.getSpecs();
JSONObject parse = (JSONObject) JSON.parse(specs);
if (parse.containsKey("unit")) {
hashMap.put("unit", parse.get("unit"));
CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.parseLong(liuliangIds));
if(cache != null){
HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
if(checkedData != null){
List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_kaixian")){
continue;
}
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", haiWeiPropertyVo.getNameEn());
put("unit", haiWeiPropertyVo.getUnit());
put("value", haiWeiPropertyVo.getValue());
put("name", haiWeiPropertyVo.getNameCn());
}};
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_guanxian")){
hashMap.put("value", Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?
"关闭":"开启");
}
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_FlowDown")){
hashMap.put("value", Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?
"异常":"正常");
}
if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_mCon")){
hashMap.put("value", Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?
"异常":"正常");
}
list.add(hashMap);
}
if (hashMap.size() > 1) {
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
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());
}
}
list.add(hashMap);
}
} else {
for (ThingsModel thingsModel : liuliangModels) {
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
put("upType", 0);
put("identifier", thingsModel.getIdentifier());
put("unit", "");
put("value", 0);
put("name", thingsModel.getModelName());
}};
list.add(hashMap);
}
}
// if (StringUtils.isNotEmpty(liuliangIds)) {
// Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
// List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
// setSerialNumber(taiyangnengDevice.getSerialNumber());
// setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
// setEndTime(DateUtil.endOfDay(dateTime).toString());
// }});
// Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
// .comparing(DeviceLog::getCreateTime, Comparator
// .nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
// for (ThingsModel thingsModel : liuliangModels) {
// HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", thingsModel.getIdentifier());
// put("unit", "");
// put("value", 0);
// put("name", thingsModel.getModelName());
// }};
// if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
// 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 = taiyangnengCollect.get(thingsModel.getIdentifier());
// 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());
// }
// }
// list.add(hashMap);
// }
// } else {
// for (ThingsModel thingsModel : liuliangModels) {
// HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
// put("upType", 0);
// put("identifier", thingsModel.getIdentifier());
// put("unit", "");
// put("value", 0);
// put("name", thingsModel.getModelName());
// }};
// list.add(hashMap);
// }
// }
return list;
}