azw 2 роки тому
батько
коміт
bb88062b83

+ 33 - 6
src/main/java/com/jd/zfjyjgfwpt/controller/PurchaseInformationController.java

@@ -1,5 +1,6 @@
 package com.jd.zfjyjgfwpt.controller;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.jd.zfjyjgfwpt.entity.PurchaseInformation;
@@ -49,9 +50,22 @@ public class PurchaseInformationController {
      */
     @PostMapping("insertPurchaseIntention")
     public Map<String, Object> insertPurchaseIntention(@Valid PurchaseInformation purchaseInformation) {
-//        if (!Blank.isPhone(purchaseInformation.getPhone())) {
-//            return SendUtil.send(false, "请输入正确的手机号", null);
-//        }
+        if (Blank.isNotEmpty(purchaseInformation.getPhone())) {
+            if (ObjectUtil.equal(purchaseInformation.getContactType(), 1)) {
+                if (!Blank.isQQPattern(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }else if (ObjectUtil.equal(purchaseInformation.getContactType(), 2)) {
+                if (!Blank.isWxPattern(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }else if (ObjectUtil.equal(purchaseInformation.getContactType(), 3)) {
+                if (!Blank.isPhone(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }
+        }
+
         if (purchaseInformation.getMoneyMax() < purchaseInformation.getMoneyMin()) {
             return SendUtil.send(false, "最高预算不能小于最低预算", null);
         }
@@ -82,9 +96,22 @@ public class PurchaseInformationController {
         if (Blank.isEmpty(purchaseInformation.getId())) {
             return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
         }
-//        if (!Blank.isPhone(purchaseInformation.getPhone())) {
-//            return SendUtil.send(false, "请输入正确的手机号", null);
-//        }
+        if (Blank.isNotEmpty(purchaseInformation.getPhone())) {
+            if (ObjectUtil.equal(purchaseInformation.getContactType(), 1)) {
+                if (!Blank.isQQPattern(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }else if (ObjectUtil.equal(purchaseInformation.getContactType(), 2)) {
+                if (!Blank.isWxPattern(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }else if (ObjectUtil.equal(purchaseInformation.getContactType(), 3)) {
+                if (!Blank.isPhone(purchaseInformation.getPhone())) {
+                    return SendUtil.send(false, "请输入正确的联系方式", null);
+                }
+            }
+        }
+
         if (purchaseInformation.getMoneyMax() < purchaseInformation.getMoneyMin()) {
             return SendUtil.send(false, "最高预算不能小于最低预算", null);
         }

+ 24 - 0
src/main/java/com/jd/zfjyjgfwpt/util/Blank.java

@@ -212,4 +212,28 @@ public class Blank {
 		return true;
 	}
 
+	public static Boolean isQQPattern(String param) {
+		if (isEmpty(param)) {
+			return false;
+		}
+		String pattern = "^[1-9][0-9]{4,13}$";
+		if (!Pattern.matches(pattern, param)) {
+			return false;
+		}
+
+		return true;
+	}
+
+	public static Boolean isWxPattern(String param) {
+		if (isEmpty(param)) {
+			return false;
+		}
+		String pattern = "^([-_a-zA-Z0-9]{5,19})$";
+		if (!Pattern.matches(pattern, param)) {
+			return false;
+		}
+
+		return true;
+	}
+
 }