skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/controller/HkController.java
@@ -333,8 +333,11 @@ public R syncVideo(@RequestBody HkVO hk) { // 通过水库编号获取区域(区县)名称 AttResAdVO info = attResBaseService.getWaterRegionInfoByResGuid(hk.getRegionIndexCode()); String resName = hk.getRegionName(); // 判断该水库同一个区县下是否存在同水库名称的,如果是存在多个,水库名称前面拼上乡镇名称 String resName = setWaterName(hk,info); // 设置区域名称 hk.setRegionName(info.getCountyName()); // 判断 // 通过区域名称查询对应的区域编号 String rootRegionId = hkService.regionNodesByParams(hk); if (null!= rootRegionId && !rootRegionId.equals("")){ @@ -364,4 +367,20 @@ } } /** * 设置水库名称( 判断该水库同一个区县下是否存在同水库名称的,如果是存在多个,水库名称前面拼上乡镇名称) * @param hk * @param info * @return */ private String setWaterName(HkVO hk, AttResAdVO info) { // 根据水库名称、所在区域查询改水库的数量 Integer number = attResBaseService.getWaterCountByResNameAndCountyName(hk.getRegionName(),info.getCountyCode()); if (number>1){ return hk.getRegionName() + "(" + info.getTownName() + ")"; }else { return hk.getRegionName(); } } } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/mapper/AttResBaseMapper.java
@@ -70,4 +70,12 @@ int getDimResInfoACount(); Boolean updateIsShowStatus(@Param("ids") String ids, @Param("isShow") Integer status); /** * 根据水库名称、所在区域查询改水库的数量 * @param resName 水库名称 * @param countyCode 区县编号 * @return */ Integer getWaterCountByResNameAndCountyName(@Param("resName") String resName,@Param("countyCode") String countyCode); } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/mapper/AttResBaseMapper.xml
@@ -236,5 +236,21 @@ </update> <!--根据水库名称、所在区域查询改水库的数量--> <select id="getWaterCountByResNameAndCountyName" resultType="java.lang.Integer"> SELECT count(1) FROM sjzt_md."att_res_base" a LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid" LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid" LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid" where a."name" = #{resName} and ( (b."ad_grad" = 3 and b."ad_code" = #{countyCode}) or (c."ad_grad" = 3 and c."ad_code" = #{countyCode}) ) </select> </mapper> skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/service/IAttResBaseService.java
@@ -57,4 +57,12 @@ int getDimResInfoACount(); Boolean updateIsShowStatus(String ids, Integer status); /** * 根据水库名称、所在区域查询改水库的数量 * @param resName 水库名称 * @param countyName 区县 * @return */ Integer getWaterCountByResNameAndCountyName(String resName, String countyName); } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/service/impl/AttResBaseServiceImpl.java
@@ -123,4 +123,15 @@ public Boolean updateIsShowStatus(String ids, Integer status) { return baseMapper.updateIsShowStatus(ids,status); } /** * 根据水库名称、所在区域查询改水库的数量 * @param resName 水库名称 * @param countyCode 区县 * @return */ @Override public Integer getWaterCountByResNameAndCountyName(String resName, String countyCode) { return baseMapper.getWaterCountByResNameAndCountyName(resName,countyCode); } } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/util/MyDateUtils.java
New file @@ -0,0 +1,39 @@ package cn.gistack.sm.sjztmd.util; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.StringUtil; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class MyDateUtils { /** * 判断当前日期是否在汛期,汛期 * @return */ public static Boolean isTodayInFloodSeason(){ Boolean inSeason = true; Date today = DateUtil.now(); String todayStr = DateUtil.format(today, "yyyy-MM-dd"); String nowYear = todayStr.split("-")[0]; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { Date startDate = sdf.parse(StringUtil.format("{}-05-01",nowYear)); Date endDate = sdf.parse(StringUtil.format("{}-11-01",nowYear)); inSeason = today.after(startDate)&&today.before(endDate); return inSeason; } catch (ParseException e) { throw new RuntimeException(e); } } } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/controller/DownTemplateController.java
@@ -2,6 +2,7 @@ import cn.gistack.sm.sjztmd.util.MyDateUtils; import cn.gistack.sm.sjztmd.word.service.ISjztmdService; import cn.gistack.sm.sjztmd.word.util.ExcelUtil; import cn.gistack.sm.sjztmd.word.util.WordUtil; @@ -73,8 +74,28 @@ List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(isShow); List<SzInfo> szInfoList = sjztmdService.getSzInfo(isShow); byte[] data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList); HashMap<String,String> over10Params = new HashMap<>(); //small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2 over10Params.put("small_start_stag", "10"); over10Params.put("mid_start_stag", "10"); over10Params.put("big_start_stag", "10"); HashMap<String,String> normalParams = new HashMap<>(); //small_start_stag=0&small_end_stag=2&mid_start_stag=0&mid_end_stag=2&big_start_stag=0&big_end_stag=2 normalParams.put("small_start_stag", "0"); normalParams.put("mid_start_stag", "0"); normalParams.put("big_start_stag", "0"); List<TotalInfo> totalOverList = sjztmdService.getTotalOverInfo(isShow,normalParams); List<TotalInfo> totalOver10List = sjztmdService.getTotalOverInfo(isShow,over10Params); byte[] data = null; if (MyDateUtils.isTodayInFloodSeason()){ data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList); }else { data= WordUtil.GetNotInSeasonOverInfo(totalList,dzkList,overDetailList,szInfoList,totalOverList,totalOver10List); } // 创建响应实体并设置响应头,将输出流作为响应体返回给客户端 InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data)); skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/service/ISjztmdService.java
@@ -37,4 +37,6 @@ List<StationExport> getImageStation(HttpServletResponse response, StationParams params, String exportFunc); List<StationExport> getOsmotic(HttpServletResponse response, StationParams params, String exportFunc); List<TotalInfo> getTotalOverInfo(String isShow, HashMap<String, String> over10Params); } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/service/impl/SjztmdServiceImpl.java
@@ -18,6 +18,7 @@ import com.alibaba.fastjson.parser.Feature; import com.baomidou.dynamic.datasource.annotation.DS; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -37,14 +38,19 @@ @Service @AllArgsConstructor @DS("zt") @Slf4j 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_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_SHEET1_TOTAL_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao_sheet1/api?small_start_stag=0&mid_start_stag=0&big_start_stag=0"; private final String RIBAO_SHEET1_OVER_NORM_POOL_STAG = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet1_over_norm_pool_stag/api?"; //中大型水库 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_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_SHEET2_ZDX_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet2_zdx/api?mid_start_stag=0&big_start_stag=0"; //超汛明细 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 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 RIBAO_SHEET3_OVER_STAG_LIST_URL = "/services/1234567890ABCDEFGHIJKLMN/ribao/sheet3_over_stag_list/api?small_start_stag=0&mid_start_stag=0&big_start_stag=0"; //省直管 private final String SZ_INFO = "/services/1234567890ABCDEFGHIJKLMN/ribao/shengzh_new_rz/api"; @@ -593,6 +599,28 @@ } @Override public List<TotalInfo> getTotalOverInfo(String isShow, HashMap<String, String> map) { String params = "&is_show=" + isShow; if (map != null){ for (Map.Entry<String, String> entry : map.entrySet()){ String key=entry.getKey(); String vlaue = entry.getValue(); String p = StringUtil.format("&{}={}",key,vlaue); params +=p; } } JSONObject ztData = this.getZtData(params, RIBAO_SHEET1_OVER_NORM_POOL_STAG); JSONArray data = ztData.getJSONArray("data"); List<TotalInfo> list = data.toJavaList(TotalInfo.class); return list; } @Override public List<DzkInfo> getDzkInfo(String isShow) { JSONObject ztData = this.getZtData("&is_show="+isShow, RIBAO_SHEET2_ZDX_URL); JSONArray data = ztData.getJSONArray("data"); @@ -1127,6 +1155,8 @@ if (activeProfile.equals("test")) { url = ZtApiUrlConstant.url_prefix_test + url + params; } log.info("请求url地址:{}", url); //设置请求头 HttpHeaders headers = new HttpHeaders(); headers.add(ZtConfigConstant.header_key, ZtConfigConstant.header_value); skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/util/WordUtil.java
@@ -1,5 +1,6 @@ package cn.gistack.sm.sjztmd.word.util; import cn.gistack.sm.sjztmd.util.MyDateUtils; import cn.gistack.sm.sjztmd.word.vo.*; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.data.NumbericRenderData; @@ -96,6 +97,27 @@ return outputStream.toByteArray(); } /** * * @param totalList 全省水库超汛 * @param dzkList 大中库超汛 * @param overDetailList 超汛明细 * @param szInfoList 省直超汛 * @param totalOverList 超正常 * @param totalOver10List 超正常10cm * @return */ public static byte[] GetNotInSeasonOverInfo(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList, List<SzInfo> szInfoList, List<TotalInfo> totalOverList, List<TotalInfo> totalOver10List) throws Exception{ InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/doc/inFloodSeason_overFloodTemplate.docx"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OverWord overWord = new OverWord(totalList, dzkList, overDetailList, szInfoList,totalOverList,totalOver10List); 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<>(); @@ -105,9 +127,16 @@ params.put("大型水库详情", overWord.getOverBigInfo()); params.put("中型水库详情", overWord.getOverMidInfo()); params.put("省直水库详情", overWord.getProvinceInfo()); //不在汛期内 if (!MyDateUtils.isTodayInFloodSeason()){ params.put("全省水库超正常", overWord.getTotalOverNormalInfo()); params.put("全省水库超正常十厘米以上", overWord.getTotalOverNormal10Info()); params.put("超正常小型水库详情", overWord.getOverNormalSmallInfo()); params.put("超正常大型水库详情", overWord.getOverNormalBigInfo()); params.put("超正常中型水库详情", overWord.getOverNormalMidInfo()); } return params; } private static byte[] GenerateWord(String templatePath, Object object) throws Exception { @@ -120,4 +149,5 @@ return outputStream.toByteArray(); } } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/word/vo/OverWord.java
@@ -7,6 +7,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -17,14 +18,28 @@ private String tm; private String hour; //超汛限 //全省超汛限 private String totalInfo; //超汛限小型水库 private String overSmallInfo; //超汛限大型水库 private String overBigInfo; //超汛限中型水库 private String overMidInfo; //省直水库 private String provinceInfo; //全省水库超正常 private String totalOverNormalInfo; //超正常小型水库 private String overNormalSmallInfo; //全省水库超正常10cm以上 private String totalOverNormal10Info; //超正常大型水库 private String overNormalBigInfo; //超正常中型水库 private String overNormalMidInfo; public OverWord(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList,List<SzInfo> szInfoList){ this.tm = new SimpleDateFormat("MM月dd日H时").format(new Date()); @@ -35,6 +50,130 @@ formatSzInfo(szInfoList); } public OverWord(List<TotalInfo> totalList, List<DzkInfo> dzkList, List<OverDetail> overDetailList,List<SzInfo> szInfoList,List<TotalInfo> totalOverList, List<TotalInfo> totalOver10List){ this.tm = new SimpleDateFormat("MM月dd日H时").format(new Date()); this.hour = new SimpleDateFormat("H时").format(new Date()); formatTotalInfo(totalList); formatDzkInfo(dzkList); formatSzInfo(szInfoList); formatOverNormal(totalOverList,totalOver10List); } /** * 构建超正常信息 * @param totalOverList * @param totalOver10List */ private void formatOverNormal(List<TotalInfo> totalOverList, List<TotalInfo> totalOver10List) { int total = 0; int big = 0; int mid = 0; int small = 0; int dangerCountTotal = 0; int overDangerCountTotal = 0; List<String> smallList = new ArrayList<>(); List<String> midList = new ArrayList<>(); List<String> bigList = new ArrayList<>(); for (int i = 0; i < totalOverList.size(); i++) { TotalInfo totalInfo = totalOverList.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){ String smallRegionCout = StringUtil.format("{}{}座",totalInfo.getP_ad_name(),totalInfo.getSmall_all()); smallList.add(smallRegionCout); } // "mid_over_detail": "许家冲水库-5.59,游河水库-1.42,马鞍山水库-0.2,桃园河水库-3.19,白果河水库-1.56,两河口水库-4.97", if (totalInfo.getBig_over_detail() != null){ String bigOverDetail = totalInfo.getBig_over_detail(); //许家冲水库-5.59 游河水库-1.42 马鞍山水库-0.2 List<String> list = Arrays.asList(bigOverDetail.split(",")); list.forEach(item->{ String reservoirName = item.split("~")[0]; bigList.add(reservoirName); }); } if (totalInfo.getMid_over_detail() != null){ String midOverDetail = totalInfo.getMid_over_detail(); //许家冲水库-5.59 游河水库-1.42 马鞍山水库-0.2 List<String> list = Arrays.asList(midOverDetail.split(",")); list.forEach(item->{ String reservoirName = item.split("~")[0]; midList.add(reservoirName); }); } } String totalValue = StringUtil.format("今日{},全省共有{}座水库超正常水位,其中大型水库{}座、中型水库{}座、小型水库{}座。全省水库持续安全运行。全省病险水库中,有{}座超正常水位,有{}座没有超正常但超了控制运用水位", this.hour,total,big,mid,small,dangerCountTotal,overDangerCountTotal); String totalOverNormal10Value = getOverNormal10(totalOver10List); String smallValue = String.join("、",smallList); String bigValue=""; if (bigList.size()>0){ bigValue= StringUtil.format(" 其中,超正常的大型水库有{}。",String.join("、",bigList)); }else{ bigValue= " 其中,没有超正常的大型水库。"; } String midValue = ""; if (midList.size()>0){ midValue= StringUtil.format(" 其中,超正常的中型水库有{}。",String.join("、",midList)); }else{ midValue= " 其中,没有超正常的中型水库。"; } this.totalOverNormalInfo = totalValue; this.overNormalSmallInfo =smallValue; this.overNormalBigInfo = bigValue; this.overNormalMidInfo = midValue; this.totalOverNormal10Info = totalOverNormal10Value; } //获取超正常10cm的水库 private String getOverNormal10(List<TotalInfo> totalOver10List) { int total = 0; int big = 0; int mid = 0; int small = 0; int dangerCountTotal = 0; int overDangerCountTotal = 0; for (int i = 0; i < totalOver10List.size(); i++) { TotalInfo totalInfo = totalOver10List.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(); } String totalValue = StringUtil.format("今日{},全省共有{}座水库超正常水位,其中大型水库{}座、中型水库{}座、小型水库{}座。全省水库持续安全运行。全省病险水库中,有{}座超正常水位,有{}座没有超正常但超了控制运用水位", this.hour,total,big,mid,small,dangerCountTotal,overDangerCountTotal); return totalValue; } /** * 构建省直信息 * @param szInfoList skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/resources/word/doc/inFloodSeason_overFloodTemplate.docxBinary files differ
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/resources/word/doc/overFloodTemplate.docxBinary files differ