|
|
|
|
@@ -3,8 +3,10 @@ package org.dromara.system.service.impl;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.crypto.digest.BCrypt;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
@@ -14,13 +16,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
|
|
|
import org.dromara.common.core.constant.Constants;
|
|
|
|
|
import org.dromara.common.core.constant.GlobalConstants;
|
|
|
|
|
import org.dromara.common.core.constant.SystemConstants;
|
|
|
|
|
import org.dromara.common.core.domain.dto.UserDTO;
|
|
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
|
|
import org.dromara.common.core.exception.user.CaptchaExpireException;
|
|
|
|
|
import org.dromara.common.core.service.UserService;
|
|
|
|
|
import org.dromara.common.core.utils.*;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.system.domain.SysUser;
|
|
|
|
|
import org.dromara.system.domain.SysUserPost;
|
|
|
|
|
@@ -357,6 +363,66 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
|
|
throw new ServiceException("修改用户{}信息失败", user.getUserName());
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateAppUser(SysUserBo user) {
|
|
|
|
|
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
|
|
|
|
|
sysUser.setUserId(LoginHelper.getUserId());
|
|
|
|
|
// 防止错误更新后导致的数据误删除
|
|
|
|
|
boolean b =true;
|
|
|
|
|
if (StringUtils.isNotEmpty(user.getPhonenumber())){
|
|
|
|
|
b = validateSmsCode(user.getPhonenumber(), user.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (StringUtils.isNotEmpty(user.getUserName()) && Validator.isMobile(user.getUserName())){
|
|
|
|
|
// b = validateSmsCode(user.getUserName(), user.getCode());
|
|
|
|
|
// }
|
|
|
|
|
if (b){
|
|
|
|
|
// String hashpw = BCrypt.hashpw(user.getPassword());
|
|
|
|
|
// sysUser.setPassword(hashpw);
|
|
|
|
|
int flag = baseMapper.updateById(sysUser);
|
|
|
|
|
if (flag < 1) {
|
|
|
|
|
throw new ServiceException("修改用户{}信息失败", user.getUserName());
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int updateUserPas(SysUserBo user) {
|
|
|
|
|
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
|
|
|
|
|
sysUser.setUserId(LoginHelper.getUserId());
|
|
|
|
|
// 防止错误更新后导致的数据误删除
|
|
|
|
|
boolean b =true;
|
|
|
|
|
if (StringUtils.isNotEmpty(user.getUserName()) && Validator.isMobile(user.getUserName())){
|
|
|
|
|
b = validateSmsCode(user.getUserName(), user.getCode());
|
|
|
|
|
}
|
|
|
|
|
if (b){
|
|
|
|
|
String hashpw = BCrypt.hashpw(user.getPassword());
|
|
|
|
|
sysUser.setPassword(hashpw);
|
|
|
|
|
int flag = baseMapper.updateById(sysUser);
|
|
|
|
|
if (flag < 1) {
|
|
|
|
|
throw new ServiceException("修改用户{}密码失败", user.getUserName());
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验短信验证码
|
|
|
|
|
*/
|
|
|
|
|
private boolean validateSmsCode( String phonenumber, String smsCode) {
|
|
|
|
|
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
|
|
|
|
|
if (StringUtils.isBlank(code)) {
|
|
|
|
|
throw new CaptchaExpireException();
|
|
|
|
|
}
|
|
|
|
|
return code.equals(smsCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|