tangzy
2021-09-08 1c5e273bbd5751664dd9b65149c4b2dd3ede94ec
src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java
@@ -427,7 +427,7 @@
      if (maps.size() == 0) {
         a = yday + "暂无降雨信息。";
      } else {
         a = yday + "点降雨量前三为:" + text.substring(0,text.length()-1)+"。";
         a = yday + "点降雨量前三为:" + 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") + "(mm),";
            }
         }
         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,158 @@
   }
   @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);
   }
}