From bc76e975aae3837eae625a2e3ffff7d02a5fc3f3 Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Mon, 13 Sep 2021 17:27:24 +0800
Subject: [PATCH] 1.山洪
---
src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java | 356 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 339 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java b/src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java
index 1f109f5..b2cec61 100644
--- a/src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java
+++ b/src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java
@@ -300,8 +300,8 @@
});
//拼接前3位降雨最大的区域
double v3 = (double) Math.round(num * 10) / 10;
- String text = "抚州市降雨:" + v3 + "(毫米)。 ";
- String text1 = "前三降雨量的是: ";
+ String text = "全市日平均降雨量:" + v3 + "(毫米)。 ";
+ String text1 = "县市区平均降雨量前3位为: ";
String tx = "";
for (int i = 0; i < entryList2.size(); i++) {
Map mapa = new HashMap();
@@ -427,7 +427,7 @@
if (maps.size() == 0) {
a = yday + "暂无降雨信息。";
} else {
- a = yday + "点降雨量前三为:" + text.substring(0,text.length()-1)+"。";
+ a = yday + "站点最大降雨量前3位为:" + text.substring(0, text.length() - 1) + "。";
}
map.put("text", a);
lists.add(map);
@@ -514,13 +514,13 @@
List<Map<String, Object>> list2 = regionWeightService.selectLALL();
List<Map<String, Object>> list3 = regionWeightService.selectLNam();
Map mc = new HashMap();
- for (int a=0;a<list2.size();a++){
- for (int b=0;b<list3.size();b++){
+ 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);
+ if (code.equals(code1)) {
+ mc.put(list3.get(b).get("cname").toString(), num);
}
}
}
@@ -625,24 +625,25 @@
}
}
- Collections.sort(listc, new Comparator<Map<String,Object>>(){
- public int compare(Map<String,Object> o1,Map<String,Object> o2){
- return (Double)o1.get("dyp")<(Double)o2.get("dyp")?1:( (Double)o1.get("dyp")==(Double)o2.get("dyp")?0:-1);
+ Collections.sort(listc, new Comparator<Map<String, Object>>() {
+ public int compare(Map<String, Object> o1, Map<String, Object> 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")+"(mm),";
+ 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)+"。";
+ String a = "流域前三的为:" + text.substring(0, text.length() - 1) + "。";
mapc.put("List", listc);
mapc.put("Num", mc);
- mapc.put("text", yday+a);
+ mapc.put("text", yday + a);
lists.add(mapc);
}
return R.data(lists);
}
+
/**
* @param type 类型 0:实时 1 历史
* @param timez 当前时间 yyyy-MM-dd HH:00:00
@@ -696,8 +697,7 @@
lists.add(map);
}
return R.data(lists);
- }
- else {
+ } else {
//当前时间
String time = timez;
@@ -743,4 +743,326 @@
}
+ @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<Map<String, Object>> maps = regionWeightService.selectYjs(beginTime, endTime);
+ String s = regionWeightService.selectCode();
+ String[] split = s.split(",");
+ String strArrays = "";
+ for (int i = 0; i < split.length; i++) {
+ strArrays += "'" + split[i] + "',";
+ }
+ String code = strArrays.substring(0, strArrays.length() - 1);
+ List<Map<String, Object>> maps = regionWeightService.ss(beginTime, endTime, code);
+ List<Map<String, Object>> lists = new ArrayList<>();
+ Map<String, Object> map = new HashMap<String, Object>();
+ 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 + "点降雨量前三为:" + 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("/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<String, Object>> map = regionWeightService.selectReM(beginTime, endTime);
+ List<Map<String, Object>> map = regionWeightService.selectReMs(beginTime, endTime,code);
+ List<Map<String, Object>> mapAll = regionWeightService.selectAll();
+ //权重值
+ List<Map<String, Object>> list = regionWeightService.selectWeight();
+ Map map1 = new HashMap();
+ Map mapc = new HashMap();
+ List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
+ List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
+ List<Map<String, Object>> listc = new ArrayList<Map<String, Object>>();
+ double v = 0;
+ //统计抚州市雨量
+ Double num = 0.0;
+ String region_code = null;
+ if (map.size() == 0) {
+ List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
+ List<Map<String, Object>> m = new ArrayList<Map<String, Object>>();
+ 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<String, Object> result1 = new HashMap<String, Object>();
+ //县/区面雨量值
+ for (Map<String, Object> 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<Map.Entry<String, Object>> entryList2 = new ArrayList<Map.Entry<String, Object>>(result1.entrySet());
+ Collections.sort(entryList2, new Comparator<Map.Entry<String, Object>>() {
+ @Override
+ public int compare(Entry<String, Object> me1, Entry<String, Object> 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);
+ }
+
}
--
Gitblit v1.9.3