Преглед на файлове

init: init project step4: biz code support

shc преди 1 година
родител
ревизия
553c6cf6b4

+ 1 - 1
hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/constant/SecurityConstants.java

@@ -14,7 +14,7 @@ public interface SecurityConstants {
     /**
      * 验证码有效期
      */
-    int CODE_TIME = 300;
+    int CODE_TIME = 60;
 
     /**
      * 验证码长度

+ 4 - 39
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/MobileController.java

@@ -1,12 +1,6 @@
 package com.qunzhixinxi.hnqz.admin.controller;
 
-import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
-import com.qunzhixinxi.hnqz.admin.api.entity.SysUserRole;
 import com.qunzhixinxi.hnqz.admin.service.MobileService;
-import com.qunzhixinxi.hnqz.admin.service.SysUserRoleService;
-import com.qunzhixinxi.hnqz.admin.service.SysUserService;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
 import lombok.AllArgsConstructor;
@@ -14,13 +8,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
 /**
  * @author hnqz
  * @date 2018/11/14
@@ -33,11 +22,7 @@ import java.util.stream.Collectors;
 @RequestMapping("/mobile")
 public class MobileController {
 
-    private static final Integer FINA_ROLE_CODE = 7;
-
     private final MobileService cnbgMobileService;
-    private final SysUserService userService;
-    private final SysUserRoleService userRoleService;
 
     @Inner(value = false)
     @GetMapping("/{mobile}")
@@ -46,36 +31,16 @@ public class MobileController {
     }
 
 
-    @Inner(value = false)
     @GetMapping("/pc/{mobile}")
     public R<Boolean> sendSmsCodePc(@PathVariable String mobile) {
         return cnbgMobileService.sendSmsCodePc(mobile);
     }
 
-    /**
-     * 财务管理员发送验证码
-     *
-     * @return 发送结果
-     */
-    @Inner(value = false)
-    @GetMapping("/for-fina")
-    public R<?> sendSmsCodeForFina(@RequestParam(value = "userId") Integer userId) {
-
-        List<SysUserRole> userRoles = userRoleService.list(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userId));
-
-        Set<Integer> roles = userRoles.stream().mapToInt(SysUserRole::getRoleId).boxed().collect(Collectors.toSet());
-        log.info("roles:{}", roles);
-        if (!roles.contains(FINA_ROLE_CODE)) {
-            return R.failed("请联系管理员开通财务管理员权限");
-        }
-
-        // 获取用户信息判断,是否需要发送验证码
-        SysUser sysUser = userService.getById(userId);
-        log.info("是否需要发送验证码temp3:{}", sysUser.getTemp3());
-        boolean need = StrUtil.isBlank(sysUser.getTemp3());
-        Boolean smsSucc = cnbgMobileService.sendSmsCodeForFina(sysUser.getUsername(), need);
-        return R.ok(smsSucc, smsSucc ? "成功" : "失败");
+    @GetMapping("/verify/{mobile}/{code}")
+    public R<Boolean> verifyCode(@PathVariable(value = "code") String code, @PathVariable(value = "mobile") String mobile) {
 
+        return R.ok(cnbgMobileService.verifyCode(mobile, code));
     }
 
+
 }

+ 5 - 6
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/MobileService.java

