用户绑定手机号判重

master
river 4 years ago
parent 4f3d0b0282
commit ae0550dfb4
  1. 4
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/UserDao.java
  2. 22
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/UserServiceImpl.java
  3. 5
      dq-financial-hrms/src/main/resources/mapper/hrms/UserDao.xml
  4. 1
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java

@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 人资管理系统员工账号信息表用于存储员工账号密码等登录相关数据 * 人资管理系统员工账号信息表用于存储员工账号密码等登录相关数据
* *
@ -28,4 +30,6 @@ public interface UserDao extends BaseMapper<UserEntity> {
Boolean updateWeChat(@Param("id") Long id, @Param("weChatId") String weChatId); Boolean updateWeChat(@Param("id") Long id, @Param("weChatId") String weChatId);
Long getEmployeeIdByUserId(Long userId); Long getEmployeeIdByUserId(Long userId);
List<String> listPhoneAccount();
} }

@ -26,6 +26,7 @@ import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -75,6 +76,13 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
&& employeeAndUserVO.getPrimaryCode() != null && employeeAndUserVO.getPrimaryCode() != null
&& employeeAndUserVO.getPrimaryCode().length() != 0) { && employeeAndUserVO.getPrimaryCode().length() != 0) {
// 没有绑定手机号,现在绑定 // 没有绑定手机号,现在绑定
List<String> phoneAccounts = this.getBaseMapper().listPhoneAccount();
for (String pAccount : phoneAccounts) {
// 判断该手机号是否已经绑定过了
if (employeeAndUserVO.getPrimaryPhone().equals(pAccount)) {
ExceptionCast.cast(HrmsCode.USER_PHONE_ACCOUNT_REPETITION);
}
}
String code = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); String code = RedisUtil.get(employeeAndUserVO.getPrimaryPhone());
if (code == null || code.length() == 0 || !Objects.equals(employeeAndUserVO.getPrimaryCode(), code)) { if (code == null || code.length() == 0 || !Objects.equals(employeeAndUserVO.getPrimaryCode(), code)) {
ExceptionCast.cast(HrmsCode.USER_PHONE_CODE_MISTAKE); ExceptionCast.cast(HrmsCode.USER_PHONE_CODE_MISTAKE);
@ -101,6 +109,13 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
ExceptionCast.cast(HrmsCode.USER_PRIMARY_CODE_MISTAKE); ExceptionCast.cast(HrmsCode.USER_PRIMARY_CODE_MISTAKE);
} }
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); RedisUtil.del(employeeAndUserVO.getPrimaryPhone());
// 判断更换的手机号是否已绑定过用户
List<String> phoneAccounts = this.getBaseMapper().listPhoneAccount();
for (String pAccount : phoneAccounts) {
if (employeeAndUserVO.getNewPhone().equals(pAccount)) {
ExceptionCast.cast(HrmsCode.USER_PHONE_ACCOUNT_REPETITION);
}
}
String newCode = RedisUtil.get(employeeAndUserVO.getNewPhone()); String newCode = RedisUtil.get(employeeAndUserVO.getNewPhone());
if (newCode == null || newCode.length() == 0 if (newCode == null || newCode.length() == 0
|| !Objects.equals(newCode, employeeAndUserVO.getNewCode())) { || !Objects.equals(newCode, employeeAndUserVO.getNewCode())) {
@ -204,6 +219,13 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
if (phone == null || phone.length() == 0 || code == null || code.length() == 0) { if (phone == null || phone.length() == 0 || code == null || code.length() == 0) {
ExceptionCast.cast(HrmsCode.USER_PHONE_OR_CODE_NOT_NULL); ExceptionCast.cast(HrmsCode.USER_PHONE_OR_CODE_NOT_NULL);
} }
// 判断当前手机号是否已绑定用户
List<String> phoneAccounts = this.getBaseMapper().listPhoneAccount();
for (String phoneAccount : phoneAccounts) {
if (phone.equals(phoneAccount)) {
ExceptionCast.cast(HrmsCode.USER_PHONE_ACCOUNT_REPETITION);
}
}
if (RedisUtil.get(phone) == null || RedisUtil.get(phone).length() == 0 if (RedisUtil.get(phone) == null || RedisUtil.get(phone).length() == 0
|| !Objects.equals(code, RedisUtil.get(phone))) { || !Objects.equals(code, RedisUtil.get(phone))) {
ExceptionCast.cast(HrmsCode.USER_BINDING_FAIL); ExceptionCast.cast(HrmsCode.USER_BINDING_FAIL);

@ -54,4 +54,9 @@
AND u.id = #{userId} AND u.id = #{userId}
</select> </select>
<!-- 获取所有的手机号 -->
<select id="listPhoneAccount" resultType="string">
SELECT phone_account FROM hrms_user WHERE del_or_not = 0
</select>
</mapper> </mapper>

@ -60,6 +60,7 @@ public enum HrmsCode implements ResultCode {
USER_FILE_IS_NULL(false,88015,"当前文件不存在,请正确选择文件!"), USER_FILE_IS_NULL(false,88015,"当前文件不存在,请正确选择文件!"),
USER_FILE_TYPE_MISTAKE(false,88013,"文件格式不正确,请重新选择图片文件!"), USER_FILE_TYPE_MISTAKE(false,88013,"文件格式不正确,请重新选择图片文件!"),
USER_FILE_UPLOAD_FAIL(false,88014,"上传图像失败,请稍后刷新再试!"), USER_FILE_UPLOAD_FAIL(false,88014,"上传图像失败,请稍后刷新再试!"),
USER_PHONE_ACCOUNT_REPETITION(false,88015,"该手机号已绑定过用户,请更换手机号!"),
PHNOE_ACCOUNT_NOT_EMPTY(false,33001,"手机号码为空!"), PHNOE_ACCOUNT_NOT_EMPTY(false,33001,"手机号码为空!"),
VERIFY_CODE_NOT_EMPTY(false,33002,"短信验证码为空!"), VERIFY_CODE_NOT_EMPTY(false,33002,"短信验证码为空!"),

Loading…
Cancel
Save