tangzy
2021-11-09 39caebba35fc84824f5cd51d189fe322d5145803
src/main/java/org/springblade/modules/regionWeight/controller/RegionWeightController.java
@@ -16,8 +16,6 @@
 */
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;
@@ -747,6 +745,7 @@
   /**
    * 点降雨
    *
    * @param beginTime
    * @param endTime
    * @return
@@ -756,11 +755,10 @@
      String substring = beginTime.substring(0, 10);
      String t = beginTime.substring(11, 13);
      String r;
      if(t.substring(0,1).equals("0")){
         r=beginTime.substring(12,13);
      }
      else {
         r=beginTime.substring(11,13);
      if (t.substring(0, 1).equals("0")) {
         r = beginTime.substring(12, 13);
      } else {
         r = beginTime.substring(11, 13);
      }
      //截取月日
      String[] strs = substring.split("-");
@@ -771,11 +769,10 @@
      String substrings = endTime.substring(0, 10);
      String ts = endTime.substring(11, 13);
      String rs;
      if(ts.substring(0,1).equals("0")){
         rs=beginTime.substring(12,13);
      }
      else {
         rs=beginTime.substring(11,13);
      if (ts.substring(0, 1).equals("0")) {
         rs = endTime.substring(12, 13);
      } else {
         rs = endTime.substring(11, 13);
      }
      //截取月日
      String[] strss = substrings.split("-");
@@ -791,6 +788,7 @@
         strArrays += "'" + split[i] + "',";
      }
      String code = strArrays.substring(0, strArrays.length() - 1);
      long cx = System.currentTimeMillis();//获取当前系统时间(毫秒)
      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>();
@@ -876,107 +874,118 @@
      }
      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;
      Timestamp timestamp = new Timestamp(System.currentTimeMillis());
      long url=timestamp.getTime();
      Map m= new HashMap();
      m.put("url",url+".png");
      String[] args1=new String[]{"python","D:\\fz\\fz.py", String.valueOf(url)};
      try {
         proc = Runtime.getRuntime().exec(args1);
         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();
      }
      long url = timestamp.getTime();
      Map m = new HashMap();
      m.put("url", url + ".png");
      lists.add(m);
      System.out.print("程序执行时间为1:");
      System.out.println(System.currentTimeMillis() - cx + "毫秒");
      long bx = System.currentTimeMillis();//获取当前系统时间(毫秒)
      Thread thread = new Thread(new Runnable() {
         @Override
         public void run() {
            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;
            String[] args1 = new String[]{"python", "D:\\fz\\fz.py", String.valueOf(url)};
            try {
               proc = Runtime.getRuntime().exec(args1);
               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();
            }
         }
      });
      thread.start();
      System.out.print("程序执行时间为2:");
      System.out.println(System.currentTimeMillis() - bx + "毫秒");
      return R.data(lists);
   }
@@ -988,11 +997,10 @@
      String substring = beginTime.substring(0, 10);
      String t = beginTime.substring(11, 13);
      String r;
      if(t.substring(0,1).equals("0")){
          r=beginTime.substring(12,13);
      }
      else {
          r=beginTime.substring(11,13);
      if (t.substring(0, 1).equals("0")) {
         r = beginTime.substring(12, 13);
      } else {
         r = beginTime.substring(11, 13);
      }
      //截取月日
      String[] strs = substring.split("-");
@@ -1003,11 +1011,10 @@
      String substrings = endTime.substring(0, 10);
      String ts = endTime.substring(11, 13);
      String rs;
      if(ts.substring(0,1).equals("0")){
         rs=beginTime.substring(12,13);
      }
      else {
         rs=beginTime.substring(11,13);
      if (ts.substring(0, 1).equals("0")) {
         rs = endTime.substring(12, 13);
      } else {
         rs = endTime.substring(11, 13);
      }
      //截取月日
      String[] strss = substrings.split("-");
@@ -1024,8 +1031,14 @@
      }
      String code = strArrays.substring(0, strArrays.length() - 1);
      //List<Map<String, Object>> map = regionWeightService.selectReM(beginTime, endTime);
      long cx = System.currentTimeMillis();//获取当前系统时间(毫秒)
      List<Map<String, Object>> map = regionWeightService.selectReMs(beginTime, endTime, code);
      List<Map<String, Object>> mapAll = regionWeightService.selectAll(beginTime, endTime,code);
      System.out.print("程序执行时间为1:");
      System.out.println(System.currentTimeMillis() - cx + "毫秒");
      long b = System.currentTimeMillis();//获取当前系统时间(毫秒)
      List<Map<String, Object>> mapAll = regionWeightService.selectAll(beginTime, endTime, code);
      System.out.print("程序执行时间为2:");
      System.out.println(System.currentTimeMillis() - b + "毫秒");
      //权重值
      List<Map<String, Object>> list = regionWeightService.selectWeight();
      Map map1 = new HashMap();
@@ -1170,11 +1183,10 @@
      String substring = beginTime.substring(0, 10);
      String t = beginTime.substring(11, 13);
      String r;
      if(t.substring(0,1).equals("0")){
         r=beginTime.substring(12,13);
      }
      else {
         r=beginTime.substring(11,13);
      if (t.substring(0, 1).equals("0")) {
         r = beginTime.substring(12, 13);
      } else {
         r = beginTime.substring(11, 13);
      }
      //截取月日
      String[] strs = substring.split("-");
@@ -1185,11 +1197,10 @@
      String substrings = endTime.substring(0, 10);
      String ts = endTime.substring(11, 13);
      String rs;
      if(t.substring(0,1).equals("0")){
         rs=beginTime.substring(12,13);
      }
      else {
         rs=beginTime.substring(11,13);
      if (t.substring(0, 1).equals("0")) {
         rs = endTime.substring(12, 13);
      } else {
         rs = endTime.substring(11, 13);
      }
      //截取月日
      String[] strss = substrings.split("-");
@@ -1199,7 +1210,7 @@
      String days = strss[2].toString();
      String yday = year + "月" + day + "日" + r + "时-" + years + "月" + days + "日" + rs + "时。";
      String text = "";
      String ss = regionWeightService.selectCodeM();
      String ss = regionWeightService.selectCodeL();
      String[] split = ss.split(",");
      String strArrays = "";
      for (int i = 0; i < split.length; i++) {
@@ -1262,6 +1273,7 @@
      List<Map<String, Object>> list = regionWeightService.selectWeights();
      List<Map<String, Object>> list2 = regionWeightService.selectLALL();
      List<Map<String, Object>> list3 = regionWeightService.selectLNam();
      List<Map<String, Object>> list4 = regionWeightService.selectLy(beginTime, endTime, codel);
      Map mc = new HashMap();
      for (int a = 0; a < list2.size(); a++) {
         for (int b = 0; b < list3.size(); b++) {
@@ -1387,12 +1399,112 @@
         String a = "流域前三的为:" + text.substring(0, text.length() - 1) + "。";
         mapc.put("List", listc);
         mapc.put("Num", mc);
         mapc.put("NumALL", list4);
         mapc.put("text", yday + a);
         lists.add(mapc);
      }
      return R.data(lists);
   }
   /**
    * 时段降雨
    */
   @ApiLog("详情")
   @PostMapping("/selectDayStation")
   @ApiOperationSupport(order = 8)
   @ApiOperation(value = "时段降雨", notes = "传入code,dateBegin,dateEnd")
   public R selectDayStation(String code, String dateBegin, String dateEnd, String sd) {
      return R.data(regionWeightService.selectDayStation(code, dateBegin, dateEnd, sd));
   }
   /**
    * 逐日雨量
    */
   @ApiLog("详情")
   @PostMapping("/selectStation")
   @ApiOperationSupport(order = 7)
   @ApiOperation(value = "逐日雨量", notes = "传入code,dateBegin,dateEnd")
   public R selectStation(String code, String dateBegin, String dateEnd) {
      return R.data(regionWeightService.selectStation(code, dateBegin, dateEnd));
   }
   /**
    * 特征雨量
    */
   @ApiLog("详情")
   @PostMapping("/selectPptnTz")
   @ApiOperationSupport(order = 11)
   @ApiOperation(value = "特征雨量", notes = "")
   public R selectPptnTz(String code) {
      List<Map<String, String>> lists = new ArrayList<>();
      Map<String, String> map = new HashMap<>(16);
      //当前时间
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
      String time = df.format(new Date());
      //查询前一小时数据
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
      String dateEnd1 = df.format(calendar.getTime());
      String map1 = regionWeightService.selectPptnTz(code, dateEnd1, time);
      map.put("drp1", map1);
      //查询前2小时数据
      Calendar calendar2 = Calendar.getInstance();
      calendar2.set(Calendar.HOUR_OF_DAY, calendar2.get(Calendar.HOUR_OF_DAY) - 2);
      String dateEnd2 = df.format(calendar2.getTime());
      String map2 = regionWeightService.selectPptnTz(code, dateEnd2, time);
      map.put("drp2", map2);
      //三个小时前的时间
      Calendar calendar3 = Calendar.getInstance();
      calendar3.set(Calendar.HOUR_OF_DAY, calendar3.get(Calendar.HOUR_OF_DAY) - 3);
      String dateEnd3 = df.format(calendar3.getTime());
      String map3 = regionWeightService.selectPptnTz(code, dateEnd3, time);
      map.put("drp3", map3);
      //六个小时前的时间
      Calendar calendar6 = Calendar.getInstance();
      calendar6.set(Calendar.HOUR_OF_DAY, calendar6.get(Calendar.HOUR_OF_DAY) - 6);
      String dateEnd6 = df.format(calendar6.getTime());
      String map6 = regionWeightService.selectPptnTz(code, dateEnd6, time);
      map.put("drp6", map6);
      //十二个小时前的时间
      Calendar calendar12 = Calendar.getInstance();
      calendar12.set(Calendar.HOUR_OF_DAY, calendar12.get(Calendar.HOUR_OF_DAY) - 12);
      String dateEnd12 = df.format(calendar12.getTime());
      String map12 = regionWeightService.selectPptnTz(code, dateEnd12, time);
      map.put("drp12", map12);
      //二十四个小时前的时间
      Calendar calendar24 = Calendar.getInstance();
      calendar24.set(Calendar.HOUR_OF_DAY, calendar24.get(Calendar.HOUR_OF_DAY) - 24);
      String dateEnd24 = df.format(calendar24.getTime());
      String map24 = regionWeightService.selectPptnTz(code, dateEnd24, time);
      map.put("drp24", map24);
      //四十八个小时前的时间
      Calendar calendar48 = Calendar.getInstance();
      calendar48.set(Calendar.HOUR_OF_DAY, calendar48.get(Calendar.HOUR_OF_DAY) - 48);
      String dateEnd48 = df.format(calendar48.getTime());
      String map48 = regionWeightService.selectPptnTz(code, dateEnd48, time);
      map.put("drp48", map48);
      //七十二个小时前的时间
      Calendar calendar72 = Calendar.getInstance();
      calendar72.set(Calendar.HOUR_OF_DAY, calendar72.get(Calendar.HOUR_OF_DAY) - 72);
      String dateEnd72 = df.format(calendar72.getTime());
      String map72 = regionWeightService.selectPptnTz(code, dateEnd72, time);
      map.put("drp72", map72);
      map.put("time", time);
      lists.add(map);
      return R.data(lists);
   }
}