Browse Source

公式相关

yangyj 3 years ago
parent
commit
e77dbf9450

+ 3 - 3
blade-common/src/main/java/org/springblade/common/utils/BaseUtils.java

@@ -9,9 +9,7 @@ import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.net.JarURLConnection;
 import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.regex.Matcher;
@@ -36,4 +34,6 @@ public class BaseUtils {
 
 
 
+
+
 }

+ 21 - 25
blade-service/blade-manager/src/main/java/com/mixsmart/utils/CustomFunction.java

@@ -539,7 +539,7 @@ public class CustomFunction {
 	public static String createStation(Object stationType) {
 		if(StringUtils.isNotEmpty(stationType)) {
 
-		    Matcher m =  matcher("[~|-]",handleNull(stationType));
+		    Matcher m =  RegexUtils.matcher("[~|-]",handleNull(stationType));
 		    if(m.find()){
 		    	StringBuilder sb = new StringBuilder();
 		    	String  splitchar = m.group(0);
@@ -557,10 +557,6 @@ public class CustomFunction {
 	    return "";
 	}
 
-	public static Matcher matcher(String regex, String value) {
-		Pattern pattern = Pattern.compile(regex);
-		return pattern.matcher(value);
-	}
 
 	/**
 	 * @Description 记录表5输入桩号代码解析,2G1#1+100>>2G1K0+100
@@ -575,7 +571,7 @@ public class CustomFunction {
 			String stakeStr = StringUtils.repaceBlank(stake.toString().toUpperCase());
 			Matcher m ;
 			if(stake.toString().contains("+")){
-				m = matcher("(([A-Z0-9]*)(#\\d*)?)\\+([\\d||\\.]*)", stakeStr);
+				m = RegexUtils.matcher("(([A-Z0-9]*)(#\\d*)?)\\+([\\d||\\.]*)", stakeStr);
 				if(m.find()){
 					String partNoD = m.group(1);
 					String partNoV = m.group(2);
@@ -585,7 +581,7 @@ public class CustomFunction {
 					result[2]=kilometer;
 				}
 			}else{
-				m =matcher("([A-Z]*)([\\d||\\.]*)", stakeStr);
+				m =RegexUtils.matcher("([A-Z]*)([\\d||\\.]*)", stakeStr);
 				if(m.find()){
 					String partNo = m.group(1);
 					String kilometer = m.group(2);
@@ -602,8 +598,8 @@ public class CustomFunction {
 		String[] result = new String[]{"",""};
 		if(StringUtils.isNotEmpty(stake)){
 			String stakeStr = StringUtils.repaceBlank(stake.toString().toUpperCase());
-			Matcher m  = matcher("([A-Z0-9]{0,3})K(\\d{1,3})\\+([\\d||\\.]*)", stakeStr);
-			Matcher m2  = matcher("([A-Z]{0,3})([\\d||\\.]+)", stakeStr);
+			Matcher m  = RegexUtils.matcher("([A-Z0-9]{0,3})K(\\d{1,3})\\+([\\d||\\.]*)", stakeStr);
+			Matcher m2  = RegexUtils.matcher("([A-Z]{0,3})([\\d||\\.]+)", stakeStr);
 			if(m.find()){
 				String partNo = m.group(1);
 				double km = Double.parseDouble(m.group(2));
@@ -632,7 +628,7 @@ public class CustomFunction {
 			if(StringUtils.isNotEmpty(n)){
 				String[] sa = n.toString().split(",");
 				for(String s:sa){
-					Matcher m = matcher("(\\d)+.(\\d)+",s);
+					Matcher m = RegexUtils.matcher("(\\d)+.(\\d)+",s);
 					if(m.find()){
 						max=Math.max(new StringBuilder(m.group()).reverse().toString().indexOf("."),max);
 					}
@@ -1070,7 +1066,7 @@ public class CustomFunction {
 	 * @Date 2021.09.17 14:31
 	 **/
    public  static boolean containsZH(Object chars){
-		Matcher m =matcher("[\u4e00-\u9fa5]",handleNull(chars));
+		Matcher m =RegexUtils.matcher("[\u4e00-\u9fa5]",handleNull(chars));
 		 return m.find();
    }
 
@@ -1082,7 +1078,7 @@ public class CustomFunction {
 	 * @Date 2021.09.17 14:31
 	 **/
 	public  static boolean containsD(Object chars){
-		Matcher m =matcher("\\d",handleNull(chars));
+		Matcher m =RegexUtils.matcher("\\d",handleNull(chars));
 		return m.find();
 	}
 
@@ -1172,7 +1168,7 @@ public class CustomFunction {
 	 **/
 	public  static  Object dateFormatter(Object date,Object format){
 		if(StringUtils.isNotEmpty(date)&&StringUtils.isNotEmpty(format)){
-			Matcher m =	matcher("(\\d{4})\\D(\\d{2})\\D(\\d{2})日?\\s*(\\d{0,2})(\\D\\d{1,2})?",date.toString());
+			Matcher m =	RegexUtils.matcher("(\\d{4})\\D(\\d{2})\\D(\\d{2})日?\\s*(\\d{0,2})(\\D\\d{1,2})?",date.toString());
             if(m.find()){
                   String yyyy = handleNull(m.group(1));
 				  String MM = handleNull(m.group(2));
@@ -1402,7 +1398,7 @@ public class CustomFunction {
 		}
 		if(!dateStr.contains("-")){
 			dateStr=StringUtils.repaceBlank(dateStr);
-			Matcher m =	matcher("\\d{4}(.)\\d{2}(.)\\d{2}(.?)",dateStr);
+			Matcher m =	RegexUtils.matcher("\\d{4}(.)\\d{2}(.)\\d{2}(.?)",dateStr);
 			if(m.find()){
 				Set<String> set = new HashSet<>();
 				set.add(m.group(1));
@@ -1431,7 +1427,7 @@ public class CustomFunction {
 			return null;
 		}
 		if(!dateStr.contains("-")){
-			Matcher m =	matcher("\\d{4}(.)\\d{2}(.)\\d{2}(日?)",dateStr);
+			Matcher m =	RegexUtils.matcher("\\d{4}(.)\\d{2}(.)\\d{2}(日?)",dateStr);
 			if(m.find()){
 				Set<String> set = new HashSet<>();
 				set.add(m.group(1));
@@ -1511,7 +1507,7 @@ public class CustomFunction {
 
 
 	public static Object k2d(Object k){
-		Matcher mt = matcher("[A-Z]*(\\d*)\\+([\\d|\\.]*)",k.toString());
+		Matcher mt = RegexUtils.matcher("[A-Z]*(\\d*)\\+([\\d|\\.]*)",k.toString());
 		if(mt.find()){
 		   return  Double.parseDouble(mt.group(1))*1000+Double.parseDouble(mt.group(2));
 		}
@@ -2183,7 +2179,7 @@ public class CustomFunction {
 				String s = handleNull(e);
 				if(StringUtils.isNotEmpty(s)){
 					if(containsZH(s)){
-						Matcher m =matcher("[\u4e00-\u9fa5]+(\\d+)\\D*合格(\\d+)\\D+",s);
+						Matcher m =RegexUtils.matcher("[\u4e00-\u9fa5]+(\\d+)\\D*合格(\\d+)\\D+",s);
 						if(m.find()){
 							checkpoints+=Integer.parseInt(m.group(1));
 							passpoints+=Integer.parseInt(m.group(2));
@@ -2598,7 +2594,7 @@ public class CustomFunction {
 			if(!StringUtils.isNumber(scale)){
 				scale=0;
 			}
-			Matcher m = matcher("(-?\\d+(\\.\\d+)?)[h|H]?[,|,](\\+?\\d+(\\.\\d+)?)[h|H]?",dev.toString().replaceAll("[(|)]",""));
+			Matcher m = RegexUtils.matcher("(-?\\d+(\\.\\d+)?)[h|H]?[,|,](\\+?\\d+(\\.\\d+)?)[h|H]?",dev.toString().replaceAll("[(|)]",""));
 			if(list instanceof  List&&m.find()){
 				List<Object> arrayList = (ArrayList<Object>) list;
 				double tick=0;
@@ -2834,7 +2830,7 @@ public class CustomFunction {
 	 * @Date 2021.01.08 16:31
 	 **/
 	public static Object matcherFindGroup(String regex, String value ,int i,boolean g){
-		Matcher m = matcher(regex,value);
+		Matcher m = RegexUtils.matcher(regex,value);
 		List<Object> result = new ArrayList<>();
 		while (m.find()){
 			result.add(m.group(i));
@@ -2881,7 +2877,7 @@ public class CustomFunction {
 					}
 				}else{
 					List<Object> datas = Arrays.asList(o.toString().split("[、, ,]"));
-					Matcher m = matcher("[、, ,]",o.toString());
+					Matcher m = RegexUtils.matcher("[、, ,]",o.toString());
 					String s="、";
 					if(m.find()){
 						s=handleNull(m.group());
@@ -2960,7 +2956,7 @@ public class CustomFunction {
 					for(int i=0;i<stakes.size();i++){
 						  Object cp = stakes.get(i);
                           if(StringUtils.isNotEmpty(cp)&&StringUtils.isNotEquals(bmd,cp)){
-							  Matcher m = matcher("(?i)zd\\d+",cp.toString());
+							  Matcher m = RegexUtils.matcher("(?i)zd\\d+",cp.toString());
 							  if(!m.find()){
 							  	 result.add(dx.get(i));
 							  }
@@ -2981,7 +2977,7 @@ public class CustomFunction {
 				if(StringUtils.isNotEmpty(bmd)){
 					for (Object cp : stakes) {
 						if (StringUtils.isNotEmpty(cp) && StringUtils.isNotEquals(bmd, cp)) {
-							Matcher m = matcher("(?i)zd\\d+", cp.toString());
+							Matcher m = RegexUtils.matcher("(?i)zd\\d+", cp.toString());
 							if (!m.find()) {
 								result.add(cp);
 							}
@@ -3007,7 +3003,7 @@ public class CustomFunction {
 					for(int i=0;i<cds.size();i++){
 						Object cp = cds.get(i);
 						if(StringUtils.isNotEmpty(cp)&&StringUtils.isNotEquals(bmd,cp)){
-							Matcher m = matcher("(?i)zd\\d+",cp.toString());
+							Matcher m = RegexUtils.matcher("(?i)zd\\d+",cp.toString());
 							if(!m.find()){
 								if(StringUtils.isNumber(cp)){
 									result.add("");
@@ -3051,7 +3047,7 @@ public class CustomFunction {
 					for(int i=0;i<cds.size();i++){
 						Object cp = cds.get(i);
 						if(StringUtils.isNotEmpty(cp)&&StringUtils.isNotEquals(bmd,cp)){
-							Matcher m = matcher("(?i)zd\\d+",cp.toString());
+							Matcher m = RegexUtils.matcher("(?i)zd\\d+",cp.toString());
 							if(!m.find()){
 								if(StringUtils.isNumber(cp)){
 									dyn.add(handleNull(dxs.get(i)));
@@ -3084,7 +3080,7 @@ public class CustomFunction {
 					for(int i=0;i<cds.size();i++){
 						Object cp = cds.get(i);
 						if(StringUtils.isNotEmpty(cp)&&StringUtils.isNotEquals(bmd,cp)){
-							Matcher m = matcher("(?i)zd\\d+",cp.toString());
+							Matcher m = RegexUtils.matcher("(?i)zd\\d+",cp.toString());
 							if(!m.find()){
 								if(StringUtils.isEquals(mode,0)){
 									if(!Pattern.matches(".+(?i)v$",cp.toString())){

+ 58 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -0,0 +1,58 @@
+package com.mixsmart.utils;
+
+
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author yangyj
+ * @Date 2022/7/14 15:55
+ * @description TODO
+ */
+public class FormulaUtils {
+    public static Map<String,Object> triangleSquare(Object ranges){
+        Map<String,Object> map =new HashMap<>();
+        if(StringUtils.isEmpty(ranges)){
+            //z的默认取值范围
+            ranges="(0,15)";
+        }
+        Matcher m = RegexUtils.matcher("[\\(||\\[](\\d*)(\\D)(\\d*)[\\)||\\]]",ranges.toString());
+        m.find();
+        Random rm = new Random();
+        int min = StringUtils.handObj2Integer(m.group(1));
+        int max = StringUtils.handObj2Integer(m.group(3));
+        Integer[] r= pythagorean(min,max);
+        map.put("X",String.valueOf(r[0]));
+        map.put("Y",String.valueOf(r[1]));
+        map.put("Z", String.valueOf(r[2]));
+        return map;
+    }
+
+    /**
+     * result[0]^2+result[1]^2=result[2]^2  result[] 元素均为正整数
+     */
+    public static Integer[] pythagorean(Integer min,Integer max){
+        Integer[] result = null;
+        List<Integer[]> list = new ArrayList<>();
+        for(int i=1;i<=max;i++){
+            for(int j=1;j<=max;j++){
+                double tmp = Math.sqrt(Math.pow(i,2)+Math.pow(j,2));
+                int z= (int) Math.round(tmp);
+
+                if(min<z&&z<=max){
+                    Integer[] arr = new Integer[]{ i,j,z};
+                    list.add(arr);
+                }
+            }
+        }
+        if(ListUtils.isNotEmpty(list)){
+            Random rm = new Random();
+            result = list.get(rm.nextInt(list.size()));
+        }
+        return result;
+    }
+
+
+
+}

+ 17 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/RegexUtils.java

@@ -0,0 +1,17 @@
+package com.mixsmart.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author yangyj
+ * @Date 2022/7/14 15:56
+ * @description TODO
+ */
+public class RegexUtils {
+
+    public static Matcher matcher(String regex, String value) {
+        Pattern pattern = Pattern.compile(regex);
+        return pattern.matcher(value);
+    }
+}