From 4513ef24bf9b188c2a77d6ce94f1a6b7e9ebf0e6 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期日, 27 四月 2025 20:40:19 +0800 Subject: [PATCH] fix(irrigatePlan): 修正灌溉计划开始时间逻辑 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/NumUtil.java | 246 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 246 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/NumUtil.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/NumUtil.java new file mode 100644 index 0000000..eaf5d63 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/NumUtil.java @@ -0,0 +1,246 @@ +package com.dy.common.util; + +@SuppressWarnings("unused") +public class NumUtil { + /** + * 鍒ゆ柇鏄惁鏄鏁存暟 + * @param str String + * @return boolean + */ + public static boolean isPlusIntNumber(String str) { + if(str == null || str.trim().equals("")){ + return false ; + } + int n = 0 ; + String token = "9876543210"; + for (int i = n; i < str.length(); i++) { + if (!token.contains(str.substring(i, i + 1))) { + return false; + } + } + return true; + } + /** + * 鍒ゆ柇鏄惁鏄暣鏁� + * + * @param str String + * @return boolean + */ + public static boolean isIntNumber(String str) { + // 鍒ゆ柇鏄惁鏄暟瀛� + if(str == null || str.trim().equals("")) + return false ; + + if(str.startsWith("-")){ + str = str.substring(1) ; + } + String token = "9876543210" ; + for (int i = 0; i < str.length(); i++) { + if (!token.contains(str.substring(i, i + 1))) { + return false; + } + } + return true; + } + /** + * 鍒ゆ柇鏄惁鏄暣鏁� + * + * @param str String + * @return boolean + */ + public static boolean isHex(String str) { + // 鍒ゆ柇鏄惁鏄暟瀛� + if(str == null || str.trim().equals("")) + return false ; + if(str.length()%2 != 0) + return false ; + + String token = "9876543210abcdefABCDEF" ; + for (int i = 0; i < str.length(); i++) { + if (!token.contains(str.substring(i, i + 1))) { + return false; + } + } + return true; + } + + /** + * 鍒ゆ柇鏄惁鏄诞鐐规暟 + * @param str String + * @return boolean + */ + public static boolean isDoubleNumber(String str) { + // 鍒ゆ柇鏄惁鏄暟瀛� + if(str == null || str.trim().equals("")){ + return false ; + } + String token = "9876543210.-" ; + for (int i = 0; i < str.length(); i++) { + if (!token.contains(str.substring(i, i + 1))) { + return false; + } + } + if(str.startsWith(".") || str.endsWith(".")){ + return false ; + }else{ + if(str.indexOf('.') != str.lastIndexOf('.')){ + return false ; + } + } + if(str.startsWith("-")){ + return str.indexOf('-') == str.lastIndexOf('-'); + } + return true; + } + /** + * 鍒ゆ柇鏄惁鏄娴偣鏁� + * @param str String + * @return boolean + */ + public static boolean isPlusDoubleNumber(String str) { + // 鍒ゆ柇鏄惁鏄暟瀛� + if(str == null || str.trim().equals("")){ + return false ; + } + String token = "9876543210." ; + for (int i = 0; i < str.length(); i++) { + if (!token.contains(str.substring(i, i + 1))) { + return false; + } + } + if(str.startsWith(".") || str.endsWith(".")){ + return false ; + }else{ + if(str.indexOf('.') != str.lastIndexOf('.')){ + return false ; + } + } + if(str.startsWith("-")){ + return str.indexOf('-') == str.lastIndexOf('-'); + } + return true; + } + + /** + * 娴偣鏁板洓鑸嶄簲鍏� + * @param d 娴偣鏁版嵁 + * @param scale 灏忔暟浣嶆暟 + * @return 鍥涜垗浜斿叆鍚庣殑娴偣鏁� + */ + public static Double roundDouble(Double d , int scale){ + if(d == null){ + return null ; + } + return Double.valueOf(new java.text.DecimalFormat("##." + "0".repeat(Math.max(0, scale))).format(d)) ; + } + + /** + * 娴偣鏁板洓鑸嶄簲鍏� + * @param d 娴偣鏁版嵁 + * @param scale 灏忔暟浣嶆暟 + * @return 鍥涜垗浜斿叆鍚庣殑娴偣鏁� + */ + public static String roundDoubleStr(Double d , int scale){ + if(d == null){ + return null ; + } + return new java.text.DecimalFormat("#0." + "0".repeat(Math.max(0, scale))).format(d); + } + + + /** + * 娴偣鏁板洓鑸嶄簲鍏� + * @param d 娴偣鏁版嵁 + * @param scale 灏忔暟浣嶆暟 + * @return 鍥涜垗浜斿叆鍚庣殑娴偣鏁� + */ + public static Float roundFloat(Float d , int scale){ + if(d == null){ + return null ; + } + // StringBuilder temp = new StringBuilder("."); + // temp.append("0".repeat(Math.max(0, scale))); + // return Float.valueOf(new java.text.DecimalFormat(temp.toString()).format(d)) ; + return Float.valueOf(new java.text.DecimalFormat("." + "0".repeat(Math.max(0, scale))).format(d)) ; + } + + /** + * 娴偣鏁板洓鑸嶄簲鍏� + * @param d 娴偣鏁版嵁 + * @return 鍥涜垗浜斿叆鍚庣殑娴偣鏁� + */ + public static Float roundFloat(Float d){ + if(d == null){ + return null ; + } + return Float.valueOf(new java.text.DecimalFormat(".00").format(d)) ; + } + + + /** + * 鍐掓场鎺掑簭锛� + * @param values 瑕佹帓搴忕殑鏁扮粍 + * @param up true 浠庡皬鍒板ぇ false 浠庡ぇ鍒板皬 + * @return 鎺掑簭鍚庣殑鏁扮粍 + */ + public static int[] sort(int[] values , boolean up){ + boolean changed; + int temp; + int end = 0 ; + for (int i = 0; i < values.length; ++i) { + changed = false ; + end++ ; + for (int j = 0; j < values.length - end ; ++j) { + if(up){ + if (values[j] > values[j + 1]) { + temp = values[j]; + values[j] = values[j + 1]; + values[j + 1] = temp; + changed = true ; + } + }else{ + if (values[j] < values[j + 1]) { + temp = values[j]; + values[j] = values[j + 1]; + values[j + 1] = temp; + changed = true ; + } + } + } + if(!changed){ + break ; + } + } + return values ; + } + /** + * 鎶婃暟鎹墠闈㈢殑0鍘绘帀 + * + * @param s String + * @return String + */ + public String clean0FromStrNum(String s) { + while (s.charAt(0) == '0' && s.length() > 1) { + s = s.substring(1); + } + return s; + } + + /** + * 鍘绘帀灏忔暟鐐� + * + * @param value String + * @return String + */ + public String cleanDotNumber(String value) { + int dot = value.indexOf('.'); + if (dot < 0) { + return value; + } + if (value.length() - dot - 1 > 2) { + value = value.substring(0, dot); + } + return value; + } + +} -- Gitblit v1.8.0