手机号验证及密码修改

dev_xiangguanfang
zhaokai 2025-12-30 16:42:29 +08:00
parent c1f71de612
commit 7fa63d12bc
9 changed files with 90 additions and 26 deletions

View File

@ -81,6 +81,14 @@ public class UserAddExe {
UserE userE = new UserE();
BeanUtils.copyProperties(cmd, userE);
userE.initAdd(tenantId, userE);
//校验手机号
// List<Integer> employmentFlagList = Arrays.asList(UserEmploymentFlagEnum.ON.getCode(), UserEmploymentFlagEnum.ENTRY_AUDIT.getCode(), UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
List<UserDO> userList = userRepository.getListByPhone( userE.getPhone(),null);
if (CollUtil.isNotEmpty(userList)) {
List<UserE> userEList = userCoConvertor.convertDOsToEs(userList);
userE.checkPhone(userEList);
}
CorpInfoDO corpInfoDO = corpInfoRepository.getById(userE.getCorpinfoId());
String corpName = null;
UserEmploymentLogE userEmploymentLogE = new UserEmploymentLogE();
@ -369,6 +377,13 @@ public class UserAddExe {
throw new BizException("未创建默认通用角色,请联系管理员");
}
userE.setRoleId(roleId);
//校验手机号
List<Integer> employmentFlagList = Arrays.asList(UserEmploymentFlagEnum.ON.getCode(), UserEmploymentFlagEnum.ENTRY_AUDIT.getCode(), UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
List<UserDO> userList = userRepository.getListByPhone(userE.getPhone(),employmentFlagList);
if(CollUtil.isNotEmpty(userList)){
List<UserE> userEList = userCoConvertor.convertDOsToEs(userList);
userE.checkXGfPhone(userEList);
}
boolean res = false;
try {

View File

@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -74,10 +75,10 @@ public class UserRemoveExe {
try {
//TODO 处理所有未完成的工作,如果是非固定人员,包括所有企业的未完成工作
// 如果是固定人员,判断是否离职
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone());
List<Integer> employmentFlagList = Arrays.asList(UserEmploymentFlagEnum.ON.getCode(), UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone(),employmentFlagList);
//过滤出固定人员
List<UserDO> fixedUserDOList = userDOList.stream().filter(userDO1 -> UserEmploymentFlagEnum.ON.equals(userDO1.getEmploymentFlag().toString())).collect(Collectors.toList());
if(CollUtil.isNotEmpty(fixedUserDOList)){
if(CollUtil.isNotEmpty(userDOList)){
throw new BizException("您目前还有未离职信息,无法直接注销,请先在\"就职单位\"页面中离职");
}

View File

@ -80,6 +80,9 @@ public class UserUpdateExe {
@Transactional(rollbackFor = Exception.class)
public void execute(UserUpdateCmd userUpdateCmd) {
//pc端不允许修改固定和流动状态
userUpdateCmd.setFlowFlag(null);
UserE userE = new UserE();
BeanUtils.copyProperties(userUpdateCmd, userE);
// 对比用户老数据与要修改数据,查看是否涉及调岗及入职
@ -130,13 +133,11 @@ public class UserUpdateExe {
public boolean executePasswordRecover(AppUserRegisterCmd cmd) {
// 根据手机号查询用户信息
List<UserDO> listByPhone = userRepository.getListByPhone(cmd.getPhone());
List<UserDO> listByPhone = userRepository.getListByPhone(cmd.getPhone(),null);
UserE userE = new UserE();
userE.checkPassword(cmd.getNewPassword(), cmd.getConfirmPassword());
if (!"123".equals(cmd.getPhoneCode())) {
// 获取redis验证码
Object phoneCodeObj = zcloudRedisUtil.get(RedisConstant.PHONE_CODE_KEY + cmd.getPhone());
if (phoneCodeObj == null || !phoneCodeObj.toString().equals(cmd.getPhoneCode())) {

View File

@ -35,5 +35,7 @@ public interface UserCoConvertor {
ZcloudUserCo converCOToDubboCO(UserCO userCO);
List<UserXmfCO> converDOsToXgfCOs(List<UserDO> data);
List<UserE> convertDOsToEs(List<UserDO> userList);
}

View File

@ -56,7 +56,7 @@ public class UserCorpRecordQueryExe {
return PageResponse.of(null, 0, userCorpRecordPageQry.getPageSize(), userCorpRecordPageQry.getPageIndex());
}
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone());
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone(),null);
//获取id list
List<Long> userIdList = userDOList.stream().map(UserDO::getId).collect(Collectors.toList());
userCorpRecordPageQry.setEqUserId(null);

View File

@ -215,7 +215,7 @@ public class UserQueryExe {
}
//返回企业列表
//根据手机号获取用户列表
List<UserDO> userDOList = userRepository.getListByPhone(cmd.getPhone());
List<UserDO> userDOList = userRepository.getListByPhone(cmd.getPhone(),null);
if(CollUtil.isEmpty(userDOList)){
throw new BizException("用户不存在");
}
@ -247,7 +247,7 @@ public class UserQueryExe {
//返回企业列表
UserDO userDO = userRepository.getById(id);
//根据手机号获取用户列表
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone());
List<UserDO> userDOList = userRepository.getListByPhone(userDO.getPhone(),null);
List<Long> userIds = userDOList.stream().map(UserDO::getId).collect(Collectors.toList());
List<UserCorpInfoDO> userCorpDOS = userRepository.getListByUserIds(userIds);

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.exception.BizException;
import com.baomidou.mybatisplus.annotation.TableField;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.framework.domain.model.BaseE;
import com.jjb.saas.framework.utils.DataEncryptDecryptUtil;
import com.zcloud.basic.info.domain.enums.CorpTypeEnum;
@ -162,12 +163,12 @@ public class UserE extends BaseE {
return StringUtils.isNotEmpty(userE.getUsername()) &&
StringUtils.isNotEmpty(userE.getPhone()) &&
StringUtils.isNotEmpty(userE.getUserIdCard()) &&
userE.getFlowFlag()!=null;
userE.getFlowFlag() != null;
}
public void initAdd(Long tenantId, UserE userE) {
if(StringUtils.isEmpty(userE.getUserId())){
if (StringUtils.isEmpty(userE.getUserId())) {
userE.setUserId(Tools.get32UUID());
}
userE.setTenantId(!ObjectUtils.isEmpty(userE.getTenantId()) ? userE.getTenantId() : tenantId);
@ -176,17 +177,17 @@ public class UserE extends BaseE {
userE.setPassword(defaultPassword);
}
public void initFormOnboarding(Long corpinfoId, Long departmentId, String postName, String userId){
public void initFormOnboarding(Long corpinfoId, Long departmentId, String postName, String userId) {
this.setCorpinfoId(corpinfoId);
this.setDepartmentId(departmentId);
this.setPostName(postName);
this.setEmploymentFlag(UserEmploymentFlagEnum.ENTRY_AUDIT.getCode());
if(StringUtils.isNotEmpty(userId)){
if (StringUtils.isNotEmpty(userId)) {
this.setUserId(userId);
}
}
public void initFromRZ(Long corpinfoId, Long roleId, RzUserRecordE rzUserRecordE){
public void initFromRZ(Long corpinfoId, Long roleId, RzUserRecordE rzUserRecordE) {
this.setCorpinfoId(corpinfoId);
this.setDepartmentId(corpinfoId);
this.setName(rzUserRecordE.getEmployeeName());
@ -290,33 +291,35 @@ public class UserE extends BaseE {
}
public void encryptionPassword() {
if(StringUtils.isNotEmpty(password)){
if (StringUtils.isNotEmpty(password)) {
this.setPassword(Sm2Util.encryptHex(MD5.md5(password), publicKey));
}
if (StringUtils.isNotEmpty(newPassword)) {
this.setNewPassword(Sm2Util.encryptHex(MD5.md5(newPassword), publicKey));
}
}
public Boolean checkUserPassword(String password,String content){
public Boolean checkUserPassword(String password, String content) {
String s = DataEncryptDecryptUtil.sm2Decrypt(privateKey, publicKey, content);
String s1 = MD5.md5(password);
return s.equalsIgnoreCase(s1);
}
public static void main(String[] args) {
String publicKey = "0402df2195296d4062ac85ad766994d73e871b887e18efb9a9a06b4cebc72372869b7da6c347c129dee2b46a0f279ff066b01c76208c2a052af75977c722a2ccee";
String privateKey = "1cfcaab309f614f10d2fed833331b65da75da7682963a6673a9a5d836b6f8c18";
String publicKey = "0402df2195296d4062ac85ad766994d73e871b887e18efb9a9a06b4cebc72372869b7da6c347c129dee2b46a0f279ff066b01c76208c2a052af75977c722a2ccee";
String privateKey = "1cfcaab309f614f10d2fed833331b65da75da7682963a6673a9a5d836b6f8c18";
System.out.println(Sm2Util.encryptHex(MD5.md5("1234"), publicKey));
System.out.println(Sm2Util.encryptHex(MD5.md5("1234"), publicKey));
String sign = Sm2Util.sign(privateKey, "1234");
boolean verify = Sm2Util.verify(publicKey, "04cd0a62599ab4613c6f1c6af1e4eaf5e650fadfd1d4fd9b7350975011bf3bccdf31c7eda8096f182f44e5601bc99554057441370bb45a8baa3386e2b6fd21110b97e579df964612167ec264d8d9752fea3630ad4d67e1dd52defd3817ffa38a19966456574fa85e59bdb889d817ccac6763c90ffe2ba5fafd567188c7a6e4b098",sign);
boolean verify = Sm2Util.verify(publicKey, "04cd0a62599ab4613c6f1c6af1e4eaf5e650fadfd1d4fd9b7350975011bf3bccdf31c7eda8096f182f44e5601bc99554057441370bb45a8baa3386e2b6fd21110b97e579df964612167ec264d8d9752fea3630ad4d67e1dd52defd3817ffa38a19966456574fa85e59bdb889d817ccac6763c90ffe2ba5fafd567188c7a6e4b098", sign);
System.out.println(verify);
String s = DataEncryptDecryptUtil.sm2Decrypt(privateKey, publicKey, "04cd0a62599ab4613c6f1c6af1e4eaf5e650fadfd1d4fd9b7350975011bf3bccdf31c7eda8096f182f44e5601bc99554057441370bb45a8baa3386e2b6fd21110b97e579df964612167ec264d8d9752fea3630ad4d67e1dd52defd3817ffa38a19966456574fa85e59bdb889d817ccac6763c90ffe2ba5fafd567188c7a6e4b098");
System.out.println(s);
String inputMd5 = MD5.md5("1234");
System.out.println(inputMd5);
}
public void setOldFlowInfo(UserCorpE userCorpE) {
this.setDepartmentId(userCorpE.getDepartmentId());
this.setPostId(userCorpE.getPostId());
@ -328,7 +331,7 @@ public class UserE extends BaseE {
}
public boolean verifyTransferFlow(UserE oldUserE, UserE newUserE) {
if(newUserE.getFlowFlag() == null){
if (newUserE.getFlowFlag() == null) {
return false;
}
if (!oldUserE.getFlowFlag().equals(newUserE.getFlowFlag())) {
@ -336,5 +339,41 @@ public class UserE extends BaseE {
}
return false;
}
public void checkPhone(List<UserE> userEList) {
if (CollUtil.isEmpty(userEList)) {
return;
}
//判断AuthContext.gettenantId在userList中是否存在
if (CollUtil.isNotEmpty(userEList)) {
//判断是否有当前企业
boolean flag = userEList.stream().anyMatch(userE -> userE.getCorpinfoId().equals(AuthContext.getTenantId()));
if (flag) {
//需要修改,不是提示
throw new BizException("当前手机号当前企业已存在");
}else{
throw new BizException("当前手机号已在其他企业存在");
}
}
}
public void checkXGfPhone(List<UserE> userEList) {
if(UserFlowFlagEnum.FIXED.getCode().equals(this.getFlowFlag())){
this.checkPhone(userEList);
}else{
//判断在其他企业是否是固定人员
List<UserE> userList = userEList.stream().filter(userE -> UserFlowFlagEnum.FIXED.getCode().equals(userE.getFlowFlag())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(userList)) {
throw new BizException("当前手机号已在其他企业属于固定人员");
}
//判断是否在当前企业存在
//判断是否有当前企业
boolean flag = userEList.stream().anyMatch(userE -> userE.getCorpinfoId().equals(AuthContext.getTenantId()));
if (flag) {
throw new BizException("当前手机号当前企业已存在");
}
}
}
}

View File

@ -83,7 +83,7 @@ public interface UserRepository extends BaseRepository<UserDO> {
void checkUserIdCard(@NotNull(message = "主键id不能为空") Long id, String userIdCard);
List<UserDO> getListByPhone(String phone);
List<UserDO> getListByPhone(String phone,List<Integer> employmentFlagList);
List<UserCorpInfoDO> getListByUserIds(List<Long> userIds);
}

View File

@ -201,10 +201,11 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserMapper, UserDO> i
Map<String, Object> verifyParam = new HashMap<>();
verifyParam.put("phone", params.get("phone"));
verifyParam.put("id", params.get("id"));
Integer count = userMapper.countUser(verifyParam);
//手机号验证改成提交时验证
/* Integer count = userMapper.countUser(verifyParam);
if (count > 0) {
return Response.buildFailure("手机号已经存在,请联系管理员");
}
}*/
}
if (!ObjectUtils.isEmpty(params.get("userIdCard"))) {
Map<String, Object> verifyParam = new HashMap<>();
@ -383,7 +384,7 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserMapper, UserDO> i
if(StringUtils.isEmpty( phone)){
userChangePassword(id, password);
}else{
List<UserDO> userDOList = getListByPhone( phone);
List<UserDO> userDOList = getListByPhone( phone,null);
for (UserDO userDO1 : userDOList) {
userChangePassword(userDO1.getId(), password);
}
@ -470,8 +471,9 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserMapper, UserDO> i
if(StringUtils.isEmpty( phone)){
userChangePassword(userDO.getId(), userDO.getNewPassword());
}else{
List<UserDO> userDOList = list(new QueryWrapper<UserDO>().eq("phone", phone));
List<UserDO> userDOList = getListByPhone( phone,null);
for (UserDO userDO1 : userDOList) {
//过滤出在职,离职审核人员
userChangePassword(userDO1.getId(), userDO.getNewPassword());
}
}
@ -558,9 +560,13 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserMapper, UserDO> i
}
@Override
public List<UserDO> getListByPhone(String phone) {
public List<UserDO> getListByPhone(String phone,List<Integer> employmentFlagList) {
QueryWrapper<UserDO> queryWrapper = new QueryWrapper<>();
if(CollUtil.isNotEmpty(employmentFlagList)){
queryWrapper.in("employment_flag", employmentFlagList);
}
queryWrapper.eq("phone", phone);
queryWrapper.orderByAsc("create_time");
return list(queryWrapper);
}