|
@@ -1,42 +1,42 @@
|
|
-package com.backendsys.service.System;
|
|
|
|
-
|
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
|
-import com.backendsys.utils.UserUtils;
|
|
|
|
-import com.backendsys.utils.MD5Util;
|
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
|
-import com.backendsys.entity.System.SysUserDTO;
|
|
|
|
-import com.backendsys.mapper.System.SysUserMapper;
|
|
|
|
-import com.backendsys.utils.response.PageInfoResult;
|
|
|
|
-
|
|
|
|
-import org.redisson.api.RLock;
|
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
-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;
|
|
|
|
-
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
-import java.util.*;
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-
|
|
|
|
-@Service
|
|
|
|
-public class SysUserServiceImpl implements SysUserService {
|
|
|
|
-
|
|
|
|
- @Value("${REDIS_LOGIN_TOKEN_PREFIX}")
|
|
|
|
- private String REDIS_LOGIN_TOKEN_PREFIX;
|
|
|
|
-
|
|
|
|
- @Lazy
|
|
|
|
- @Autowired
|
|
|
|
- RedissonClient redissonClient;
|
|
|
|
- @Autowired
|
|
|
|
- private RedisTemplate redisTemplate;
|
|
|
|
- @Autowired
|
|
|
|
- private SysUserMapper sysUserMapper;
|
|
|
|
-
|
|
|
|
|
|
+//package com.backendsys.service.System;
|
|
|
|
+//
|
|
|
|
+//import cn.hutool.core.convert.Convert;
|
|
|
|
+//import com.backendsys.utils.UserUtils;
|
|
|
|
+//import com.backendsys.utils.MD5Util;
|
|
|
|
+//import com.github.pagehelper.PageHelper;
|
|
|
|
+//import com.backendsys.entity.System.SysUserDTO;
|
|
|
|
+//import com.backendsys.mapper.System.SysUserMapper;
|
|
|
|
+//import com.backendsys.utils.response.PageInfoResult;
|
|
|
|
+//
|
|
|
|
+//import org.redisson.api.RLock;
|
|
|
|
+//import org.redisson.api.RedissonClient;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+//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;
|
|
|
|
+//
|
|
|
|
+//import java.security.NoSuchAlgorithmException;
|
|
|
|
+//import java.util.*;
|
|
|
|
+//import java.util.concurrent.TimeUnit;
|
|
|
|
+//import java.util.stream.Collectors;
|
|
|
|
+//
|
|
|
|
+//@Service
|
|
|
|
+//public class SysUserServiceImpl implements SysUserService {
|
|
|
|
+//
|
|
|
|
+// @Value("${REDIS_LOGIN_TOKEN_PREFIX}")
|
|
|
|
+// private String REDIS_LOGIN_TOKEN_PREFIX;
|
|
|
|
+//
|
|
|
|
+// @Lazy
|
|
|
|
+// @Autowired
|
|
|
|
+// RedissonClient redissonClient;
|
|
|
|
+// @Autowired
|
|
|
|
+// private RedisTemplate redisTemplate;
|
|
|
|
+// @Autowired
|
|
|
|
+// private SysUserMapper sysUserMapper;
|
|
|
|
+//
|
|
// /**
|
|
// /**
|
|
// * 查询 系统用户列表
|
|
// * 查询 系统用户列表
|
|
// */
|
|
// */
|
|
@@ -71,34 +71,34 @@ public class SysUserServiceImpl implements SysUserService {
|
|
//
|
|
//
|
|
// return sysUserMapper.queryUserWithLogined(last_login_uuids);
|
|
// return sysUserMapper.queryUserWithLogined(last_login_uuids);
|
|
// }
|
|
// }
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查询 系统用户详情
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Map<String, Object> queryUserById(Long user_id) {
|
|
|
|
- Map<String, Object> sysUser = sysUserMapper.queryUserDetail(user_id);
|
|
|
|
- if (sysUser == null) { return null; }
|
|
|
|
-
|
|
|
|
- // 原格式 roles: [{ id, module_name, module_codes: "sy:userRole:update,sy:userRole:create"
|
|
|
|
- // [格式化] 输出 modules: ["sy:userRole:update", "sy:userRole:create"]
|
|
|
|
- List<Map<String, Object>> roles = (List<Map<String, Object>>) sysUser.get("roles");
|
|
|
|
- sysUser.put("modules", UserUtils.extractModuleCodes(roles));
|
|
|
|
-
|
|
|
|
- // [格式化] 输出 roles: [{ id, module_name }]
|
|
|
|
- roles.forEach(role -> role.remove("module_ids"));
|
|
|
|
- sysUser.put("roles", roles);
|
|
|
|
-
|
|
|
|
- // [格式化] 输出 role_ids: [1, 2]
|
|
|
|
- List<Long> role_ids = roles.stream().map(role -> (Long) role.get("id")).collect(Collectors.toList());
|
|
|
|
- sysUser.put("role_id", role_ids);
|
|
|
|
-
|
|
|
|
- return sysUser;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 查询 系统用户详情
|
|
|
|
+// */
|
|
|
|
+// @Override
|
|
|
|
+// public Map<String, Object> queryUserById(Long user_id) {
|
|
|
|
+// Map<String, Object> sysUser = sysUserMapper.queryUserDetail(user_id);
|
|
|
|
+// if (sysUser == null) { return null; }
|
|
|
|
+//
|
|
|
|
+// // 原格式 roles: [{ id, module_name, module_codes: "sy:userRole:update,sy:userRole:create"
|
|
|
|
+// // [格式化] 输出 modules: ["sy:userRole:update", "sy:userRole:create"]
|
|
|
|
+// List<Map<String, Object>> roles = (List<Map<String, Object>>) sysUser.get("roles");
|
|
|
|
+// sysUser.put("modules", UserUtils.extractModuleCodes(roles));
|
|
|
|
+//
|
|
|
|
+// // [格式化] 输出 roles: [{ id, module_name }]
|
|
|
|
+// roles.forEach(role -> role.remove("module_ids"));
|
|
|
|
+// sysUser.put("roles", roles);
|
|
|
|
+//
|
|
|
|
+// // [格式化] 输出 role_ids: [1, 2]
|
|
|
|
+// List<Long> role_ids = roles.stream().map(role -> (Long) role.get("id")).collect(Collectors.toList());
|
|
|
|
+// sysUser.put("role_id", role_ids);
|
|
|
|
+//
|
|
|
|
+// return sysUser;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
// /**
|
|
// /**
|
|
// * 创建 系统用户
|
|
// * 创建 系统用户
|
|
// * @param sysUserDTO
|
|
// * @param sysUserDTO
|
|
@@ -138,48 +138,48 @@ public class SysUserServiceImpl implements SysUserService {
|
|
// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
// } finally { lock.unlock(); }
|
|
// } finally { lock.unlock(); }
|
|
// }
|
|
// }
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 更新 系统用户信息
|
|
|
|
- * @param sysUserDTO
|
|
|
|
- * @return { user_id }
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- @Transactional
|
|
|
|
- public Map<String, Object> updateUserInfo(SysUserDTO sysUserDTO) {
|
|
|
|
- RLock lock = redissonClient.getLock("updateUserInfo");
|
|
|
|
- try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
|
-
|
|
|
|
- // 当 status 状态为 -1(禁用) 时,同时清除登录状态
|
|
|
|
- Integer status = sysUserDTO.getStatus();
|
|
|
|
- if (status != null && status == -1) {
|
|
|
|
- String last_login_uuid = sysUserDTO.getLast_login_uuid();
|
|
|
|
- redisTemplate.delete(REDIS_LOGIN_TOKEN_PREFIX + last_login_uuid);
|
|
|
|
- sysUserDTO.setLast_login_uuid("");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 获取参数,并将 [1,2] 转换为 [{ id: 1 }, { id: 2 }]
|
|
|
|
- List<Long> role_id = sysUserDTO.getRole_id();
|
|
|
|
- if (role_id != null && role_id.size() > 0) {
|
|
|
|
- List<LinkedHashMap<String, Object>> convertedList = role_id.stream()
|
|
|
|
- .map(id -> {
|
|
|
|
- LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
|
|
|
- map.put("id", id);
|
|
|
|
- return map;
|
|
|
|
- })
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- sysUserDTO.setRoles(convertedList);
|
|
|
|
- }
|
|
|
|
- // ------------------------------------------------------
|
|
|
|
-
|
|
|
|
- // 更新
|
|
|
|
- sysUserMapper.updateUserInfo(sysUserDTO);
|
|
|
|
- return Map.of("user_id", sysUserDTO.getUser_id());
|
|
|
|
-
|
|
|
|
- } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
|
- } finally { lock.unlock(); }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 更新 系统用户信息
|
|
|
|
+// * @param sysUserDTO
|
|
|
|
+// * @return { user_id }
|
|
|
|
+// */
|
|
|
|
+// @Override
|
|
|
|
+// @Transactional
|
|
|
|
+// public Map<String, Object> updateUserInfo(SysUserDTO sysUserDTO) {
|
|
|
|
+// RLock lock = redissonClient.getLock("updateUserInfo");
|
|
|
|
+// try { lock.tryLock(3, TimeUnit.SECONDS);
|
|
|
|
+//
|
|
|
|
+// // 当 status 状态为 -1(禁用) 时,同时清除登录状态
|
|
|
|
+// Integer status = sysUserDTO.getStatus();
|
|
|
|
+// if (status != null && status == -1) {
|
|
|
|
+// String last_login_uuid = sysUserDTO.getLast_login_uuid();
|
|
|
|
+// redisTemplate.delete(REDIS_LOGIN_TOKEN_PREFIX + last_login_uuid);
|
|
|
|
+// sysUserDTO.setLast_login_uuid("");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 获取参数,并将 [1,2] 转换为 [{ id: 1 }, { id: 2 }]
|
|
|
|
+// List<Long> role_id = sysUserDTO.getRole_id();
|
|
|
|
+// if (role_id != null && role_id.size() > 0) {
|
|
|
|
+// List<LinkedHashMap<String, Object>> convertedList = role_id.stream()
|
|
|
|
+// .map(id -> {
|
|
|
|
+// LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
|
|
|
+// map.put("id", id);
|
|
|
|
+// return map;
|
|
|
|
+// })
|
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
+// sysUserDTO.setRoles(convertedList);
|
|
|
|
+// }
|
|
|
|
+// // ------------------------------------------------------
|
|
|
|
+//
|
|
|
|
+// // 更新
|
|
|
|
+// sysUserMapper.updateUserInfo(sysUserDTO);
|
|
|
|
+// return Map.of("user_id", sysUserDTO.getUser_id());
|
|
|
|
+//
|
|
|
|
+// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
|
|
+// } finally { lock.unlock(); }
|
|
|
|
+// }
|
|
|
|
+//
|
|
// /**
|
|
// /**
|
|
// * 审核 系统用户
|
|
// * 审核 系统用户
|
|
// * @param sysUserDTO
|
|
// * @param sysUserDTO
|
|
@@ -375,5 +375,5 @@ public class SysUserServiceImpl implements SysUserService {
|
|
// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
// } catch (InterruptedException e) { throw new RuntimeException(e);
|
|
// } finally { lock.unlock(); }
|
|
// } finally { lock.unlock(); }
|
|
// }
|
|
// }
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+//
|
|
|
|
+//}
|