From 87204491aac135822f96f3fff297ddca400ea8c9 Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Wed, 20 Oct 2021 15:09:32 +0800
Subject: [PATCH] 1.山洪

---
 src/main/java/org/springblade/modules/rsvr/controller/RsvrRController.java |  126 +++++++++++++++++++++++++++++++-----------
 1 files changed, 93 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/springblade/modules/rsvr/controller/RsvrRController.java b/src/main/java/org/springblade/modules/rsvr/controller/RsvrRController.java
index 931b57c..6c4a99d 100644
--- a/src/main/java/org/springblade/modules/rsvr/controller/RsvrRController.java
+++ b/src/main/java/org/springblade/modules/rsvr/controller/RsvrRController.java
@@ -172,17 +172,17 @@
 				edmd = e2;
 			}
 		}
-//		String s = rsvrRService.selectCode(beginTime, endTime);
-//		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);
+		String s = rsvrRService.selectCode(beginTime, endTime);
+		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>> map = rsvrRService.selectyjck(egmd, edmd, beginTime, endTime);
-//		List<Map<String, Object>> sel = rsvrRService.sel(egmd, edmd, code);
-//		map.addAll(sel);
+		List<Map<String, Object>> sel = rsvrRService.sel(egmd, edmd, code);
+		map.addAll(sel);
 		//用来判断是否重复统计超警信息
 		Map mnum = new HashMap();
 		Map mnums = new HashMap();
@@ -228,7 +228,8 @@
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texta += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texta += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texta += "蓄水量暂无数据、";
@@ -243,7 +244,8 @@
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texta += "出库流量" + OTQ + "立方米每秒;";
+								String vc  = formatSignificantDigit(OTQ);
+								texta += "出库流量" + vc + "立方米每秒;";
 							}
 						}
 						if (stnm.equals("廖坊")) {
@@ -260,7 +262,8 @@
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texth += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texth += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texth += "蓄水量暂无数据、";
@@ -275,7 +278,8 @@
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texth += "出库流量" + OTQ + "立方米每秒。";
+								String vc  = formatSignificantDigit(OTQ);
+								texth += "出库流量" + vc + "立方米每秒。";
 							}
 						}
 						alist.add(map.get(i));
@@ -295,7 +299,8 @@
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texta += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texta += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texta += "蓄水量暂无数据、";
@@ -310,7 +315,8 @@
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texta += "出库流量" + OTQ + "立方米每秒;";
+								String vc  = formatSignificantDigit(OTQ);
+								texta += "出库流量" + vc + "立方米每秒;";
 							}
 						}
 						if (stnm.equals("廖坊")) {
@@ -321,7 +327,8 @@
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texth += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texth += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texth += "蓄水量暂无数据、";
@@ -336,7 +343,8 @@
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
 								//DecimalFormat df = new DecimalFormat("#0.000");
-								texth += "出库流量" + OTQ + "立方米每秒。";
+								String vc  = formatSignificantDigit(OTQ);
+								texth += "出库流量" + vc + "立方米每秒。";
 							}
 						}
 						alist.add(map.get(i));
@@ -362,7 +370,8 @@
 									BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 									double INQ = inq.doubleValue();
 									//DecimalFormat df = new DecimalFormat("#0.000");
-									texta += "入库流量" + INQ + "立方米每秒、";
+									String vc  = formatSignificantDigit(INQ);
+									texta += "入库流量" + vc + "立方米每秒、";
 								}
 								if (map.get(i).get("W") == null) {
 									texta += "蓄水量暂无数据、";
@@ -377,7 +386,8 @@
 									BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 									double OTQ = otq.doubleValue();
 									//DecimalFormat df = new DecimalFormat("#0.000");
-									texta += "出库流量" + OTQ + "立方米每秒;";
+									String vc  = formatSignificantDigit(OTQ);
+									texta += "出库流量" + vc + "立方米每秒;";
 								}
 							}
 							if (stnm.equals("廖坊")) {
@@ -388,7 +398,8 @@
 									BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 									double INQ = inq.doubleValue();
 									//DecimalFormat df = new DecimalFormat("#0.000");
-									texth += "入库流量" + INQ + "立方米每秒、";
+									String vc  = formatSignificantDigit(INQ);
+									texth += "入库流量" + vc + "立方米每秒、";
 								}
 								if (map.get(i).get("W") == null) {
 									texth += "蓄水量暂无数据、";
@@ -403,7 +414,8 @@
 									BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 									double OTQ = otq.doubleValue();
 									//DecimalFormat df = new DecimalFormat("#0");
-									texth += "出库流量" + OTQ + "立方米每秒。";
+									String vc  = formatSignificantDigit(OTQ);
+									texth += "出库流量" + vc + "立方米每秒。";
 								}
 							}
 						}