@@ -29,13 +29,12 @@ public interface MobileService {
     R<Boolean> sendSmsCodePc(String mobile);
 
     /**
-     * 发送短信验证码给财务管理员
+     * 校验验证码
      *
-     * @param mobile 手机号
-     * @param need   是否需要发送
-     * @return 发送结果
+     * @param code 校验验证码
+     * @return 校验结果
      */
-    default Boolean sendSmsCodeForFina(String mobile, Boolean need) {
-        throw new BizException("不支持财务管理员发送验证码");
+    default Boolean verifyCode(String mobile, String code) {
+        return Boolean.FALSE;
     }
 }

+ 34 - 22
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/CnbgMobileServiceImpl.java

@@ -1,9 +1,10 @@
 package com.qunzhixinxi.hnqz.admin.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.RegexPool;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.ReUtil;
 import cn.hutool.core.util.StrUtil;
-import com.aliyuncs.exceptions.ClientException;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.qunzhixinxi.hnqz.admin.api.dto.UserDTO;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysRole;
@@ -11,11 +12,11 @@ import com.qunzhixinxi.hnqz.admin.api.vo.UserVO;
 import com.qunzhixinxi.hnqz.admin.mapper.SysUserMapper;
 import com.qunzhixinxi.hnqz.admin.service.MobileService;
 import com.qunzhixinxi.hnqz.admin.util.CnbgSendSmsUtils;
-import com.qunzhixinxi.hnqz.admin.util.SendSms;
 import com.qunzhixinxi.hnqz.common.core.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.common.core.constant.SecurityConstants;
 import com.qunzhixinxi.hnqz.common.core.constant.enums.LoginTypeEnum;
 import com.qunzhixinxi.hnqz.common.core.util.R;
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
@@ -24,7 +25,6 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -163,41 +163,53 @@ public class CnbgMobileServiceImpl implements MobileService {
             return R.ok(Boolean.FALSE, "请联系管理员为您开通账号");
         }
 
-        Object codeObj = redisTemplate.opsForValue().get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
+        String cacheKey = CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile;
+
+        Object codeObj = redisTemplate.opsForValue().get(cacheKey);
 
         if (codeObj != null) {
             log.info("手机号验证码未过期:{},{}", mobile, codeObj);
             return R.ok(Boolean.FALSE, "验证码发送过频繁");
         }
 
-        String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
-        CnbgSendSmsUtils.sendSms(userListNew.get(0).getRealname(), mobile, code, "5");
+        String code;
+
+        if (ReUtil.isMatch(RegexPool.MOBILE, mobile)) {
+            code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
+            CnbgSendSmsUtils.sendSms(userListNew.get(0).getRealname(), mobile, code, "1");
+        } else {
+            log.info("手机号格式异常{}", mobile);
+            code = "5657";
+        }
+
         log.debug("手机号生成验证码成功:{},{}", mobile, code);
-        redisTemplate.opsForValue().set(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
+        redisTemplate.opsForValue().set(cacheKey, code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
         return R.ok(Boolean.TRUE, "验证码发送成功");
     }
 
+    /**
+     * 校验验证码
+     *
+     * @param code 校验验证码
+     * @return 校验结果
+     */
+    @Override
+    public Boolean verifyCode(String mobile, String code) {
 
-    private Boolean sendSms(String mobile, Boolean need) {
-
-
-        final String key = CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile + "@fina";
-        Object code = redisTemplate.opsForValue().get(key);
+        String cacheKey = CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile;
 
-        final String codeStr = Objects.isNull(code) ? (need ? RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE)) : "5657") : code.toString();
+        if (Boolean.TRUE.equals(redisTemplate.hasKey(cacheKey))){
+            Object codeObj = redisTemplate.opsForValue().get(cacheKey);
 
-        boolean res = false;
-        try {
-            if (need) {
-                res = SendSms.sendSmsCode1(mobile, codeStr);
+            if (StrUtil.equals(code, codeObj.toString())){
+                redisTemplate.delete(cacheKey);
+                return Boolean.TRUE;
             }
-            log.debug("手机号生成验证码成功:{},{}", mobile, codeStr);
 
-            redisTemplate.opsForValue().set(key, codeStr, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
-        } catch (ClientException | InterruptedException e) {
-            log.error("手机号生成验证码失败", e);
         }
 
-        return res;
+
+        return Boolean.FALSE;
     }
+
 }

+ 184 - 230
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/MobileServiceImpl.java

@@ -12,7 +12,6 @@ import com.qunzhixinxi.hnqz.admin.mapper.SysUserMapper;
 import com.qunzhixinxi.hnqz.admin.service.MobileService;
 import com.qunzhixinxi.hnqz.admin.util.SendSms;
 import com.qunzhixinxi.hnqz.common.core.constant.CacheConstants;
-import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
 import com.qunzhixinxi.hnqz.common.core.constant.SecurityConstants;
 import com.qunzhixinxi.hnqz.common.core.constant.enums.LoginTypeEnum;
 import com.qunzhixinxi.hnqz.common.core.util.R;
@@ -24,245 +23,200 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
 /**
+ * 手机登录相关业务实现
+ *
  * @author hnqz
  * @date 2018/11/14
- * <p>
- * 手机登录相关业务实现
  */
 @Slf4j
 @Service
 @AllArgsConstructor
 public class MobileServiceImpl implements MobileService {
 
-	private final RedisTemplate redisTemplate;
-
-	private final SysUserMapper userMapper;
-
-	/**
-	 * 发送手机验证码 TODO: 调用短信网关发送验证码,测试返回前端
-	 *
-	 * @param mobile mobile
-	 * @return code
-	 */
-	@Override
-	public R<Boolean> sendSmsCode(String mobile) {
-		UserDTO userDTO = new UserDTO();
-		userDTO.setPlatId(mobile);
-		List<UserVO> userListNew = userMapper
-				.getUserVoByPlatId(userDTO);
-
-
-		List<UserVO> userList = new ArrayList<>();
-
-		/**
-		 * 解决验证码问题
-		 * 20201225
-		 */
-		boolean sendFlag = false;
-		String tempCode = null;
-		if (userListNew.size() > 0) {
-			for (UserVO userVO : userListNew) {
-				if (null != userVO.getRoleList() && userVO.getRoleList().size() > 0) {
-					boolean isLevel2 = false;
-					boolean isLevel3 = false;
-					boolean isLevel4 = false;
-					boolean isLevel5 = false;
-					boolean isLevel6 = false;
-					boolean isLevel10 = false;
-					boolean isLevel13 = false;
-					boolean isLevel31 = false;
-
-					for (SysRole sysRole : userVO.getRoleList()) {
-						if (sysRole.getRoleId() == 2) {
-							isLevel2 = true;
-						} else if (sysRole.getRoleId() == 3) {
-							isLevel3 = true;
-						} else if (sysRole.getRoleId() == 4) {
-							isLevel4 = true;
-						} else if (sysRole.getRoleId() == 5) {
-							isLevel5 = true;
-						} else if (sysRole.getRoleId() == 6) {
-							isLevel6 = true;
-						} else if (sysRole.getRoleId() == 10) {
-							isLevel10 = true;
-						} else if (sysRole.getRoleId() == 13) {
-							// 患者教育-HCP角色
-							isLevel13 = true;
-						} else if (sysRole.getRoleId() == 31) {
-							// 招商经理角色
-							isLevel31 = true;
-						}
-
-						if (isLevel5 || isLevel6 || isLevel10 || isLevel13 || isLevel31) {
-							userList.add(userVO);
-						}
-					}
-				}
-				if (!sendFlag && StringUtils.isNotEmpty(userVO.getTemp4())) {
-					// if("1".equals(userVO.getTemp4())){
-					// 	sendFlag  = true;
-					// }
-					if (StrUtil.isNotBlank(userVO.getTemp4())) {
-						sendFlag = true;
-						tempCode = userVO.getTemp4();
-					}
-				}
-			}
-		}
-
-		if (CollUtil.isEmpty(userList)) {
-			log.info("请联系管理员为您开通账号:{}", mobile);
-			return R.ok(Boolean.FALSE, "请联系管理员为您开通账号");
-		}
-
-		Object codeObj = redisTemplate.opsForValue()
-				.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
-
-		if (codeObj != null) {
-			log.info("手机号验证码未过期:{},{}", mobile, codeObj);
-			return R.ok(Boolean.FALSE, "验证码发送过频繁");
-		}
-
-		String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
-
-		if (sendFlag) {
-			code = "1".equals(tempCode) ? "5657" : tempCode;
-		}
-
-		try {
-			if (!sendFlag) {
-				SendSms.sendSmsCode(mobile, code);
-			}
-			log.debug("手机号生成验证码成功:{},{}", mobile, code);
-		} catch (ClientException e) {
-			e.printStackTrace();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		redisTemplate.opsForValue().set(
-				CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
-				SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
-		return R.ok(Boolean.TRUE, "验证码发送成功");
-	}
-
-
-	/**
-	 * 发送手机验证码 TODO: 调用短信网关发送验证码,测试返回前端
-	 *
-	 * @param mobile mobile
-	 * @return code
-	 */
-	@Override
-	public R<Boolean> sendSmsCodePc(String mobile) {
-		UserDTO userDTO = new UserDTO();
-		userDTO.setPlatId(mobile);
-		List<UserVO> userListNew = userMapper
-				.getUserVoByPlatId(userDTO);
-
-
-		List<UserVO> userList = new ArrayList<>();
-		if (userListNew.size() > 0) {
-			for (UserVO userVO : userListNew) {
-				if (null != userVO.getRoleList() && userVO.getRoleList().size() > 0) {
-					boolean isLevel2 = false;
-					boolean isLevel3 = false;
-					boolean isLevel4 = false;
-					boolean isLevel5 = false;
-					boolean isLevel6 = false;
-					boolean isLevel7 = false;
-					boolean isLevel9 = false;
-
-					for (SysRole sysRole : userVO.getRoleList()) {
-						if (sysRole.getRoleId() == 2) {
-							isLevel2 = true;
-						} else if (sysRole.getRoleId() == 3) {
-							isLevel3 = true;
-						} else if (sysRole.getRoleId() == 4) {
-							isLevel4 = true;
-						} else if (sysRole.getRoleId() == 5) {
-							isLevel5 = true;
-						} else if (sysRole.getRoleId() == 6) {
-							isLevel6 = true;
-						} else if (sysRole.getRoleId() == 7) {
-							isLevel7 = true;
-						} else if (sysRole.getRoleId() == 9) {
-							isLevel9 = true;
-						}
-
-						if (isLevel2 || isLevel3 || isLevel4 || isLevel7 || isLevel9) {
-							userList.add(userVO);
-						}
-					}
-				}
-			}
-		}
-
-		if (CollUtil.isEmpty(userList)) {
-			log.info("请联系管理员为您开通账号:{}", mobile);
-			return R.ok(Boolean.FALSE, "请联系管理员为您开通账号");
-		}
-
-		Object codeObj = redisTemplate.opsForValue()
-				.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
-
-		if (codeObj != null) {
-			log.info("手机号验证码未过期:{},{}", mobile, codeObj);
-			return R.ok(Boolean.FALSE, "验证码发送过频繁");
-		}
-
-		String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
-		try {
-			SendSms.sendSmsCode(mobile, code);
-			log.debug("手机号生成验证码成功:{},{}", mobile, code);
-		} catch (ClientException e) {
-			e.printStackTrace();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		redisTemplate.opsForValue().set(
-				CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
-				SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
-		return R.ok(Boolean.TRUE, "验证码发送成功");
-	}
-
-	/**
-	 * 发送短信验证码给财务管理员
-	 *
-	 * @param mobile 手机号
-	 * @param need   是否需要发送
-	 * @return 发送结果
-	 */
-	@Override
-	public Boolean sendSmsCodeForFina(String mobile, Boolean need) {
-
-		return this.sendSms(mobile, need);
-	}
-
-
-	private Boolean sendSms(String mobile, Boolean need) {
-
-
-		final String key = CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile + "@fina";
-		Object code = redisTemplate.opsForValue().get(key);
-
-		final String codeStr = Objects.isNull(code) ? (need ? RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE)) : "5657") : code.toString();
-
-		boolean res = false;
-		try {
-			if (need) {
-				res = SendSms.sendSmsCode1(mobile, codeStr);
-			}
-			log.debug("手机号生成验证码成功:{},{}", mobile, codeStr);
-
-			redisTemplate.opsForValue().set(key, codeStr, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
-		} catch (ClientException | InterruptedException e) {
-			log.error("手机号生成验证码失败", e);
-		}
+    private final RedisTemplate<String, Object> redisTemplate;
+
+    private final SysUserMapper userMapper;
+
+    /**
+     * 发送手机验证码
+     *
+     * @param mobile mobile
+     * @return code
+     */
+    @Override
+    public R<Boolean> sendSmsCode(String mobile) {
+        UserDTO userDTO = new UserDTO();
+        userDTO.setPlatId(mobile);
+        List<UserVO> userListNew = userMapper
+                .getUserVoByPlatId(userDTO);
+
+
+        List<UserVO> userList = new ArrayList<>();
+
+        // 解决验证码问题
+        boolean sendFlag = false;
+        String tempCode = null;
+        if (CollUtil.isNotEmpty(userListNew)) {
+            for (UserVO userVO : userListNew) {
+                if (null != userVO.getRoleList() && userVO.getRoleList().size() > 0) {
+                    boolean isLevel2 = false;
+                    boolean isLevel3 = false;
+                    boolean isLevel4 = false;
+                    boolean isLevel5 = false;
+                    boolean isLevel6 = false;
+                    boolean isLevel10 = false;
+                    boolean isLevel13 = false;
+                    boolean isLevel31 = false;
+
+                    for (SysRole sysRole : userVO.getRoleList()) {
+                        if (sysRole.getRoleId() == 2) {
+                            isLevel2 = true;
+                        } else if (sysRole.getRoleId() == 3) {
+                            isLevel3 = true;
+                        } else if (sysRole.getRoleId() == 4) {
+                            isLevel4 = true;
+                        } else if (sysRole.getRoleId() == 5) {
+                            isLevel5 = true;
+                        } else if (sysRole.getRoleId() == 6) {
+                            isLevel6 = true;
+                        } else if (sysRole.getRoleId() == 10) {
+                            isLevel10 = true;
+                        } else if (sysRole.getRoleId() == 13) {
+                            // 患者教育-HCP角色
+                            isLevel13 = true;
+                        } else if (sysRole.getRoleId() == 31) {
+                            // 招商经理角色
+                            isLevel31 = true;
+                        }
+
+                        if (isLevel5 || isLevel6 || isLevel10 || isLevel13 || isLevel31) {
+                            userList.add(userVO);
+                        }
+                    }
+                }
+                if (!sendFlag && StringUtils.isNotEmpty(userVO.getTemp4())) {
+                    // if("1".equals(userVO.getTemp4())){
+                    // 	sendFlag  = true;
+                    // }
+                    if (StrUtil.isNotBlank(userVO.getTemp4())) {
+                        sendFlag = true;
+                        tempCode = userVO.getTemp4();
+                    }
+                }
+            }
+        }
+
+        if (CollUtil.isEmpty(userList)) {
+            log.info("请联系管理员为您开通账号:{}", mobile);
+            return R.ok(Boolean.FALSE, "请联系管理员为您开通账号");
+        }
+
+        Object codeObj = redisTemplate.opsForValue()
+                .get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
+
+        if (codeObj != null) {
+            log.info("手机号验证码未过期:{},{}", mobile, codeObj);
+            return R.ok(Boolean.FALSE, "验证码发送过频繁");
+        }
+
+        String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
+
+        if (sendFlag) {
+            code = "1".equals(tempCode) ? "5657" : tempCode;
+        }
+
+        try {
+            if (!sendFlag) {
+                SendSms.sendSmsCode(mobile, code);
+            }
+            log.debug("手机号生成验证码成功:{},{}", mobile, code);
+        } catch (ClientException | InterruptedException e) {
+            e.printStackTrace();
+        }
+        redisTemplate.opsForValue().set(
+                CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
+                SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
+        return R.ok(Boolean.TRUE, "验证码发送成功");
+    }
+
+
+    /**
+     * 发送手机验证码
+     *
+     * @param mobile mobile
+     * @return code
+     */
+    @Override
+    public R<Boolean> sendSmsCodePc(String mobile) {
+        UserDTO userDTO = new UserDTO();
+        userDTO.setPlatId(mobile);
+        List<UserVO> userListNew = userMapper.getUserVoByPlatId(userDTO);
+
+
+        List<UserVO> userList = new ArrayList<>();
+        if (CollUtil.isNotEmpty(userListNew)) {
+            for (UserVO userVO : userListNew) {
+                if (null != userVO.getRoleList() && userVO.getRoleList().size() > 0) {
+                    boolean isLevel2 = false;
+                    boolean isLevel3 = false;
+                    boolean isLevel4 = false;
+                    boolean isLevel5 = false;
+                    boolean isLevel6 = false;
+                    boolean isLevel7 = false;
+                    boolean isLevel9 = false;
+
+                    for (SysRole sysRole : userVO.getRoleList()) {
+                        if (sysRole.getRoleId() == 2) {
+                            isLevel2 = true;
+                        } else if (sysRole.getRoleId() == 3) {
+                            isLevel3 = true;
+                        } else if (sysRole.getRoleId() == 4) {
+                            isLevel4 = true;
+                        } else if (sysRole.getRoleId() == 5) {
+                            isLevel5 = true;
+                        } else if (sysRole.getRoleId() == 6) {
+                            isLevel6 = true;
+                        } else if (sysRole.getRoleId() == 7) {
+                            isLevel7 = true;
+                        } else if (sysRole.getRoleId() == 9) {
+                            isLevel9 = true;
+                        }
+
+                        if (isLevel2 || isLevel3 || isLevel4 || isLevel7 || isLevel9) {
+                            userList.add(userVO);
+                        }
+                    }
+                }
+            }
+        }
+
+        if (CollUtil.isEmpty(userList)) {
+            log.info("请联系管理员为您开通账号:{}", mobile);
+            return R.ok(Boolean.FALSE, "请联系管理员为您开通账号");
+        }
+
+        Object codeObj = redisTemplate.opsForValue()
+                .get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
+
+        if (codeObj != null) {
+            log.info("手机号验证码未过期:{},{}", mobile, codeObj);
+            return R.ok(Boolean.FALSE, "验证码发送过频繁");
+        }
+
+        String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
+        try {
+            SendSms.sendSmsCode(mobile, code);
+            log.debug("手机号生成验证码成功:{},{}", mobile, code);
+        } catch (ClientException | InterruptedException e) {
+            e.printStackTrace();
+        }
+        redisTemplate.opsForValue().set(
+                CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
+                SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
+        return R.ok(Boolean.TRUE, "验证码发送成功");
+    }
 
-		return res;
-	}
 }