|
@@ -10,11 +10,13 @@ import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.LoginDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.UserDto;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.VerifyCodeCheckDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.DescribeImportDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.SysUserImportDto;
|
|
|
import com.qmth.teachcloud.common.bean.params.ApproveUserResult;
|
|
|
import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
|
import com.qmth.teachcloud.common.bean.result.UserBatchDisposeResult;
|
|
|
+import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.*;
|
|
@@ -80,6 +82,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Resource
|
|
|
SysUserService sysUserService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ DictionaryConfig dictionaryConfig;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<UserDto> list(String loginName, String roleId, Boolean enable, String realName, Integer pageNumber, Integer pageSize) {
|
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
@@ -135,6 +141,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return this.updateById(user);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public boolean updatePassword(SysUser user) throws NoSuchAlgorithmException {
|
|
|
SysUser sysUser = this.getById(user.getId());
|
|
@@ -144,13 +151,37 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
if (!StringUtils.equals(sysUser.getPassword(), user.getOldPassword())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("原密码不正确");
|
|
|
}
|
|
|
- sysUser.setPwdCount(sysUser.getPwdCount() == null ? 1 : sysUser.getPwdCount() + 1);
|
|
|
- sysUser.setPwdUpdateTime(System.currentTimeMillis());
|
|
|
- sysUser.setPassword(user.getPassword());
|
|
|
+ String newPwd = user.getPassword();
|
|
|
+ String mobilePhone = user.getMobileNumber();
|
|
|
+ String verifyCode = user.getVerifyCode();
|
|
|
+ if (SystemConstant.strNotNull(newPwd)) {
|
|
|
+ // 参数中存在密码 -》 更新密码
|
|
|
+ sysUser.setPwdCount(sysUser.getPwdCount() == null ? 1 : sysUser.getPwdCount() + 1);
|
|
|
+ sysUser.setPwdUpdateTime(System.currentTimeMillis());
|
|
|
+ sysUser.setPassword(newPwd);
|
|
|
+ }
|
|
|
+ if (SystemConstant.strNotNull(mobilePhone)) {
|
|
|
+ // 参数中存在手机号 -》 更新手机号
|
|
|
+ if (!SystemConstant.strNotNull(verifyCode)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("验证码不存在");
|
|
|
+ }
|
|
|
+ this.checkSmsCode(user.getId(), mobilePhone, verifyCode);
|
|
|
+ // 更新电话
|
|
|
+ sysUser.setMobileNumber(mobilePhone);
|
|
|
+ }
|
|
|
boolean success = this.updateById(sysUser);
|
|
|
- //如果原密码和旧密码不一致,需要重新登录
|
|
|
- if (!Objects.equals(user.getOldPassword(), sysUser.getPassword())) {
|
|
|
- commonService.removeUserInfo(sysUser.getId(), false);
|
|
|
+ //如果原密码和旧密码不一致,且用户已经登陆,需要重新登录
|
|
|
+ Object object = ServletUtil.getRequest().getAttribute(SystemConstant.SESSION);
|
|
|
+ if (Objects.nonNull(object)){
|
|
|
+ if (SystemConstant.strNotNull(newPwd)){
|
|
|
+ if (!Objects.equals(user.getOldPassword(), sysUser.getPassword())){
|
|
|
+ commonService.removeUserInfo(sysUser.getId(), false);
|
|
|
+ }
|
|
|
+ } else if (SystemConstant.strNotNull(mobilePhone)) {
|
|
|
+ if (!Objects.equals(mobilePhone, sysUser.getMobileNumber())){
|
|
|
+ commonService.removeUserInfo(sysUser.getId(), false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return success;
|
|
|
}
|
|
@@ -306,10 +337,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
}
|
|
|
}
|
|
|
// 手机号检验
|
|
|
- SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, mobileNumber));
|
|
|
- if (Objects.nonNull(checkMobileNumber)) {
|
|
|
- if (!checkMobileNumber.getId().equals(userSaveParams.getId())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("用户手机号【" + mobileNumber + "】重复");
|
|
|
+ if (SystemConstant.strNotNull(mobileNumber)){
|
|
|
+ SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, mobileNumber));
|
|
|
+ if (Objects.nonNull(checkMobileNumber)) {
|
|
|
+ if (!checkMobileNumber.getId().equals(userSaveParams.getId())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("用户手机号【" + mobileNumber + "】重复");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -535,7 +568,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
userSaveParams.setOrgId(orgId);
|
|
|
userSaveParams.setRealName(name);
|
|
|
userSaveParams.setRoleIds(roleIdList.toArray(new Long[0]));
|
|
|
- userSaveParams.setMobileNumber(phoneNumber);
|
|
|
+ if (SystemConstant.strNotNull(phoneNumber)){
|
|
|
+ userSaveParams.setMobileNumber(phoneNumber);
|
|
|
+ }
|
|
|
userSaveParams.setCode(code);
|
|
|
userSaveParamsList.add(userSaveParams);
|
|
|
}
|
|
@@ -655,6 +690,30 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return sysUserMapper.findById(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void checkSmsCode(Long userId,String mobileNumber, String code) {
|
|
|
+ SysConfig value = sysConfigService.getByKey("sys.code.enable");
|
|
|
+ if (Objects.nonNull(value) && value.getConfigValue().equals("true")) {
|
|
|
+ if (Objects.isNull(code)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("验证码为空");
|
|
|
+ }
|
|
|
+ if (!dictionaryConfig.smsDomain().getSmsNormalCode().equals(code)) {
|
|
|
+ List<VerifyCodeCheckDto> verifyCodeCheckDtoList = this.baseMapper.findVerifyCodeByUser(userId,mobileNumber);
|
|
|
+ if (verifyCodeCheckDtoList.size() < 1){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("请确认已经发送了验证码");
|
|
|
+ }
|
|
|
+ VerifyCodeCheckDto accessControl = verifyCodeCheckDtoList.get(0);
|
|
|
+ if (accessControl == null || !accessControl.getVerifyCode().equals(code)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("短信验证码错误,请仔细核对后再次输入");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (new Date(accessControl.getExpireTime()).before(new Date())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("短信验证码已过期");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量处理用户信息帮助类
|
|
|
*
|
|
@@ -681,10 +740,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
}
|
|
|
}
|
|
|
// 手机号检验
|
|
|
- SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, mobileNumber));
|
|
|
- if (Objects.nonNull(checkMobileNumber)) {
|
|
|
- if (!checkMobileNumber.getId().equals(userSaveParams.getId())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("用户手机号【" + mobileNumber + "】重复");
|
|
|
+ if (SystemConstant.strNotNull(mobileNumber)){
|
|
|
+ SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, mobileNumber));
|
|
|
+ if (Objects.nonNull(checkMobileNumber)) {
|
|
|
+ if (!checkMobileNumber.getId().equals(userSaveParams.getId())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("用户手机号【" + mobileNumber + "】重复");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|