|
@@ -2,6 +2,7 @@ package com.backendsys.modules.system.service.impl;
|
|
|
|
|
|
import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
|
+import com.backendsys.modules.common.utils.MybatisUtil;
|
|
|
import com.backendsys.modules.system.dao.*;
|
|
|
import com.backendsys.modules.system.entity.SysUser.SysUser;
|
|
|
import com.backendsys.modules.system.entity.SysUser.SysUserDTO;
|
|
@@ -10,6 +11,8 @@ import com.backendsys.modules.system.entity.SysUser.SysUserRole;
|
|
|
import com.backendsys.modules.system.service.SysUserV2Service;
|
|
|
import com.backendsys.utils.response.PageEntity;
|
|
|
import com.backendsys.utils.response.PageInfoResult;
|
|
|
+import com.backendsys.utils.response.Result;
|
|
|
+import com.backendsys.utils.response.ResultEnum;
|
|
|
import com.backendsys.utils.v2.PageUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -18,7 +21,6 @@ import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -72,12 +74,6 @@ public class SysUserV2ServiceImpl extends ServiceImpl<SysUserDao, SysUser> imple
|
|
|
return new PageInfoResult(list).toEntity();
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public SysUserInfo selectById(Long user_id) {
|
|
|
-//// return sysUserInfoDao.selectOne(new QueryWrapper<SysUserInfo>().eq("user_id", user_id));
|
|
|
-// return sysUserInfoDao.selectById(user_id);
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 获得系统用户详情
|
|
|
*/
|
|
@@ -160,6 +156,9 @@ public class SysUserV2ServiceImpl extends ServiceImpl<SysUserDao, SysUser> imple
|
|
|
RLock lock = redissonClient.getLock("updateUserInfo");
|
|
|
try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
|
|
|
+ // 判断记录是否存在
|
|
|
+ MybatisUtil.checkExists(sysUserDao, "id", sysUserDTO.getUser_id(), "用户不存在");
|
|
|
+
|
|
|
// 当 status 状态为 -1(禁用) 时,同时清除登录状态
|
|
|
Integer status = sysUserDTO.getStatus();
|
|
|
if (status != null && status == -1) {
|
|
@@ -176,5 +175,38 @@ public class SysUserV2ServiceImpl extends ServiceImpl<SysUserDao, SysUser> imple
|
|
|
} finally { lock.unlock(); }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 编辑系统用户密码
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> updateUserPassword(SysUserDTO sysUserDTO) {
|
|
|
+ RLock lock = redissonClient.getLock("updateUserPassword");
|
|
|
+ try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ // 查询用户
|
|
|
+ SysUser sysUser = sysUserDao.selectOne(new QueryWrapper<SysUser>().eq("id", sysUserDTO.getUser_id()));
|
|
|
+ if (sysUser == null) throw new CustException("原密码不正确");
|
|
|
+
|
|
|
+ BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
|
|
|
|
|
+ // [判断] 原密码是否正确
|
|
|
+ String old_password_request = sysUserDTO.getOld_password();
|
|
|
+ String old_password = sysUser.getPassword();
|
|
|
+ if (!encoder.matches(old_password_request, old_password)) {
|
|
|
+ throw new CustException("原密码不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码二次加密
|
|
|
+ SysUser entity = new SysUser();
|
|
|
+ entity.setId(sysUserDTO.getUser_id());
|
|
|
+ entity.setPassword(encoder.encode(sysUserDTO.getPassword()));
|
|
|
+ System.out.println(entity);
|
|
|
+ sysUserDao.updateById(entity);
|
|
|
+
|
|
|
+ return Map.of("user_id", sysUserDTO.getUser_id());
|
|
|
+
|
|
|
+ } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
+ } finally { lock.unlock(); }
|
|
|
+ }
|
|
|
}
|