@@ -593,7 +605,8 @@
 						} else {
 							BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 							double INQ = inq.doubleValue();
-							texta += "入库流量" + INQ + "立方米每秒、";
+							String vc  = formatSignificantDigit(INQ);
+							texta += "入库流量" + vc + "立方米每秒、";
 						}
 						if (map.get(i).get("W") == null) {
 							texta += "蓄水量暂无数据、";
@@ -607,7 +620,8 @@
 						} else {
 							BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 							double OTQ = otq.doubleValue();
-							texta += "出库流量" + OTQ + "立方米每秒;";
+							String vc  = formatSignificantDigit(OTQ);
+							texta += "出库流量" + vc + "立方米每秒;";
 						}
 //						texta += "汛限水位暂无数据;";
 					} else if (stnm.equals("廖坊")) {
@@ -627,7 +641,8 @@
 						} else {
 							BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 							double INQ = inq.doubleValue();
-							texth += "入库流量" + INQ + "立方米每秒、";
+							String vc  = formatSignificantDigit(INQ);
+							texth += "入库流量" + vc + "立方米每秒、";
 						}
 						if (map.get(i).get("W") == null) {
 							texth += "蓄水量暂无数据、";
@@ -641,7 +656,8 @@
 						} else {
 							BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 							double OTQ = otq.doubleValue();
-							texth += "出库流量" + OTQ + "立方米每秒。";
+							String vc  = formatSignificantDigit(OTQ);
+							texth += "出库流量" + vc + "立方米每秒。";
 						}
 					}
 					blist.add(map.get(i));
@@ -672,7 +688,8 @@
 						} else {
 							BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 							double INQ = inq.doubleValue();
-							texta += "入库流量" + INQ + "立方米每秒、";
+							String vc  = formatSignificantDigit(INQ);
+							texta += "入库流量" + vc + "立方米每秒、";
 						}
 						if (map.get(i).get("W") == null) {
 							texta += "蓄水量暂无数据、";
@@ -686,7 +703,8 @@
 						} else {
 							BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 							double OTQ = otq.doubleValue();
-							texta += "出库流量" + OTQ + "立方米每秒;";
+							String vc  = formatSignificantDigit(OTQ);
+							texta += "出库流量" + vc + "立方米每秒;";
 						}
 //						texta += "汛限水位暂无数据;";
 					} else if (stnm.equals("廖坊")) {
@@ -706,7 +724,8 @@
 						} else {
 							BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 							double INQ = inq.doubleValue();
-							texth += "入库流量" + INQ + "立方米每秒、";
+							String vc  = formatSignificantDigit(INQ);
+							texth += "入库流量" + vc + "立方米每秒、";
 						}
 						if (map.get(i).get("W") == null) {
 							texth += "蓄水量暂无数据、";
@@ -720,7 +739,8 @@
 						} else {
 							BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 							double OTQ = otq.doubleValue();
-							texth += "出库流量" + OTQ + "立方米每秒。";
+							String vc  = formatSignificantDigit(OTQ);
+							texth += "出库流量" + vc + "立方米每秒。";
 						}
 					}
 					blist.add(map.get(i));
@@ -756,7 +776,8 @@
 							} else {
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
-								texta += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texta += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texta += "蓄水量暂无数据、";
@@ -770,7 +791,8 @@
 							} else {
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
-								texta += "出库流量" + OTQ + "立方米每秒;";
+								String vc  = formatSignificantDigit(OTQ);
+								texta += "出库流量" + vc + "立方米每秒;";
 							}
 //						texta += "汛限水位暂无数据;";
 						} else if (stnm.equals("廖坊")) {
@@ -790,7 +812,8 @@
 							} else {
 								BigDecimal inq = (BigDecimal) map.get(i).get("INQ");
 								double INQ = inq.doubleValue();
-								texth += "入库流量" + INQ + "立方米每秒、";
+								String vc  = formatSignificantDigit(INQ);
+								texth += "入库流量" + vc + "立方米每秒、";
 							}
 							if (map.get(i).get("W") == null) {
 								texth += "蓄水量暂无数据、";
@@ -804,7 +827,8 @@
 							} else {
 								BigDecimal otq = (BigDecimal) map.get(i).get("OTQ");
 								double OTQ = otq.doubleValue();
-								texth += "出库流量" + OTQ + "立方米每秒。";
+								String vc  = formatSignificantDigit(OTQ);
+								texth += "出库流量" + vc + "立方米每秒。";
 							}
 						}
 					}
@@ -1020,5 +1044,41 @@
 		return R.data(lists);
 	}
 
+	public static int magnitude(Double price){
+		if (price == 0.0) {return 0;}
+		int fac;
+		Long i;
+		Long k = 10L;
+		if (price > 1) {
+			i = price.longValue();
+			fac = 0;
+			while (i / k != 0L) {
+				fac++;
+				k *= 10;
+			}
+		} else {
+			fac = -1;
+			while (price * k < 1) {
+				fac--;
+				k *= 10;
+			}
+		}
+		return fac;
+	}
+	/**
+	 * 数字格式化 - 最少保留{num}位有效数字 - 保留 {min}~{max} 为小数 - format02
+	 */
+	public static String formatSignificantDigit(Double price) {
+		int min = 2;
+		int max= 8;
+		int num = 3;
+		boolean sign = false;
+		Double rate = 1.0;
+		Double value = price * rate;
+		int level = magnitude(Math.abs(value));
+		int count = Math.max(min, Math.min(max, num - level - 1));
+		return String.format("%"+(sign?"+": "")+"."+count + "f", value);
+	}
+
 }
 

--
Gitblit v1.9.3