年度渗压统计查询及导出

master
wany 2024-07-12 11:21:22 +08:00
parent 1d52363389
commit 62a2b2d4de
11 changed files with 418 additions and 63 deletions

View File

@ -2,7 +2,6 @@ package com.gunshi.project.xyt.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R; import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.so.InfiltraLineSo;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo; import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo; import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.OsmoticChartVo; import com.gunshi.project.xyt.entity.vo.OsmoticChartVo;
@ -21,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
* : * :
* author: xusan * author: xusan
@ -70,25 +70,43 @@ public class OsmoticPressRController {
@Operation(summary = "测值查询(数据表)") @Operation(summary = "测值查询(数据表)")
@PostMapping("/query/value") @PostMapping("/query/value")
public R<List<OsmoticStationVo>> queryValue(@RequestBody OsmoticQuerySo osmoticQuerySo) { public R<List<OsmoticStationVo>> queryValue(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.queryValue(osmoticQuerySo)); return R.ok(service.queryValue(osmoticQuerySo,null));
} }
@Operation(summary = "测值查询(多图单表)") @Operation(summary = "测值查询(多图单表)")
@PostMapping("/query/chart") @PostMapping("/query/chart")
public R<List<OsmoticChartVo>> queryChart(@RequestBody OsmoticQuerySo osmoticQuerySo) { public R<List<OsmoticChartVo>> queryChart(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.queryChart(osmoticQuerySo)); return R.ok(service.queryChart(osmoticQuerySo,null));
} }
@Operation(summary = "浸润线查询") @Operation(summary = "浸润线查询")
@PostMapping("/infiltra/line") @PostMapping("/infiltra/line")
public R<List<OsmoticStationVo>> infiltraLine(@RequestBody InfiltraLineSo infiltraLineSo) { public R<List<OsmoticStationVo>> infiltraLine(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.infiltraLine(infiltraLineSo)); return R.ok(service.infiltraLine(osmoticQuerySo));
} }
@Operation(summary = "浸润线导出") @Operation(summary = "浸润线导出")
@PostMapping( "/export") @PostMapping( "/export")
public void export(@RequestBody InfiltraLineSo infiltraLineSo, HttpServletResponse response) { public void export(@RequestBody OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) {
service.export(infiltraLineSo,response); service.export(osmoticQuerySo,response);
}
@Operation(summary = "年度渗压统计(表格)")
@PostMapping("/year/stat")
public R<List<OsmoticStationVo>> yearStat(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.yearStat(osmoticQuerySo));
}
@Operation(summary = "年度渗压统计(全年度特征值统计)")
@PostMapping("/year/stat/value")
public R<List<OsmoticChartVo>> yearStatValue(@RequestBody OsmoticQuerySo osmoticQuerySo) {
return R.ok(service.yearStatValue(osmoticQuerySo));
}
@Operation(summary = "年度渗压统计导出")
@PostMapping( "/year/stat/export")
public void yearStatExport(@RequestBody OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) {
service.yearStatExport(osmoticQuerySo,response);
} }
} }

View File

@ -1,24 +0,0 @@
package com.gunshi.project.xyt.entity.so;
import com.gunshi.db.dto.DateTimeRangeSo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* Description:
* Created by wanyan on 2024/7/11
*
* @author wanyan
* @version 1.0
*/
@Data
@Schema(description = "浸润线查询对象")
public class InfiltraLineSo {
@Schema(description = "上报时间")
private DateTimeRangeSo dateTimeRangeSo;
@Schema(description = "监测断面")
private String profileCode;
}

View File

