| | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import liquibase.pro.packaged.S; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.boot.ctrl.BladeController; |
| | | import org.springblade.core.log.annotation.ApiLog; |
| | |
| | | import org.springblade.modules.river.wrapper.RiverRWrapper; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | String hss = time.substring(11, 13); |
| | | int hs = Integer.parseInt(hss); |
| | | //前一天的8时 |
| | | String timec = years + "-" + months + "-" + da + " 08:00:00"; |
| | | //String timec = years + "-" + months + "-" + da + " 08:00:00"; |
| | | SimpleDateFormat sdfs=new SimpleDateFormat("yyyy-MM-dd 08:00:00"); |
| | | Calendar now = Calendar.getInstance(); |
| | | now.setTime(new Date()); |
| | | now.add(Calendar.DAY_OF_MONTH, -1); |
| | | String timec = sdfs.format(now.getTime()); |
| | | //前24小时 |
| | | Calendar calendar6 = Calendar.getInstance(); |
| | | calendar6.set(Calendar.HOUR_OF_DAY, calendar6.get(Calendar.HOUR_OF_DAY) - 24); |
| | |
| | | //定义List保存未警戒信息 |
| | | List blist = new ArrayList(); |
| | | //河道超警信息 |
| | | List<Map<String, Object>> selecthd = riverRService.selecthdt(dateBegin24, time); |
| | | List<Map<String, Object>> selecthd = riverRService.selecthdt(dateBegin24, time, timec); |
| | | //Map<String, Object> sel = riverRService.sel(); |
| | | //selecthd.add(sel); |
| | | List<Map<String, Object>> list1 = riverRService.selectP(); |
| | |
| | | texta += "流量暂无数据;"; |
| | | } else { |
| | | //DecimalFormat dfl = new DecimalFormat("#0.000"); |
| | | texta += "流量" + Q + "立方米每秒;"; |
| | | double v5 = roundToSignificantFigures(Q, 3); |
| | | String a = String.valueOf(v5); |
| | | String s1 = subZeroAndDot(a); |
| | | texta += "流量" + s1 + "立方米每秒;"; |
| | | } |
| | | } |
| | | blist.add(selecthd.get(i)); |
| | |
| | | if (selecthd.get(i).get("Q") == null) { |
| | | texta += "流量暂无数据、"; |
| | | } else { |
| | | DecimalFormat dfl = new DecimalFormat("#0.000"); |
| | | texta += "流量" + Q + "立方米每秒;"; |
| | | //DecimalFormat dfl = new DecimalFormat("#0.000"); |
| | | //texta += "流量" + Q + "立方米每秒;"; |
| | | double v5 = roundToSignificantFigures(Q, 3); |
| | | String a = String.valueOf(v5); |
| | | String s1 = subZeroAndDot(a); |
| | | texta += "流量" + s1 + "立方米每秒;"; |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public static double roundToSignificantFigures(double num, int n) { |
| | | |
| | | if (num == 0) { |
| | | |
| | | return 0; |
| | | |
| | | } |
| | | |
| | | final double d = Math.ceil(Math.log10(num < 0 ? -num : num)); |
| | | |
| | | final int power = n - (int) d; |
| | | |
| | | final double magnitude = Math.pow(10, power); |
| | | |
| | | final long shifted = Math.round(num * magnitude); |
| | | |
| | | return shifted / magnitude; |
| | | |
| | | } |
| | | |
| | | public static String subZeroAndDot(String s) { |
| | | if (s.indexOf(".") > 0) { |
| | | s = s.replaceAll("0+?$", "");//去掉多余的0 |
| | | s = s.replaceAll("[.]$", "");//如最后一位是.则去掉 |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | // @PostMapping("/ss") |
| | | // public void ss() { |
| | | // String s = riverRService.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); |
| | | // System.out.println(code); |
| | | // } |
| | | |
| | | // /** |
| | | // * 河道自定义时间查询 |
| | | // * |
| | | // * @param beginTime |
| | | // * @param endTime |
| | | // * @return |
| | | // * @throws ParseException |
| | | // */ |
| | | // @PostMapping("/selecthd") |
| | | // public R selecthd(String beginTime, String endTime) throws ParseException { |
| | | // String substring = beginTime.substring(0, 10); |
| | | // String substrings = endTime.substring(0, 10); |
| | | // String t = beginTime.substring(11, 13); |
| | | // String hs; |
| | | // if (t.substring(0, 1).equals("0")) { |
| | | // hs = beginTime.substring(12, 13); |
| | | // } else { |
| | | // hs = beginTime.substring(11, 13); |
| | | // } |
| | | // String ts = endTime.substring(11, 13); |
| | | // String hss; |
| | | // if (ts.substring(0, 1).equals("0")) { |
| | | // hss = beginTime.substring(12, 13); |
| | | // } else { |
| | | // hss = beginTime.substring(11, 13); |
| | | // } |
| | | // //截取月日 |
| | | // String[] strs = substring.split("-"); |
| | | // //月 |
| | | // String year = strs[1].toString(); |
| | | // //日 |
| | | // String day = strs[2].toString(); |
| | | // //截取月日 |
| | | // String[] strss = substrings.split("-"); |
| | | // //月 |
| | | // String years = strss[1].toString(); |
| | | // //日 |
| | | // String days = strss[2].toString(); |
| | | // //定义短信内容头 |
| | | // String text = year + "月" + day + "日" + hs + "时" + "-" + years + "月" + days + "日" + hss + "时"; |
| | | // String texta = ""; |
| | | // //定义统计数量 |
| | | // int number = 0; |
| | | // //河道超警信息 |
| | | // List<Map<String, Object>> selecthd = riverRService.selecthdcs(beginTime, endTime); |
| | | // //Map<String, Object> sel = riverRService.sel(); |
| | | // //selecthd.add(sel); |
| | | // //基本站信息 |
| | | // List<Map<String, Object>> list1 = riverRService.selectP(); |
| | | // //用来判断是否重复统计超警信息 |
| | | // Map mnum = new HashMap(); |
| | | // Map mnums = new HashMap(); |
| | | // //定义list保存预警信息 |
| | | // List ylist = new ArrayList(); |
| | | // //定义list保存未预警信息 |
| | | // List alist = new ArrayList(); |
| | | // Map m1 = new HashMap(); |
| | | // Map m2 = new HashMap(); |
| | | // Map czf = new HashMap(); |
| | | // Map m = new HashMap(); |
| | | // List list = new ArrayList(); |
| | | // //查询数据为空 |
| | | // if (selecthd.size() == 0) { |
| | | // text += "暂无河道超警信息。廖家湾水位暂无数据,流量暂无数据;娄家村水位暂无数据,流量暂无数据;"; |
| | | // } |
| | | // //不为空遍历数据计算是否超出预警值 |
| | | // else { |
| | | // int c = 0; |
| | | // for (int i = 0; i < selecthd.size(); i++) { |
| | | // //实时河道水位值 |
| | | // BigDecimal z = (BigDecimal) selecthd.get(i).get("Z"); |
| | | // double Z = z.doubleValue(); |
| | | // String stcd = selecthd.get(i).get("STCD").toString(); |
| | | // //站点名称 |
| | | // String stnms = selecthd.get(i).get("STNM").toString(); |
| | | // //最大值 |
| | | // BigDecimal maxZ = (BigDecimal) selecthd.get(i).get("maxZ"); |
| | | // //最小值 |
| | | // BigDecimal minZ = (BigDecimal) selecthd.get(i).get("minZ"); |
| | | // double v = maxZ.doubleValue(); |
| | | // double v1 = minZ.doubleValue(); |
| | | // //涨幅值 |
| | | // double v2 = v - v1; |
| | | // double v4 = (double) Math.round(v2 * 100) / 100; |
| | | // m1.put(v4, stnms.replaceAll(" ", "") + "站"); |
| | | // czf.put(stcd, v4); |
| | | // //超警戒水位值 |
| | | // if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) { |
| | | // } else { |
| | | // if (selecthd.get(i).get("WRZ") == null || selecthd.get(i).get("Q") == null) { |
| | | // String stnm = selecthd.get(i).get("STNM").toString(); |
| | | // mnum.put(selecthd.get(i).get("STCD").toString(), i); |
| | | // if (stnm.equals("廖家湾") || stnm.equals("娄家村")) { |
| | | // DecimalFormat df = new DecimalFormat("#0.00"); |
| | | // texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,"; |
| | | // if (selecthd.get(i).get("Q") == null) { |
| | | // texta += "流量暂无数据"; |
| | | // } |
| | | // } |
| | | // alist.add(selecthd.get(i)); |
| | | // continue; |
| | | // } |
| | | // BigDecimal wrz = (BigDecimal) selecthd.get(i).get("WRZ"); |
| | | // double WRZ = wrz.doubleValue(); |
| | | // BigDecimal q = (BigDecimal) selecthd.get(i).get("Q"); |
| | | // double Q = q.doubleValue(); |
| | | // if (Z <= WRZ) { |
| | | // if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) { |
| | | // } else { |
| | | // String stnm = selecthd.get(i).get("STNM").toString(); |
| | | // mnum.put(selecthd.get(i).get("STCD").toString(), i); |
| | | // if (stnm.equals("廖家湾") || stnm.equals("娄家村")) { |
| | | // DecimalFormat df = new DecimalFormat("#0.00"); |
| | | // texta += stnm.replaceAll(" ", "") + "水位" + df.format(Z) + "米,"; |
| | | // if (selecthd.get(i).get("Q") == null) { |
| | | // texta += "流量暂无数据"; |
| | | // } else { |
| | | // double v5 = roundToSignificantFigures(Q, 3); |
| | | // String a = String.valueOf(v5); |
| | | // String s1 = subZeroAndDot(a); |
| | | // texta += "流量" + s1 + "立方米每秒;"; |
| | | // } |
| | | // } |
| | | // } |
| | | // alist.add(selecthd.get(i)); |
| | | // } else { |
| | | // //如果map集合保存了站点则不重复统计数量 |
| | | // if (mnum.containsKey(selecthd.get(i).get("STCD").toString()) == true) { |
| | | // } else { |
| | | // ylist.add(selecthd.get(i)); |
| | | // mnum.put(selecthd.get(i).get("STCD").toString(), i); |
| | | // number++; |
| | | // //超出警戒水位多少 |
| | | // Double num = Z - WRZ; |
| | | // double v3 = (double) Math.round(num * 100) / 100; |
| | | // //县,市 |
| | | // String addvcd5 = selecthd.get(i).get("ADDVNM").toString(); |
| | | // //站点名称 |
| | | // String stnm = selecthd.get(i).get("STNM").toString(); |
| | | // if (stnm.equals("廖家湾") || stnm.equals("娄家村")) { |
| | | // DecimalFormat df = new DecimalFormat("#0.00"); |
| | | // texta += stnm.replaceAll(" ", "") + "站超出警戒水位" + df.format(v3) + "米," + "水位" + df.format(Z) + "米,"; |
| | | // if (selecthd.get(i).get("Q") == null) { |
| | | // texta += "流量暂无数据;"; |
| | | // } else { |
| | | // //DecimalFormat dfs = new DecimalFormat("#0.000"); |
| | | // double v5 = roundToSignificantFigures(Q, 3); |
| | | // String a = String.valueOf(v5); |
| | | // String s1 = subZeroAndDot(a); |
| | | // texta += "流量" + s1 + "立方米每秒;"; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | // if (number == 0) { |
| | | // text += "暂无河道超警戒信息。" + texta; |
| | | // } else { |
| | | // text += "有" + number + "个河道站超警戒。" + texta; |
| | | // } |
| | | // if (m1.size() != 0) { |
| | | // Object maxKey = getMaxKey(m1); |
| | | // String s1 = m1.get(maxKey).toString(); |
| | | // text += " 涨幅最大的是:" + s1 + "(涨" + maxKey + "米)。"; |
| | | // } |
| | | // m.put("text", text); |
| | | // m.put("number", number); |
| | | // m.put("Yjlist", ylist); |
| | | // m.put("list", alist); |
| | | // m.put("list1", list1); |
| | | // m.put("clist", czf); |
| | | // list.add(m); |
| | | // return R.data(list); |
| | | // |
| | | // } |
| | | |
| | | /** |
| | | * 河道自定义时间查询 |
| | |
| | | public R selecthd(String beginTime, String endTime) throws ParseException { |
| | | String substring = beginTime.substring(0, 10); |
| | | String substrings = endTime.substring(0, 10); |
| | | String hs = beginTime.substring(11, 13); |
| | | String hss = endTime.substring(11, 13); |
| | | String t = beginTime.substring(11, 13); |
| | | String hs; |
| | | if (t.substring(0, 1).equals("0")) { |
| | | hs = beginTime.substring(12, 13); |
| | | } else { |
| | | hs = beginTime.substring(11, 13); |
| | | } |
| | | String ts = endTime.substring(11, 13); |
| | | String hss; |
| | | if (ts.substring(0, 1).equals("0")) { |
| | | hss = beginTime.substring(12, 13); |
| | | } else { |
| | | hss = beginTime.substring(11, 13); |
| | | } |
| | | //截取月日 |
| | | String[] strs = substring.split("-"); |
| | | //月 |
| | |
| | | String texta = ""; |
| | | //定义统计数量 |
| | | int number = 0; |
| | | String s = riverRService.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>> selecthd = riverRService.selecthdcs(beginTime, endTime); |
| | | //Map<String, Object> sel = riverRService.sel(); |
| | | //selecthd.add(sel); |
| | | List<Map<String, Object>> selecthd = riverRService.selecthdcss(beginTime, endTime,code); |
| | | Collections.sort(selecthd, new Comparator<Map<String, Object>>() { |
| | | public int compare(Map<String, Object> o1, Map<String, Object> o2) { |
| | | Double name1 = Double.valueOf(o1.get("Z").toString()) ;//name1是从你list里面拿出来的一个 |
| | | Double name2 = Double.valueOf(o2.get("Z").toString()) ; //name1是从你list里面拿出来的第二个name |
| | | return name2.compareTo(name1); |
| | | } |
| | | }); |
| | | //基本站信息 |
| | | List<Map<String, Object>> list1 = riverRService.selectP(); |
| | | //用来判断是否重复统计超警信息 |
| | |
| | | if (selecthd.get(i).get("Q") == null) { |
| | | texta += "流量暂无数据"; |
| | | } else { |
| | | DecimalFormat dfs = new DecimalFormat("#0.000"); |
| | | texta += "流量" + Q + "立方米每秒;"; |
| | | double v5 = roundToSignificantFigures(Q, 3); |
| | | String a = String.valueOf(v5); |
| | | String s1 = subZeroAndDot(a); |
| | | texta += "流量" + s1 + "立方米每秒;"; |
| | | } |
| | | } |
| | | } |
| | |
| | | texta += "流量暂无数据;"; |
| | | } else { |
| | | //DecimalFormat dfs = new DecimalFormat("#0.000"); |
| | | texta += "流量" + Q + "立方米每秒;"; |
| | | double v5 = roundToSignificantFigures(Q, 3); |
| | | String a = String.valueOf(v5); |
| | | String s1 = subZeroAndDot(a); |
| | | texta += "流量" + s1 + "立方米每秒;"; |
| | | } |
| | | } |
| | | } |
| | |
| | | return R.data(list); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // @PostMapping("/ss") |
| | | // public R ss(String beginTime, String endTime) { |
| | | // String s = riverRService.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>> list = riverRService.selecthdcss(beginTime, endTime, code); |
| | | // Collections.sort(list, new Comparator<Map<String, Object>>() { |
| | | // public int compare(Map<String, Object> o1, Map<String, Object> o2) { |
| | | // Double name1 = Double.valueOf(o1.get("Z").toString()) ;//name1是从你list里面拿出来的一个 |
| | | // Double name2 = Double.valueOf(o2.get("Z").toString()) ; //name1是从你list里面拿出来的第二个name |
| | | // return name2.compareTo(name1); |
| | | // } |
| | | // }); |
| | | // return R.data(list); |
| | | // } |
| | | } |