gunshi-project-ss/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java

437 lines
19 KiB
Java
Raw Normal View History

2024-07-08 17:47:02 +08:00
package com.gunshi.project.xyt.service;
2024-07-11 10:58:35 +08:00
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
2024-07-08 17:47:02 +08:00
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
2024-07-12 11:21:22 +08:00
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
2024-07-10 16:28:20 +08:00
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.*;
2024-07-08 17:47:02 +08:00
import com.gunshi.project.xyt.mapper.OsmoticPressRMapper;
2024-07-12 11:21:22 +08:00
import com.gunshi.project.xyt.model.*;
import com.gunshi.project.xyt.model.AttDamProfileAutoDao;
2024-07-12 14:32:30 +08:00
import com.gunshi.project.xyt.model.OsmoticFlowDeviceAutoDao;
2024-07-11 10:58:35 +08:00
import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao;
2024-07-10 16:28:20 +08:00
import com.gunshi.project.xyt.util.DateUtil;
2024-07-11 13:36:44 +08:00
import com.gunshi.project.xyt.util.ExcelUtil;
2024-07-10 16:28:20 +08:00
import com.gunshi.project.xyt.util.MyBeanUtil;
import jakarta.annotation.Resource;
2024-07-11 13:36:44 +08:00
import jakarta.servlet.http.HttpServletResponse;
2024-07-08 17:47:02 +08:00
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
2024-07-10 16:28:20 +08:00
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
2024-07-08 17:47:02 +08:00
/**
* :
* author: xusan
* date: 2024-07-08 17:30:37
*/
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, OsmoticPressR>
{
@Resource
private OsmoticPressRMapper mapper;
2024-07-08 17:47:02 +08:00
2024-07-12 11:21:22 +08:00
@Resource
private AttDamProfileAutoDao profileAutoDao;
2024-07-11 10:58:35 +08:00
@Resource
private OsmoticPressDeviceAutoDao pressDeviceAutoDao;
2024-07-12 14:32:30 +08:00
@Resource
private OsmoticFlowDeviceAutoDao flowDeviceAutoDao;
public Page<OsmoticPressR> queryPage(OsmoticQueryPageSo osmoticQueryPageSo) {
return mapper.queryPage(osmoticQueryPageSo.getPageSo().toPage(),osmoticQueryPageSo);
}
2024-07-10 16:28:20 +08:00
/**
* 8
* @param osmoticQuerySo
* @return
*/
2024-07-12 11:21:22 +08:00
public List<OsmoticStationVo> queryValue(OsmoticQuerySo osmoticQuerySo,Integer year) {
Boolean isDesc = true;
//查询测站降雨量
Map<String,BigDecimal> drpMap = new HashMap<>();
if(year != null){
isDesc = false;
List<StRzVo> drpList = mapper.queryDrp(year);
drpMap = drpList.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
}
List<String> dateList = DateUtil.getDatesBetween(osmoticQuerySo.getDateTimeRangeSo().getStart(), osmoticQuerySo.getDateTimeRangeSo().getEnd(),isDesc);
2024-07-10 16:28:20 +08:00
List<OsmoticStationVo> resList = new ArrayList<>();
//查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
2024-07-12 14:32:30 +08:00
//查询测站管水位/渗流量
2024-07-10 16:28:20 +08:00
List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo);
//数据处理
for(String str : dateList){
OsmoticStationVo vo = new OsmoticStationVo();
vo.setTm(str);
vo.setRz(rzMap.get(str));
2024-07-12 11:21:22 +08:00
vo.setDrp(drpMap.get(str));
2024-07-11 13:36:44 +08:00
vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).map(t->{
t.setRz(vo.getRz());
return t;
}).collect(Collectors.toList()));
2024-07-10 16:28:20 +08:00
resList.add(vo);
}
return resList;
}
2024-07-12 11:21:22 +08:00
public List<OsmoticChartVo> queryChart(OsmoticQuerySo osmoticQuerySo,Integer year) {
2024-07-10 16:28:20 +08:00
List<OsmoticChartVo> resList = new ArrayList<>();
2024-07-12 11:29:02 +08:00
List<String> stationCodes = osmoticQuerySo.getStationCodes();
2024-07-10 16:28:20 +08:00
//查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
2024-07-12 11:21:22 +08:00
//查询测站降雨量
2024-07-12 14:32:30 +08:00
List<StRzVo> drpList;
2024-07-12 11:21:22 +08:00
if(year != null){
drpList = mapper.queryDrp(year);
OsmoticChartVo chartVo = new OsmoticChartVo();
chartVo.setStationCode("rz");
if(CollectionUtils.isNotEmpty(list)){
StRzVo max = list.stream().max(Comparator.comparing(StRzVo::getRz)).get();
StRzVo min = list.stream().min(Comparator.comparing(StRzVo::getRz)).get();
chartVo.setMaxValue(max.getRz());
chartVo.setMaxTm(max.getTm());
chartVo.setMinValue(min.getRz());
chartVo.setMinTm(min.getTm());
chartVo.setDiff(max.getRz().subtract(min.getRz()));
resList.add(chartVo);
}
if(CollectionUtils.isNotEmpty(drpList)){
OsmoticChartVo drpVo = new OsmoticChartVo();
drpVo.setStationCode("drp");
StRzVo maxDrp = drpList.stream().max(Comparator.comparing(StRzVo::getRz)).get();
StRzVo minDrp = drpList.stream().min(Comparator.comparing(StRzVo::getRz)).get();
drpVo.setMaxValue(maxDrp.getRz());
drpVo.setMaxTm(maxDrp.getTm());
drpVo.setMinValue(minDrp.getRz());
drpVo.setMinTm(minDrp.getTm());
drpVo.setDiff(maxDrp.getRz().subtract(minDrp.getRz()));
resList.add(drpVo);
}
}
2024-07-10 16:28:20 +08:00
//查询测站管水位
List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo);
//按测站分组
Map<String, List<OsmoticValueVo>> map = valueList.stream().collect(Collectors.groupingBy(OsmoticValueVo::getStationCode));
2024-07-12 11:29:02 +08:00
for(String code : stationCodes){
2024-07-10 16:28:20 +08:00
OsmoticChartVo vo = new OsmoticChartVo();
2024-07-12 11:29:02 +08:00
vo.setStationCode(code);
if(map.containsKey(code)){
List<OsmoticValueVo> voList = map.get(code);
OsmoticValueVo max = voList.stream().max(Comparator.comparing(OsmoticValueVo::getValue)).get();
OsmoticValueVo min = voList.stream().min(Comparator.comparing(OsmoticValueVo::getValue)).get();
vo.setStationCode(code);
vo.setMaxValue(max.getValue());
vo.setMaxTm(max.getTm());
vo.setMinValue(min.getValue());
vo.setMinTm(min.getTm());
vo.setDiff(max.getValue().subtract(min.getValue()));
if(year == null){
vo.setDetailVos(bindData(MyBeanUtil.collectionCopy(list,OsmoticChartDetailVo.class),MyBeanUtil.collectionCopy(voList,OsmoticChartDetailVo.class)));
}
2024-07-12 11:21:22 +08:00
}
2024-07-10 16:28:20 +08:00
resList.add(vo);
2024-07-12 11:29:02 +08:00
}
2024-07-10 16:28:20 +08:00
return resList;
}
2024-07-12 11:21:22 +08:00
2024-07-10 16:28:20 +08:00
//根据监测时间合并管水位和库水位数据
private List<OsmoticChartDetailVo> bindData(List<OsmoticChartDetailVo> tmRzList, List<OsmoticChartDetailVo> voList) {
HashSet<String> strings = new HashSet<>();
tmRzList.stream().forEach(v1 -> strings.add(v1.getTm()));
voList.stream().forEach(v1 -> strings.add(v1.getTm()));
List<OsmoticChartDetailVo> result = new ArrayList<>();
strings.stream().forEach(v1 ->{
OsmoticChartDetailVo v = new OsmoticChartDetailVo();
v.setTm(v1);
result.add(v);
});
List<OsmoticChartDetailVo> list = result.stream().map(v1 -> {
tmRzList.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> {
v1.setRz(v2.getRz());
});
voList.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> {
v1.setValue(v2.getValue());
});
return v1;
}).collect(Collectors.toList());
return list.stream().sorted(Comparator.comparing(OsmoticChartDetailVo::getTm)).collect(Collectors.toList());
}
2024-07-11 10:58:35 +08:00
2024-07-12 11:21:22 +08:00
public List<OsmoticStationVo> infiltraLine(OsmoticQuerySo osmoticQuerySo) {
2024-07-11 10:58:35 +08:00
List<OsmoticStationVo> resList = new ArrayList<>();
2024-07-12 11:21:22 +08:00
String profileCode = osmoticQuerySo.getProfileCode();
2024-07-11 13:36:44 +08:00
//通过断面查询渗压设备
List<String> stationCodes = queryPressList(profileCode);
if(CollectionUtils.isEmpty(stationCodes)){
2024-07-11 10:58:35 +08:00
return resList;
}
2024-07-12 11:21:22 +08:00
osmoticQuerySo.setStationCodes(stationCodes);
2024-07-11 10:58:35 +08:00
//查询库水位
2024-07-12 11:21:22 +08:00
List<StRzVo> list = mapper.queryLineRz(osmoticQuerySo);
2024-07-11 10:58:35 +08:00
Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
//查询测站管水位
2024-07-12 11:21:22 +08:00
List<OsmoticValueVo> valueList = mapper.queryLineValue(osmoticQuerySo);
2024-07-11 10:58:35 +08:00
//查询测站预警信息
2024-07-12 11:21:22 +08:00
List<OsmoticValueVo> warnList = mapper.queryWarn(osmoticQuerySo);
2024-07-11 10:58:35 +08:00
valueList.stream().map(vo->{
Boolean b = warnList.stream().filter(o->o.getStationCode().equals(vo.getStationCode()) && o.getTm().equals(vo.getTm())).findAny().isPresent();
if(b){
vo.setStatus(0);
}
return vo;
}).collect(Collectors.toList());
HashSet<String> dateList = new HashSet<>();
list.stream().forEach(v1 -> dateList.add(v1.getTm()));
valueList.stream().forEach(v1 -> dateList.add(v1.getTm()));
for(String str : dateList){
OsmoticStationVo vo = new OsmoticStationVo();
vo.setTm(str);
vo.setRz(rzMap.get(str));
List<OsmoticValueVo> newList = valueList.stream().filter(o->str.equals(o.getTm())).collect(Collectors.toList());
vo.setList(newList);
if(CollectionUtils.isNotEmpty(newList) && newList.stream().filter(o->o.getStatus() == 0).findAny().isPresent()){
vo.setStatus(0);
}
resList.add(vo);
}
return resList;
}
2024-07-11 13:36:44 +08:00
private List<String> queryPressList(String profileCode){
List<OsmoticPressDevice> pressList = pressDeviceAutoDao.list(new QueryWrapper<OsmoticPressDevice>().eq("profile_code", profileCode));
return pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList());
}
2024-07-12 14:32:30 +08:00
private List<String> queryFlowList(){
List<OsmoticFlowDevice> flowList = flowDeviceAutoDao.list();
return flowList.stream().map(OsmoticFlowDevice::getStationCode).collect(Collectors.toList());
}
2024-07-12 11:21:22 +08:00
public void export(OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) {
2024-07-11 13:36:44 +08:00
//通过断面查询渗压设备
2024-07-12 11:21:22 +08:00
List<String> stationCodes = queryPressList(osmoticQuerySo.getProfileCode());
2024-07-11 13:36:44 +08:00
//表头信息
List<String> heads = new ArrayList<>();
2024-07-12 11:21:22 +08:00
heads.add("序号");
2024-07-11 13:36:44 +08:00
heads.add("时间");
heads.add("库水位(m)");
heads.addAll(stationCodes);
heads.add("结果分析");
//表格数据
2024-07-12 11:21:22 +08:00
List<OsmoticStationVo> resList = infiltraLine(osmoticQuerySo);
2024-07-11 13:36:44 +08:00
List<Map<String, Object>> list = new ArrayList<>();
2024-07-12 11:21:22 +08:00
for (int j = 0;j < resList.size(); j++) {
OsmoticStationVo vo = resList.get(j);
2024-07-11 13:36:44 +08:00
Map<String, Object> test = new LinkedHashMap<>();
2024-07-12 11:21:22 +08:00
test.put("t0",j+1);
2024-07-11 13:36:44 +08:00
test.put("t1", vo.getTm());
test.put("t2", vo.getRz());
2024-07-12 11:21:22 +08:00
for(int i = 0;i < stationCodes.size();i++){
2024-07-11 13:36:44 +08:00
String code = stationCodes.get(i);
OsmoticValueVo valueVo = vo.getList().stream().filter(o->code.equals(o.getStationCode())).findFirst().orElse(null);
2024-07-12 14:32:30 +08:00
test.put(code,valueVo != null ? valueVo.getValue() : "");
2024-07-11 13:36:44 +08:00
}
test.put("t4", vo.getStatus() == 0 ? "异常":"正常");
list.add(test);
}
List<List<String>> hs = new ArrayList<>();
for (String s : heads) {
hs.add(Arrays.asList(s));
}
2024-07-12 11:21:22 +08:00
ExcelUtil.exportExcel(hs, tableData(list), "浸润线", response, "浸润线");
}
private OsmoticQuerySo commonQueryHandle(OsmoticQuerySo osmoticQuerySo){
2024-07-12 14:32:30 +08:00
List<String> stationCodes;
if(osmoticQuerySo.getType() == 2){
//查询所有的渗流设备
stationCodes = queryFlowList();
}else{
String profileCode = osmoticQuerySo.getProfileCode();
//通过断面查询渗压设备
stationCodes = queryPressList(profileCode);
}
2024-07-12 11:21:22 +08:00
osmoticQuerySo.setStationCodes(stationCodes);
Integer year = osmoticQuerySo.getYear();
Date start = DateUtil.convertStringToDate(year + "-01-01 00:00:00");
Date end = DateUtil.convertStringToDate(year + "-12-31 00:00:00");
DateTimeRangeSo so = new DateTimeRangeSo();
so.setStart(start);
so.setEnd(end);
osmoticQuerySo.setDateTimeRangeSo(so);
return osmoticQuerySo;
}
public List<OsmoticStationVo> yearStat(OsmoticQuerySo osmoticQuerySo) {
commonQueryHandle(osmoticQuerySo);
return queryValue(osmoticQuerySo,osmoticQuerySo.getYear());
}
public List<OsmoticChartVo> yearStatValue(OsmoticQuerySo osmoticQuerySo) {
commonQueryHandle(osmoticQuerySo);
return queryChart(osmoticQuerySo,osmoticQuerySo.getYear());
}
public void yearStatExport(OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) {
2024-07-12 14:32:30 +08:00
String headName = "断面测压管水位(m)";
String fileName = "断面年度渗压统计";
String sheetName = "年度渗压统计";
if(osmoticQuerySo.getType() == 1){
//断面名称
AttDamProfile damProfile = profileAutoDao.getById(osmoticQuerySo.getProfileCode());
if(damProfile != null){
headName = damProfile.getProfileName() + headName;
fileName = damProfile.getProfileName() + fileName;
}
}else {
headName = "渗流量(L/s)";
fileName = "年度渗流统计";
sheetName = "年度渗流统计";
2024-07-12 11:21:22 +08:00
}
2024-07-12 14:32:30 +08:00
2024-07-12 11:21:22 +08:00
//上方表格数据
List<OsmoticStationVo> resList = yearStat(osmoticQuerySo);
//下方特征值数据
List<OsmoticChartVo> chartList = queryChart(osmoticQuerySo,osmoticQuerySo.getYear());
List<String> stationCodes = osmoticQuerySo.getStationCodes();
//表头信息
List<List<String>> headList = new ArrayList<>();
List<String> heads1 = new ArrayList<>();
heads1.add("序号");
heads1.add("序号");
headList.add(heads1);
List<String> heads2 = new ArrayList<>();
heads2.add("监测日期");
heads2.add("监测日期");
headList.add(heads2);
for(String code : stationCodes){
List<String> heads = new ArrayList<>();
2024-07-12 14:32:30 +08:00
heads.add(headName);
2024-07-12 11:21:22 +08:00
heads.add(code);
headList.add(heads);
}
List<String> heads3 = new ArrayList<>();
heads3.add("库水位(m)");
heads3.add("库水位(m)");
headList.add(heads3);
List<String> heads4 = new ArrayList<>();
heads4.add("降雨量(mm)");
heads4.add("降雨量(mm)");
headList.add(heads4);
List<Map<String, Object>> list = new ArrayList<>();
for (int j = 0;j < resList.size(); j++) {
OsmoticStationVo vo = resList.get(j);
Map<String, Object> test = new LinkedHashMap<>();
test.put("t0",j+1);
test.put("t1", vo.getTm());
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
OsmoticValueVo valueVo = vo.getList().stream().filter(o->code.equals(o.getStationCode())).findFirst().orElse(null);
test.put(code,valueVo != null ? valueVo.getValue() : "");
}
test.put("t2", vo.getRz());
test.put("t3", vo.getDrp());
list.add(test);
}
Map<String, Object> max = new LinkedHashMap<>();
max.put("t0","全年度特征值统计");
max.put("t1", "最大值");
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
max.put(code,chartList.stream().filter(o->code.equals(o.getStationCode())).findFirst().get().getMaxValue());
}
max.put("t2", chartList.stream().filter(o->"rz".equals(o.getStationCode())).findFirst().get().getMaxValue());
max.put("t3", chartList.stream().filter(o->"drp".equals(o.getStationCode())).findFirst().get().getMaxValue());
list.add(max);
Map<String, Object> maxTm = new LinkedHashMap<>();
maxTm.put("t0","全年度特征值统计");
maxTm.put("t1", "日期");
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
maxTm.put(code,chartList.stream().filter(o->code.equals(o.getStationCode())).findFirst().get().getMaxTm());
}
maxTm.put("t2", chartList.stream().filter(o->"rz".equals(o.getStationCode())).findFirst().get().getMaxTm());
maxTm.put("t3", chartList.stream().filter(o->"drp".equals(o.getStationCode())).findFirst().get().getMaxTm());
list.add(maxTm);
Map<String, Object> min = new LinkedHashMap<>();
min.put("t0","全年度特征值统计");
min.put("t1", "最大值");
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
min.put(code,chartList.stream().filter(o->code.equals(o.getStationCode())).findFirst().get().getMinValue());
}
min.put("t2", chartList.stream().filter(o->"rz".equals(o.getStationCode())).findFirst().get().getMinValue());
min.put("t3", chartList.stream().filter(o->"drp".equals(o.getStationCode())).findFirst().get().getMinValue());
list.add(min);
Map<String, Object> minTm = new LinkedHashMap<>();
minTm.put("t0","全年度特征值统计");
minTm.put("t1", "日期");
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
minTm.put(code,chartList.stream().filter(o->code.equals(o.getStationCode())).findFirst().get().getMinTm());
}
minTm.put("t2", chartList.stream().filter(o->"rz".equals(o.getStationCode())).findFirst().get().getMinTm());
minTm.put("t3", chartList.stream().filter(o->"drp".equals(o.getStationCode())).findFirst().get().getMinTm());
list.add(minTm);
Map<String, Object> diff = new LinkedHashMap<>();
diff.put("t0","全年度特征值统计");
diff.put("t1", "年变幅");
for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i);
diff.put(code,chartList.stream().filter(o->code.equals(o.getStationCode())).findFirst().get().getDiff());
}
diff.put("t2", chartList.stream().filter(o->"rz".equals(o.getStationCode())).findFirst().get().getDiff());
diff.put("t3", chartList.stream().filter(o->"drp".equals(o.getStationCode())).findFirst().get().getDiff());
list.add(diff);
2024-07-12 14:32:30 +08:00
ExcelUtil.exportExcel(headList,tableData(list),2,new int[]{0},fileName,response,sheetName);
2024-07-12 11:21:22 +08:00
}
2024-07-11 13:36:44 +08:00
2024-07-12 11:21:22 +08:00
private List<List> tableData( List<Map<String, Object>> list){
2024-07-11 13:36:44 +08:00
List<List> list2 = new ArrayList<>();
Collection values;
for (int i = 0; i < list.size(); i++) {
values = list.get(i).values();
List objects = new ArrayList<>();
for (Object value : values) {
2024-07-12 11:21:22 +08:00
objects.add(value == null ? "" : value.toString());
2024-07-11 13:36:44 +08:00
}
list2.add(objects);
}
2024-07-12 11:21:22 +08:00
return list2;
2024-07-11 13:36:44 +08:00
}
2024-07-08 17:47:02 +08:00
}