@ -17,9 +17,14 @@ import java.util.List;
@Schema(description = "测值查询对象") @Schema(description = "测值查询对象")
public class OsmoticQuerySo { public class OsmoticQuerySo {
@Schema(description = "年度")
private Integer year;
@Schema(description = "时间") @Schema(description = "时间")
private DateTimeRangeSo dateTimeRangeSo; private DateTimeRangeSo dateTimeRangeSo;
@Schema(description = "监测断面")
private String profileCode;
@Schema(description = "测点编号") @Schema(description = "测点编号")
private List<String> stationCodes; private List<String> stationCodes;

View File

@ -46,6 +46,12 @@ public class OsmoticChartVo {
@Schema(description="最小值时间") @Schema(description="最小值时间")
private String minTm; private String minTm;
/**
*
*/
@Schema(description="变幅")
private BigDecimal diff;
@Schema(description = "数据") @Schema(description = "数据")
private List<OsmoticChartDetailVo> detailVos; private List<OsmoticChartDetailVo> detailVos;
} }

View File

@ -3,6 +3,7 @@ package com.gunshi.project.xyt.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -13,11 +14,14 @@ import java.util.List;
* @version 1.0 * @version 1.0
*/ */
@Data @Data
public class OsmoticStationVo extends StRzVo{ public class OsmoticStationVo extends StRzVo {
@Schema(description = "结果分析0异常 1正常") @Schema(description = "结果分析0异常 1正常")
private Integer status = 1; private Integer status = 1;
@Schema(description="测值") @Schema(description="测值")
private List<OsmoticValueVo> list; private List<OsmoticValueVo> list;
@Schema(description = "降雨量")
private BigDecimal drp;
} }

View File

@ -2,7 +2,6 @@ package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.project.xyt.entity.so.InfiltraLineSo;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo; import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo; import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.OsmoticValueVo; import com.gunshi.project.xyt.entity.vo.OsmoticValueVo;
@ -97,14 +96,14 @@ public interface OsmoticPressRMapper extends BaseMapper<OsmoticPressR> {
order by t.tm desc order by t.tm desc
</script> </script>
""") """)
List<StRzVo> queryLineRz(@Param("obj") InfiltraLineSo infiltraLineSo); List<StRzVo> queryLineRz(@Param("obj") OsmoticQuerySo osmoticQuerySo);
@Select(""" @Select("""
<script> <script>
select t.station_code as stationCode,to_char(t.tm,'YYYY-MM-DD HH24:MI:SS') as tm,t.value select t.station_code as stationCode,to_char(t.tm,'YYYY-MM-DD HH24:MI:SS') as tm,t.value
from public.osmotic_press_r t from public.osmotic_press_r t
where station_code in where station_code in
<foreach collection="list" item="code" separator="," open="(" close=")"> <foreach collection="obj.stationCodes" item="code" separator="," open="(" close=")">
#{code} #{code}
</foreach> </foreach>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null"> <if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
@ -116,14 +115,14 @@ public interface OsmoticPressRMapper extends BaseMapper<OsmoticPressR> {
order by t.tm desc order by t.tm desc
</script> </script>
""") """)
List<OsmoticValueVo> queryLineValue(@Param("obj") InfiltraLineSo infiltraLineSo,@Param("list") List<String> stationCodes); List<OsmoticValueVo> queryLineValue(@Param("obj") OsmoticQuerySo osmoticQuerySo);
@Select(""" @Select("""
<script> <script>
select t.station_code as stationCode,to_char(t.tm,'YYYY-MM-DD HH24:MI:SS') as tm select t.station_code as stationCode,to_char(t.tm,'YYYY-MM-DD HH24:MI:SS') as tm
from public.osmotic_warn_r t from public.osmotic_warn_r t
where station_code in where station_code in
<foreach collection="list" item="code" separator="," open="(" close=")"> <foreach collection="obj.stationCodes" item="code" separator="," open="(" close=")">
#{code} #{code}
</foreach> </foreach>
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null"> <if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
@ -135,5 +134,15 @@ public interface OsmoticPressRMapper extends BaseMapper<OsmoticPressR> {
order by t.tm desc order by t.tm desc
</script> </script>
""") """)
List<OsmoticValueVo> queryWarn(@Param("obj") InfiltraLineSo infiltraLineSo,@Param("list") List<String> stationCodes); List<OsmoticValueVo> queryWarn(@Param("obj") OsmoticQuerySo osmoticQuerySo);
@Select("""
<script>
select to_char(t.tm,'YYYY-MM-DD') as tm,t.drp as rz
from public.st_pptn_r_d t
where t.year = #{year} and t.stcd = '2'
order by t.tm desc
</script>
""")
List<StRzVo> queryDrp(@Param("year") Integer year);
} }

View File

@ -4,14 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.entity.so.InfiltraLineSo; import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo; import com.gunshi.project.xyt.entity.so.OsmoticQueryPageSo;
import com.gunshi.project.xyt.entity.so.OsmoticQuerySo; import com.gunshi.project.xyt.entity.so.OsmoticQuerySo;
import com.gunshi.project.xyt.entity.vo.*; import com.gunshi.project.xyt.entity.vo.*;
import com.gunshi.project.xyt.mapper.OsmoticPressRMapper; import com.gunshi.project.xyt.mapper.OsmoticPressRMapper;
import com.gunshi.project.xyt.model.OsmoticPressDevice; import com.gunshi.project.xyt.model.*;
import com.gunshi.project.xyt.model.AttDamProfileAutoDao;
import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao; import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao;
import com.gunshi.project.xyt.model.OsmoticPressR;
import com.gunshi.project.xyt.util.DateUtil; import com.gunshi.project.xyt.util.DateUtil;
import com.gunshi.project.xyt.util.ExcelUtil; import com.gunshi.project.xyt.util.ExcelUtil;
import com.gunshi.project.xyt.util.MyBeanUtil; import com.gunshi.project.xyt.util.MyBeanUtil;
@ -38,6 +38,9 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
@Resource @Resource
private OsmoticPressRMapper mapper; private OsmoticPressRMapper mapper;
@Resource
private AttDamProfileAutoDao profileAutoDao;
@Resource @Resource
private OsmoticPressDeviceAutoDao pressDeviceAutoDao; private OsmoticPressDeviceAutoDao pressDeviceAutoDao;
@ -50,8 +53,16 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
* @param osmoticQuerySo * @param osmoticQuerySo
* @return * @return
*/ */
public List<OsmoticStationVo> queryValue(OsmoticQuerySo osmoticQuerySo) { public List<OsmoticStationVo> queryValue(OsmoticQuerySo osmoticQuerySo,Integer year) {
List<String> dateList = DateUtil.getDatesBetween(osmoticQuerySo.getDateTimeRangeSo().getStart(), osmoticQuerySo.getDateTimeRangeSo().getEnd()); 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);
List<OsmoticStationVo> resList = new ArrayList<>(); List<OsmoticStationVo> resList = new ArrayList<>();
//查询库水位 //查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo); List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
@ -63,6 +74,7 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
OsmoticStationVo vo = new OsmoticStationVo(); OsmoticStationVo vo = new OsmoticStationVo();
vo.setTm(str); vo.setTm(str);
vo.setRz(rzMap.get(str)); vo.setRz(rzMap.get(str));
vo.setDrp(drpMap.get(str));
vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).map(t->{ vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).map(t->{
t.setRz(vo.getRz()); t.setRz(vo.getRz());
return t; return t;
@ -72,10 +84,40 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
return resList; return resList;
} }
public List<OsmoticChartVo> queryChart(OsmoticQuerySo osmoticQuerySo) { public List<OsmoticChartVo> queryChart(OsmoticQuerySo osmoticQuerySo,Integer year) {
List<OsmoticChartVo> resList = new ArrayList<>(); List<OsmoticChartVo> resList = new ArrayList<>();
//查询库水位 //查询库水位
List<StRzVo> list = mapper.queryRz(osmoticQuerySo); List<StRzVo> list = mapper.queryRz(osmoticQuerySo);
//查询测站降雨量
List<StRzVo> drpList = new ArrayList<>();
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);
}
}
//查询测站管水位 //查询测站管水位
List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo); List<OsmoticValueVo> valueList = mapper.queryValue(osmoticQuerySo);
//按测站分组 //按测站分组
@ -90,12 +132,17 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
vo.setMaxTm(max.getTm()); vo.setMaxTm(max.getTm());
vo.setMinValue(min.getValue()); vo.setMinValue(min.getValue());
vo.setMinTm(min.getTm()); 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))); vo.setDetailVos(bindData(MyBeanUtil.collectionCopy(list,OsmoticChartDetailVo.class),MyBeanUtil.collectionCopy(voList,OsmoticChartDetailVo.class)));
}
resList.add(vo); resList.add(vo);
}); });
return resList; return resList;
} }
//根据监测时间合并管水位和库水位数据 //根据监测时间合并管水位和库水位数据
private List<OsmoticChartDetailVo> bindData(List<OsmoticChartDetailVo> tmRzList, List<OsmoticChartDetailVo> voList) { private List<OsmoticChartDetailVo> bindData(List<OsmoticChartDetailVo> tmRzList, List<OsmoticChartDetailVo> voList) {
HashSet<String> strings = new HashSet<>(); HashSet<String> strings = new HashSet<>();
@ -122,21 +169,22 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
return list.stream().sorted(Comparator.comparing(OsmoticChartDetailVo::getTm)).collect(Collectors.toList()); return list.stream().sorted(Comparator.comparing(OsmoticChartDetailVo::getTm)).collect(Collectors.toList());
} }
public List<OsmoticStationVo> infiltraLine(InfiltraLineSo infiltraLineSo) { public List<OsmoticStationVo> infiltraLine(OsmoticQuerySo osmoticQuerySo) {
List<OsmoticStationVo> resList = new ArrayList<>(); List<OsmoticStationVo> resList = new ArrayList<>();
String profileCode = infiltraLineSo.getProfileCode(); String profileCode = osmoticQuerySo.getProfileCode();
//通过断面查询渗压设备 //通过断面查询渗压设备
List<String> stationCodes = queryPressList(profileCode); List<String> stationCodes = queryPressList(profileCode);
if(CollectionUtils.isEmpty(stationCodes)){ if(CollectionUtils.isEmpty(stationCodes)){
return resList; return resList;
} }
osmoticQuerySo.setStationCodes(stationCodes);
//查询库水位 //查询库水位
List<StRzVo> list = mapper.queryLineRz(infiltraLineSo); List<StRzVo> list = mapper.queryLineRz(osmoticQuerySo);
Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
//查询测站管水位 //查询测站管水位
List<OsmoticValueVo> valueList = mapper.queryLineValue(infiltraLineSo,stationCodes); List<OsmoticValueVo> valueList = mapper.queryLineValue(osmoticQuerySo);
//查询测站预警信息 //查询测站预警信息
List<OsmoticValueVo> warnList = mapper.queryWarn(infiltraLineSo,stationCodes); List<OsmoticValueVo> warnList = mapper.queryWarn(osmoticQuerySo);
valueList.stream().map(vo->{ valueList.stream().map(vo->{
Boolean b = warnList.stream().filter(o->o.getStationCode().equals(vo.getStationCode()) && o.getTm().equals(vo.getTm())).findAny().isPresent(); Boolean b = warnList.stream().filter(o->o.getStationCode().equals(vo.getStationCode()) && o.getTm().equals(vo.getTm())).findAny().isPresent();
if(b){ if(b){
@ -166,24 +214,27 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
return pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList()); return pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList());
} }
public void export(InfiltraLineSo infiltraLineSo, HttpServletResponse response) { public void export(OsmoticQuerySo osmoticQuerySo, HttpServletResponse response) {
//通过断面查询渗压设备 //通过断面查询渗压设备
List<String> stationCodes = queryPressList(infiltraLineSo.getProfileCode()); List<String> stationCodes = queryPressList(osmoticQuerySo.getProfileCode());
//表头信息 //表头信息
List<String> heads = new ArrayList<>(); List<String> heads = new ArrayList<>();
heads.add("序号");
heads.add("时间"); heads.add("时间");
heads.add("库水位(m)"); heads.add("库水位(m)");
heads.addAll(stationCodes); heads.addAll(stationCodes);
heads.add("结果分析"); heads.add("结果分析");
//表格数据 //表格数据
List<OsmoticStationVo> resList = infiltraLine(infiltraLineSo); List<OsmoticStationVo> resList = infiltraLine(osmoticQuerySo);
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (OsmoticStationVo vo : resList) { for (int j = 0;j < resList.size(); j++) {
OsmoticStationVo vo = resList.get(j);
Map<String, Object> test = new LinkedHashMap<>(); Map<String, Object> test = new LinkedHashMap<>();
test.put("t0",j+1);
test.put("t1", vo.getTm()); test.put("t1", vo.getTm());
test.put("t2", vo.getRz()); test.put("t2", vo.getRz());
for(int i = 0;i<stationCodes.size();i++){ for(int i = 0;i < stationCodes.size();i++){
String code = stationCodes.get(i); String code = stationCodes.get(i);
OsmoticValueVo valueVo = vo.getList().stream().filter(o->code.equals(o.getStationCode())).findFirst().orElse(null); OsmoticValueVo valueVo = vo.getList().stream().filter(o->code.equals(o.getStationCode())).findFirst().orElse(null);
test.put(code,valueVo != null ? valueVo.getValue() : "-"); test.put(code,valueVo != null ? valueVo.getValue() : "-");
@ -195,18 +246,161 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
for (String s : heads) { for (String s : heads) {
hs.add(Arrays.asList(s)); hs.add(Arrays.asList(s));
} }
ExcelUtil.exportExcel(hs, tableData(list), "浸润线", response, "浸润线");
}
private OsmoticQuerySo commonQueryHandle(OsmoticQuerySo osmoticQuerySo){
String profileCode = osmoticQuerySo.getProfileCode();
//通过断面查询渗压设备
List<String> stationCodes = queryPressList(profileCode);
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) {
String profileName = "";
//断面名称
AttDamProfile damProfile = profileAutoDao.getById(osmoticQuerySo.getProfileCode());
if(damProfile != null){
profileName = damProfile.getProfileName();
}
//上方表格数据
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<>();
heads.add(profileName + "断面测压管水位(m)");
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);
ExcelUtil.exportExcel(headList,tableData(list),2,new int[]{0},profileName+"断面年度渗压统计",response,"年度渗压统计");
}
private List<List> tableData( List<Map<String, Object>> list){
List<List> list2 = new ArrayList<>(); List<List> list2 = new ArrayList<>();
Collection values; Collection values;
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
values = list.get(i).values(); values = list.get(i).values();
List objects = new ArrayList<>(); List objects = new ArrayList<>();
for (Object value : values) { for (Object value : values) {
objects.add(value.toString()); objects.add(value == null ? "" : value.toString());
} }
list2.add(objects); list2.add(objects);
} }
ExcelUtil.exportExcel(hs, list2, "浸润线", null, response, "浸润线"); return list2;
} }
} }

View File

@ -141,7 +141,7 @@ public class DateUtil {
return now.format(ym); return now.format(ym);
} }
public static List<String> getDatesBetween(Date startDate, Date endDate) { public static List<String> getDatesBetween(Date startDate, Date endDate,Boolean isDesc) {
List<String> dates = new ArrayList<>(); List<String> dates = new ArrayList<>();
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate); calendar.setTime(startDate);
@ -150,8 +150,12 @@ public class DateUtil {
dates.add(convertDateToString(calendar.getTime())); dates.add(convertDateToString(calendar.getTime()));
calendar.add(Calendar.DATE, 1); calendar.add(Calendar.DATE, 1);
} }
dates.add(convertDateToString(endDate));
if(isDesc){
return dates.reversed(); return dates.reversed();
} }
return dates;
}
} }

