Commit 516cb67e authored by 高建强's avatar 高建强

item:优化管网压力JSON配置

parent f624be12
......@@ -18,7 +18,7 @@ public enum PressurePumpRelateEnum {
TWO_HOUR("2.0", "2小时"),
FOUR_HOUR("4.0", "4小时"),
START_FIVE("5", "稳压泵启动5分钟"),
PIPE_PRESSURE_DIFF("0.5", "管网压力差判定标准,> 0.05Mpa 异常, <= 0.05 正常"),
PIPE_PRESSURE_DIFF("0.05", "管网压力差判定标准,> 0.05Mpa 异常, <= 0.05 正常"),
PRESSURE_PUMP_START_BEFORE_MINUTE("-5", "稳压泵启泵前分钟数"),
PIPE_PRESSURE_NORMAL_STATUS("正常", "稳压泵管网压力正常状态"),
PIPE_PRESSURE_ABNORMAL_STATUS("异常", "稳压泵管网压力异常状态"),
......
......@@ -131,5 +131,5 @@ public interface IPressurePumpService {
* @param aClass
* @return
*/
Object mapToObject(Map<String,String> map,Class<?> aClass) throws IllegalAccessException, InstantiationException;
Object mapToObject(Map<String,String> map,Class<?> aClass, String indexKey) throws IllegalAccessException, InstantiationException;
}
......@@ -228,6 +228,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
if (!CollectionUtils.isEmpty(infoList)) {
Map map = infoList.get(0);
String equipmentCode = map.get("equipmentCode").toString();
String pipePressureEquipmentCode = map.get("pipePressureEquipmentCode").toString();
String faultNameKey = map.get("faultNameKey").toString();
String top = map.get("top").toString();
// 1. 判断稳压泵整体是否故障
......@@ -238,7 +239,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
List<IotDataVO> dataList = dataMap.get("dataList");
List<IotDataVO> dataListFilterTrue = dataMap.get("dataListFilterTrue");
List<IotDataVO> dataListFilterFalse = dataMap.get("dataListFilterFalse");
Map<String, List<IotDataVO>> dataPipMap = pressurePumpService.getDataList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), equipmentCode, top, pressurePumpPipePressure, bizOrgCode, null);
Map<String, List<IotDataVO>> dataPipMap = pressurePumpService.getDataList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pipePressureEquipmentCode, top, pressurePumpPipePressure, bizOrgCode, null);
List<IotDataVO> dataPipeList = dataPipMap.get("dataList");
String nowStrLong = DateUtils.getDateNowString();
......
......@@ -174,21 +174,16 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
// 过滤指定值数据
List<IotDataVO> dataListFilterTrue = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
List<IotDataVO> dataListFilterFalse = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
// 通过 equipmentCode 获取装备
List<Map<String, Object>> pumpInfoList = equipmentSpecificSerivce.getFirePumpInfoEQ(equipmentCode, bizOrgCode);
if (!ObjectUtils.isEmpty(pumpInfoList)) {
iotCode = pumpInfoList.get(0).get("iotCode").toString();
if (iotCode.length() > 8) {
String prefix = iotCode.substring(0, 8);
//获取iot的数据
if(ObjectUtils.isEmpty(dataList) || ObjectUtils.isEmpty(dataListFilterTrue) || ObjectUtils.isEmpty(dataListFilterFalse)){
dataList = getIotData(top, prefix, nameKey);
// 过滤物联指定值数据
dataListFilterTrue = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
dataListFilterFalse = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
if (pressurePumpPipePressure.equalsIgnoreCase(nameKey)) {
if (ObjectUtils.isEmpty(dataList) || dataList.size() < 2) {
dataList = getIotData(top, nameKey, equipmentCode, bizOrgCode);
}
} else {
throw new BadRequest("装备物联编码错误,请确认!");
if (ObjectUtils.isEmpty(dataList) || ObjectUtils.isEmpty(dataListFilterTrue) || ObjectUtils.isEmpty(dataListFilterFalse)) {
dataList = getIotData(top, nameKey, equipmentCode, bizOrgCode);
dataListFilterTrue = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
dataListFilterFalse = getDataListFilter(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
}
}
map.put("dataList", dataList);
......@@ -197,23 +192,34 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
return map;
}
private List<IotDataVO> getIotData(String top, String prefix, String indexKey) {
private List<IotDataVO> getIotData(String top, String nameKey, String equipmentCode, String bizOrgCode) {
List<IotDataVO> dataList = new ArrayList<>();
List<Map<String, String>> iotDataList = getIotTopSingleField(top, prefix, null, null, indexKey);
// 通过 equipmentCode 获取装备
List<Map<String, Object>> pumpInfoList = equipmentSpecificSerivce.getFirePumpInfoEQ(equipmentCode, bizOrgCode);
if (!ObjectUtils.isEmpty(pumpInfoList)) {
String iotCode = pumpInfoList.get(0).get("iotCode").toString();
if (iotCode.length() > 8) {
String prefix = iotCode.substring(0, 8);
List<Map<String, String>> iotDataList = getIotTopSingleField(top, prefix, null, null, nameKey);
//将iot的List<Map<String, String>>转化为List<IotDataVO>类型
iotDataList.stream().forEach(e -> {
iotDataList.forEach(e -> {
try {
IotDataVO iotDataVO = (IotDataVO) mapToObject(e, IotDataVO.class);
IotDataVO iotDataVO = (IotDataVO) mapToObject(e, IotDataVO.class, nameKey);
dataList.add(iotDataVO);
} catch (Exception el) {
throw new BadRequest("IOT数据类型转换失败");
}
});
}
} else {
throw new BadRequest("装备物联编码错误,请确认!");
}
return dataList;
}
/**
* map 转化为对象
*
* @param map 需要转化的参数
* @param aClass 要转化成的对象
* @return 转化成功的对象
......@@ -221,25 +227,25 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
* @throws InstantiationException 实例化异常
*/
@Override
public Object mapToObject(Map<String,String> map,Class<?> aClass) throws IllegalAccessException, InstantiationException {
if(map.isEmpty()){
public Object mapToObject(Map<String, String> map, Class<?> aClass, String indexKey) throws IllegalAccessException, InstantiationException {
if (map.isEmpty()) {
return null;
}
Object o = aClass.newInstance();
Field[] declaredFields = o.getClass().getDeclaredFields();
for (Field field :declaredFields) {
for (Field field : declaredFields) {
int modifiers = field.getModifiers();
if(Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)){
if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)) {
continue;
}
// (此处如果不设置 无法获取对象的私有属性)
field.setAccessible(true);
if("key".equals(field.getName())){
field.set(o,pressurePumpStart);
} else if("value".equals(field.getName())){
field.set(o,map.get(pressurePumpStart));
if ("key".equals(field.getName())) {
field.set(o, indexKey);
} else if ("value".equals(field.getName())) {
field.set(o, map.get(indexKey));
} else {
field.set(o,map.get(field.getName()));
field.set(o, map.get(field.getName()));
}
}
......@@ -257,6 +263,13 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
return dataList.stream().filter(x -> value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
}
private List<IotDataVO> getDataListFilter(List<IotDataVO> dataList, Date beforeDate) {
if (beforeDate != null) {
return dataList.stream().filter(x -> DateUtils.dateCompare(DateUtils.longStr2Date(x.getCreatedTime()), beforeDate) >= 0).collect(Collectors.toList());
}
return dataList;
}
private List<Map<String, String>> getIotDataFilterList(List<Map<String, String>> iotDataList, String value, Date beforeDate) {
if (beforeDate != null) {
return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && DateUtils.dateCompare(DateUtils.longStr2Date(x.get(PressurePumpRelateEnum.CREATED_TIME.getValue())), beforeDate) >= 0 && value.equalsIgnoreCase(x.get(pressurePumpPipePressure))).collect(Collectors.toList());
......@@ -313,7 +326,7 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
try {
Date stop5BeforeDate = DateUtils.dateAddMinutes(DateUtils.convertStrToDate(createdTime, DateUtils.DATE_TIME_PATTERN), Integer.parseInt(minutes));
// 获取指定之前时间,指定值数据
List<IotDataVO> dataFilterList = getDataListFilter(dataPipeList, value, stop5BeforeDate);
List<IotDataVO> dataFilterList = getDataListFilter(dataPipeList, stop5BeforeDate);
if (CollectionUtils.isNotEmpty(dataFilterList)) {
double val1 = Double.parseDouble(dataPipeList.get(0).getValue().toString());
double val2 = Double.parseDouble(dataFilterList.get(dataFilterList.size() - 1).getValue().toString());
......
......@@ -164,7 +164,7 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
List<Map<String, String>> iotDataList = pressurePumpService.getIotTopSingleField(top, prefix, null, null, pressurePumpStart);
iotDataList.stream().forEach(e -> {
try {
IotDataVO iotDataVO = (IotDataVO) pressurePumpService.mapToObject(e, IotDataVO.class);
IotDataVO iotDataVO = (IotDataVO) pressurePumpService.mapToObject(e, IotDataVO.class, pressurePumpStart);
DataList.add(iotDataVO);
} catch (Exception el) {
throw new RuntimeException();
......
......@@ -6,6 +6,7 @@
"faultNameKey": "FHS_PressurePump_Fault,FHS_PressurePump_RunFault,FHS_PressurePump_OverLoadFault",
"expire": 14400,
"equipmentCode": "92010800KAL44",
"pipePressureEquipmentCode": "92011000T5Q44",
"top": "100"
}
]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment