分页显示总览数据
@GetMapping("/search")
public ShuifenEventVoWrapper getWarehouseByCondition(//接口处获得搜索限制词,和分页信息
@RequestParam(required = false) Long chargeId,
@RequestParam(required = false) Long warehouseId,
@RequestParam(required = false) Long segmentId,
@RequestParam(required = false) Integer xunzhenStatus,
@RequestParam(required = false) Float touyaoLiangStart,
@RequestParam(required = false) Float touyaoLiangEnd,
@RequestParam(required = false) Long startTime,
@RequestParam(required = false) Long endTime,
@RequestParam(required = false) String queryStr,
@RequestParam Integer limit,
@RequestParam Integer offset
) {
String startStr = getDateStr(startTime, false);
String endStr = getDateStr(endTime, true);
List<EventCommonInfo> shuifenEventVos = xunzhenEventVoDao.querySegmentListByCondition(//获取数据库表中相关数据
startStr,
endStr,
segmentId,
chargeId,
warehouseId,
xunzhenStatus,
touyaoLiangStart,
touyaoLiangEnd,
queryStr,
limit,
offset
);
Long total = xunzhenEventVoDao.queryCountByCondition(//查询总记录数
startStr,
endStr,
segmentId,
chargeId,
warehouseId,
xunzhenStatus,
touyaoLiangStart,
touyaoLiangEnd,
queryStr
);
List<EventCommonInfo> tableData =
shuifenEventVos.stream().map(shuifenEventVo -> {
Long id = shuifenEventVo.getSegmentId();
Tuple4 tuple4 = aggregateService.getMax4Data(id);//得到仓间最大温湿度,和户外温湿度
shuifenEventVo.setHumidity((Float) tuple4.first);
shuifenEventVo.setTemperature((Float) tuple4.second);
shuifenEventVo.setOutterHumidity(Float.valueOf((String) tuple4.third));
shuifenEventVo.setOutterTemperature(Float.valueOf((String) tuple4.fourth));
Tuple3 tuple3 = conditionService.getXunzhenCondition(id);//得到仓间内ppm浓度和包芯内ppm浓度,以及当前熏蒸状况
Timestamp startTimestamp = new Timestamp(shuifenEventVo.getStartTime().getTime());
Timestamp endTimestamp = shuifenEventVo.getEndTime()!=null?new Timestamp(shuifenEventVo.getEndTime().getTime()):
new Timestamp(System.currentTimeMillis());
Tuple2 xunzhenResult = conditionService.computeXunzhenResult(id,startTimestamp,endTimestamp);
shuifenEventVo.setHzsppm(((Double)tuple3.first).floatValue());
shuifenEventVo.setBaoxinHzsppm(((Double)tuple3.second).floatValue());
shuifenEventVo.setCondition(((XunzhenCondition)tuple3.third).getNumber());
shuifenEventVo.setEventResult(((XunzhenResult)xunzhenResult.first).getNumber());//得到熏蒸事件结果
return shuifenEventVo;
}).collect(Collectors.toList());
ShuifenEventVoWrapper res = new ShuifenEventVoWrapper();
res.setTableData(tableData);
res.setTotal(total);
return res;
}
具体业务数据实现
public Tuple4 getMax4Data(Long segmentId) {
List<Device> devices = deviceService.getDeviceListBySegmentId(segmentId, 1);//根据仓间id和类型取得所有设备信息
return getMax4Data(
devices.stream().map(Device::getNumber).collect(Collectors.toList())//得到设备number
);
}
public Tuple4 getMax4Data(List<String> deviceIds) {
List<KmSensorInfoHis> kmSensorInfoHis = getLastDataTempAndHumDataByDeviceIds(deviceIds);//根据设备id得到最新的数据
return getLastMaxTempAndHumAndOutterTempAndOutterHum(kmSensorInfoHis);//选择数据的最大值
}
public List<KmSensorInfoHis> getLastDataTempAndHumDataByDeviceIds(List<String> deviceIds) {
return deviceIds.stream().map(id -> {
return kmSensorInfoHisService.getLastDataByDeviceId(id);//根据设备id获得最新的数据
}).filter(k -> k != null).collect(Collectors.toList());//过滤为空的信息
}
private Tuple4 getLastMaxTempAndHumAndOutterTempAndOutterHum(List<KmSensorInfoHis> kmSensorInfoHis) {
List<Float> humList = kmSensorInfoHis.stream().map(KmSensorInfoHis::getHumidity).filter(m -> m != null).collect(Collectors.toList());//得到湿度列表
List<Float> tempList = kmSensorInfoHis.stream().map(KmSensorInfoHis::getTemp).filter(m -> m != null).collect(Collectors.toList());//得到温度列表
Float maxHum = humList != null && humList.size() > 0 ? Collections.max(humList) : 0f;//得到湿度的最大值,如果没有湿度值则为0
Float maxTemp = tempList != null && tempList.size() > 0 ? Collections.max(tempList) : 0f;//得到温度的最大值,如果没有温度值则为0
WeatherInfo weatherInfo = weatherInfoService.getLastData();//查询室外的温湿度信息
String maxOutterHum = weatherInfo.getOutHum();//得到室外的湿度值
String maxOutterTemp = weatherInfo.getTempOut();//得到室外的温度值
return Tuple4.with(maxHum, maxTemp, maxOutterHum, maxOutterTemp);
}
public Tuple3 getXunzhenCondition(Long segmentId) {
//这里要用挂壁式的设备型号
List<Device> devices = deviceService.getDeviceListBySegmentId(segmentId, 1);//根据仓间id和类型去查询设备信息
//包芯磷化氢设备
List<String> deviceIds = segmentDeviceDao.getDeviceIdsBySegmentId(//为什么用segment去查设备id?包芯设备应该可以移动 不和仓间绑定
segmentId,
EventType.XUNZHEN.getNumber()
);
List<String> guabiDeviceIds = devices.stream().map(Device::getNumber).collect(Collectors.toList());//将挂壁设备的number转为字符串
List<KmSensorInfoHis> lastData = aggregateService.getLastDataTempAndHumDataByDeviceIds(//查询挂壁设备的最新数据
guabiDeviceIds
);
List<KmSensorInfoHis> baoxinLastData = aggregateService.getLastDataTempAndHumDataByDeviceIds(//查询包芯内设备的最新数据
deviceIds
);
Double maxHzs = lastData.stream().mapToDouble(KmSensorInfoHis::getHzsppm).max().orElse(0d);//取得仓间最大ppm,若没有则为0
Double maxBaoxinHzs = baoxinLastData.stream().mapToDouble(KmSensorInfoHis::getHzsppm).max().orElse(0d);//取得包芯最大ppm,若没有则为0
XunzhenCondition xunzhenCondition;
if (maxHzs <= 0.3) {
xunzhenCondition = XunzhenCondition.RENYUANKEYIJINRU;//人员可以进入
} else if (0.3 < maxHzs && maxHzs <= 7) {
xunzhenCondition = XunzhenCondition.GUOLVSHIJINRU;//可佩戴过滤式防毒面具进入
} else if (7 < maxHzs && maxHzs <= 200) {
xunzhenCondition = XunzhenCondition.ZHENGYASHIJINRU;//可佩戴正压式空气呼吸器或氧气呼吸器进入
} else if (maxHzs > 200) {
xunzhenCondition = XunzhenCondition.JINZHIRENYUANJINRU;//禁止人员进入
} else {
xunzhenCondition = XunzhenCondition.YICHANG;//异常
}
return Tuple3.with(maxHzs, maxBaoxinHzs, xunzhenCondition);
}