View File

@ -7,8 +7,10 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.gunshi.project.xyt.util.excel.ExcelFillCellMergeStrategy;
import com.gunshi.project.xyt.util.excel.ExcelListener; import com.gunshi.project.xyt.util.excel.ExcelListener;
import com.gunshi.project.xyt.util.excel.ExcelResult; import com.gunshi.project.xyt.util.excel.ExcelResult;
import com.gunshi.project.xyt.util.excel.VoteTitleHandler;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -52,11 +54,20 @@ public class ExcelUtil {
} }
} }
public static <T> void exportExcel(List<List<String>> head,List<T> data, String filename, Class<T> clazz, HttpServletResponse response,String sheetName) { /**
*
* @param head
* @param data
* @param filename
* @param response
* @param sheetName
* @param <T>
*/
public static <T> void exportExcel(List<List<String>> head,List<T> data, String filename, HttpServletResponse response,String sheetName) {
OutputStream out = null; OutputStream out = null;
try { try {
out = getOutputStream(filename,response); out = getOutputStream(filename,response);
ExcelWriterSheetBuilder builder = EasyExcel.write(out, clazz) ExcelWriterSheetBuilder builder = EasyExcel.write(out)
//是否自动关闭流 //是否自动关闭流
.autoCloseStream(Boolean.FALSE) .autoCloseStream(Boolean.FALSE)
//自动列宽(不太精确) //自动列宽(不太精确)
@ -76,7 +87,39 @@ public class ExcelUtil {
} }
} }
/**
*
* @param head
* @param data
* @param mergeRowIndex
* @param mergeColumnIndex new int[]{0,1,2,3,4}
* @param filename
* @param response
* @param sheetName
* @param <T>
*/
public static <T> void exportExcel(List<List<String>> head,List<T> data,int mergeRowIndex,int[] mergeColumnIndex, String filename, HttpServletResponse response,String sheetName) {
OutputStream out = null;
try {
out = getOutputStream(filename,response);
ExcelWriterSheetBuilder builder = EasyExcel.write(out)
//是否自动关闭流
.autoCloseStream(Boolean.FALSE)
.registerWriteHandler(new ExcelFillCellMergeStrategy(mergeRowIndex,mergeColumnIndex))
.head(head)
.sheet(sheetName);
builder.doWrite(data);
} finally {
try {
if (out != null){
out.flush();
out.close();
}
} catch (IOException e) {
throw new RuntimeException("导出Excel异常");
}
}
}
/** /**
* {.} * {.}

View File

@ -0,0 +1,96 @@
package com.gunshi.project.xyt.util.excel;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import lombok.Data;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import java.util.List;
@Data
public class ExcelFillCellMergeStrategy implements CellWriteHandler {
/**
* new int[]{0,1,2,3,4}
*/
private int[] mergeColumnIndex;
/**
* 2
*/
private int mergeRowIndex;
public ExcelFillCellMergeStrategy(int mergeRowIndex, int[] mergeColumnIndex) {
this.mergeRowIndex = mergeRowIndex;
this.mergeColumnIndex = mergeColumnIndex;
}
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Head head, Integer integer, Integer integer1, Boolean aBoolean) {
}
@Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
Head head, Integer integer, Boolean aBoolean) {
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<WriteCellData<?>> list, Cell cell, Head head, Integer integer, Boolean aBoolean) {
//当前行
int curRowIndex = cell.getRowIndex();
//当前列
int curColIndex = cell.getColumnIndex();
if (curRowIndex > mergeRowIndex) {
for (int i = 0; i < mergeColumnIndex.length; i++) {
if (curColIndex == mergeColumnIndex[i]) {
mergeWithPrevRow(writeSheetHolder, cell, curRowIndex, curColIndex);
break;
}
}
}
}
private void mergeWithPrevRow(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex) {
//获取当前行的当前列的数据和上一行的当前列列数据,通过上一行数据是否相同进行合并
Object curData = cell.getCellTypeEnum() == CellType.STRING ? cell.getStringCellValue() :
cell.getNumericCellValue();
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex);
Object preData = preCell.getCellTypeEnum() == CellType.STRING ? preCell.getStringCellValue() :preCell.getNumericCellValue();
// 比较当前行的第一列的单元格与上一行是否相同,相同合并当前单元格与上一行
if (curData.equals(preData)) {
Sheet sheet = writeSheetHolder.getSheet();
List<CellRangeAddress> mergeRegions = sheet.getMergedRegions();
boolean isMerged = false;
for (int i = 0; i < mergeRegions.size() && !isMerged; i++) {
CellRangeAddress cellRangeAddr = mergeRegions.get(i);
// 若上一个单元格已经被合并,则先移出原有的合并单元,再重新添加合并单元
if (cellRangeAddr.isInRange(curRowIndex - 1, curColIndex)) {
sheet.removeMergedRegion(i);
cellRangeAddr.setLastRow(curRowIndex);
sheet.addMergedRegion(cellRangeAddr);
isMerged = true;
}
}
// 若上一个单元格未被合并,则新增合并单元
if (!isMerged) {
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex - 1, curRowIndex, curColIndex,
curColIndex);
sheet.addMergedRegion(cellRangeAddress);
}
}
}
}

View File

@ -1,4 +1,4 @@
package com.gunshi.project.xyt.util; package com.gunshi.project.xyt.util.excel;
import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.handler.CellWriteHandler;