日降雨年报表
parent
f6d1745fa0
commit
24a8cc4c15
|
|
@ -2,6 +2,9 @@ package com.gunshi.project.xyt.controller;
|
|||
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.db.dto.DateRangeSo;
|
||||
import com.gunshi.project.xyt.entity.so.StatisticsQuerySo;
|
||||
import com.gunshi.project.xyt.entity.vo.RjyNbStatVo;
|
||||
import com.gunshi.project.xyt.entity.vo.RjyNbVo;
|
||||
import com.gunshi.project.xyt.entity.vo.SdJyRbVo;
|
||||
import com.gunshi.project.xyt.entity.vo.SdSwRbVo;
|
||||
import com.gunshi.project.xyt.service.StatisticsService;
|
||||
|
|
@ -54,4 +57,22 @@ public class StatisticsController{
|
|||
service.sdSwRbExport(dateRangeSo,response);
|
||||
}
|
||||
|
||||
@Operation(summary = "日降雨年报表(上方表格)")
|
||||
@PostMapping("/rjyNb")
|
||||
public R<List<RjyNbVo>> rjyNb(@Validated @RequestBody StatisticsQuerySo statisticsQuerySo) {
|
||||
return R.ok(service.rjyNb(statisticsQuerySo));
|
||||
}
|
||||
|
||||
@Operation(summary = "日降雨年报表(下方统计)")
|
||||
@PostMapping("/rjyNb/stat")
|
||||
public R<RjyNbStatVo> rjyNbStat(@Validated @RequestBody StatisticsQuerySo statisticsQuerySo) {
|
||||
return R.ok(service.rjyNbStat(statisticsQuerySo));
|
||||
}
|
||||
|
||||
@Operation(summary = "日降雨年报表导出")
|
||||
@PostMapping("/rjyNb/export")
|
||||
public void rjyNbExport(@Validated @RequestBody StatisticsQuerySo statisticsQuerySo, HttpServletResponse response) {
|
||||
service.rjyNbExport(statisticsQuerySo,response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.gunshi.project.xyt.entity.so;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Created by wanyan on 2024/3/19
|
||||
*
|
||||
* @author wanyan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "报表统计查询对象")
|
||||
public class StatisticsQuerySo {
|
||||
|
||||
@Schema(description="年份")
|
||||
private Integer year;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class RjyNbStatVo {
|
||||
|
||||
@Schema(description="降水量")
|
||||
private BigDecimal drpSum;
|
||||
|
||||
@Schema(description="降雨日数")
|
||||
private Long dayCount;
|
||||
|
||||
@Schema(description = "统计数据")
|
||||
private List<RjyNbVo> list;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class RjyNbVo {
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","日期"})
|
||||
@ColumnWidth(15)
|
||||
private String date;
|
||||
|
||||
@ExcelProperty({"${title}","一月"})
|
||||
private String drpM1;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","二月"})
|
||||
private String drpM2;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","三月"})
|
||||
private String drpM3;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","四月"})
|
||||
private String drpM4;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","五月"})
|
||||
private String drpM5;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","六月"})
|
||||
private String drpM6;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","七月"})
|
||||
private String drpM7;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","八月"})
|
||||
private String drpM8;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","九月"})
|
||||
private String drpM9;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","十月"})
|
||||
private String drpM10;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","十一月"})
|
||||
private String drpM11;
|
||||
|
||||
|
||||
@ExcelProperty({"${title}","十二月"})
|
||||
private String drpM12;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.gunshi.project.xyt.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.xyt.entity.vo.StRzVo;
|
||||
import com.gunshi.project.xyt.model.StPptnRD;
|
||||
import com.gunshi.project.xyt.model.StPptnRH;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -19,4 +20,6 @@ public interface StPptnRHMapper extends BaseMapper<StPptnRH> {
|
|||
List<StPptnRH> queryList(@Param("start") String start,@Param("end") String end);
|
||||
|
||||
List<StRzVo> queryRzList(@Param("start") String start,@Param("end") String end);
|
||||
|
||||
List<StPptnRD> queryDayDrp(@Param("year") Integer year);
|
||||
}
|
||||
|
|
@ -90,4 +90,10 @@ public class StPptnRD implements Serializable {
|
|||
|
||||
@TableField(exist = false)
|
||||
private String adcd;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String day;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String month;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package com.gunshi.project.xyt.service;
|
|||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.gunshi.db.dto.DateRangeSo;
|
||||
import com.gunshi.project.xyt.entity.vo.SdJyRbVo;
|
||||
import com.gunshi.project.xyt.entity.vo.SdSwRbVo;
|
||||
import com.gunshi.project.xyt.entity.vo.StRzVo;
|
||||
import com.gunshi.project.xyt.entity.so.StatisticsQuerySo;
|
||||
import com.gunshi.project.xyt.entity.vo.*;
|
||||
import com.gunshi.project.xyt.mapper.StPptnRHMapper;
|
||||
import com.gunshi.project.xyt.model.StPptnRD;
|
||||
import com.gunshi.project.xyt.model.StPptnRH;
|
||||
import com.gunshi.project.xyt.util.DateUtil;
|
||||
import com.gunshi.project.xyt.util.ExcelUtil;
|
||||
|
|
@ -18,9 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -281,6 +279,182 @@ public class StatisticsService {
|
|||
String fileName = start + "-" + end + "时段水位日报表";
|
||||
ExcelUtil.exportExcel(list, fileName, SdSwRbVo.class, response, fileName);
|
||||
}
|
||||
|
||||
public List<RjyNbVo> rjyNb(StatisticsQuerySo statisticsQuerySo) {
|
||||
List<RjyNbVo> res = new ArrayList<>();
|
||||
Integer year = statisticsQuerySo.getYear();
|
||||
List<StPptnRD> list = stPptnRHMapper.queryDayDrp(year);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return res;
|
||||
}
|
||||
Map<String, List<StPptnRD>> map = list.stream().collect(Collectors.groupingBy(StPptnRD::getDay));
|
||||
for (int i = 1; i < 32; i++) {
|
||||
RjyNbVo vo = new RjyNbVo();
|
||||
String s = String.valueOf(i);
|
||||
vo.setDate(s);
|
||||
if(i < 10){
|
||||
s = "0" + i;
|
||||
}
|
||||
List<StPptnRD> rds = map.get(s);
|
||||
if(CollectionUtils.isNotEmpty(rds)){
|
||||
for (int j = 0; j < rds.size(); j++) {
|
||||
StPptnRD rd = rds.get(j);
|
||||
if (rd.getDrp() != null) {
|
||||
vo = setDayDrp(vo, rd.getMonth(), rd.getDrp());
|
||||
}
|
||||
}
|
||||
}
|
||||
res.add(vo);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private RjyNbVo setDayDrp(RjyNbVo vo, String month, BigDecimal drp) {
|
||||
switch (month) {
|
||||
case "01":
|
||||
vo.setDrpM1(drp.toString());
|
||||
break;
|
||||
case "02":
|
||||
vo.setDrpM2(drp.toString());
|
||||
break;
|
||||
case "03":
|
||||
vo.setDrpM3(drp.toString());
|
||||
break;
|
||||
case "04":
|
||||
vo.setDrpM4(drp.toString());
|
||||
break;
|
||||
case "05":
|
||||
vo.setDrpM5(drp.toString());
|
||||
break;
|
||||
case "06":
|
||||
vo.setDrpM6(drp.toString());
|
||||
break;
|
||||
case "07":
|
||||
vo.setDrpM7(drp.toString());
|
||||
break;
|
||||
case "08":
|
||||
vo.setDrpM8(drp.toString());
|
||||
break;
|
||||
case "09":
|
||||
vo.setDrpM9(drp.toString());
|
||||
break;
|
||||
case "10":
|
||||
vo.setDrpM10(drp.toString());
|
||||
break;
|
||||
case "11":
|
||||
vo.setDrpM11(drp.toString());
|
||||
break;
|
||||
case "12":
|
||||
vo.setDrpM12(drp.toString());
|
||||
break;
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public RjyNbStatVo rjyNbStat(StatisticsQuerySo statisticsQuerySo) {
|
||||
RjyNbStatVo vo = new RjyNbStatVo();
|
||||
Integer year = statisticsQuerySo.getYear();
|
||||
List<StPptnRD> list = stPptnRHMapper.queryDayDrp(year);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return vo;
|
||||
}
|
||||
BigDecimal drpSum = list.stream().map(StPptnRD::getDrp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
vo.setDrpSum(drpSum);
|
||||
Long count = list.stream().filter(o -> o.getDrp().compareTo(new BigDecimal(0)) > 0).collect(Collectors.counting());
|
||||
vo.setDayCount(count);
|
||||
//按月份分组
|
||||
Map<String, List<StPptnRD>> map = list.stream().collect(Collectors.groupingBy(StPptnRD::getMonth));
|
||||
|
||||
List<RjyNbVo> childList = new ArrayList<>();
|
||||
RjyNbVo rjyNbVo = new RjyNbVo();
|
||||
rjyNbVo.setDate("月降雨量");
|
||||
setMonthSumDrp(rjyNbVo,map);
|
||||
childList.add(rjyNbVo);
|
||||
|
||||
RjyNbVo rVo = new RjyNbVo();
|
||||
rVo.setDate("降雨日数");
|
||||
setMonthDrpDay(rVo,map);
|
||||
childList.add(rVo);
|
||||
|
||||
RjyNbVo max = new RjyNbVo();
|
||||
max.setDate("最大日量");
|
||||
setMonthDrpMax(max,map);
|
||||
childList.add(max);
|
||||
|
||||
vo.setList(childList);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private void setMonthDrpMax(RjyNbVo rjyNbVo, Map<String, List<StPptnRD>> map) {
|
||||
for(int i = 1;i< 13;i++){
|
||||
String s = String.valueOf(i);
|
||||
if(i < 10){
|
||||
s = "0" + i;
|
||||
}
|
||||
List<StPptnRD> list = map.get(s);
|
||||
if(CollectionUtils.isNotEmpty(list)) {
|
||||
BigDecimal maxDrp = list.stream().max(Comparator.comparing(StPptnRD::getDrp)).get().getDrp();
|
||||
setDayDrp(rjyNbVo, s, maxDrp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setMonthSumDrp(RjyNbVo rjyNbVo, Map<String, List<StPptnRD>> map) {
|
||||
for(int i = 1;i< 13;i++){
|
||||
String s = String.valueOf(i);
|
||||
if(i < 10){
|
||||
s = "0" + i;
|
||||
}
|
||||
List<StPptnRD> list = map.get(s);
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
BigDecimal drpSum = list.stream().map(StPptnRD::getDrp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
setDayDrp(rjyNbVo,s,drpSum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setMonthDrpDay(RjyNbVo rjyNbVo, Map<String, List<StPptnRD>> map) {
|
||||
for(int i = 1;i< 13;i++){
|
||||
String s = String.valueOf(i);
|
||||
if(i < 10){
|
||||
s = "0" + i;
|
||||
}
|
||||
List<StPptnRD> list = map.get(s);
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
Long count = list.stream().filter(o -> o.getDrp().compareTo(new BigDecimal(0)) > 0).collect(Collectors.counting());
|
||||
setDayDrp(rjyNbVo,s,new BigDecimal(count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rjyNbExport(StatisticsQuerySo statisticsQuerySo, HttpServletResponse response) {
|
||||
//上方数据
|
||||
List<RjyNbVo> rjyNb = rjyNb(statisticsQuerySo);
|
||||
//下方统计数据
|
||||
RjyNbStatVo vo = rjyNbStat(statisticsQuerySo);
|
||||
List<RjyNbVo> list = vo.getList();
|
||||
rjyNb.addAll(list);
|
||||
//最下方拼接一条数据
|
||||
RjyNbVo rjyNbVo = new RjyNbVo();
|
||||
rjyNbVo.setDate("年统计");
|
||||
rjyNbVo.setDrpM1("降水量");
|
||||
rjyNbVo.setDrpM2("降水量");
|
||||
rjyNbVo.setDrpM3(vo.getDrpSum().toString());
|
||||
rjyNbVo.setDrpM4(vo.getDrpSum().toString());
|
||||
rjyNbVo.setDrpM5(vo.getDrpSum().toString());
|
||||
rjyNbVo.setDrpM6(vo.getDrpSum().toString());
|
||||
rjyNbVo.setDrpM7("降雨日数");
|
||||
rjyNbVo.setDrpM8("降雨日数");
|
||||
rjyNbVo.setDrpM9(vo.getDayCount().toString());
|
||||
rjyNbVo.setDrpM10(vo.getDayCount().toString());
|
||||
rjyNbVo.setDrpM11(vo.getDayCount().toString());
|
||||
rjyNbVo.setDrpM12(vo.getDayCount().toString());
|
||||
rjyNb.add(rjyNbVo);
|
||||
|
||||
String fileName = "小玉潭水库" + statisticsQuerySo.getYear() + "年日降雨年报表";
|
||||
ExcelUtil.exportExcel(rjyNb, fileName, RjyNbVo.class, response, fileName,true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alibaba.excel.EasyExcel;
|
|||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
|
||||
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.gunshi.project.xyt.util.excel.ExcelFillCellMergeStrategy;
|
||||
import com.gunshi.project.xyt.util.excel.ExcelListener;
|
||||
|
|
@ -54,6 +55,45 @@ public class ExcelUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel,合并指定单元格
|
||||
*
|
||||
* @param list 导出数据集合,加动态表头
|
||||
* @param filename 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param response 响应体
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String filename, Class<T> clazz, HttpServletResponse response,String sheetName,Boolean isMerge) {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
out = getOutputStream(filename,response);
|
||||
OnceAbsoluteMergeStrategy strategy = new OnceAbsoluteMergeStrategy(36,36,1,2);
|
||||
OnceAbsoluteMergeStrategy strategy1 = new OnceAbsoluteMergeStrategy(36,36,3,6);
|
||||
OnceAbsoluteMergeStrategy strategy2 = new OnceAbsoluteMergeStrategy(36,36,7,8);
|
||||
OnceAbsoluteMergeStrategy strategy3 = new OnceAbsoluteMergeStrategy(36,36,9,12);
|
||||
ExcelWriterSheetBuilder builder = EasyExcel.write(out, clazz)
|
||||
//是否自动关闭流
|
||||
.autoCloseStream(Boolean.FALSE)
|
||||
//自动列宽(不太精确)
|
||||
.registerWriteHandler(new VoteTitleHandler(filename))
|
||||
.registerWriteHandler(strategy)
|
||||
.registerWriteHandler(strategy1)
|
||||
.registerWriteHandler(strategy2)
|
||||
.registerWriteHandler(strategy3)
|
||||
.sheet(sheetName);
|
||||
builder.doWrite(list);
|
||||
} finally {
|
||||
try {
|
||||
if (out != null){
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出动态列
|
||||
* @param head 表头
|
||||
|
|
|
|||
|
|
@ -14,4 +14,10 @@
|
|||
and stcd = (select stcd from public.att_res_base where res_code = '42120250085')
|
||||
order by tm asc
|
||||
</select>
|
||||
|
||||
<select id="queryDayDrp" resultType="com.gunshi.project.xyt.model.StPptnRD">
|
||||
select tm,drp,TO_CHAR(tm, 'DD') as day,TO_CHAR(tm, 'MM') as month from public.st_pptn_r_d where year = #{year}
|
||||
and stcd = (select stcd from public.att_res_base where res_code = '42120250085')
|
||||
order by tm asc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue