Commit 2f4fdd5d authored by 高建强's avatar 高建强

item:添加稳压泵启停状态图详情接口,及bug修改

parent bc61b69b
......@@ -577,7 +577,7 @@ public class EmergencyController extends AbstractBaseController {
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getPressurePumpStatusChart")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵启停状态图", notes = "四横八纵-稳压泵启停状态图")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵启停状态图", notes = "四横八纵-稳压泵启停状态图,取舍补点")
public ResponseModel getPressurePumpStatusChart(@RequestParam String startTime, @RequestParam String endTime,
@RequestParam(required = false) String bizOrgCode) {
if(StringUtils.isEmpty(bizOrgCode)) {
......@@ -595,6 +595,25 @@ public class EmergencyController extends AbstractBaseController {
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getPressurePumpStatusDetailChart")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵启停状态图", notes = "四横八纵-稳压泵启停状态图,分钟级补点")
public ResponseModel getPressurePumpStatusDetailChart(@RequestParam String startTime, @RequestParam String endTime,
@RequestParam(required = false) String bizOrgCode) {
if(StringUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
if (bizOrgCode == null) {
return CommonResponseUtil.success(Collections.EMPTY_MAP);
}
}
}
return CommonResponseUtil.success(iEmergencyService.getPressurePumpStatusDetailChart(startTime, endTime, bizOrgCode));
}
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getPressurePumpDiagnosticAnalysis")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵诊断分析", notes = "四横八纵-稳压泵诊断分析")
public ResponseModel getPressurePumpDiagnosticAnalysis(@RequestParam(required = false) String bizOrgCode) {
......
......@@ -57,6 +57,8 @@ public interface IEmergencyService {
Map<String, Object> getPressurePumpStatusChart(String startTime, String endTime, String bizOrgCode);
Map<String, Object> getPressurePumpStatusDetailChart(String startTime, String endTime, String bizOrgCode);
List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String bizOrgCode);
Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus);
......
......@@ -178,4 +178,11 @@ public interface IPressurePumpService {
* @return
*/
List<OrgUsrDto> getOrgUsrDtoInfo(Map<String, String> map);
/**
* 获取公司顶级bizOrgCode
* @param bizOrgCode
* @return
*/
String getCompanyBizOrgCode(String bizOrgCode);
}
......@@ -383,12 +383,13 @@ public class EmergencyServiceImpl implements IEmergencyService {
dataList.add(xMap);
});
dataListMap.put(iotCode.toString(), dataList);
} else {
List<Map<String, String>> dataList = getDataList(startTime, endTime, iotCode);
dataListMap.put(iotCode.toString(), dataList);
}
} else if (iotCode.toString().length() > 8) {
// iot获取数据
String prefix = iotCode.toString().substring(0, 8);
String suffix = iotCode.toString().substring(8);
List<Map<String, String>> dataList = pressurePumpService.getIotCommonListData(startTime, endTime, prefix, suffix, null, pressurePumpStart);
List<Map<String, String>> dataList = getDataList(startTime, endTime, iotCode);
dataList.forEach(z -> timeSet.add(z.get(PressurePumpRelateEnum.CREATED_TIME.getValue())));
dataListMap.put(iotCode.toString(), dataList);
}
......@@ -438,9 +439,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
}
}
} else {
timeList.forEach(t -> {
yList.add(Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
});
timeList.forEach(t -> yList.add(Integer.parseInt(PressurePumpRelateEnum.STOP.getValue())));
}
yMap.put("data", yList);
yData.add(yMap);
......@@ -456,6 +455,111 @@ public class EmergencyServiceImpl implements IEmergencyService {
return map;
}
@Override
public Map<String, Object> getPressurePumpStatusDetailChart(String startTime, String endTime, String bizOrgCode) {
Map<String, Object> map = new LinkedHashMap<>();
try {
// 从 json 配置文件获取配置信息
List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue());
if (!CollectionUtils.isEmpty(infoList)) {
Date dateNow = DateUtils.getDateNow();
Map infoMap = infoList.get(0);
String equipmentCode = infoMap.get("equipmentCode").toString();
// 获取稳压泵
List<Map<String, Object>> list = equipmentSpecificSerivce.getListByEquipmentCode(equipmentCode, bizOrgCode);
// 获取各稳压泵数据,及时间戳
if (!CollectionUtils.isEmpty(list)) {
// 获取查询时间范围内的时间戳
List<String> timeHourList = DateUtils.getTimeStrListByStartAndEnd(startTime, endTime, DateUtils.MONTH_DAY_HOUR_MINUTE_PATTERN);
List<Map<String, Object>> yData = new ArrayList<>();
LinkedHashMap<String, List<Map<String, String>>> dataListMap = new LinkedHashMap<>();
for (Map<String, Object> x : list) {
Object iotCode = x.get("iotCode");
if (iotCode != null) {
// 判断开始时间,是否在redis缓存有效期之内,是,redis获取数据,否则,iot获取数据
int expire = Integer.parseInt(infoMap.get("expire").toString()) * -1;
Date beforeDate = DateUtils.dateAddSeconds(dateNow, expire);
Date startDate = DateUtils.convertStrToDate(startTime, DateUtils.DATE_TIME_PATTERN);
Date endDate = DateUtils.convertStrToDate(endTime, DateUtils.DATE_TIME_PATTERN);
if (DateUtils.dateCompare(startDate, beforeDate) >= 0) {
// 获取redis稳压泵缓存数据,默认JSON配置最近4小时
List<IotDataVO> redisDataList = pressurePumpService.getDataToRedisByDateBetween(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpStart, iotCode.toString(), startDate, endDate, bizOrgCode);
if (!CollectionUtils.isEmpty(redisDataList)) {
List<Map<String, String>> dataList = new ArrayList<>();
redisDataList.forEach(y -> {
Map<String, String> xMap = new HashMap<>();
xMap.put(pressurePumpStart, y.getValue().toString());
xMap.put(PressurePumpRelateEnum.CREATED_TIME.getValue(), y.getCreatedTime());
dataList.add(xMap);
});
dataListMap.put(iotCode.toString(), dataList);
} else {
List<Map<String, String>> dataList = getDataList(startTime, endTime, iotCode);
dataListMap.put(iotCode.toString(), dataList);
}
} else if (iotCode.toString().length() > 8) {
// iot获取数据
List<Map<String, String>> dataList = getDataList(startTime, endTime, iotCode);
dataListMap.put(iotCode.toString(), dataList);
}
}
}
// 遍历稳压泵,dataListMap获取各稳压泵数据,没有数据的进行补0
list.forEach(x -> {
Map<String, Object> yMap = new HashMap<>();
List<Integer> yList = new ArrayList<>();
String name = x.get("name").toString();
yMap.put("name", name);
Object iotCode = x.get("iotCode");
if (!ObjectUtils.isEmpty(iotCode)) {
List<Map<String, String>> dataList = dataListMap.get(iotCode.toString());
// 获取最新稳压泵启动指标值,作为后续稳压泵启停参考值
String flag = null;
if (!CollectionUtils.isEmpty(dataList)) {
Collections.reverse(dataList);
Map<String, List<Map<String, String>>> dataMap = dataList.stream().filter(y -> y.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue())).collect(Collectors.groupingBy(e -> e.get("createdTime").substring(5, 16)));
List<Map<String, String>> yDataList = null;
for (String t : timeHourList) {
List<Map<String, String>> data = dataMap.get(t);
if (!CollectionUtils.isEmpty(data)) {
yDataList = data.stream().filter(o -> PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(o.get(pressurePumpStart))).collect(Collectors.toList());
flag = data.get(data.size() - 1).get(pressurePumpStart);
yList.add(!CollectionUtils.isEmpty(yDataList) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(flag) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
} else {
yList.add(StringUtils.isNotBlank(flag) && PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(flag) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
}
}
} else {
String prefix = iotCode.toString().substring(0, 8);
String suffix = iotCode.toString().substring(8);
List<Map<String, String>> iotDataList = pressurePumpService.getIotTopSingleField("1", prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), pressurePumpStart);
if (!CollectionUtils.isEmpty(iotDataList)) {
flag = iotDataList.get(0).get(pressurePumpStart);
}
String finalFlag = flag;
timeHourList.forEach(t -> yList.add(StringUtils.isNotBlank(finalFlag) && PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(finalFlag) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : Integer.parseInt(PressurePumpRelateEnum.STOP.getValue())));
}
yMap.put("data", yList);
yData.add(yMap);
}
});
map.put("xData", timeHourList);
map.put("yData", yData);
}
}
} catch (Exception e) {
log.error("getPressurePumpStatusChart-->获取稳压泵启停状态图失败:{}", e.getMessage());
}
return map;
}
private List<Map<String, String>> getDataList(String startTime, String endTime, Object iotCode) {
String prefix = iotCode.toString().substring(0, 8);
String suffix = iotCode.toString().substring(8);
List<Map<String, String>> dataList = pressurePumpService.getIotCommonListData(startTime, endTime, prefix, suffix, null, pressurePumpStart);
return dataList;
}
@Override
public Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page, String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus) {
......@@ -487,7 +591,6 @@ public class EmergencyServiceImpl implements IEmergencyService {
long countExpire = Long.parseLong(infoMap.get("countExpire").toString());
List<Map<String, Object>> pumpInfoList = equipmentSpecificSerivce.getFirePumpInfoEQ(equipmentCode, null);
if (!CollectionUtils.isEmpty(pumpInfoList)){
Map<String, String> params = new HashMap<>();
for (Map<String, Object> map : pumpInfoList) {
// iot获取数据,返回并存储redis
Object iotCode = map.get("iotCode");
......@@ -495,19 +598,12 @@ public class EmergencyServiceImpl implements IEmergencyService {
String bizOrgCode = ObjectUtils.isEmpty(orgCode) ? "" : orgCode.toString();
if (!ObjectUtils.isEmpty(iotCode) && !ObjectUtils.isEmpty(bizOrgCode)) {
// 获取公司顶级bizOrgCode
params.put("bizOrgType", PressurePumpRelateEnum.BIZ_ORG_TYPE_COMPANY.getValue());
params.put("bizOrgCode", bizOrgCode);
List<OrgUsrDto> orgUsrDtoList = pressurePumpService.getOrgUsrDtoInfo(params);
if (!CollectionUtils.isEmpty(orgUsrDtoList)) {
bizOrgCode = orgUsrDtoList.get(0).getBizOrgCode();
if (StringUtils.isNotBlank(bizOrgCode)) {
String iotCodeStr = iotCode.toString();
String prefix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(0, 8);
String suffix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(8);
List<PressurePumpCountVo> dataList = pressurePumpService.getIotCountData(startTime, endTime, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), pressurePumpStart, countExpire, bizOrgCode);
dataMap.put(iotCodeStr, dataList);
}
}
bizOrgCode = pressurePumpService.getCompanyBizOrgCode(bizOrgCode);
String iotCodeStr = iotCode.toString();
String prefix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(0, 8);
String suffix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(8);
List<PressurePumpCountVo> dataList = pressurePumpService.getIotCountData(startTime, endTime, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), pressurePumpStart, countExpire, bizOrgCode);
dataMap.put(iotCodeStr, dataList);
}
}
}
......
......@@ -58,13 +58,8 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
@Async
public void saveDataToRedis(List<IotDataVO> iotDatalist, String iotCode, String bizOrgCode) {
// 获取公司顶级bizOrgCode
Map<String, String> params = new HashMap<>();
params.put("bizOrgType", PressurePumpRelateEnum.BIZ_ORG_TYPE_COMPANY.getValue());
params.put("bizOrgCode", bizOrgCode);
List<OrgUsrDto> orgUsrDtoList = getOrgUsrDtoInfo(params);
if (CollectionUtils.isNotEmpty(orgUsrDtoList)) {
bizOrgCode = orgUsrDtoList.get(0).getBizOrgCode();
if (StringUtils.isNotBlank(bizOrgCode)) {
bizOrgCode = getCompanyBizOrgCode(bizOrgCode);
if (StringUtils.isNotBlank(bizOrgCode)) {
String pressurePumpValue = PressurePumpRelateEnum.PRESSURE_PUMP.getValue();
// 获取配置JSON信息集合
List<Map> list = getNameKeyInfoList(pressurePumpValue);
......@@ -84,6 +79,17 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
}
}
@Override
public String getCompanyBizOrgCode(String bizOrgCode) {
Map<String, String> params = new HashMap<>();
params.put("bizOrgType", PressurePumpRelateEnum.BIZ_ORG_TYPE_COMPANY.getValue());
params.put("bizOrgCode", bizOrgCode);
List<OrgUsrDto> orgUsrDtoList = getOrgUsrDtoInfo(params);
if (CollectionUtils.isNotEmpty(orgUsrDtoList)) {
bizOrgCode = orgUsrDtoList.get(orgUsrDtoList.size() - 1).getBizOrgCode();
}
return bizOrgCode;
}
@Override
......@@ -303,6 +309,8 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
PressurePumpCountVo countVo = new PressurePumpCountVo();
countVo.setTime(time);
countVo.setValue(dataMap.get(time).size());
// 获取公司顶级bizOrgCode
bizOrgCode = getCompanyBizOrgCode(bizOrgCode);
// 获取的数据存储到redis
String topic = String.join(":", infoCode, bizOrgCode, countRedisKey, fieldKey, iotCode, time);
countVo.setIotCode(topic);
......
......@@ -64,8 +64,9 @@
biz_org_type = #{bizOrgType}
</if>
<if test="bizOrgCode != null and bizOrgCode != ''">
AND locate( #{bizOrgCode}, biz_org_code ) > 0
AND locate( biz_org_code, #{bizOrgCode} ) > 0
</if>
</where>
ORDER BY sequence_nbr
</select>
</mapper>
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