/* * 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.mountainrain.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.apache.poi.hssf.usermodel.*; import org.springblade.core.boot.ctrl.BladeController; 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.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.modules.mountain.entity.Mountain; import org.springblade.modules.mountain.service.IMountainService; import org.springblade.modules.mountain.vo.MountainVO; import org.springblade.modules.mountainrain.entity.Mountainrain; import org.springblade.modules.mountainrain.entity.Yucpptn; import org.springblade.modules.mountainrain.excel.BgrExcel; import org.springblade.modules.mountainrain.excel.BgrImporter; import org.springblade.modules.mountainrain.excel.MgrExcel; import org.springblade.modules.mountainrain.excel.MgrImporter; import org.springblade.modules.mountainrain.service.IMountainrainService; import org.springblade.modules.mountainrain.vo.*; import org.springblade.modules.mountainrain.wrapper.MountainrainWrapper; import org.springblade.modules.regionWeight.service.IRegionWeightService; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.excel.UserImporter; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.*; import java.math.BigDecimal; import java.net.URLEncoder; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * 控制器 * * @author BladeX * @since 2020-02-27 */ @RestController @AllArgsConstructor @RequestMapping("/mountainrain") @Component @Api(value = "", tags = "接口") public class MountainrainController extends BladeController { private IMountainrainService mountainrainService; private IMountainService mountainService; private final IRegionWeightService regionWeightService; /** * 分页 */ @GetMapping("/pages") public R> page(@ApiIgnore @RequestParam Map blog, Query query) { IPage pages = mountainrainService.page(Condition.getPage(query), Condition.getQueryWrapper(blog, Mountainrain.class)); return R.data(pages); } /** * 详情 */ @ApiLog("详情") @GetMapping("/detail") @ApiOperationSupport(order = 1) @ApiOperation(value = "详情", notes = "传入mountainrain") public R detail(Mountainrain mountainrain) { Mountainrain detail = mountainrainService.getOne(Condition.getQueryWrapper(mountainrain)); return R.data(MountainrainWrapper.build().entityVO(detail)); } /** * 详情 */ @ApiLog("详情") @GetMapping("/details") @ApiOperationSupport(order = 1) public R detail(String id) { return R.data(mountainrainService.selectInfo(id)); } /** * 分页 */ @GetMapping("/list") @ApiOperationSupport(order = 2) @ApiOperation(value = "分页", notes = "传入mountainrain") public R> list(Mountainrain mountainrain, Query query) { IPage pages = mountainrainService.page(Condition.getPage(query), Condition.getQueryWrapper(mountainrain)); return R.data(MountainrainWrapper.build().pageVO(pages)); } /** * 自定义分页 */ @GetMapping("/page") @ApiOperationSupport(order = 3) @ApiOperation(value = "分页", notes = "传入mountainrain") public R> page(MountainrainVO mountainrain, Query query) { IPage pages = mountainrainService.selectMountainrainPage(Condition.getPage(query), mountainrain); return R.data(pages); } /** * 新增 */ @PostMapping("/save") @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入mountainrain") public R save(@Valid @RequestBody Mountainrain mountainrain) { return R.status(mountainrainService.save(mountainrain)); } /** * 修改 */ @PostMapping("/update") @ApiOperationSupport(order = 5) @ApiOperation(value = "修改", notes = "传入mountainrain") public R update(@Valid @RequestBody Mountainrain mountainrain) { return R.status(mountainrainService.updateById(mountainrain)); } /** * 新增或修改 */ @PostMapping("/submit") @ApiOperationSupport(order = 6) @ApiOperation(value = "新增或修改", notes = "传入mountainrain") public R submit(@Valid @RequestBody Mountainrain mountainrain) { return R.status(mountainrainService.saveOrUpdate(mountainrain)); } /** * 新增或修改 */ @PostMapping("/submits") public R submits(@Valid @RequestBody MountainrainSSVO mountainrain) { String crainfall = mountainrain.getCrainfall(); String cenconding = mountainrain.getCenconding(); String arainfall = mountainrain.getArainfall(); String aconding = mountainrain.getAconding(); Integer gohour = mountainrain.getGohour(); Integer gthour = mountainrain.getGthour(); Integer gshour = mountainrain.getGshour(); Integer imohour = mountainrain.getImohour(); Integer imthour = mountainrain.getImthour(); Integer imshour = mountainrain.getImshour(); Long id = mountainrain.getId(); //Long mid = mountainrain.getMid(); Mountainrain mountainrain1 = new Mountainrain(); mountainrain1.setCrainfall(crainfall); mountainrain1.setCenconding(cenconding); mountainrain1.setGohour(gohour); mountainrain1.setGthour(gthour); mountainrain1.setGshour(gshour); mountainrain1.setImohour(imohour); mountainrain1.setImthour(imthour); mountainrain1.setImshour(imshour); mountainrain1.setId(id); //山洪详情表数据修改 String township = mountainrain.getTownship(); String village = mountainrain.getVillage(); String villagegroup = mountainrain.getVillage_group(); String bw = mountainrain.getBw(); String dj = mountainrain.getDj(); String fyear = mountainrain.getFyear(); String tyear = mountainrain.getTyear(); String oyear = mountainrain.getOyear(); String county = mountainrain.getCounty(); Mountain mountain = new Mountain(); mountain.setCenconding(cenconding); mountain.setAconding(aconding); mountain.setTownship(township); mountain.setVillage(village); mountain.setVillage_group(villagegroup); mountain.setBw(bw); mountain.setDj(dj); mountain.setFyear(fyear); mountain.setTyear(tyear); mountain.setOyear(oyear); mountain.setCounty(county); //mountain.setId(mid); mountainrainService.saveOrUpdate(mountainrain1); mountainService.saveOrUpdate(mountain); return R.success("修改成功"); } /** * 新增或修改 */ @ApiLog("新增或修改") @PostMapping("/submitde") public R submitde(@Valid @RequestBody MountainrainSSVO mountainrain) { String crainfall = mountainrain.getCrainfall(); String cenconding = mountainrain.getCenconding(); String arainfall = mountainrain.getArainfall(); String aconding = mountainrain.getAconding(); Integer gohour = mountainrain.getGohour(); Integer gthour = mountainrain.getGthour(); Integer gshour = mountainrain.getGshour(); Integer imohour = mountainrain.getImohour(); Integer imthour = mountainrain.getImthour(); Integer imshour = mountainrain.getImshour(); Mountainrain mountainrain1 = new Mountainrain(); mountainrain1.setCrainfall(crainfall); mountainrain1.setCenconding(cenconding); mountainrain1.setGohour(gohour); mountainrain1.setGthour(gthour); mountainrain1.setGshour(gshour); mountainrain1.setImohour(imohour); mountainrain1.setImthour(imthour); mountainrain1.setImshour(imshour); //山洪详情表数据修改 String township = mountainrain.getTownship(); String village = mountainrain.getVillage(); String villagegroup = mountainrain.getVillage_group(); String bw = mountainrain.getBw(); String dj = mountainrain.getDj(); String fyear = mountainrain.getFyear(); String tyear = mountainrain.getTyear(); String oyear = mountainrain.getOyear(); String county = mountainrain.getCounty(); Mountain mountain = new Mountain(); mountain.setCenconding(cenconding); mountain.setAconding(aconding); mountain.setTownship(township); mountain.setVillage(village); mountain.setVillage_group(villagegroup); mountain.setBw(bw); mountain.setDj(dj); mountain.setFyear(fyear); mountain.setTyear(tyear); mountain.setOyear(oyear); mountain.setCounty(county); mountainrainService.saveOrUpdate(mountainrain1); mountainService.saveOrUpdate(mountain); return R.success("新增成功"); } /** * 删除 @PostMapping("/remove") @ApiOperationSupport(order = 7) @ApiOperation(value = "逻辑删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { return R.status(mountainrainService.deleteLogic(Func.toLongList(ids))); }*/ /** * 删除 */ @PostMapping("/remove") public R remove(@RequestParam String ids, String mid) { //mountainrainService.removeByIds(Func.toIntList(ids)); mountainService.removeByIds(Func.toIntList(mid)); return R.success("删除成功"); } /** * 顶级列表 */ @ApiLog("详情") @GetMapping("/parent-lists") @ApiOperation(value = "列表", notes = "传入dict") public R> parentList(@ApiIgnore @RequestParam Map blog, Query query) { return R.data(mountainrainService.parentList(blog, query)); } /** * 子列表 */ @ApiLog("详情") @GetMapping("/child-list") @ApiOperation(value = "列表", notes = "传入dict") public R> childList(@ApiIgnore @RequestParam Map dict, @RequestParam(required = false, defaultValue = "-1") String parentId, Query query) { return R.data(mountainService.childList(dict, parentId, query)); } @ApiLog("详情") @RequestMapping(value = "/cs", method = RequestMethod.POST) @ResponseBody public R saveImg(@RequestParam("file") MultipartFile file) { mountainrainService.upLoadFile(file); return R.success("成功"); } /** * 多表联合查询自定义分页 */ @ApiLog("详情") @GetMapping("/pagess") @ApiOperationSupport(order = 3) @ApiOperation(value = "分页", notes = "传入notice") public R> page(@ApiIgnore MountainrainSSVO mountainrainSSVO, Query query) { IPage pages = mountainrainService.selectNoticePage(Condition.getPage(query), mountainrainSSVO); return R.data(pages); } /** * 分页 */ @ApiLog("详情") @GetMapping("/listss") @ApiOperationSupport(order = 4) @ApiOperation(value = "分页", notes = "传入tmpR") public R> listss(String query) { List list = mountainrainService.selectNoticeList(query); return R.data(list); } /** * 山洪分析接口:按行政区分 */ @GetMapping("/queryXZ") public List queryXZ() { List list = mountainrainService.queryXZ(); return list; } /** * 山洪分析接口:按行政区分 */ @GetMapping("/queryZL") public List> queryZL() { List list = mountainrainService.queryZL(); List> data = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap<>(); if (list.get(i).getSttp() != null) { if (list.get(i).getSttp().equals("PP")) { map.put("name", "雨量站"); map.put("value", list.get(i).getCount()); } else if (list.get(i).getSttp().equals("ZQ")) { map.put("name", "水文站"); map.put("value", list.get(i).getCount()); } else if (list.get(i).getSttp().equals("ZZ")) { map.put("name", "水位站"); map.put("value", list.get(i).getCount()); } else if (list.get(i).getSttp().equals("RR")) { map.put("name", "水库站"); map.put("value", list.get(i).getCount()); } } data.add(map); } return data; } /** * 查询洪水预警 */ @ApiLog("查询洪水预警") @GetMapping("/ss") public R selectcInfos(int type, String time, String dateEnds1, String dateEnds3, String dateEnds6, String dateEnds24, int k, String timei) { if (type == 0 && k == 13) { //当前时间 String times = time; String dateEnd1 = dateEnds1; String timess = timei; //三个小时前的时间 String dateEnd3 = dateEnds3; //六个小时前的时间 String dateEnd6 = dateEnds6; //二十四个小时前的时间 String dateEnd24 = dateEnds24; //对应雨量站 long startTime = System.currentTimeMillis(); List mountainrainsCVOS = mountainrainService.selectcInfos(times, dateEnd24, dateEnd1, dateEnd3, dateEnd6, timess); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); int Max = mountainrainService.Max(mountainrainsCVOS.get(i).getDrp1(), mountainrainsCVOS.get(i).getDrp3(), mountainrainsCVOS.get(i).getGohour(), mountainrainsCVOS.get(i).getGthour()); map.put("List", mountainrainsCVOS.get(i)); map.put("Max", Max); lists.add(map); } return R.data(lists); } else { //当前时间 String times = time; String dateEnd1 = dateEnds1; String timess = timei; //三个小时前的时间 String dateEnd3 = dateEnds3; //六个小时前的时间 String dateEnd6 = dateEnds6; //二十四个小时前的时间 String dateEnd24 = dateEnds24; //对应雨量站 List mountainrainsCVOS = mountainrainService.selectcInfo(times, dateEnd24, dateEnd1, dateEnd3, dateEnd6, timess); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { Map map = new HashMap(); int Max = mountainrainService.Max(mountainrainsCVOS.get(i).getDrp1(), mountainrainsCVOS.get(i).getDrp3(), mountainrainsCVOS.get(i).getGohour(), mountainrainsCVOS.get(i).getGthour()); map.put("List", mountainrainsCVOS.get(i)); map.put("Max", Max); lists.add(map); } return R.data(lists); } } /** * 查询洪水预警 */ @ApiLog("查询洪水预警") @GetMapping("/sss") public R selectcInfoss(int type, String time, String dateEnds1, String dateEnds2, String dateEnds3) { //第二种方式预警 if (type == 0) { //当前时间 String times = time; String dateEnd1 = dateEnds1; //2个小时前的时间 String dateEnd2 = dateEnds2; //3个小时前的时间 String dateEnd3 = dateEnds3; //对应雨量站 String s = mountainrainService.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 mountainrainsCVOS = mountainrainService.Mountains(times, dateEnd1, dateEnd2, dateEnd3, code); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthours()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 2); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthour()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 1); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } } } //色斑图 String file = ""; // 第一步,创建一个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 < mountainrainsCVOS.size(); i++) { row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(mountainrainsCVOS.get(i).getDj()); row.createCell((short) 1).setCellValue(mountainrainsCVOS.get(i).getBw()); if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { row.createCell((short) 2).setCellValue(2); continue; } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthours()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { row.createCell((short) 2).setCellValue(2); continue; } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthour()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } } try { file = "D:/mou.xlsx"; FileOutputStream fout = new FileOutputStream(file); 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\\mou.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(); } lists.add(m); return R.data(lists); } //第一种方式预警(雨量表数据) else { //当前时间 String times = time; //一个小时前的时间 String dateEnd1 = dateEnds1; //两个小时前的时间 String dateEnd2 = dateEnds2; //三个小时前的时间 String dateEnd3 = dateEnds3; 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> list = mountainrainService.selecMone(times, dateEnd1, dateEnd2, dateEnd3, code); List> lists = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); BigDecimal w2 = (BigDecimal) list.get(i).get("drp2"); double drp2 = w2.doubleValue(); BigDecimal w3 = (BigDecimal) list.get(i).get("drp3"); double drp3 = w3.doubleValue(); if (drp1 > 30) { map.put("flage1", "true"); } else { map.put("flage1", "false"); } if (drp2 > 50) { map.put("flage2", "true"); } else { map.put("flage2", "false"); } if (drp3 > 80) { map.put("flage3", "true"); } else { map.put("flage3", "false"); } map.put("List", list.get(i)); 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(new HSSFRichTextString("lon")); cell = row.createCell((short) 1); cell.setCellValue(new HSSFRichTextString("lat")); cell = row.createCell((short) 2); cell.setCellValue(new HSSFRichTextString("rain")); for (int i = 0; i < list.size(); i++) { // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); BigDecimal w2 = (BigDecimal) list.get(i).get("drp2"); double drp2 = w2.doubleValue(); BigDecimal w3 = (BigDecimal) list.get(i).get("drp3"); double drp3 = w3.doubleValue(); row.createCell((short) 0).setCellValue(list.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(list.get(i).get("LTTD").toString()); if (drp1 > 30) { row.createCell((short) 2).setCellValue(2); continue; } if (drp2 > 50) { row.createCell((short) 2).setCellValue(2); continue; } if (drp3 > 80) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } // 第六步,将文件存到指定位置 try { fileName = "D:/moup.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\\moup.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(); } lists.add(m); return R.data(lists); } } /** * 土壤湿度计算 * * @return */ @GetMapping("/soleval") public R soleval(String time, int b) { //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //String dateNow = sdf.format(new Date()); String dateNow = time; //mountainrainService.soildel(); int intervals = 32 + b; ArrayList passDaysList = new ArrayList<>(); for (int i = 1 + b; i < intervals; i++) { passDaysList.add(getDays(i, false)); } Collections.sort(passDaysList); //String s = mountainrainService.selectCode(); 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); for (int i = 0; i < split.length; i++) { Integer num = 30; double v1 = 0; String stcd = null; for (int j = 0; j < passDaysList.size() - 2; j++) { List> map = mountainrainService.selectMtwo(passDaysList.get(j).toString(), passDaysList.get(j + 1).toString(), code); if (map.size() == 0 || i > map.size() - 1) { //stcd=split[i]; break; } BigDecimal w = (BigDecimal) map.get(i).get("drp"); double drp = w.doubleValue(); stcd = map.get(i).get("STCD").toString(); //计算湿度 if (j == 0) { v1 = formatDouble1((num + drp) * 0.85); if (v1 > 60) { v1 = 60; } } else { v1 += drp; v1 = formatDouble1(v1 * 0.85); if (v1 > 60) { v1 = 60; } } } if (stcd != null) { if (v1 > 60) { mountainrainService.soleInster(stcd, "60", dateNow); } else { String a = String.valueOf(v1); mountainrainService.soleInster(stcd, a, dateNow); } } } return R.success("成功"); } public static double formatDouble1(double d) { return (double) Math.round(d * 10) / 10; } private static String getDays(int i, boolean b) { Calendar calendar = Calendar.getInstance(); if (b) { calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + i); } else { calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - i); } Date today = calendar.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 08:00:00"); String result = format.format(today); return result; } /** * 山洪预报 * * @param addvcd 行政区编码 * @param time 时间 * @param intv 降雨时段 * @return */ @GetMapping("/yuc") public R yuc(String addvcd, String time, String intv, String drp, int type) throws ParseException { mountainrainService.del(); List yucpptnList = new ArrayList<>(); //通过行政区查询站点编码 List> list = mountainrainService.selectAddvcd(addvcd); for (int i = 0; i < list.size(); i++) { Yucpptn yucpptn = new Yucpptn(); //站点编码 String stcd = list.get(i).get("STCD").toString(); yucpptn.setSTCD(stcd); yucpptn.setTM(time); yucpptn.setDRP(drp); yucpptn.setINTV(intv); yucpptnList.add(yucpptn); } //预警信息添加 mountainrainService.insertYuc(yucpptnList); //第二种预警 if (type == 0) { List mountainrainsCVOS = mountainrainService.selectYum(); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthours()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 2); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } } else { //0.5雨量湿度 int Max = mountainrainService.Max(mountainrainsCVOS.get(i).getDrp1(), mountainrainsCVOS.get(i).getDrp3(), mountainrainsCVOS.get(i).getGohour(), mountainrainsCVOS.get(i).getGthour()); if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthour()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 1); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } } } return R.data(lists); } else { //第一种方式预警(雨量表) List> list1 = mountainrainService.selectYup(); List> listyp = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); String w1 = list1.get(i).get("drp").toString(); double drp1 = Double.parseDouble(w1); String intv1 = list1.get(i).get("INTV").toString(); //一小时预警 if (intv1.equals("1")) { if (drp1 > 30) { map.put("flage1", "true"); map.put("flage2", "false"); map.put("flage3", "false"); } else { map.put("flage1", "false"); map.put("flage2", "false"); map.put("flage3", "false"); } } else if (intv1.equals("2")) { if (drp1 > 50) { map.put("flage2", "true"); map.put("flage1", "false"); map.put("flage3", "false"); } else { map.put("flage1", "false"); map.put("flage2", "false"); map.put("flage3", "false"); } } else { if (drp1 > 80) { map.put("flage3", "true"); map.put("flage1", "false"); map.put("flage2", "false"); } else { map.put("flage1", "false"); map.put("flage2", "false"); map.put("flage3", "false"); } } map.put("List", list1.get(i)); listyp.add(map); } return R.data(listyp); } } /** * 中小河流预警 * * @return */ @GetMapping("/selectsmriver") public R selectsmriver(String time) throws ParseException { Date date = null; // 把Date按照格式转换成字符串 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } String dateEnd = sdf.format(date); DateFormat sdfc = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date datess = sdfc.parse(time); String now = sdfc.format(datess); //当前时间的前24小时 Date beforeHour1 = beforeHourToNowDate(now, 24); String begintime24 = sdf.format(beforeHour1); List> selctsmriver = mountainrainService.selctsmriver(time, dateEnd, begintime24); //预警数据 List listyj = new ArrayList(); //无预警数据 List listzc = new ArrayList(); for (int i = 0; i < selctsmriver.size(); i++) { //警戒水位 String yjsw = selctsmriver.get(i).get("yjsw").toString(); Double yjz = Double.parseDouble(yjsw); //水位 String zs = selctsmriver.get(i).get("Z").toString(); Double z = Double.parseDouble(zs); if (z > yjz) { listyj.add(selctsmriver.get(i)); } else { listzc.add(selctsmriver.get(i)); } } Map map = new HashMap(); map.put("yj", listyj); map.put("zc", listzc); List list = new ArrayList(); list.add(map); return R.data(list); } /** * 大江大河预警 * * @return */ @GetMapping("/selectbgriver") public R selectbgriver(String time) throws ParseException { Date date = null; // 把Date按照格式转换成字符串 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } String dateEnd = sdf.format(date); DateFormat sdfc = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date datess = sdfc.parse(time); String now = sdfc.format(datess); //当前时间的前24小时 Date beforeHour1 = beforeHourToNowDate(now, 24); String begintime24 = sdf.format(beforeHour1); List> selctsmriver = mountainrainService.selctbgriver(time, dateEnd, begintime24); //预警数据 List listyj = new ArrayList(); //无预警数据 List listzc = new ArrayList(); for (int i = 0; i < selctsmriver.size(); i++) { //警戒水位 String yjsw = selctsmriver.get(i).get("yjsw").toString(); Double yjz = Double.parseDouble(yjsw); //水位 String zs = selctsmriver.get(i).get("Z").toString(); Double z = Double.parseDouble(zs); if (z > yjz) { listyj.add(selctsmriver.get(i)); } else { listzc.add(selctsmriver.get(i)); } } Map map = new HashMap(); map.put("yj", listyj); map.put("zc", listzc); List list = new ArrayList(); list.add(map); return R.data(list); } /** * 土壤 * * @return */ @GetMapping("/selectTu") public R selectTu() { List> maps = mountainrainService.selectTu(); List> list = new ArrayList(); //镇 List> listz = new ArrayList(); //乡 List> listx = new ArrayList(); Map mapZ = new HashMap(); for (int i = 0; i < maps.size(); i++) { Map map = new HashMap(); String village = maps.get(i).get("village").toString(); String soilval = maps.get(i).get("soilval").toString(); String county = maps.get(i).get("county").toString(); String cenconding = maps.get(i).get("cenconding").toString(); //土壤湿度 Double soilv = Double.parseDouble(soilval); boolean status = village.contains("镇"); if (status) { String str1 = village.substring(0, village.indexOf("镇") + 1); map.put("name", str1); map.put("soilv", soilv); map.put("addvnm", county); map.put("cenconding", cenconding); listz.add(map); } else { String str2 = village.substring(0, village.indexOf("乡") + 1); map.put("name", str2); map.put("soilv", soilv); map.put("addvnm", county); map.put("cenconding", cenconding); listx.add(map); } } System.out.println("镇" + listz.size()); System.out.println("乡" + listx.size()); Map>> mapMap = new HashMap<>(); for (Map newMap : listz) { List> newl = new ArrayList<>(); // map是否包含此key,若已经包含则添加一个新的数字到对应value集合中 if (mapMap.containsKey(newMap.get("name").toString())) { //mapList.add(Integer.valueOf(newMap.get("C").toString()),newMap); mapMap.get(newMap.get("name").toString()).add(newMap); } else { newl.add(newMap); mapMap.put(newMap.get("name").toString(), newl); } } mapZ.put("listz", mapMap); //乡 Map>> mapMapx = new HashMap<>(); for (Map newMap : listx) { List> newl = new ArrayList<>(); // map是否包含此key,若已经包含则添加一个新的数字到对应value集合中 if (mapMapx.containsKey(newMap.get("name").toString())) { //mapList.add(Integer.valueOf(newMap.get("C").toString()),newMap); mapMapx.get(newMap.get("name").toString()).add(newMap); } else { newl.add(newMap); mapMapx.put(newMap.get("name").toString(), newl); } } mapZ.put("listx", mapMapx); list.add(mapZ); return R.data(list); } /** * 查询预警1小时 */ @GetMapping("/Yi") public R Yi(int type, String time, String dateEnds1) { //第二种方式预警 if (type == 0) { //当前时间 String times = time; String dateEnd1 = dateEnds1; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } String stime = sdf.format(date); //对应雨量站 String s = mountainrainService.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 mountainrainsCVOS = mountainrainService.MountainYi(times, dateEnd1, code, stime); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohours = mountainrainsCVOS.get(i).getGohours(); float i1 = (float) drp1 - gohours; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("status", 2); map.put("num", a); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("status", 2); lists.add(map); } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohour = mountainrainsCVOS.get(i).getGohour(); float i1 = (float) drp1 - gohour; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("status", 1); map.put("num", a); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("status", 1); lists.add(map); } } } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); Thread thread = new Thread(new Runnable() { @Override public void run() { //色斑图 String file = ""; // 第一步,创建一个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 < mountainrainsCVOS.size(); i++) { row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(mountainrainsCVOS.get(i).getDj()); row.createCell((short) 1).setCellValue(mountainrainsCVOS.get(i).getBw()); if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } } try { file = "D:/mou.xlsx"; FileOutputStream fout = new FileOutputStream(file); wb.write(fout); fout.close(); wb.close(); } catch (Exception e) { e.printStackTrace(); } Process proc; String[] args1 = new String[]{"python", "D:\\fz\\mou.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(); return R.data(lists); } //第一种方式预警(雨量表数据) else { //当前时间 String times = time; //一个小时前的时间 String dateEnd1 = dateEnds1; 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> list = mountainrainService.selecMoneYi(times, dateEnd1, code); List> lists = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); if (drp1 > 30) { double v = drp1 - 30; double v1 = (double) Math.round(v * 100) / 100; String a = String.valueOf(v1); map.put("flage1", "true"); map.put("num", a); } else { map.put("flage1", "false"); } map.put("List", list.get(i)); lists.add(map); } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); 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(new HSSFRichTextString("lon")); cell = row.createCell((short) 1); cell.setCellValue(new HSSFRichTextString("lat")); cell = row.createCell((short) 2); cell.setCellValue(new HSSFRichTextString("rain")); for (int i = 0; i < list.size(); i++) { // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); row.createCell((short) 0).setCellValue(list.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(list.get(i).get("LTTD").toString()); if (drp1 > 30) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } // 第六步,将文件存到指定位置 try { fileName = "D:/moup.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\\moup.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(); return R.data(lists); } } /** * 查询预警2小时 */ @GetMapping("/Tw") public R Tw(int type, String time, String dateEnds2) { //第二种方式预警 if (type == 0) { //当前时间 String times = time; //2个小时前的时间 String dateEnd2 = dateEnds2; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } String stime = sdf.format(date); //对应雨量站 String s = mountainrainService.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 mountainrainsCVOS = mountainrainService.MountainTw(times, dateEnd2, code, stime); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohours = mountainrainsCVOS.get(i).getGohours(); float i1 = (float) drp1 - gohours; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 2); map.put("num", a); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthours()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 2); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohour = mountainrainsCVOS.get(i).getGohour(); float i1 = (float) drp1 - gohour; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "true"); map.put("flage3", "false"); map.put("status", 1); map.put("num", a); lists.add(map); } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthour()) { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "true"); map.put("status", 1); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage1", "false"); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } } } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); Thread thread = new Thread(new Runnable() { @Override public void run() { //色斑图 String file = ""; // 第一步,创建一个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 < mountainrainsCVOS.size(); i++) { row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(mountainrainsCVOS.get(i).getDj()); row.createCell((short) 1).setCellValue(mountainrainsCVOS.get(i).getBw()); if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohours()) { row.createCell((short) 2).setCellValue(2); continue; } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthours()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGohour()) { row.createCell((short) 2).setCellValue(2); continue; } else if (mountainrainsCVOS.get(i).getDrp3() > mountainrainsCVOS.get(i).getGthour()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } } try { file = "D:/mou.xlsx"; FileOutputStream fout = new FileOutputStream(file); wb.write(fout); fout.close(); wb.close(); } catch (Exception e) { e.printStackTrace(); } Process proc; String[] args1 = new String[]{"python", "D:\\fz\\mou.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(); return R.data(lists); } //第一种方式预警(雨量表数据) else { //当前时间 String times = time; //两个小时前的时间 String dateEnd2 = dateEnds2; 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> list = mountainrainService.selecMoneYi(times, dateEnd2, code); List> lists = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); if (drp1 > 50) { double v = drp1 - 50; double v1 = (double) Math.round(v * 10) / 10; map.put("flage2", "true"); map.put("num", v1); } else { map.put("flage2", "false"); } map.put("List", list.get(i)); lists.add(map); } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); 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(new HSSFRichTextString("lon")); cell = row.createCell((short) 1); cell.setCellValue(new HSSFRichTextString("lat")); cell = row.createCell((short) 2); cell.setCellValue(new HSSFRichTextString("rain")); for (int i = 0; i < list.size(); i++) { // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); row.createCell((short) 0).setCellValue(list.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(list.get(i).get("LTTD").toString()); if (drp1 > 50) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } // 第六步,将文件存到指定位置 try { fileName = "D:/moup.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\\moup.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(); return R.data(lists); } } /** * 查询预警3小时 */ @GetMapping("/Tr") public R Tr(int type, String time, String dateEnds3) { //第二种方式预警 if (type == 0) { //当前时间 String times = time; //2个小时前的时间 String dateEnd3 = dateEnds3; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } String stime = sdf.format(date); //对应雨量站 String s = mountainrainService.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 mountainrainsCVOS = mountainrainService.MountainTr(times, dateEnd3, code, stime); List> lists = new ArrayList<>(); for (int i = 0; i < mountainrainsCVOS.size(); i++) { if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } Map map = new HashMap(); if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGthours()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohours = mountainrainsCVOS.get(i).getGohours(); float i1 = (float) drp1 - gohours; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage3", "true"); map.put("status", 2); map.put("num", a); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage3", "false"); map.put("status", 2); lists.add(map); } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGthour()) { int drp1 = mountainrainsCVOS.get(i).getDrp1(); Integer gohour = mountainrainsCVOS.get(i).getGohour(); float i1 = (float) drp1 - gohour; float v = (float) (Math.round(i1 * 10)) / 10; String a = String.valueOf(v); map.put("List", mountainrainsCVOS.get(i)); map.put("flage3", "true"); map.put("status", 1); map.put("num", a); lists.add(map); } else { map.put("List", mountainrainsCVOS.get(i)); map.put("flage3", "false"); map.put("status", 1); lists.add(map); } } } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); Thread thread = new Thread(new Runnable() { @Override public void run() { //色斑图 String file = ""; // 第一步,创建一个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 < mountainrainsCVOS.size(); i++) { row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(mountainrainsCVOS.get(i).getDj()); row.createCell((short) 1).setCellValue(mountainrainsCVOS.get(i).getBw()); if (mountainrainsCVOS.get(i).getCenconding() == null) { continue; } if (mountainrainsCVOS.get(i).getSoilval() > 30) { //0.8雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGthours()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } else { //0.5雨量湿度 if (mountainrainsCVOS.get(i).getDrp1() > mountainrainsCVOS.get(i).getGthour()) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } } try { file = "D:/mou.xlsx"; FileOutputStream fout = new FileOutputStream(file); wb.write(fout); fout.close(); wb.close(); } catch (Exception e) { e.printStackTrace(); } Process proc; String[] args1 = new String[]{"python", "D:\\fz\\mou.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(); return R.data(lists); } //第一种方式预警(雨量表数据) else { //当前时间 String times = time; //两个小时前的时间 String dateEnd3 = dateEnds3; 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> list = mountainrainService.selecMoneYi(times, dateEnd3, code); List> lists = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); if (drp1 > 80) { double v = drp1 - 80; double v1 = (double) Math.round(v * 10) / 10; map.put("flage3", "true"); map.put("num", v1); } else { map.put("flage3", "false"); } map.put("List", list.get(i)); lists.add(map); } Timestamp timestamp = new Timestamp(System.currentTimeMillis()); long url = timestamp.getTime(); Map m = new HashMap(); m.put("url", url + ".png"); lists.add(m); 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(new HSSFRichTextString("lon")); cell = row.createCell((short) 1); cell.setCellValue(new HSSFRichTextString("lat")); cell = row.createCell((short) 2); cell.setCellValue(new HSSFRichTextString("rain")); for (int i = 0; i < list.size(); i++) { // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); BigDecimal w1 = (BigDecimal) list.get(i).get("drp1"); double drp1 = w1.doubleValue(); row.createCell((short) 0).setCellValue(list.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(list.get(i).get("LTTD").toString()); if (drp1 > 80) { row.createCell((short) 2).setCellValue(2); continue; } else { row.createCell((short) 2).setCellValue(1); continue; } } // 第六步,将文件存到指定位置 try { fileName = "D:/moup.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\\moup.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(); return R.data(lists); } } /** * 土壤色斑图 */ @GetMapping("/selectS") public R selectS(String time) { List> list = mountainrainService.selectS(time); 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(new HSSFRichTextString("lon")); cell = row.createCell((short) 1); cell.setCellValue(new HSSFRichTextString("lat")); cell = row.createCell((short) 2); cell.setCellValue(new HSSFRichTextString("rain")); for (int i = 0; i < list.size(); i++) { String stcd = list.get(i).get("stcd").toString(); // 第四步,创建单元格,并设置值 row = sheet.createRow((int) i + 1); HSSFCell celli = row.createCell((short) 0); row.createCell((short) 0).setCellValue(list.get(i).get("LGTD").toString()); row.createCell((short) 1).setCellValue(list.get(i).get("LTTD").toString()); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); if (stcd.equals("62455350")) { row.createCell((short) 0).setCellValue("117.344876"); row.createCell((short) 1).setCellValue("27.827067"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62334845")) { row.createCell((short) 0).setCellValue("115.625720"); row.createCell((short) 1).setCellValue("27.152794"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62433800")) { row.createCell((short) 0).setCellValue("115.618546"); row.createCell((short) 1).setCellValue("27.683604"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62436760")) { row.createCell((short) 0).setCellValue("116.060889"); row.createCell((short) 1).setCellValue("28.216806"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62437250")) { row.createCell((short) 0).setCellValue("116.622783"); row.createCell((short) 1).setCellValue("28.489384"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62433700")) { row.createCell((short) 0).setCellValue("115.558771"); row.createCell((short) 1).setCellValue("27.518623"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62425740")) { row.createCell((short) 0).setCellValue("117.208587"); row.createCell((short) 1).setCellValue("27.298647"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62437235")) { row.createCell((short) 0).setCellValue("116.780591"); row.createCell((short) 1).setCellValue("28.391352"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } if (stcd.equals("62437250")) { row.createCell((short) 0).setCellValue("116.555834"); row.createCell((short) 1).setCellValue("28.518077"); row.createCell((short) 2).setCellValue(list.get(i).get("soilval").toString()); } } // 第六步,将文件存到指定位置 try { fileName = "D:/tur.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\\tur.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(); } return R.data(m); } public static Date beforeHourToNowDate(String date, int hours) { Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { c.setTime(sdf.parse(date)); c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) - hours); } catch (Exception e) { e.printStackTrace(); } return c.getTime(); } private static String ss(int i, int j, boolean b) { Calendar calendar = Calendar.getInstance(); if (b) { calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + i); } else { calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - i); } calendar.add(Calendar.DATE, -j); Date today = calendar.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 08:00:00"); String result = format.format(today); return result; } @GetMapping("/cs") public R cs() { for (int c = 2; c < 25; c++) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -c); //得到前一天 Date date = calendar.getTime(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String dateNow = df.format(df.format(date)); int intervals = 31; ArrayList passDaysList = new ArrayList<>(); for (int i = 0; i < intervals; i++) { passDaysList.add(ss(i, c, false)); } Collections.sort(passDaysList); //String s = mountainrainService.selectCode(); 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); for (int i = 0; i < split.length; i++) { Integer num = 30; double v1 = 0; String stcd = null; for (int j = 0; j < passDaysList.size() - 2; j++) { List> map = mountainrainService.selectMtwo(passDaysList.get(j).toString(), passDaysList.get(j + 1).toString(), code); if (map.size() == 0 || i > map.size() - 1) { //stcd=split[i]; break; } BigDecimal w = (BigDecimal) map.get(i).get("drp"); double drp = w.doubleValue(); stcd = map.get(i).get("STCD").toString(); //计算湿度 if (j == 0) { v1 = formatDouble1((num + drp) * 0.85); if (v1 > 60) { v1 = 60; } } else { v1 += drp; v1 = formatDouble1(v1 * 0.85); if (v1 > 60) { v1 = 60; } } } if (stcd != null) { if (v1 > 60) { mountainrainService.soleInster(stcd, "60", dateNow); } else { String a = String.valueOf(v1); mountainrainService.soleInster(stcd, a, dateNow); } } } } return R.data("成功"); } }