|
@@ -1,7 +1,13 @@
|
|
|
package com.diagbot.util;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+
|
|
|
/**
|
|
|
* @description: 校验工具类
|
|
|
* @author: zhoutg
|
|
@@ -29,4 +35,50 @@ public class VerifyUtil {
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(verifyCode("1", "1.01"));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 校验公式编码
|
|
|
+ * @param coding 编码
|
|
|
+ * @param str 公式
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean checkCodeEquation(List<String> coding, String str) {
|
|
|
+ boolean res = false;
|
|
|
+ // 分割出所有的数字
|
|
|
+ String[] split = str.split("\\+");
|
|
|
+ String[] digitalSplit = str.split("[+ ( / ) 任 一 二 三 四 五 六 七 八 九 十 ]");
|
|
|
+ List<String> numberList = new ArrayList<String>();
|
|
|
+ for (int i = 0; i < digitalSplit.length; i++) {
|
|
|
+ if (!digitalSplit[i].equals("")) {
|
|
|
+ numberList.add(digitalSplit[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ res = coding.containsAll(numberList);
|
|
|
+ if (res == true) {
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String str1 = split[i].substring(0, split[i].indexOf(")") + 1);
|
|
|
+ // 检查是否以括号开头,以括号结尾
|
|
|
+ boolean start = str1.startsWith("(");
|
|
|
+ boolean end = str1.endsWith(")");
|
|
|
+
|
|
|
+ if (start == false || end == false) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "公式格式有误");
|
|
|
+ }
|
|
|
+ String str2 = split[i].substring(split[i].indexOf(")") + 1);
|
|
|
+ String[] array = { "任一", "任二", "任三", "任四", "任五", "任六", "任七", "任八", "任九", "任十" };
|
|
|
+ if (str2.length() > 0) {
|
|
|
+ boolean pp = Arrays.asList(array).contains(str2);
|
|
|
+ if (pp == false) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "公式格式有误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "公式格式有误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "公式格式有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|