/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.regionWeight.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.reactivex.Observable; import io.swagger.annotations.*; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import lombok.AllArgsConstructor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.*; import java.text.SimpleDateFormat; import java.util.Map.Entry; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.python.util.PythonInterpreter; import org.springblade.core.excel.util.ExcelUtil; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.modules.regionWeight.excel.regionExcel; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.excel.UserExcel; import org.springframework.aop.support.JdkRegexpMethodPointcut; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.modules.regionWeight.entity.RegionWeight; import org.springblade.modules.regionWeight.vo.RegionWeightVO; import org.springblade.modules.regionWeight.service.IRegionWeightService; import org.springblade.core.boot.ctrl.BladeController; import springfox.documentation.annotations.ApiIgnore; import java.math.BigDecimal; import java.util.*; /** * 控制器 * * @author BladeX * @since 2021-05-12 */ @RestController @AllArgsConstructor @RequestMapping("regionWeight/regionweight") @Api(value = "", tags = "接口") public class RegionWeightController extends BladeController { private final IRegionWeightService regionWeightService; /** * 详情 */ @GetMapping("/detail") @ApiOperationSupport(order = 1) @ApiOperation(value = "详情", notes = "传入regionWeight") public R detail(RegionWeight regionWeight) { RegionWeight detail = regionWeightService.getOne(Condition.getQueryWrapper(regionWeight)); return R.data(detail); } /** * 分页 */ @GetMapping("/list") @ApiOperationSupport(order = 2) @ApiOperation(value = "分页", notes = "传入regionWeight") public R> list(RegionWeight regionWeight, Query query) { IPage pages = regionWeightService.page(Condition.getPage(query), Condition.getQueryWrapper(regionWeight)); return R.data(pages); } /** * 自定义分页 */ @GetMapping("/page") @ApiOperationSupport(order = 3) @ApiOperation(value = "分页", notes = "传入regionWeight") public R> page(RegionWeightVO regionWeight, Query query, Long deptId) { IPage pages = null; if (deptId == null || deptId == 361000) { deptId = null; pages = regionWeightService.selectRegionWeightPage(Condition.getPage(query), regionWeight, deptId); } else { int length = deptId.toString().length(); if (length == 6) { pages = regionWeightService.selectRegionWeights(Condition.getPage(query), regionWeight, deptId); } else { pages = regionWeightService.selectRegionWeightPage(Condition.getPage(query), regionWeight, deptId); } } return R.data(pages); } /** * 新增 */ @PostMapping("/save") @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入regionWeight") public R save(@Valid @RequestBody RegionWeight regionWeight) { return R.status(regionWeightService.save(regionWeight)); } /** * 修改 */ @PostMapping("/update") @ApiOperationSupport(order = 5) @ApiOperation(value = "修改", notes = "传入regionWeight") public R update(@Valid @RequestBody RegionWeight regionWeight) { return R.status(regionWeightService.updateById(regionWeight)); } /** * 新增或修改 */ @PostMapping("/submit") @ApiOperationSupport(order = 6) @ApiOperation(value = "新增或修改", notes = "传入regionWeight") public R submit(@Valid @RequestBody RegionWeight regionWeight) { return R.status(regionWeightService.saveOrUpdate(regionWeight)); } /** * 删除 */ @PostMapping("/remove") @ApiOperationSupport(order = 8) @ApiOperation(value = "删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { return R.status(regionWeightService.removeByIds(Func.toLongList(ids))); } /** * 懒加载树形结构 */ @GetMapping("/lazy-tree") public R> lazyTree(String code) { List tree = regionWeightService.lazyTree(code); return R.data(tree); } // /** // * 面降雨量 // */ // @GetMapping("/selectReM") // public R selectReM(String beginTime, String endTime) { // String substring = beginTime.substring(0, 10); // String r = beginTime.substring(11, 13); // //截取月日 // String[] strs = substring.split("-"); // //月 // String year = strs[1].toString(); // //日 // String day = strs[2].toString(); // String substrings = endTime.substring(0, 10); // String rs = endTime.substring(11, 13); // //截取月日 // String[] strss = substrings.split("-"); // //月 // String years = strss[1].toString(); // //日 // String days = strss[2].toString(); // String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时"; // //最新雨量值 // List> map = regionWeightService.selectReM(beginTime, endTime); // List> mapAll = regionWeightService.selectAll(); // //权重值 // List> list = regionWeightService.selectWeight(); // Map map1 = new HashMap(); // Map mapc = new HashMap(); // List> list1 = new ArrayList>(); // List> lists = new ArrayList>(); // List> listc = new ArrayList>(); // double v = 0; // //统计抚州市雨量 // Double num = 0.0; // String region_code = null; // if (map.size() == 0) { // List> l = new ArrayList>(); // List> m = new ArrayList>(); // mapc.put("List", l); // mapc.put("Num", m); // mapc.put("text", yday + "暂无降雨信息。"); // lists.add(mapc); // } else { // for (int i = 0; i < map.size(); i++) { // region_code = map.get(i).get("REGION_CODE").toString(); // //获取行政区编码 // if (i != 0) { // String region_code1 = map.get(i - 1).get("REGION_CODE").toString(); // if (!region_code.equals(region_code1)) { // map1.put("id", region_code1); // map1.put("value", v); // list1.add(map1); // v = 0; // map1 = new HashMap(); // for (int j = 0; j < list.size(); j++) { // if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { // BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); // double drp = bigDecimaldrp.floatValue(); // String weight1 = map.get(i).get("WEIGHT").toString(); // float weight = Float.parseFloat(weight1); // v += drp * weight; // break; // } // } // } else { // for (int j = 0; j < list.size(); j++) { // if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { // BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); // double drp = bigDecimaldrp.floatValue(); // String weight1 = map.get(i).get("WEIGHT").toString(); // float weight = Float.parseFloat(weight1); // System.out.println(Math.round(drp)); // v += drp * weight; // break; // } // } // } // } else { // for (int j = 0; j < list.size(); j++) { // if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { // BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); // double drp = bigDecimaldrp.floatValue(); // String weight1 = map.get(i).get("WEIGHT").toString(); // float weight = Float.parseFloat(weight1); // System.out.println(Math.round(drp)); // v += drp * weight; // break; // } // } // } // } // map1.put("id", region_code); // map1.put("value", v); // list1.add(map1); // Map result1 = new HashMap(); // //县/区面雨量值 // for (Map maps : list1) { // String id = maps.get("id").toString(); // Double value = Double.parseDouble(maps.get("value").toString()); // if (result1.containsKey(id)) { // Double temp = Double.parseDouble(result1.get(id).toString()); // value += temp; // } // result1.put(id, value); // } // //计算市的面雨量 // for (String k : result1.keySet()) { // for (int c = 0; c < list.size(); c++) { // if (k.equals(list.get(c).get("STATION_CODE").toString())) { // String s = result1.get(k).toString(); // Double w = Double.parseDouble(s); // String weight = list.get(c).get("WEIGHT").toString(); // Double weights = Double.parseDouble(weight); // double v1 = w * weights; // num += v1; // } else { // continue; // } // // } // } // // 排序 // List> entryList2 = new ArrayList>(result1.entrySet()); // Collections.sort(entryList2, new Comparator>() { // @Override // public int compare(Entry me1, Entry me2) { // return me2.getValue().toString().compareTo(me1.getValue().toString()); // 升序排序 // } // }); // //拼接前3位降雨最大的区域 // double v3 = (double) Math.round(num * 10) / 10; // String text = "全市日平均降雨量:" + v3 + "毫米。 "; // String text1 = "县市区平均降雨量前3位为: "; // String tx = ""; // for (int i = 0; i < entryList2.size(); i++) { // Map mapa = new HashMap(); // String codes = entryList2.get(i).getKey(); // String values = entryList2.get(i).getValue().toString(); // Double a = Double.parseDouble(values); // double as = (double) Math.round(a * 10) / 10; // for (int j = 0; j < list.size(); j++) { // if (codes.equals(list.get(j).get("STATION_CODE").toString())) { // String station_name = list.get(j).get("STATION_NAME").toString(); // mapa.put("region", station_name); // mapa.put("dyp", as); // listc.add(mapa); // if (i < 3) { // tx += station_name + "降雨量为:" + as + "毫米,"; // } // } // // } // } // mapc.put("List", listc); // mapc.put("Num", mapAll); // mapc.put("text", yday + text); // lists.add(mapc); // } // return R.data(lists); // } // /** // * 点降雨量(时段降雨,自定义降雨) // * // * @param beginTime // * @param endTime // * @return // */ // @GetMapping("/selectReD") // public R selectReD(String beginTime, String endTime) { // String substring = beginTime.substring(0, 10); // String r = beginTime.substring(11, 13); // //截取月日 // String[] strs = substring.split("-"); // //月 // String year = strs[1].toString(); // //日 // String day = strs[2].toString(); // String substrings = endTime.substring(0, 10); // String rs = endTime.substring(11, 13); // //截取月日 // String[] strss = substrings.split("-"); // //月 // String years = strss[1].toString(); // //日 // String days = strss[2].toString(); // List> maps = regionWeightService.selectYjs(beginTime, endTime); // List> lists = new ArrayList<>(); // Map map = new HashMap(); // String text = ""; // String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时。"; // //0-10降雨量范围 // List lista = new ArrayList<>(); // //10-25降雨量范围 // List listb = new ArrayList<>(); // //25-50降雨量范围 // List listc = new ArrayList<>(); // //50-100降雨量范围 // List listd = new ArrayList<>(); // //100-250降雨量范围 // List liste = new ArrayList<>(); // //250降雨量范围 // List listf = new ArrayList<>(); // for (int i = 0; i < maps.size(); i++) { // if (i < 3) { // String addvnm = maps.get(i).get("ADDVNM").toString(); // String stnm = maps.get(i).get("STNM").toString(); // BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 // double dyp = bigDecimaldyp.doubleValue(); // if (dyp > 0 && dyp <= 10) { // lista.add(maps.get(i)); // } else if (dyp > 10 && dyp <= 25) { // listb.add(maps.get(i)); // } else if (dyp > 25 && dyp <= 50) { // listc.add(maps.get(i)); // } else if (dyp > 50 && dyp <= 100) { // listd.add(maps.get(i)); // } else if (dyp > 100 && dyp <= 250) { // liste.add(maps.get(i)); // } else if (dyp > 250) { // listf.add(maps.get(i)); // } // text += stnm + "站" + dyp + "毫米,"; // } else { // BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 // double dyp = bigDecimaldyp.doubleValue(); // if (dyp > 0 && dyp <= 10) { // lista.add(maps.get(i)); // } else if (dyp > 10 && dyp <= 25) { // listb.add(maps.get(i)); // } else if (dyp > 25 && dyp <= 50) { // listc.add(maps.get(i)); // } else if (dyp > 50 && dyp <= 100) { // listd.add(maps.get(i)); // } else if (dyp > 100 && dyp <= 250) { // liste.add(maps.get(i)); // } else if (dyp > 250) { // listf.add(maps.get(i)); // } // } // } // //0-10 // map.put("one", lista); // //10-25 // map.put("two", listb); // //25-50 // map.put("three", listc); // //50-100 // map.put("four", listd); // //100-250 // map.put("five", liste); // //250 // map.put("six", listf); // String a = ""; // if (maps.size() == 0) { // a = yday + "暂无降雨信息。"; // } else { // a = yday + "站点最大降雨量前3位为:" + text.substring(0, text.length() - 1) + "。"; // } // map.put("text", a); // lists.add(map); // String fileName = ""; // // 第一步,创建一个webbook,对应一个Excel文件 // HSSFWorkbook wb = new HSSFWorkbook(); // // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet // HSSFSheet sheet = wb.createSheet("雨量表"); // // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short // HSSFRow row = sheet.createRow((int) 0); // // 第四步,创建单元格,并设置值表头 设置表头居中 // HSSFCellStyle style = wb.createCellStyle(); // //style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 // HSSFCell cell = row.createCell((short) 0); // cell.setCellValue("lon"); // cell = row.createCell((short) 1); // cell.setCellValue("lat"); // cell = row.createCell((short) 2); // cell.setCellValue("rain"); // for (int i = 0; i < maps.size(); i++) { // // 第四步,创建单元格,并设置值 // row = sheet.createRow((int) i + 1); // HSSFCell celli = row.createCell((short) 0); // row.createCell((short) 0).setCellValue(maps.get(i).get("LGTD").toString()); // row.createCell((short) 1).setCellValue(maps.get(i).get("LTTD").toString()); // row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); // } // // 第六步,将文件存到指定位置 // try { // fileName = "D:/pptnd.xlsx"; // FileOutputStream fout = new FileOutputStream(fileName); // wb.write(fout); // fout.close(); // wb.close(); // } catch (Exception e) { // e.printStackTrace(); // } // Process proc; // try { // proc = Runtime.getRuntime().exec("python D:\\fz\\fz.py"); // BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); // String line = null; // while ((line = in.readLine()) != null) { // System.out.println(line); // } // in.close(); // proc.waitFor(); // } catch (IOException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } // return R.data(lists); // } // /** * 流域 *//* @GetMapping("/selectReL") public R selectReL(String beginTime, String endTime) { String substring = beginTime.substring(0, 10); String r = beginTime.substring(11, 13); //截取月日 String[] strs = substring.split("-"); //月 String year = strs[1].toString(); //日 String day = strs[2].toString(); String substrings = endTime.substring(0, 10); String rs = endTime.substring(11, 13); //截取月日 String[] strss = substrings.split("-"); //月 String years = strss[1].toString(); //日 String days = strss[2].toString(); String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时。"; String text = ""; //最新雨量值 List> map = regionWeightService.selectReL(beginTime, endTime); //权重值 List> list = regionWeightService.selectWeights(); List> list2 = regionWeightService.selectLALL(); List> list3 = regionWeightService.selectLNam(); Map mc = new HashMap(); for (int a = 0; a < list2.size(); a++) { for (int b = 0; b < list3.size(); b++) { String code = list2.get(a).get("code").toString(); String num = list2.get(a).get("num").toString(); String code1 = list3.get(b).get("code").toString(); if (code.equals(code1)) { mc.put(list3.get(b).get("cname").toString(), num); } } } Map map1 = new HashMap(); Map mapc = new HashMap(); List> list1 = new ArrayList>(); List> lists = new ArrayList>(); List> listc = new ArrayList>(); double v = 0; //统计抚州市雨量 Double num = 0.0; String region_code = null; if (map.size() == 0) { List> l = new ArrayList>(); List> m = new ArrayList>(); mapc.put("List", l); mapc.put("Num", m); mapc.put("text", yday + "暂无流域信息。"); lists.add(mapc); } else { for (int i = 0; i < map.size(); i++) { region_code = map.get(i).get("REGION_CODE").toString(); //获取行政区编码 if (i != 0) { String region_code1 = map.get(i - 1).get("REGION_CODE").toString(); if (!region_code.equals(region_code1)) { map1.put("id", region_code1); map1.put("value", v); list1.add(map1); v = 0; map1 = new HashMap(); for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } } map1.put("id", region_code); map1.put("value", v); list1.add(map1); Map result1 = new HashMap(); //县/区面雨量值 for (Map maps : list1) { String id = maps.get("id").toString(); Double value = Double.parseDouble(maps.get("value").toString()); if (result1.containsKey(id)) { Double temp = Double.parseDouble(result1.get(id).toString()); value += temp; } result1.put(id, value); } // 排序 List> entryList2 = new ArrayList>(result1.entrySet()); Collections.sort(entryList2, new Comparator>() { @Override public int compare(Entry me1, Entry me2) { return me2.getValue().toString().compareTo(me1.getValue().toString()); // 升序排序 } }); for (int i = 0; i < entryList2.size(); i++) { Map mapa = new HashMap(); String codes = entryList2.get(i).getKey(); String values = entryList2.get(i).getValue().toString(); Double a = Double.parseDouble(values); double as = (double) Math.round(a * 10) / 10; for (int j = 0; j < list.size(); j++) { if (codes.equals(list.get(j).get("STATION_CODE").toString())) { String station_name = list.get(j).get("STATION_NAME").toString(); mapa.put("region", station_name); mapa.put("dyp", as); listc.add(mapa); } } } Collections.sort(listc, new Comparator>() { public int compare(Map o1, Map o2) { return (Double) o1.get("dyp") < (Double) o2.get("dyp") ? 1 : ((Double) o1.get("dyp") == (Double) o2.get("dyp") ? 0 : -1); } }); for (int c = 0; c < listc.size(); c++) { if (c < 3) { text += listc.get(c).get("region").toString() + ":" + listc.get(c).get("dyp") + "毫米,"; } } String a = "流域前三的为:" + text.substring(0, text.length() - 1) + "。"; mapc.put("List", listc); mapc.put("Num", mc); mapc.put("text", yday + a); lists.add(mapc); } return R.data(lists); }*/ /** * @param type 类型 0:实时 1 历史 * @param timez 当前时间 yyyy-MM-dd HH:00:00 * @param dateBegins1 前一小时 * @param dateBegins3 前三小时 * @param dateBegins6 前六小时 * @param timet 当天的8点 yyyy-MM-dd 08:00:00 * @return */ @ApiLog("雨量预警") @GetMapping("/pptnYj") public R selectcInfos(int type, String timez, String dateBegins1, String dateBegins3, String dateBegins6, String timet, int k) { if (type == 0 && k == 13) { //当前时间 String time = timez; //当天的8点 String times = timet; //查询前一小时数据 String dateBegin1 = dateBegins1; //三个小时前的时间 String dateBegin3 = dateBegins3; //六个小时前的时间 String dateBegin6 = dateBegins6; List> maps = regionWeightService.selectppyj(time, dateBegin1, dateBegin3, dateBegin6, times); List> lists = new ArrayList<>(); for (int i = 0; i < maps.size(); i++) { Map map = new HashMap(); BigDecimal bigDecimaldrp1 = (BigDecimal) maps.get(i).get("drp1");//1小时 BigDecimal bigDecimaldrp3 = (BigDecimal) maps.get(i).get("drp3");//3小时 BigDecimal bigDecimaldrp6 = (BigDecimal) maps.get(i).get("drp6");//6小时 BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 double drp1 = bigDecimaldrp1.doubleValue(); double drp3 = bigDecimaldrp3.doubleValue(); double drp6 = bigDecimaldrp6.doubleValue(); double dyp = bigDecimaldyp.doubleValue(); if (drp1 >= 30 || drp3 >= 50 || drp6 >= 80 || dyp >= 80) { maps.get(i).put("YJ", "一级预警"); } else if (drp1 >= 50 || drp3 >= 80 || drp6 >= 100 || dyp >= 100) { maps.get(i).put("YJ", "二级预警"); } else if (drp1 >= 80 || drp3 >= 100 || drp6 >= 120 || dyp >= 120) { maps.get(i).put("YJ", "三级预警"); } else { maps.get(i).put("YJ", "无预警"); } map.put("YjList", maps.get(i)); lists.add(map); } return R.data(lists); } else { //当前时间 String time = timez; //当天的8点 String times = timet; //查询前一小时数据 String dateBegin1 = dateBegins1; //三个小时前的时间 String dateBegin3 = dateBegins3; //六个小时前的时间 String dateBegin6 = dateBegins6; List> maps = regionWeightService.selectppyj(time, dateBegin1, dateBegin3, dateBegin6, times); List> lists = new ArrayList<>(); for (int i = 0; i < maps.size(); i++) { Map map = new HashMap(); BigDecimal bigDecimaldrp1 = (BigDecimal) maps.get(i).get("drp1");//1小时 BigDecimal bigDecimaldrp3 = (BigDecimal) maps.get(i).get("drp3");//3小时 BigDecimal bigDecimaldrp6 = (BigDecimal) maps.get(i).get("drp6");//6小时 BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 double drp1 = bigDecimaldrp1.doubleValue(); double drp3 = bigDecimaldrp3.doubleValue(); double drp6 = bigDecimaldrp6.doubleValue(); double dyp = bigDecimaldyp.doubleValue(); if (drp1 >= 30 || drp3 >= 50 || drp6 >= 80 || dyp >= 80) { maps.get(i).put("YJ", "一级预警"); } else if (drp1 >= 50 || drp3 >= 80 || drp6 >= 100 || dyp >= 100) { maps.get(i).put("YJ", "二级预警"); } else if (drp1 >= 80 || drp3 >= 100 || drp6 >= 120 || dyp >= 120) { maps.get(i).put("YJ", "三级预警"); } else { maps.get(i).put("YJ", "无预警"); } map.put("YjList", maps.get(i)); lists.add(map); } return R.data(lists); } } /** * 点降雨 * @param beginTime * @param endTime * @return */ @GetMapping("/selectReDc") public R selectReDc(String beginTime, String endTime) { String substring = beginTime.substring(0, 10); String r = beginTime.substring(11, 13); //截取月日 String[] strs = substring.split("-"); //月 String year = strs[1].toString(); //日 String day = strs[2].toString(); String substrings = endTime.substring(0, 10); String rs = endTime.substring(11, 13); //截取月日 String[] strss = substrings.split("-"); //月 String years = strss[1].toString(); //日 String days = strss[2].toString(); //List> maps = regionWeightService.selectYjs(beginTime, endTime); String s = regionWeightService.selectCode(); String[] split = s.split(","); String strArrays = ""; System.out.println("数量:"+split.length); for (int i = 0; i < split.length; i++) { strArrays += "'" + split[i] + "',"; } String code = strArrays.substring(0, strArrays.length() - 1); List> maps = regionWeightService.ss(beginTime, endTime, code); List> lists = new ArrayList<>(); Map map = new HashMap(); String text = ""; String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时"; //0-10降雨量范围 List lista = new ArrayList<>(); //10-25降雨量范围 List listb = new ArrayList<>(); //25-50降雨量范围 List listc = new ArrayList<>(); //50-100降雨量范围 List listd = new ArrayList<>(); //100-250降雨量范围 List liste = new ArrayList<>(); //250降雨量范围 List listf = new ArrayList<>(); for (int i = 0; i < maps.size(); i++) { if (i < 3) { String addvnm = maps.get(i).get("ADDVNM").toString(); String stnm = maps.get(i).get("STNM").toString(); BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 double dyp = bigDecimaldyp.doubleValue(); if (dyp > 0 && dyp <= 10) { lista.add(maps.get(i)); } else if (dyp > 10 && dyp <= 25) { listb.add(maps.get(i)); } else if (dyp > 25 && dyp <= 50) { listc.add(maps.get(i)); } else if (dyp > 50 && dyp <= 100) { listd.add(maps.get(i)); } else if (dyp > 100 && dyp <= 250) { liste.add(maps.get(i)); } else if (dyp > 250) { listf.add(maps.get(i)); } if (i == 0) { text += addvnm + stnm + "站" + dyp + "毫米,"; } if (i == 1) { text += addvnm + stnm + "站" + dyp + "毫米次之,"; } if (i == 2) { text += addvnm + stnm + "站" + dyp + "毫米第三,"; } } else { BigDecimal bigDecimaldyp = (BigDecimal) maps.get(i).get("dyp");//日雨量 double dyp = bigDecimaldyp.doubleValue(); if (dyp > 0 && dyp <= 10) { lista.add(maps.get(i)); } else if (dyp > 10 && dyp <= 25) { listb.add(maps.get(i)); } else if (dyp > 25 && dyp <= 50) { listc.add(maps.get(i)); } else if (dyp > 50 && dyp <= 100) { listd.add(maps.get(i)); } else if (dyp > 100 && dyp <= 250) { liste.add(maps.get(i)); } else if (dyp > 250) { listf.add(maps.get(i)); } } } //0-10 map.put("one", lista); //10-25 map.put("two", listb); //25-50 map.put("three", listc); //50-100 map.put("four", listd); //100-250 map.put("five", liste); //250 map.put("six", listf); String a = ""; if (maps.size() == 0) { a = yday + "暂无降雨信息。"; } else { a = yday + "点最大降雨量为" + text.substring(0, text.length() - 1) + "。"; } map.put("text", a); lists.add(map); String fileName = ""; // 第一步,创建一个webbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet HSSFSheet sheet = wb.createSheet("雨量表"); // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short HSSFRow row = sheet.createRow((int) 0); // 第四步,创建单元格,并设置值表头 设置表头居中 HSSFCellStyle style = wb.createCellStyle(); //style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 HSSFCell cell = row.createCell((short) 0); cell.setCellValue("lon"); cell = row.createCell((short) 1); cell.setCellValue("lat"); cell = row.createCell((short) 2); cell.setCellValue("rain"); for (int i = 0; i < maps.size(); i++) { String stcd = maps.get(i).get("STCD").toString(); // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(maps.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(maps.get(i).get("LTTD").toString()); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); if (stcd.equals("62455350")){ row.createCell((short) 0).setCellValue("117.344876"); row.createCell((short) 1).setCellValue("27.827067"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62334845")){ row.createCell((short) 0).setCellValue("115.625720"); row.createCell((short) 1).setCellValue("27.152794"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62433800")){ row.createCell((short) 0).setCellValue("115.618546"); row.createCell((short) 1).setCellValue("27.683604"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62436760")){ row.createCell((short) 0).setCellValue("116.060889"); row.createCell((short) 1).setCellValue("28.216806"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62437250")){ row.createCell((short) 0).setCellValue("116.622783"); row.createCell((short) 1).setCellValue("28.489384"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62433700")){ row.createCell((short) 0).setCellValue("115.558771"); row.createCell((short) 1).setCellValue("27.518623"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62425740")){ row.createCell((short) 0).setCellValue("117.208587"); row.createCell((short) 1).setCellValue("27.298647"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62437235")){ row.createCell((short) 0).setCellValue("116.780591"); row.createCell((short) 1).setCellValue("28.391352"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } if (stcd.equals("62437250")){ row.createCell((short) 0).setCellValue("116.555834"); row.createCell((short) 1).setCellValue("28.518077"); row.createCell((short) 2).setCellValue(maps.get(i).get("dyp").toString()); } } // 第六步,将文件存到指定位置 try { fileName = "D:/pptnd.xlsx"; FileOutputStream fout = new FileOutputStream(fileName); wb.write(fout); fout.close(); wb.close(); } catch (Exception e) { e.printStackTrace(); } Process proc; try { proc = Runtime.getRuntime().exec("python D:\\fz\\fz.py"); BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.out.println(line); } in.close(); proc.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return R.data(lists); } /** * 面降雨量 */ @GetMapping("/selectReMs") public R selectReMs(String beginTime, String endTime) { String substring = beginTime.substring(0, 10); String r = beginTime.substring(11, 13); //截取月日 String[] strs = substring.split("-"); //月 String year = strs[1].toString(); //日 String day = strs[2].toString(); String substrings = endTime.substring(0, 10); String rs = endTime.substring(11, 13); //截取月日 String[] strss = substrings.split("-"); //月 String years = strss[1].toString(); //日 String days = strss[2].toString(); String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时"; String ss = regionWeightService.selectCodeM(); String[] split = ss.split(","); String strArrays = ""; for (int i = 0; i < split.length; i++) { strArrays += "'" + split[i] + "',"; } String code = strArrays.substring(0, strArrays.length() - 1); //List> map = regionWeightService.selectReM(beginTime, endTime); List> map = regionWeightService.selectReMs(beginTime, endTime, code); List> mapAll = regionWeightService.selectAll(beginTime, endTime,code); //权重值 List> list = regionWeightService.selectWeight(); Map map1 = new HashMap(); Map mapc = new HashMap(); List> list1 = new ArrayList>(); List> lists = new ArrayList>(); List> listc = new ArrayList>(); double v = 0; //统计抚州市雨量 Double num = 0.0; String region_code = null; if (map.size() == 0) { List> l = new ArrayList>(); List> m = new ArrayList>(); mapc.put("List", l); mapc.put("Num", m); mapc.put("text", yday + "暂无降雨信息。"); lists.add(mapc); } else { for (int i = 0; i < map.size(); i++) { region_code = map.get(i).get("REGION_CODE").toString(); //获取行政区编码 if (i != 0) { String region_code1 = map.get(i - 1).get("REGION_CODE").toString(); if (!region_code.equals(region_code1)) { map1.put("id", region_code1); map1.put("value", v); list1.add(map1); v = 0; map1 = new HashMap(); for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); //System.out.println(Math.round(drp)); v += drp * weight; break; } } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } } map1.put("id", region_code); map1.put("value", v); list1.add(map1); Map result1 = new HashMap(); //县/区面雨量值 for (Map maps : list1) { String id = maps.get("id").toString(); Double value = Double.parseDouble(maps.get("value").toString()); if (result1.containsKey(id)) { Double temp = Double.parseDouble(result1.get(id).toString()); value += temp; } result1.put(id, value); } //计算市的面雨量 for (String k : result1.keySet()) { for (int c = 0; c < list.size(); c++) { if (k.equals(list.get(c).get("STATION_CODE").toString())) { String s = result1.get(k).toString(); Double w = Double.parseDouble(s); String weight = list.get(c).get("WEIGHT").toString(); Double weights = Double.parseDouble(weight); double v1 = w * weights; num += v1; } else { continue; } } } // 排序 List> entryList2 = new ArrayList>(result1.entrySet()); Collections.sort(entryList2, new Comparator>() { @Override public int compare(Entry me1, Entry me2) { return me2.getValue().toString().compareTo(me1.getValue().toString()); // 升序排序 } }); //拼接前3位降雨最大的区域 double v3 = (double) Math.round(num * 10) / 10; String text = "全市日平均降雨量:" + v3 + "毫米。 "; String text1 = "县市区平均降雨量前3位为: "; String tx = ""; for (int i = 0; i < entryList2.size(); i++) { Map mapa = new HashMap(); String codes = entryList2.get(i).getKey(); String values = entryList2.get(i).getValue().toString(); Double a = Double.parseDouble(values); double as = (double) Math.round(a * 10) / 10; for (int j = 0; j < list.size(); j++) { if (codes.equals(list.get(j).get("STATION_CODE").toString())) { String station_name = list.get(j).get("STATION_NAME").toString(); mapa.put("region", station_name); mapa.put("dyp", as); listc.add(mapa); if (i < 3) { tx += station_name + "降雨量为:" + as + "毫米,"; } } } } mapc.put("List", listc); mapc.put("Num", mapAll); mapc.put("text", yday + text); lists.add(mapc); } return R.data(lists); } /** * 流域 */ @GetMapping("/selectReL") public R selectReL(String beginTime, String endTime) { String substring = beginTime.substring(0, 10); String r = beginTime.substring(11, 13); //截取月日 String[] strs = substring.split("-"); //月 String year = strs[1].toString(); //日 String day = strs[2].toString(); String substrings = endTime.substring(0, 10); String rs = endTime.substring(11, 13); //截取月日 String[] strss = substrings.split("-"); //月 String years = strss[1].toString(); //日 String days = strss[2].toString(); String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时。"; String text = ""; String ss = regionWeightService.selectCodeM(); String[] split = ss.split(","); String strArrays = ""; for (int i = 0; i < split.length; i++) { strArrays += "'" + split[i] + "',"; } String codel = strArrays.substring(0, strArrays.length() - 1); //最新雨量值 List> map = regionWeightService.selectReL(beginTime, endTime, codel); // //色斑图 // String fileName = ""; // // 第一步,创建一个webbook,对应一个Excel文件 // HSSFWorkbook wb = new HSSFWorkbook(); // // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet // HSSFSheet sheet = wb.createSheet("土壤湿度表"); // // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short // HSSFRow row = sheet.createRow((int) 0); // // 第四步,创建单元格,并设置值表头 设置表头居中 // HSSFCellStyle style = wb.createCellStyle(); // //style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 // HSSFCell cell = row.createCell((short) 0); // cell.setCellValue("lon"); // cell = row.createCell((short) 1); // cell.setCellValue("lat"); // cell = row.createCell((short) 2); // cell.setCellValue("rain"); // for (int i = 0; i < map.size(); i++) { // // 第四步,创建单元格,并设置值 // row = sheet.createRow((int) i + 1); // HSSFCell celli = row.createCell((short) 0); // row.createCell((short) 0).setCellValue(map.get(i).get("LGTD").toString()); // row.createCell((short) 1).setCellValue(map.get(i).get("LTTD").toString()); // row.createCell((short) 2).setCellValue(map.get(i).get("DRP").toString()); // } // // 第六步,将文件存到指定位置 // try { // fileName = "D:/myl.xlsx"; // FileOutputStream fout = new FileOutputStream(fileName); // wb.write(fout); // fout.close(); // wb.close(); // } catch (Exception e) { // e.printStackTrace(); // } // Process proc; // try { // proc = Runtime.getRuntime().exec("python D:\\fz\\myl.py"); // BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); // String line = null; // while ((line = in.readLine()) != null) { // System.out.println(line); // } // in.close(); // proc.waitFor(); // } catch (IOException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } //权重值 List> list = regionWeightService.selectWeights(); List> list2 = regionWeightService.selectLALL(); List> list3 = regionWeightService.selectLNam(); Map mc = new HashMap(); for (int a = 0; a < list2.size(); a++) { for (int b = 0; b < list3.size(); b++) { String code = list2.get(a).get("code").toString(); String num = list2.get(a).get("num").toString(); String code1 = list3.get(b).get("code").toString(); if (code.equals(code1)) { mc.put(list3.get(b).get("cname").toString(), num); } } } Map map1 = new HashMap(); Map mapc = new HashMap(); List> list1 = new ArrayList>(); List> lists = new ArrayList>(); List> listc = new ArrayList>(); double v = 0; //统计抚州市雨量 Double num = 0.0; String region_code = null; if (map.size() == 0) { List> l = new ArrayList>(); List> m = new ArrayList>(); mapc.put("List", l); mapc.put("Num", m); mapc.put("text", yday + "暂无流域信息。"); lists.add(mapc); } else { for (int i = 0; i < map.size(); i++) { region_code = map.get(i).get("REGION_CODE").toString(); //获取行政区编码 if (i != 0) { String region_code1 = map.get(i - 1).get("REGION_CODE").toString(); if (!region_code.equals(region_code1)) { map1.put("id", region_code1); map1.put("value", v); list1.add(map1); v = 0; map1 = new HashMap(); for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } } else { for (int j = 0; j < list.size(); j++) { if (region_code.equals(list.get(j).get("STATION_CODE").toString())) { BigDecimal bigDecimaldrp = (BigDecimal) map.get(i).get("DRP"); double drp = bigDecimaldrp.floatValue(); String weight1 = map.get(i).get("WEIGHT").toString(); float weight = Float.parseFloat(weight1); v += drp * weight; break; } } } } map1.put("id", region_code); map1.put("value", v); list1.add(map1); Map result1 = new HashMap(); //县/区面雨量值 for (Map maps : list1) { String id = maps.get("id").toString(); Double value = Double.parseDouble(maps.get("value").toString()); if (result1.containsKey(id)) { Double temp = Double.parseDouble(result1.get(id).toString()); value += temp; } result1.put(id, value); } // 排序 List> entryList2 = new ArrayList>(result1.entrySet()); Collections.sort(entryList2, new Comparator>() { @Override public int compare(Entry me1, Entry me2) { return me2.getValue().toString().compareTo(me1.getValue().toString()); // 升序排序 } }); for (int i = 0; i < entryList2.size(); i++) { Map mapa = new HashMap(); String codes = entryList2.get(i).getKey(); String values = entryList2.get(i).getValue().toString(); Double a = Double.parseDouble(values); double as = (double) Math.round(a * 10) / 10; for (int j = 0; j < list.size(); j++) { if (codes.equals(list.get(j).get("STATION_CODE").toString())) { String station_name = list.get(j).get("STATION_NAME").toString(); mapa.put("region", station_name); mapa.put("dyp", as); listc.add(mapa); } } } Collections.sort(listc, new Comparator>() { public int compare(Map o1, Map o2) { return (Double) o1.get("dyp") < (Double) o2.get("dyp") ? 1 : ((Double) o1.get("dyp") == (Double) o2.get("dyp") ? 0 : -1); } }); for (int c = 0; c < listc.size(); c++) { if (c < 3) { text += listc.get(c).get("region").toString() + ":" + listc.get(c).get("dyp") + "毫米,"; } } String a = "流域前三的为:" + text.substring(0, text.length() - 1) + "。"; mapc.put("List", listc); mapc.put("Num", mc); mapc.put("text", yday + a); lists.add(mapc); } return R.data(lists); } }