Przeglądaj źródła

fixed 手机号隐藏功能

fushengqian 1 rok temu
rodzic
commit
b240b3439d

+ 5 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java

@@ -411,6 +411,10 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
                 throw new BusinessCheckException("该会员等级有误");
             }
         }
+        String mobile = mtUser.getMobile();
+        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
+            mtUser.setMobile(mobile);
+        }
 
         // 检查会员号是否重复
         if (StringUtil.isNotEmpty(mtUser.getUserNo())) {
@@ -555,7 +559,6 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
                 }
             }
         }
-
         return mtUser;
     }
 
@@ -662,7 +665,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
                return null;
             }
             // 补充手机号
-            if (StringUtil.isNotEmpty(mobile)) {
+            if (StringUtil.isNotEmpty(mobile) && PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
                 user.setMobile(mobile);
                 updateById(user);
             }

+ 12 - 2
fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java

@@ -16,6 +16,7 @@ import com.fuint.repository.mapper.MtStaffMapper;
 import com.fuint.repository.model.MtStaff;
 import com.fuint.repository.model.MtStore;
 import com.fuint.repository.model.MtUser;
+import com.fuint.utils.StringUtil;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import org.apache.commons.lang.StringUtils;
@@ -97,7 +98,15 @@ public class StaffServiceImpl extends ServiceImpl<MtStaffMapper, MtStaff> implem
 
         lambdaQueryWrapper.orderByDesc(MtStaff::getId);
         List<MtStaff> dataList = mtStaffMapper.selectList(lambdaQueryWrapper);
-
+        if (dataList != null && dataList.size() > 0) {
+            for (MtStaff mtStaff : dataList) {
+                // 隐藏手机号中间四位
+                String phone = mtStaff.getMobile();
+                if (phone != null && StringUtil.isNotEmpty(phone) && phone.length() == 11) {
+                    mtStaff.setMobile(phone.substring(0, 3) + "****" + phone.substring(7));
+                }
+            }
+        }
         PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
         PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
         PaginationResponse<MtStaff> paginationResponse = new PaginationResponse(pageImpl, MtStaff.class);
@@ -167,7 +176,8 @@ public class StaffServiceImpl extends ServiceImpl<MtStaffMapper, MtStaff> implem
      */
     @Override
     public MtStaff queryStaffById(Integer id) {
-        return mtStaffMapper.selectById(id);
+        MtStaff mtStaff = mtStaffMapper.selectById(id);
+        return mtStaff;
     }
 
     /**

+ 5 - 0
fuint-application/src/main/java/com/fuint/common/util/PhoneFormatCheckUtils.java

@@ -1,5 +1,7 @@
 package com.fuint.common.util;
 
+import com.fuint.utils.StringUtil;
+
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -28,6 +30,9 @@ public class PhoneFormatCheckUtils {
      * 147
      */
     public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {
+        if (str == null || StringUtil.isEmpty(str)) {
+            return false;
+        }
         String regExp = "^[1][3,4,5,6,7,8,9][0-9]{9}$";
         Pattern p = Pattern.compile(regExp);
         Matcher m = p.matcher(str);

+ 10 - 6
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -246,11 +246,7 @@ public class BackendMemberController extends BaseController {
         String startTime = param.get("startTime") == null ? "" : param.get("startTime").toString();
         String endTime = param.get("endTime") == null ? "" : param.get("endTime").toString();
 
-        if (!PhoneFormatCheckUtils.isChinaPhoneLegal(mobile) && StringUtil.isNotEmpty(mobile)) {
-            return getFailureResult(201, "手机号格式有误!");
-        }
-
-        if (StringUtil.isNotEmpty(mobile)) {
+        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
             // 重置该手机号
             memberService.resetMobile(mobile, StringUtil.isEmpty(id) ? 0 : Integer.parseInt(id));
         }
@@ -261,12 +257,15 @@ public class BackendMemberController extends BaseController {
         } else {
             memberInfo = memberService.queryMemberById(Integer.parseInt(id));
         }
+
         memberInfo.setMerchantId(accountInfo.getMerchantId());
         memberInfo.setName(name);
         memberInfo.setStatus(status);
         memberInfo.setGradeId(gradeId);
         memberInfo.setUserNo(userNo);
-        memberInfo.setMobile(mobile);
+        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
+            memberInfo.setMobile(mobile);
+        }
         memberInfo.setSex(Integer.parseInt(sex));
         memberInfo.setIdcard(idCard);
         memberInfo.setBirthday(birthday);
@@ -307,6 +306,11 @@ public class BackendMemberController extends BaseController {
         }
 
         MtUser mtUserInfo = memberService.queryMemberById(id);
+        // 隐藏手机号中间四位
+        String phone = mtUserInfo.getMobile();
+        if (phone != null && StringUtil.isNotEmpty(phone) && phone.length() == 11) {
+            mtUserInfo.setMobile(phone.substring(0, 3) + "****" + phone.substring(7));
+        }
 
         Map<String, Object> param = new HashMap<>();
         List<MtUserGrade> userGradeList = memberService.queryMemberGradeByParams(param);

+ 10 - 6
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendStaffController.java

@@ -160,10 +160,6 @@ public class BackendStaffController extends BaseController {
             return getFailureResult(1001, "请先登录");
         }
 
-        if (!PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
-            return getFailureResult(201, "手机号格式有误!");
-        }
-
         MtStaff mtStaff = new MtStaff();
         if (StringUtil.isNotEmpty(id)) {
             mtStaff = staffService.queryStaffById(Integer.parseInt(id));
@@ -175,7 +171,9 @@ public class BackendStaffController extends BaseController {
         mtStaff.setMerchantId(accountInfo.getMerchantId());
         mtStaff.setStoreId(Integer.parseInt(storeId));
         mtStaff.setRealName(realName);
-        mtStaff.setMobile(mobile);
+        if (PhoneFormatCheckUtils.isChinaPhoneLegal(mobile)) {
+            mtStaff.setMobile(mobile);
+        }
         mtStaff.setAuditedStatus(status);
         mtStaff.setDescription(description);
         mtStaff.setCategory(Integer.parseInt(category));
@@ -214,7 +212,13 @@ public class BackendStaffController extends BaseController {
         }
 
         MtStaff staffInfo = staffService.queryStaffById(id);
-
+        if (staffInfo != null) {
+            // 隐藏手机号中间四位
+            String phone = staffInfo.getMobile();
+            if (phone != null && StringUtil.isNotEmpty(phone) && phone.length() == 11) {
+                staffInfo.setMobile(phone.substring(0, 3) + "****" + phone.substring(7));
+            }
+        }
         Map<String, Object> result = new HashMap<>();
         result.put("staffInfo", staffInfo);