//package com.gunshi.project.hsz.service; // //import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; //import com.baomidou.mybatisplus.extension.plugins.pagination.Page; //import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //import com.gunshi.db.dto.DateTimeRangeSo; //import com.gunshi.project.hsz.entity.so.OsmoticDetailQuerySo; //import com.gunshi.project.hsz.entity.so.OsmoticQueryPageSo; //import com.gunshi.project.hsz.entity.so.OsmoticQuerySo; //import com.gunshi.project.hsz.entity.vo.*; //import com.gunshi.project.hsz.mapper.OsmoticPressRMapper; //import com.gunshi.project.hsz.model.OsmoticPressR; //import com.gunshi.project.hsz.util.DataHandleUtil; //import com.gunshi.project.hsz.util.DateUtil; //import com.gunshi.project.hsz.util.ExcelUtil; //import com.gunshi.project.hsz.util.MyBeanUtil; //import jakarta.servlet.http.HttpServletResponse; //import lombok.extern.slf4j.Slf4j; //import org.springframework.beans.BeanUtils; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.stereotype.Service; //import org.springframework.transaction.annotation.Transactional; // //import java.math.BigDecimal; //import java.util.*; //import java.util.stream.Collectors; //import java.util.stream.Stream; // ///** // * 描述: 渗压监测记录表 // * author: xusan // * date: 2024-07-08 17:30:37 // */ //@Service //@Slf4j //@Transactional(rollbackFor = Exception.class) //public class OsmoticPressRService extends ServiceImpl //{ // @Autowired // private OsmoticShiftRService shiftRService; // // public Page queryPage(OsmoticQueryPageSo osmoticQueryPageSo) { // return baseMapper.queryPage(osmoticQueryPageSo.getPageSo().toPage(),osmoticQueryPageSo); // } // // /** // * 测值查询,管水位和库水位数据固定查询每日早8点 // * @param osmoticQuerySo // * @return // */ // public List queryValue(OsmoticQuerySo osmoticQuerySo,Integer year) { // if(osmoticQuerySo.getType() == null) { // osmoticQuerySo.setType(1); // } // List resList = new ArrayList<>(); // if(CollectionUtils.isEmpty(osmoticQuerySo.getStationCodes())){ // return resList; // } // String stcd = shiftRService.getStcd(); // Boolean isDesc = true; // //查询测站降雨量 // Map drpMap = new HashMap<>(); // if(year != null){ // isDesc = false; // List drpList = baseMapper.queryDrp(year,stcd); // drpMap = drpList.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); // } // List dateList = DateUtil.getDatesBetween(osmoticQuerySo.getDateTimeRangeSo().getStart(), osmoticQuerySo.getDateTimeRangeSo().getEnd(),isDesc); // // //查询库水位 // List list = baseMapper.queryRz(osmoticQuerySo,stcd); // Map rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); // //查询测站管水位/渗流量 // List valueList = baseMapper.queryValue(osmoticQuerySo); // //数据处理 // for(String str : dateList){ // OsmoticStationVo vo = new OsmoticStationVo(); // vo.setTm(str); // vo.setRz(rzMap.get(str)); // vo.setDrp(drpMap.get(str)); // vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).map(t->{ // t.setRz(vo.getRz()); // return t; // }).collect(Collectors.toList())); // resList.add(vo); // } // return resList; // } // // public List queryChart(OsmoticQuerySo osmoticQuerySo,Integer year) { // List resList = new ArrayList<>(); // List stationCodes = osmoticQuerySo.getStationCodes(); // if(CollectionUtils.isEmpty(stationCodes)){ // return resList; // } // String stcd = shiftRService.getStcd(); // //查询库水位 // List list = baseMapper.queryRz(osmoticQuerySo,stcd); // //查询测站管水位 // List valueList = baseMapper.queryValue(osmoticQuerySo); // //按测站分组 // Map> map = valueList.stream().collect(Collectors.groupingBy(OsmoticValueVo::getStationCode)); // for(String code : stationCodes){ // OsmoticChartVo vo = new OsmoticChartVo(); // vo.setStationCode(code); // if(map.containsKey(code)){ // List 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))); // } // }else { // vo.setDetailVos(new ArrayList<>()); // } // resList.add(vo); // } // //查询测站降雨量 // List drpList; // if(year != null){ // drpList = baseMapper.queryDrp(year,stcd); // 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); // } // } // return resList; // } // // // // //根据监测时间合并管水位和库水位数据 // private List bindData(List tmRzList, List voList) { // HashSet strings = new HashSet<>(); // tmRzList.stream().forEach(v1 -> strings.add(v1.getTm())); // voList.stream().forEach(v1 -> strings.add(v1.getTm())); // // List result = new ArrayList<>(); // strings.stream().forEach(v1 ->{ // OsmoticChartDetailVo v = new OsmoticChartDetailVo(); // v.setTm(v1); // result.add(v); // }); // // List 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()); // } // // public List infiltraLine(OsmoticQuerySo osmoticQuerySo) { // List resList = new ArrayList<>(); // String stcd = shiftRService.getStcd(); // //查询库水位 // List list = baseMapper.queryLineRz(osmoticQuerySo,stcd); // Map rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); // //查询测站管水位 // List valueList = baseMapper.queryLineValue(osmoticQuerySo); // //查询测站预警信息 // List warnList = baseMapper.queryWarn(osmoticQuerySo); // 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 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 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.stream().sorted(Comparator.comparing(OsmoticStationVo::getTm)).collect(Collectors.toList()); // } // // // public void export(OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) { // //通过断面查询渗压设备 // List stationCodes = osmoticQuerySo.getStationCodes(); // //表头信息 // List heads = new ArrayList<>(); // heads.add("序号"); // heads.add("时间"); // heads.add("库水位(m)"); // heads.addAll(stationCodes); // heads.add("结果分析"); // // //表格数据 // List resList = infiltraLine(osmoticQuerySo); // List> list = new ArrayList<>(); // for (int j = 0;j < resList.size(); j++) { // OsmoticStationVo vo = resList.get(j); // Map test = new LinkedHashMap<>(); // test.put("t0",j+1); // test.put("t1", vo.getTm()); // test.put("t2", vo.getRz()); // 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("t4", vo.getStatus() == 0 ? "异常":"正常"); // list.add(test); // } // List> hs = new ArrayList<>(); // for (String s : heads) { // hs.add(Arrays.asList(s)); // } // ExcelUtil.exportExcel(hs, DataHandleUtil.tableData(list), "浸润线", response, "浸润线"); // } // // private OsmoticQuerySo commonQueryHandle(OsmoticQuerySo osmoticQuerySo){ // 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 yearStat(OsmoticQuerySo osmoticQuerySo) { // commonQueryHandle(osmoticQuerySo); // return queryValue(osmoticQuerySo,osmoticQuerySo.getYear()); // } // // public List yearStatValue(OsmoticQuerySo osmoticQuerySo) { // commonQueryHandle(osmoticQuerySo); // return queryChart(osmoticQuerySo,osmoticQuerySo.getYear()); // } // // public void yearStatExport(OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) { // String headName = osmoticQuerySo.getProfileName() + "断面测压管水位(m)"; // String fileName = "断面年度渗压统计"; // String sheetName = "年度渗压统计"; // if(osmoticQuerySo.getType() == 1){ // fileName = osmoticQuerySo.getProfileName() + fileName; // }else { // headName = "渗流量(L/s)"; // fileName = "年度渗流统计"; // sheetName = "年度渗流统计"; // } // // //上方表格数据 // List resList = yearStat(osmoticQuerySo); // //下方特征值数据 // List chartList = queryChart(osmoticQuerySo,osmoticQuerySo.getYear()); // List stationCodes = osmoticQuerySo.getStationCodes(); // //表头信息 // List> headList = new ArrayList<>(); // List heads1 = new ArrayList<>(); // heads1.add("序号"); // heads1.add("序号"); // headList.add(heads1); // // List heads2 = new ArrayList<>(); // heads2.add("监测日期"); // heads2.add("监测日期"); // headList.add(heads2); // // for(String code : stationCodes){ // List heads = new ArrayList<>(); // heads.add(headName); // heads.add(code); // headList.add(heads); // } // // List heads3 = new ArrayList<>(); // heads3.add("库水位(m)"); // heads3.add("库水位(m)"); // headList.add(heads3); // // List heads4 = new ArrayList<>(); // heads4.add("降雨量(mm)"); // heads4.add("降雨量(mm)"); // headList.add(heads4); // // List> list = new ArrayList<>(); // for (int j = 0;j < resList.size(); j++) { // OsmoticStationVo vo = resList.get(j); // Map 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 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 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 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 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 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); // // ExcelUtil.exportExcel(headList, DataHandleUtil.tableData(list),2,new int[]{0},fileName,response,sheetName); // } // // public List listValue(Integer type) { // List list; // if(type == 1){ // list = baseMapper.listValue(); // }else { // list = baseMapper.flowListValue(); // } // OsmoticQuerySo so = new OsmoticQuerySo(); // List stationCodes = list.stream().map(OsmoticPressVo::getStationCode).collect(Collectors.toList()); // if(list.stream().filter(o->o.getTm() != null).collect(Collectors.toList()).size() > 0 ){ // String maxTm = list.stream().filter(o->o.getTm() != null).max(Comparator.comparing(OsmoticPressVo::getTm)).get().getTm(); // String minTm = list.stream().filter(o->o.getTm() != null).min(Comparator.comparing(OsmoticPressVo::getTm)).get().getTm(); // so.setStationCodes(stationCodes); // DateTimeRangeSo dateTimeRangeSo = new DateTimeRangeSo(); // dateTimeRangeSo.setStart(DateUtil.convertStringToDate(minTm)); // dateTimeRangeSo.setEnd(DateUtil.convertStringToDate(maxTm)); // so.setDateTimeRangeSo(dateTimeRangeSo); // List warnList = baseMapper.queryWarn(so); // list.stream().map(o->{ // if(o.getTm() != null && DateUtil.hoursBetweenDate(DateUtil.convertStringToDate(o.getTm()), new Date()) > 48){ // o.setFlag(1); // } // Boolean b = warnList.stream().filter(t->t.getStationCode().equals(o.getStationCode()) && t.getTm().equals(o.getTm())).findAny().isPresent(); // if(b){ // o.setStatus(1); // } // return o; // }).collect(Collectors.toList()); // } // return list; // } // // public List detailValue(OsmoticDetailQuerySo so) { // List list = baseMapper.detailValue(so); // if(so.getType() == 2){ // return list; // } // OsmoticQuerySo osmoticQuerySo = new OsmoticQuerySo(); // BeanUtils.copyProperties(so,osmoticQuerySo); // List stRzVos = baseMapper.queryLineRz(osmoticQuerySo,shiftRService.getStcd()); // return bindPressDetail(list,stRzVos); // } // // private List bindPressDetail(List list, List stRzVos) { // HashSet strings = new HashSet<>(); // list.stream().forEach(v1 -> strings.add(v1.getTm())); // stRzVos.stream().forEach(v1 -> strings.add(v1.getTm())); // // List result = new ArrayList<>(); // strings.stream().forEach(v1 ->{ // OsmoticPressDetailVo v = new OsmoticPressDetailVo(); // v.setTm(v1); // result.add(v); // }); // // List resList = result.stream().map(v1 -> { // stRzVos.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> { // v1.setRz(v2.getRz()); // }); // // list.stream().filter(v2 -> v1.getTm().equals(v2.getTm())).forEach(v2 -> { // v1.setValue(v2.getValue()); // }); // return v1; // }).collect(Collectors.toList()); // return resList.stream().sorted(Comparator.comparing(OsmoticPressDetailVo::getTm)).collect(Collectors.toList()); // } // // public Map stat() { // Map map = new HashMap<>(); // List press = this.listValue(1); // Integer pressSize = press.size(); // Long pressWarn = press.stream().filter(o -> o.getStatus() == 1).collect(Collectors.counting()); // // List flow = this.listValue(2); // Integer flowSize = flow.size(); // Long flowWarn = flow.stream().filter(o -> o.getStatus() == 1).collect(Collectors.counting()); // // List shift = shiftRService.listValue(); // Integer shiftSize = shift.size(); // Long shiftWarn = shift.stream().filter(o -> o.getXStatus() == 1 || o.getYStatus() ==1 || o.getHStatus() == 1).collect(Collectors.counting()); // // Integer size = pressSize + flowSize + shiftSize; // Integer warn = Stream.of(pressWarn, flowWarn, shiftWarn).mapToInt(Long::intValue).sum(); // map.put(warn,size); // return map; // } //} // //