| | |
| | | |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | |
| | | } |