4 files modified
1 files renamed
9 files added
| | |
| | | |
| | | |
| | | import cn.gistack.sm.sjztmd.word.service.ISjztmdService; |
| | | import cn.gistack.sm.sjztmd.word.util.ExcelUtil; |
| | | import cn.gistack.sm.sjztmd.word.util.WordUtil; |
| | | import cn.gistack.sm.sjztmd.word.vo.TbWordVO; |
| | | import cn.gistack.sm.sjztmd.word.vo.*; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | .body(resource); // 将InputStreamResource对象作为响应体 |
| | | } |
| | | |
| | | @GetMapping("/download/eightFloodInfo") |
| | | public ResponseEntity eightFloodInfo() throws Exception{ |
| | | @GetMapping("/download/overFloodInfo") |
| | | public ResponseEntity overFloodInfo() throws Exception{ |
| | | String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); |
| | | |
| | | String fileName = time+ "全省水库防汛情况.docx"; |
| | | byte[] data = WordUtil.GetEightFloodInfo(); |
| | | String fileNameURL = URLEncoder.encode(fileName, "UTF-8"); |
| | | //获取总览、大中库、明细数据 |
| | | List<TotalInfo> totalList = sjztmdService.getTotalInfo(); |
| | | List<DzkInfo> dzkList = sjztmdService.getDzkInfo(); |
| | | List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(); |
| | | List<SzInfo> szInfoList = sjztmdService.getSzInfo(); |
| | | |
| | | byte[] data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList); |
| | | |
| | | // 创建响应实体并设置响应头,将输出流作为响应体返回给客户端 |
| | | InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data)); |
| | |
| | | // 将临时文件添加到响应中,以便用户下载 |
| | | return ResponseEntity.ok() |
| | | .contentType(MediaType.APPLICATION_OCTET_STREAM) // 设置响应的内容类型为二进制流(octet stream) |
| | | .header("Content-Disposition", "attachment; filename=\"" + fileName) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件 |
| | | .header("Content-Disposition", "attachment; filename=\"" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件 |
| | | .body(resource); // 将InputStreamResource对象作为响应体 |
| | | } |
| | | |
| | | @GetMapping("/download/getOverFloodInfoExcel") |
| | | public void getOverFloodInfoExcel(HttpServletResponse response) throws Exception { |
| | | |
| | | //获取总览、大中库、明细数据 |
| | | List<TotalInfo> totalList = sjztmdService.getTotalInfo(); |
| | | List<DzkInfo> dzkList = sjztmdService.getDzkInfo(); |
| | | List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(); |
| | | |
| | | ExcelUtil.generateExcel(response,totalList,dzkList,overDetailList); |
| | | } |
| | | |
| | | } |
| | |
| | | package cn.gistack.sm.sjztmd.word.service; |
| | | |
| | | import cn.gistack.sm.sjztmd.word.vo.TbWordVO; |
| | | import cn.gistack.sm.sjztmd.word.vo.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface ISjztmdService { |
| | | |
| | |
| | | */ |
| | | TbWordVO getTbWordVO(String resCd); |
| | | |
| | | |
| | | List<TotalInfo> getTotalInfo(); |
| | | |
| | | List<DzkInfo> getDzkInfo(); |
| | | |
| | | List<OverDetail> getOverDetailInfo(); |
| | | |
| | | List<SzInfo> getSzInfo(); |
| | | } |
| | |
| | | import cn.gistack.sm.sjztmd.mapper.SjztMdMapper; |
| | | import cn.gistack.sm.sjztmd.service.*; |
| | | import cn.gistack.sm.sjztmd.word.service.ISjztmdService; |
| | | import cn.gistack.sm.sjztmd.word.vo.TbWordVO; |
| | | import cn.gistack.sm.sjztmd.word.vo.*; |
| | | import cn.gistack.sm.sjztods.constant.ZtApiUrlConstant; |
| | | import cn.gistack.sm.sjztods.constant.ZtConfigConstant; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | |
| | | @AllArgsConstructor |
| | | @DS("zt") |
| | | public class SjztmdServiceImpl implements ISjztmdService { |
| | | |
| | | //总计 |
| | | private final String RIBAO_SHEET1_TOTAL_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao_sheet1/api?small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2"; |
| | | //中大型水库 |
| | | private final String RIBAO_SHEET2_ZDX_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet2_zdx/api?mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2"; |
| | | //超汛明细 |
| | | private final String RIBAO_SHEET3_OVER_STAG_LIST_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet3_over_stag_list/api?small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2"; |
| | | //省直管 |
| | | private final String SZ_INFO = "/services/1234567890ABCDEFGHIJKLMN/ribao/shengzh_new_rz/api"; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | private final SjztMdMapper mapper; |
| | |
| | | return tbWordVO; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<TotalInfo> getTotalInfo(){ |
| | | JSONObject ztData = this.getZtData(null, RIBAO_SHEET1_TOTAL_URL); |
| | | JSONArray data = ztData.getJSONArray("data"); |
| | | List<TotalInfo> list = data.toJavaList(TotalInfo.class); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<DzkInfo> getDzkInfo() { |
| | | JSONObject ztData = this.getZtData(null, RIBAO_SHEET2_ZDX_URL); |
| | | JSONArray data = ztData.getJSONArray("data"); |
| | | List<DzkInfo> list = data.toJavaList(DzkInfo.class); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<OverDetail> getOverDetailInfo() { |
| | | JSONObject ztData = this.getZtData(null, RIBAO_SHEET3_OVER_STAG_LIST_URL); |
| | | JSONArray data = ztData.getJSONArray("data"); |
| | | List<OverDetail> list = data.toJavaList(OverDetail.class); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<SzInfo> getSzInfo() { |
| | | JSONObject ztData = this.getZtData(null, SZ_INFO); |
| | | JSONArray data = ztData.getJSONArray("data"); |
| | | List<SzInfo> list = data.toJavaList(SzInfo.class); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 调用接口获取中台数据 |
| | | */ |
| | |
| | | try { |
| | | //有请求头,有参数请求 |
| | | ResponseEntity<String> responseEntity = |
| | | restTemplate.exchange(url + params, |
| | | restTemplate.exchange(url, |
| | | HttpMethod.GET, |
| | | formEntity, |
| | | String.class); |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.util; |
| | | |
| | | import ch.qos.logback.core.pattern.FormatInfo; |
| | | import cn.gistack.sm.sjztmd.word.vo.DzkInfo; |
| | | import cn.gistack.sm.sjztmd.word.vo.OverDetail; |
| | | import cn.gistack.sm.sjztmd.word.vo.TotalInfo; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.alibaba.excel.util.FileUtils; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.metadata.fill.FillWrapper; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | /** |
| | | * excel工具类 |
| | | */ |
| | | public class ExcelUtil { |
| | | |
| | | |
| | | public static void generateExcel(HttpServletResponse response, List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList) throws Exception { |
| | | |
| | | String tm = new SimpleDateFormat("MM月dd日H时").format(new Date()); |
| | | HashMap<String,String> map = new HashMap<>(); |
| | | map.put("time",tm); |
| | | |
| | | HashMap<String, Object> info = formatInfo(totalList, dzkList, overDetailList); |
| | | info.put("time",tm); |
| | | |
| | | //获取模板(带公式的模板需要文件编辑之后才会显示正常数据) |
| | | InputStream inputStream = ExcelUtil.class.getClassLoader().getResourceAsStream("excel/xlsx/totalTemplateNoFormula.xlsx"); |
| | | String fileName = StringUtil.format("水库超汛限水位情况计表({}).xlsx",tm); |
| | | ExcelWriter excelWriter = EasyExcel.write(getOutputStream(fileName, response)).withTemplate(inputStream).excelType(ExcelTypeEnum.XLSX).build(); |
| | | //设置公式生效 |
| | | // excelWriter.writeContext().writeWorkbookHolder().getWorkbook().setForceFormulaRecalculation(true); |
| | | WriteSheet writeSheet1 = EasyExcel.writerSheet(0,"总表").build(); |
| | | WriteSheet writeSheet2 = EasyExcel.writerSheet(1,"大中库").build(); |
| | | WriteSheet writeSheet3 = EasyExcel.writerSheet(2,"明细").build(); |
| | | |
| | | |
| | | |
| | | // 这个传进去的 map 就是非表格数据,详见我定义的模板中图片位置上方那部分 |
| | | excelWriter.fill(info, writeSheet1); |
| | | excelWriter.fill(new FillWrapper("data", totalList), writeSheet1); |
| | | |
| | | excelWriter.fill(map, writeSheet2); |
| | | excelWriter.fill(new FillWrapper("data", dzkList), writeSheet2); |
| | | |
| | | excelWriter.fill(map, writeSheet3); |
| | | excelWriter.fill(new FillWrapper("data", overDetailList), writeSheet3); |
| | | excelWriter.finish(); |
| | | } |
| | | |
| | | private static HashMap<String,Object> formatInfo(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList) { |
| | | HashMap<String,Object> info = new HashMap<>(); |
| | | |
| | | int overTotal = 0; |
| | | int overBig = 0; |
| | | int overMid = 0; |
| | | int overSmall = 0; |
| | | |
| | | int wzTotal = 0; |
| | | int wzBig = 0; |
| | | int wzMid = 0; |
| | | int wzSmall = 0; |
| | | |
| | | int yzTotal=0; |
| | | int yzBig = 0; |
| | | int yzMid = 0; |
| | | int yzSmall = 0; |
| | | |
| | | int dangerTotal = 0; |
| | | int dangerBig = 0; |
| | | int dangerMid = 0; |
| | | int dangerSmall = 0; |
| | | |
| | | int overDangerTotal = 0; |
| | | int overDangerBig = 0; |
| | | int overDangerMid = 0; |
| | | int overDangerSmall = 0; |
| | | |
| | | //给总览加序号 |
| | | for (int i = 0; i < totalList.size(); i++) { |
| | | |
| | | TotalInfo totalInfo = totalList.get(i); |
| | | |
| | | totalInfo.setIndex(String.valueOf(i+1)); |
| | | |
| | | overTotal+=isNull(totalInfo.getCount_all()); |
| | | overBig +=isNull(totalInfo.getBig_all()); |
| | | overMid +=isNull(totalInfo.getMid_all()); |
| | | overSmall +=isNull(totalInfo.getSmall_all()); |
| | | |
| | | wzTotal +=isNull(totalInfo.getWz_count_all()); |
| | | wzBig+=isNull(totalInfo.getWz_big()); |
| | | wzMid+=isNull(totalInfo.getWz_mid()); |
| | | wzSmall+=isNull(totalInfo.getWz_small()); |
| | | |
| | | yzTotal+=isNull(totalInfo.getYz_count_all()); |
| | | yzBig+=isNull(totalInfo.getYz_big()); |
| | | yzMid +=isNull(totalInfo.getYz_mid()); |
| | | yzSmall += isNull(totalInfo.getYz_small()); |
| | | |
| | | dangerTotal +=isNull(totalInfo.getDanger_count_all()); |
| | | dangerBig +=isNull(totalInfo.getDanger_big_all()); |
| | | dangerMid += isNull(totalInfo.getDanger_mid_all()); |
| | | dangerSmall += isNull(totalInfo.getDanger_small_all()); |
| | | |
| | | overDangerTotal +=isNull(totalInfo.getOver_danger_count_all()); |
| | | overDangerBig += isNull(totalInfo.getOver_danger_big_all()); |
| | | overDangerMid += isNull(totalInfo.getOver_danger_mid_all()); |
| | | overDangerSmall += isNull(totalInfo.getOver_danger_small_all()); |
| | | } |
| | | info.put("overTotal", overTotal); |
| | | info.put("overBig", overBig); |
| | | info.put("overMid", overMid); |
| | | info.put("overSmall", overSmall); |
| | | |
| | | info.put("wzTotal", wzTotal); |
| | | info.put("wzBig", wzBig); |
| | | info.put("wzMid", wzMid); |
| | | info.put("wzSmall", wzSmall); |
| | | |
| | | info.put("yzTotal", yzTotal); |
| | | info.put("yzBig", yzBig); |
| | | info.put("yzMid", yzMid); |
| | | info.put("yzSmall", yzSmall); |
| | | |
| | | info.put("dangerTotal", dangerTotal); |
| | | info.put("dangerBig", dangerBig); |
| | | info.put("dangerMid", dangerMid); |
| | | info.put("dangerSmall", dangerSmall); |
| | | |
| | | info.put("overDangerTotal", overDangerTotal); |
| | | info.put("overDangerBig", overDangerBig); |
| | | info.put("overDangerMid", overDangerMid); |
| | | info.put("overDangerSmall", overDangerSmall); |
| | | |
| | | //给大中库加序号、是否病险转换 |
| | | for (int i = 0; i < dzkList.size(); i++) { |
| | | dzkList.get(i).setIndex(String.valueOf(i+1)); |
| | | if (dzkList.get(i).getIs_danger() != null){ |
| | | if (dzkList.get(i).getIs_danger()){ |
| | | dzkList.get(i).setIs_dangerText("1"); |
| | | }else if (!dzkList.get(i).getIs_danger()){ |
| | | dzkList.get(i).setIs_dangerText("0"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //给明细是否病险转换 |
| | | for (int i = 0; i < overDetailList.size(); i++) { |
| | | if (overDetailList.get(i).getIs_danger() != null){ |
| | | if (overDetailList.get(i).getIs_danger()){ |
| | | overDetailList.get(i).setIs_dangerText("1"); |
| | | }else if (!overDetailList.get(i).getIs_danger()){ |
| | | overDetailList.get(i).setIs_dangerText("0"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return info; |
| | | } |
| | | |
| | | /** |
| | | * 导出文件时为Writer生成OutputStream. |
| | | * |
| | | * @param fileName 文件名 |
| | | * @param response response |
| | | * @return "" |
| | | */ |
| | | public static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception { |
| | | try { |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf8"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
| | | return response.getOutputStream(); |
| | | } catch (IOException e) { |
| | | throw new Exception("导出excel表格失败!", e); |
| | | } |
| | | } |
| | | |
| | | public static Integer isNull(Integer num){ |
| | | if (num == null){ |
| | | return 0; |
| | | }else { |
| | | return num; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | package cn.gistack.sm.sjztmd.word.util; |
| | | |
| | | import cn.gistack.sm.sjztmd.word.vo.TbWordVO; |
| | | import cn.gistack.sm.sjztmd.word.vo.*; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.data.NumbericRenderData; |
| | | |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | public static byte[] GetEightFloodInfo() throws Exception{ |
| | | String templatePath = "word/doc/eightFloodInfoTemplate.docx"; |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | byte[] bytes = GenerateWord(templatePath, map); |
| | | return bytes; |
| | | } |
| | | |
| | | private static byte[] GenerateWord(String templatePath,Object object) throws Exception { |
| | | InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream(templatePath); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream).render(object); |
| | | template.write(outputStream); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * 根据水库id获取数据 |
| | | * |
| | | * @return |
| | | */ |
| | | private static Map<String, Object> createParams(TbWordVO tbWordVO) { |
| | |
| | | params.put("县", tbWordVO.getCountyName()); |
| | | params.put("镇", tbWordVO.getTownName()); |
| | | params.put("河流名称", tbWordVO.getLocRvName()); |
| | | params.put("水库功能",tbWordVO.getResFuncText()); |
| | | params.put("水库功能", tbWordVO.getResFuncText()); |
| | | params.put("调节性能", tbWordVO.getAdjustPropText()); |
| | | params.put("水库坝址以上控制流域面积", tbWordVO.getConArea()); |
| | | params.put("流域多年平均降雨量", tbWordVO.getMoyearRainAvg()); |
| | |
| | | params.put("校核洪水标准", tbWordVO.getChecFlSta()); |
| | | params.put("总库容", tbWordVO.getTotalCap()); |
| | | params.put("水文特征", tbWordVO.getHydrologicalCharacteristics()); |
| | | params.put("工程等别",tbWordVO.getEngGrad()); |
| | | params.put("挡水建筑物泄洪建筑物正常溢洪道",tbWordVO.getBuildingText()); |
| | | params.put("主坝信息",tbWordVO.getMainDamInfo()); |
| | | params.put("挡水建筑物泄洪建筑物正常溢洪道等详情",tbWordVO.getBuildingInfo()); |
| | | params.put("输水建筑物输水道形式",tbWordVO.getAqueductType());//若有两个以上输水建筑物,则描述设计流量较大的,若只有一个输水建筑物则去掉“主要” |
| | | params.put("断面尺寸",tbWordVO.getSection()); |
| | | params.put("进口底槛高程",tbWordVO.getThresholdElevation()); |
| | | params.put("设计流量",tbWordVO.getDesignFlow()); |
| | | params.put("电站信息",tbWordVO.getPowerStationInfo()); |
| | | params.put("保护城市",tbWordVO.getProtectCity()); |
| | | params.put("保护人口保护耕地",tbWordVO.getProtectPersonLand()); |
| | | params.put("保护铁路",tbWordVO.getProtectThings());//铁路、公路、管线、企业几个依次罗列,超过三个列出第二个后为“XX等”,后面不需罗列 |
| | | params.put("经济效益",tbWordVO.getEconomicBenefit());//若既有灌溉又有供水,则有“此外,”,无灌溉有供水直接介绍供水 |
| | | params.put("工程始建时间",tbWordVO.getStartTime()); |
| | | params.put("下闸蓄水时间",tbWordVO.getWaterStorageTm()); |
| | | params.put("工程等别", tbWordVO.getEngGrad()); |
| | | params.put("挡水建筑物泄洪建筑物正常溢洪道", tbWordVO.getBuildingText()); |
| | | params.put("主坝信息", tbWordVO.getMainDamInfo()); |
| | | params.put("挡水建筑物泄洪建筑物正常溢洪道等详情", tbWordVO.getBuildingInfo()); |
| | | params.put("输水建筑物输水道形式", tbWordVO.getAqueductType());//若有两个以上输水建筑物,则描述设计流量较大的,若只有一个输水建筑物则去掉“主要” |
| | | params.put("断面尺寸", tbWordVO.getSection()); |
| | | params.put("进口底槛高程", tbWordVO.getThresholdElevation()); |
| | | params.put("设计流量", tbWordVO.getDesignFlow()); |
| | | params.put("电站信息", tbWordVO.getPowerStationInfo()); |
| | | params.put("保护城市", tbWordVO.getProtectCity()); |
| | | params.put("保护人口保护耕地", tbWordVO.getProtectPersonLand()); |
| | | params.put("保护铁路", tbWordVO.getProtectThings());//铁路、公路、管线、企业几个依次罗列,超过三个列出第二个后为“XX等”,后面不需罗列 |
| | | params.put("经济效益", tbWordVO.getEconomicBenefit());//若既有灌溉又有供水,则有“此外,”,无灌溉有供水直接介绍供水 |
| | | params.put("工程始建时间", tbWordVO.getStartTime()); |
| | | params.put("下闸蓄水时间", tbWordVO.getWaterStorageTm()); |
| | | // 鉴定时间 > 除险加固 |
| | | params.put("安全鉴定和除险加固",tbWordVO.getSafetyMonitorText()); |
| | | params.put("安全鉴定和除险加固", tbWordVO.getSafetyMonitorText()); |
| | | // 鉴定时间 < 除险加固 |
| | | //params.put("安全鉴定和除险加固","2012年9月,水库进行安全鉴定,鉴定结果为“三类坝”(加一个双引号),工程主要存在问题为坝顶及心墙顶欠高,大坝渗透系数偏大,溢洪道过流能力不足、边墙高度不足等(加一个“等”)。 |
| | | // 针对水库安全鉴定发现的问题,水库除险加固工程于2019年11月动工,2022年6月蓄水验收。"); |
| | | params.put("管理单位名称",tbWordVO.getMUnitName()); |
| | | params.put("管理单位性质",tbWordVO.getMUnitNature()); |
| | | params.put("主管部门",tbWordVO.getCUnitName());// 水库基本信息表,不是填报表 |
| | | params.put("管理单位职工人数",tbWordVO.getMUnitPersonNumber()); |
| | | params.put("主管部门责任人",tbWordVO.getCompetentDepartmentInfo()); // 责任人信息表,不是填报表 |
| | | params.put("行政主管单位",tbWordVO.getAdministrativeUnit()); |
| | | params.put("行政责任人职务手机号码",tbWordVO.getAdministrativeInfo()); // 责任人信息表,不是填报表 |
| | | params.put("管理单位名称", tbWordVO.getMUnitName()); |
| | | params.put("管理单位性质", tbWordVO.getMUnitNature()); |
| | | params.put("主管部门", tbWordVO.getCUnitName());// 水库基本信息表,不是填报表 |
| | | params.put("管理单位职工人数", tbWordVO.getMUnitPersonNumber()); |
| | | params.put("主管部门责任人", tbWordVO.getCompetentDepartmentInfo()); // 责任人信息表,不是填报表 |
| | | params.put("行政主管单位", tbWordVO.getAdministrativeUnit()); |
| | | params.put("行政责任人职务手机号码", tbWordVO.getAdministrativeInfo()); // 责任人信息表,不是填报表 |
| | | return params; |
| | | } |
| | | |
| | | |
| | | public static byte[] GetOverInfo(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList,List<SzInfo> szInfoList) throws Exception { |
| | | InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/doc/overFloodTemplate.docx"); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | OverWord overWord = new OverWord(totalList, dzkList, overDetailList, szInfoList); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream).render(createOverWordParam(overWord)); |
| | | template.write(outputStream); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | private static Map<String, Object> createOverWordParam(OverWord overWord) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | |
| | | params.put("时间", overWord.getTm()); |
| | | params.put("全省水库超汛限", overWord.getTotalInfo()); |
| | | params.put("小型水库详情", overWord.getOverSmallInfo()); |
| | | params.put("大型水库详情", overWord.getOverBigInfo()); |
| | | params.put("中型水库详情", overWord.getOverMidInfo()); |
| | | params.put("省直水库详情", overWord.getProvinceInfo()); |
| | | |
| | | return params; |
| | | |
| | | } |
| | | |
| | | private static byte[] GenerateWord(String templatePath, Object object) throws Exception { |
| | | InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream(templatePath); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream).render(object); |
| | | template.write(outputStream); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DzkInfo { |
| | | private String index; |
| | | |
| | | //父行政区划名 |
| | | private String p_ad_name; |
| | | |
| | | //行政区划 |
| | | private String ad_name; |
| | | |
| | | //水库名称 |
| | | private String res_name; |
| | | |
| | | //工程类型 |
| | | private String eng_scal; |
| | | |
| | | //24h降雨 |
| | | private Double drp; |
| | | |
| | | //水位 |
| | | private Double rz; |
| | | |
| | | //汛限水位 |
| | | private Double tb_flse_lim_stag; |
| | | |
| | | //比汛限 |
| | | private Double over_stag; |
| | | |
| | | //是否病险 |
| | | private Boolean is_danger; |
| | | private String is_dangerText; |
| | | |
| | | //控制运用水位 |
| | | private Double tb_control_z; |
| | | |
| | | //比控制水位 |
| | | private Double over_control_z; |
| | | |
| | | //堰顶高程 |
| | | private Double tb_weir_top_elevation; |
| | | |
| | | //总库容 |
| | | private Double tot_cap; |
| | | |
| | | //集雨面积 |
| | | private Double wat_shed_area; |
| | | |
| | | //是否有闸 |
| | | private String is_gate; |
| | | |
| | | //溢洪道型式 |
| | | private String spillway_type; |
| | | |
| | | //出库流量 |
| | | private Double otq; |
| | | |
| | | //溢洪道最大泄洪量 |
| | | private Double sum_all; |
| | | |
| | | //除险加固时间 |
| | | private String reinforce_tm; |
| | | |
| | | //坝型 |
| | | private String dam_type; |
| | | |
| | | //备注 |
| | | private String note; |
| | | |
| | | //时间 |
| | | private String tm; |
| | | |
| | | //正常蓄水位 |
| | | private Double tb_norm_pool_stag; |
| | | |
| | | } |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 超汛明细 |
| | | */ |
| | | @Data |
| | | public class OverDetail { |
| | | //市 |
| | | private String p_ad_name; |
| | | //县 |
| | | private String ad_name; |
| | | //水库地点 |
| | | private String res_loc; |
| | | |
| | | //水库名称 |
| | | private String res_name; |
| | | //工程规模 |
| | | private String eng_scal; |
| | | //是否有闸 |
| | | private String is_gate; |
| | | //当日水位 |
| | | private String rz; |
| | | |
| | | //堰顶 |
| | | private String tb_weir_top_elevation; |
| | | |
| | | //汛限 |
| | | private String tb_flse_lim_stag; |
| | | |
| | | //正常 |
| | | private String tb_norm_pool_stag; |
| | | |
| | | //设计 |
| | | private String tb_des_fl_stag; |
| | | |
| | | //校核 |
| | | private String tb_chec_fl_stag; |
| | | |
| | | //比堰顶 |
| | | private String over_weir_top_elevation; |
| | | |
| | | //比汛限 |
| | | private String over_flse_lim_stag; |
| | | |
| | | //比正常 |
| | | private String over_norm_pool_stag; |
| | | |
| | | //出库流量 |
| | | private String otq; |
| | | |
| | | //注册登记号 |
| | | private String res_reg_code; |
| | | |
| | | //是否病险 |
| | | private Boolean is_danger; |
| | | private String is_dangerText; |
| | | |
| | | //控制运用水位 |
| | | private String tb_control_z; |
| | | |
| | | //比控制水位 |
| | | private String over_control_z; |
| | | |
| | | //连续超汛天数 |
| | | private String consecutive_cnt; |
| | | |
| | | //时间 |
| | | private String tm; |
| | | } |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.vo; |
| | | |
| | | import lombok.Data; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.ObjectUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Data |
| | | public class OverWord { |
| | | |
| | | private String tm; |
| | | private String hour; |
| | | |
| | | //超汛限 |
| | | private String totalInfo; |
| | | private String overSmallInfo; |
| | | private String overBigInfo; |
| | | private String overMidInfo; |
| | | |
| | | //省直水库 |
| | | private String provinceInfo; |
| | | |
| | | public OverWord(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList,List<SzInfo> szInfoList){ |
| | | this.tm = new SimpleDateFormat("MM月dd日H时").format(new Date()); |
| | | this.hour = new SimpleDateFormat("H时").format(new Date()); |
| | | |
| | | formatTotalInfo(totalList); |
| | | formatDzkInfo(dzkList); |
| | | formatSzInfo(szInfoList); |
| | | } |
| | | |
| | | /** |
| | | * 构建省直信息 |
| | | * @param szInfoList |
| | | */ |
| | | private void formatSzInfo(List<SzInfo> szInfoList) { |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < szInfoList.size(); i++) { |
| | | SzInfo szInfo = szInfoList.get(i); |
| | | String text = generateSzInfo(szInfo); |
| | | list.add(text); |
| | | } |
| | | |
| | | this.provinceInfo = String.join("\n\r\r\r\r",list); |
| | | } |
| | | |
| | | private String generateSzInfo(SzInfo szInfo){ |
| | | String text = ""; |
| | | |
| | | String oldTm = new SimpleDateFormat("MM月dd日H时").format(DateUtil.parse(szInfo.getOld_tm(),"yyyy-MM-dd HH:mm:ss")); |
| | | Double oldRz = szInfo.getOld_rz(); |
| | | |
| | | String newTm = new SimpleDateFormat("MM月dd日H时").format(DateUtil.parse(szInfo.getNew_tm(),"yyyy-MM-dd HH:mm:ss")); |
| | | Double newRz = szInfo.getNew_rz(); |
| | | |
| | | Double diffRz = Math.abs(szInfo.getDiff_rz()); |
| | | String resNm = szInfo.getStcd(); |
| | | String upOrDown = ""; |
| | | if (diffRz>=0){ |
| | | upOrDown = "上涨"; |
| | | }else { |
| | | upOrDown = "下降"; |
| | | } |
| | | String flse_lim_stag=""; |
| | | String control_z = ""; |
| | | String wat_shed_area = ""; |
| | | |
| | | switch (resNm){ |
| | | case "高关水库": |
| | | flse_lim_stag = "118"; |
| | | control_z="117"; |
| | | wat_shed_area = "303"; |
| | | break; |
| | | case "王英水库": |
| | | flse_lim_stag = "70"; |
| | | control_z="67"; |
| | | wat_shed_area = "243"; |
| | | break; |
| | | case "吴岭水库": |
| | | flse_lim_stag = "62.20"; |
| | | control_z=""; |
| | | wat_shed_area = "102"; |
| | | break; |
| | | case "富水水库": |
| | | flse_lim_stag = "57"; |
| | | control_z="55"; |
| | | wat_shed_area = "2450"; |
| | | break; |
| | | case "漳河水库": |
| | | flse_lim_stag = "122.6"; |
| | | control_z="122"; |
| | | wat_shed_area = "2212"; |
| | | break; |
| | | } |
| | | |
| | | List<String> detailList = new ArrayList<>(); |
| | | if (StringUtil.isNotBlank(flse_lim_stag)){ |
| | | detailList.add(StringUtil.format("汛限水位{}米",flse_lim_stag)); |
| | | } |
| | | if (StringUtil.isNotBlank(control_z)){ |
| | | detailList.add(StringUtil.format("控制运用水位{}米",control_z)); |
| | | } |
| | | if (StringUtil.isNotBlank(wat_shed_area)){ |
| | | detailList.add(StringUtil.format("集雨面积{}平方千米",wat_shed_area)); |
| | | } |
| | | String detail = StringUtil.join(detailList,","); |
| | | |
| | | text = StringUtil.format("{}{}水位{}米,{}库水位{}米,({}{}米,{})。", |
| | | resNm,oldTm,oldRz,newTm,newRz,upOrDown,diffRz,detail); |
| | | |
| | | return text; |
| | | } |
| | | |
| | | /** |
| | | * 构建大中库信息 |
| | | * @param dzkList |
| | | */ |
| | | private void formatDzkInfo(List<DzkInfo> dzkList) { |
| | | |
| | | //大型 |
| | | List<DzkInfo> bigList = dzkList.stream().filter(dzkInfo -> dzkInfo.getEng_scal().indexOf("大") > -1).collect(Collectors.toList()); |
| | | //中型 |
| | | List<DzkInfo> midList = dzkList.stream().filter(dzkInfo -> dzkInfo.getEng_scal().indexOf("中") > -1).collect(Collectors.toList()); |
| | | |
| | | List<String> bigListInfo = new ArrayList<>(); |
| | | List<String> midListInfo = new ArrayList<>(); |
| | | for (int i = 0; i < bigList.size(); i++) { |
| | | DzkInfo dzkInfo = bigList.get(i); |
| | | bigListInfo.add(generateDzkInfo(dzkInfo)); |
| | | } |
| | | |
| | | for (int i = 0; i < midList.size(); i++) { |
| | | DzkInfo dzkInfo = midList.get(i); |
| | | midListInfo.add(generateDzkInfo(dzkInfo)); |
| | | } |
| | | |
| | | this.overBigInfo = String.join("\n\r\r\r\r",bigListInfo); |
| | | this.overMidInfo = String.join("\n\r\r\r\r",midListInfo); |
| | | } |
| | | |
| | | private String generateDzkInfo(DzkInfo dzkInfo){ |
| | | String text = ""; |
| | | |
| | | List<String> detailList = new ArrayList<>(); |
| | | if (StringUtil.isNotBlank(dzkInfo.getIs_gate())){ |
| | | detailList.add(StringUtil.format("溢洪道{}",dzkInfo.getIs_gate())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(dzkInfo.getOver_stag())){ |
| | | detailList.add(StringUtil.format("超汛限水位{}米",dzkInfo.getOver_stag())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(dzkInfo.getTot_cap())){ |
| | | detailList.add(StringUtil.format("总库容{}万立方米",dzkInfo.getTot_cap())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(dzkInfo.getWat_shed_area())){ |
| | | detailList.add(StringUtil.format("集雨面积{}平方千米",dzkInfo.getWat_shed_area())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(dzkInfo.getTb_norm_pool_stag())){ |
| | | detailList.add(StringUtil.format("正常蓄水位{}米",dzkInfo.getTb_norm_pool_stag())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(dzkInfo.getTb_flse_lim_stag())){ |
| | | detailList.add(StringUtil.format("汛限水位{}米",dzkInfo.getTb_flse_lim_stag())); |
| | | } |
| | | |
| | | String detail = String.join(",",detailList); |
| | | text = StringUtil.format("{}{}{}({})",dzkInfo.getP_ad_name(),dzkInfo.getAd_name(),dzkInfo.getRes_name(),detail); |
| | | |
| | | return text; |
| | | } |
| | | |
| | | /** |
| | | * 构建全省水库超汛限信息 |
| | | * @param totalList |
| | | * @return |
| | | */ |
| | | private void formatTotalInfo(List<TotalInfo> totalList){ |
| | | String totalLabel = "全省水库超汛限:"; |
| | | String smallLable = "超汛限的小型水库有:"; |
| | | |
| | | int total = 0; |
| | | int big = 0; |
| | | int mid = 0; |
| | | int small = 0; |
| | | int dangerCountTotal = 0; |
| | | int overDangerCountTotal = 0; |
| | | List<String> smallList = new ArrayList<>(); |
| | | |
| | | |
| | | for (int i = 0; i < totalList.size(); i++) { |
| | | TotalInfo totalInfo = totalList.get(i); |
| | | total += totalInfo.getCount_all(); |
| | | big += totalInfo.getBig_all(); |
| | | mid += totalInfo.getMid_all(); |
| | | small += totalInfo.getSmall_all(); |
| | | dangerCountTotal += totalInfo.getDanger_count_all(); |
| | | overDangerCountTotal += totalInfo.getOver_danger_count_all(); |
| | | |
| | | if (totalInfo.getSmall_all() == 0){ |
| | | continue; |
| | | } |
| | | |
| | | String smallRegionCout = StringUtil.format("{}{}座",totalInfo.getP_ad_name(),totalInfo.getSmall_all()); |
| | | smallList.add(smallRegionCout); |
| | | } |
| | | |
| | | String totalValue = |
| | | StringUtil.format("今日{},全省共有{}座水库超汛限水位,其中大型水库{}座、中型水库{}座、小型水库{}座。全省水库持续安全运行。全省病险水库中,有{}座超汛限水位,有{}座没有超汛限但超了控制运用水位。", |
| | | this.hour,total,big,mid,small,dangerCountTotal,overDangerCountTotal); |
| | | |
| | | String smallValue = String.join("、",smallList); |
| | | |
| | | this.totalInfo = totalLabel+totalValue; |
| | | this.overSmallInfo = smallLable+smallValue; |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 省直管水库详情 |
| | | */ |
| | | @Data |
| | | public class SzInfo { |
| | | //水库名称 |
| | | private String stcd; |
| | | |
| | | //当日8时水位 |
| | | private Double new_rz; |
| | | |
| | | //当日时间 |
| | | private String new_tm; |
| | | |
| | | //昨日8时水位 |
| | | private Double old_rz; |
| | | |
| | | private String old_tm; |
| | | |
| | | //水位差值 |
| | | private Double diff_rz; |
| | | } |
| New file |
| | |
| | | package cn.gistack.sm.sjztmd.word.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.alibaba.excel.annotation.write.style.ColumnWidth; |
| | | import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
| | | import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
| | | import lombok.Data; |
| | | import org.springframework.boot.actuate.integration.IntegrationGraphEndpoint; |
| | | |
| | | @Data |
| | | @ColumnWidth(25) |
| | | @HeadRowHeight(20) |
| | | @ContentRowHeight(18) |
| | | public class TotalInfo { |
| | | |
| | | private String index; |
| | | |
| | | //行政区名 |
| | | private String p_ad_name; |
| | | |
| | | //总数 |
| | | private Integer count_all; |
| | | //大型总数 |
| | | private Integer big_all; |
| | | //中型总数 |
| | | private Integer mid_all; |
| | | //小型总数 |
| | | private Integer small_all; |
| | | |
| | | //无闸 |
| | | private Integer wz_count_all; |
| | | private Integer wz_big; |
| | | private Integer wz_mid; |
| | | private Integer wz_small; |
| | | |
| | | //有闸 |
| | | private Integer yz_count_all; |
| | | private Integer yz_big; |
| | | private Integer yz_mid; |
| | | private Integer yz_small; |
| | | |
| | | //超汛限病险 |
| | | private Integer danger_count_all; |
| | | private Integer danger_big_all; |
| | | private Integer danger_mid_all; |
| | | private Integer danger_small_all; |
| | | |
| | | //超控制病险 |
| | | private Integer over_danger_count_all; |
| | | private Integer over_danger_big_all; |
| | | private Integer over_danger_mid_all; |
| | | private Integer over_danger_small_all; |
| | | |
| | | //详情 |
| | | private String big_over_detail; |
| | | private String mid_over_detail; |
| | | private String small_over_detail; |
| | | } |