|
|
@ -68,7 +68,7 @@ public class UserController { |
|
|
@Operation(summary = "保存用户分组", description = "单个分组,保存到 group_ids 字段") |
|
|
@Operation(summary = "保存用户分组", description = "单个分组,保存到 group_ids 字段") |
|
|
public Result<?> saveGroup(@RequestBody JSONObject jsonObject) { |
|
|
public Result<?> saveGroup(@RequestBody JSONObject jsonObject) { |
|
|
Long userId = jsonObject.getLong("userId"); |
|
|
Long userId = jsonObject.getLong("userId"); |
|
|
String groupId = jsonObject.getStr("groupIds"); // 前端传分组ID
|
|
|
String groupId = jsonObject.getStr("groupIds"); |
|
|
|
|
|
|
|
|
userService.saveUserGroup(userId, groupId); |
|
|
userService.saveUserGroup(userId, groupId); |
|
|
return ResultUtils.success(); |
|
|
return ResultUtils.success(); |
|
|
@ -104,6 +104,27 @@ public class UserController { |
|
|
return ResultUtils.success(); |
|
|
return ResultUtils.success(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/updateLanguage") |
|
|
|
|
|
@Operation(summary = "更新用户语言", description = "更新当前用户的语言设置:zh/en/jp/kor等") |
|
|
|
|
|
public Result<?> updateLanguage(@RequestBody JSONObject jsonObject) { |
|
|
|
|
|
String language = jsonObject.getStr("language"); |
|
|
|
|
|
if (StrUtil.isBlank(language)) { |
|
|
|
|
|
return ResultUtils.error(ResultCode.XSS_PARAM_ERROR, "语言不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UserSession session = SessionContext.getSession(); |
|
|
|
|
|
Long userId = session.getUserId(); |
|
|
|
|
|
|
|
|
|
|
|
User user = userService.getById(userId); |
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
return ResultUtils.error(ResultCode.XSS_PARAM_ERROR, "用户不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user.setLanguage(language); |
|
|
|
|
|
boolean success = userService.updateById(user); |
|
|
|
|
|
return success ? ResultUtils.success("语言更新成功") : ResultUtils.error(ResultCode.XSS_PARAM_ERROR, "更新失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@GetMapping("/findByName") |
|
|
@GetMapping("/findByName") |
|
|
@Operation(summary = "查找用户", description = "根据用户名或昵称查找用户") |
|
|
@Operation(summary = "查找用户", description = "根据用户名或昵称查找用户") |
|
|
public Result<List<UserVO>> findByName(@RequestParam String name) { |
|
|
public Result<List<UserVO>> findByName(@RequestParam String name) { |
|
|
@ -113,18 +134,15 @@ public class UserController { |
|
|
@PostMapping("/getEnableChangeCustomer") |
|
|
@PostMapping("/getEnableChangeCustomer") |
|
|
@Operation(summary = "获取可转接的客服", description = "转接客服") |
|
|
@Operation(summary = "获取可转接的客服", description = "转接客服") |
|
|
public Result<List<Map<String, Object>>> getEnableChangeCustomer() { |
|
|
public Result<List<Map<String, Object>>> getEnableChangeCustomer() { |
|
|
// 获取当前客服id、转接客服id、转接用户id
|
|
|
|
|
|
UserSession session = SessionContext.getSession(); |
|
|
UserSession session = SessionContext.getSession(); |
|
|
Long userId = session.getUserId(); |
|
|
Long userId = session.getUserId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(userId)){ |
|
|
if(ObjectUtil.isNull(userId)){ |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<User> list = userService.getEnableChangeCustomerList(userId); |
|
|
List<User> list = userService.getEnableChangeCustomerList(userId); |
|
|
|
|
|
|
|
|
//使用Map返回id、昵称
|
|
|
|
|
|
List<Map<String, Object>> result = list.stream().map(user -> { |
|
|
List<Map<String, Object>> result = list.stream().map(user -> { |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
map.put("id", user.getId()); |
|
|
map.put("id", user.getId()); |
|
|
@ -152,7 +170,6 @@ public class UserController { |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取当前用户信息
|
|
|
|
|
|
User currentUser = userService.getById(userId); |
|
|
User currentUser = userService.getById(userId); |
|
|
if (currentUser == null) { |
|
|
if (currentUser == null) { |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
@ -160,7 +177,6 @@ public class UserController { |
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
// 获取可切换的账号ID列表(逗号分隔的字符串,如 "13,14")
|
|
|
|
|
|
String switchableIdsStr = currentUser.getSwitchableAccountIds(); |
|
|
String switchableIdsStr = currentUser.getSwitchableAccountIds(); |
|
|
List<Map<String, Object>> switchableUsers = new ArrayList<>(); |
|
|
List<Map<String, Object>> switchableUsers = new ArrayList<>(); |
|
|
|
|
|
|
|
|
@ -173,7 +189,6 @@ public class UserController { |
|
|
|
|
|
|
|
|
if (!ids.isEmpty()) { |
|
|
if (!ids.isEmpty()) { |
|
|
List<User> users = userService.listByIds(ids); |
|
|
List<User> users = userService.listByIds(ids); |
|
|
// 过滤掉被封禁的账号
|
|
|
|
|
|
users = users.stream() |
|
|
users = users.stream() |
|
|
.filter(u -> !Boolean.TRUE.equals(u.getIsBanned())) |
|
|
.filter(u -> !Boolean.TRUE.equals(u.getIsBanned())) |
|
|
.collect(Collectors.toList()); |
|
|
.collect(Collectors.toList()); |
|
|
@ -192,27 +207,21 @@ public class UserController { |
|
|
|
|
|
|
|
|
result.put("switchableUsers", switchableUsers); |
|
|
result.put("switchableUsers", switchableUsers); |
|
|
|
|
|
|
|
|
// 获取当前用户的 unique_token
|
|
|
|
|
|
String currentUserUniqueToken = currentUser.getUniqueToken(); |
|
|
String currentUserUniqueToken = currentUser.getUniqueToken(); |
|
|
|
|
|
|
|
|
// 构建查询条件
|
|
|
|
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>() |
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>() |
|
|
.eq(User::getIsCustomer, 2) |
|
|
.eq(User::getIsCustomer, 2) |
|
|
.ne(User::getId, userId) |
|
|
.ne(User::getId, userId) |
|
|
.eq(User::getIsBanned, 0); |
|
|
.eq(User::getIsBanned, 0); |
|
|
|
|
|
|
|
|
// 添加 unique_token 条件
|
|
|
|
|
|
if (StrUtil.isNotBlank(currentUserUniqueToken)) { |
|
|
if (StrUtil.isNotBlank(currentUserUniqueToken)) { |
|
|
// 当前用户有 unique_token,只查询相同 unique_token 的客服
|
|
|
|
|
|
queryWrapper.eq(User::getUniqueToken, currentUserUniqueToken); |
|
|
queryWrapper.eq(User::getUniqueToken, currentUserUniqueToken); |
|
|
} else { |
|
|
} else { |
|
|
// 当前用户没有 unique_token,只查询也没有 unique_token 的客服
|
|
|
|
|
|
queryWrapper.isNull(User::getUniqueToken).or().eq(User::getUniqueToken, ""); |
|
|
queryWrapper.isNull(User::getUniqueToken).or().eq(User::getUniqueToken, ""); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<User> availableUsers = userService.list(queryWrapper); |
|
|
List<User> availableUsers = userService.list(queryWrapper); |
|
|
|
|
|
|
|
|
// 获取已添加的ID集合
|
|
|
|
|
|
Set<Long> existingIds = new HashSet<>(); |
|
|
Set<Long> existingIds = new HashSet<>(); |
|
|
if (StrUtil.isNotBlank(switchableIdsStr)) { |
|
|
if (StrUtil.isNotBlank(switchableIdsStr)) { |
|
|
Arrays.stream(switchableIdsStr.split(",")) |
|
|
Arrays.stream(switchableIdsStr.split(",")) |
|
|
@ -221,14 +230,12 @@ public class UserController { |
|
|
.forEach(existingIds::add); |
|
|
.forEach(existingIds::add); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 标记是否已添加
|
|
|
|
|
|
List<Map<String, Object>> availableUsersList = availableUsers.stream().map(user -> { |
|
|
List<Map<String, Object>> availableUsersList = availableUsers.stream().map(user -> { |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
map.put("id", user.getId()); |
|
|
map.put("id", user.getId()); |
|
|
map.put("userName", user.getUserName()); |
|
|
map.put("userName", user.getUserName()); |
|
|
map.put("nickName", user.getNickName()); |
|
|
map.put("nickName", user.getNickName()); |
|
|
map.put("headImage", user.getHeadImage()); |
|
|
map.put("headImage", user.getHeadImage()); |
|
|
// map.put("headImageThumb", user.getHeadImageThumb());
|
|
|
|
|
|
map.put("isAdded", existingIds.contains(user.getId())); |
|
|
map.put("isAdded", existingIds.contains(user.getId())); |
|
|
return map; |
|
|
return map; |
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
@ -244,7 +251,6 @@ public class UserController { |
|
|
|
|
|
|
|
|
UserSession session = SessionContext.getSession(); |
|
|
UserSession session = SessionContext.getSession(); |
|
|
|
|
|
|
|
|
// 获取当前客服id、转接客服id、转接用户id
|
|
|
|
|
|
Long customerId = session.getUserId(); |
|
|
Long customerId = session.getUserId(); |
|
|
Long targetId = jsonObject.getLong("targetId"); |
|
|
Long targetId = jsonObject.getLong("targetId"); |
|
|
Long userId = jsonObject.getLong("userId"); |
|
|
Long userId = jsonObject.getLong("userId"); |
|
|
@ -267,22 +273,18 @@ public class UserController { |
|
|
Long targetUserId = jsonObject.getLong("targetUserId"); |
|
|
Long targetUserId = jsonObject.getLong("targetUserId"); |
|
|
Integer terminal = jsonObject.getInt("terminal"); |
|
|
Integer terminal = jsonObject.getInt("terminal"); |
|
|
|
|
|
|
|
|
// 获取当前登录用户
|
|
|
|
|
|
UserSession currentSession = SessionContext.getSession(); |
|
|
UserSession currentSession = SessionContext.getSession(); |
|
|
User currentUser = userService.getById(currentSession.getUserId()); |
|
|
User currentUser = userService.getById(currentSession.getUserId()); |
|
|
|
|
|
|
|
|
// 权限校验:只有客服才能切换账号
|
|
|
|
|
|
if (currentUser.getIsCustomer() != 2) { |
|
|
if (currentUser.getIsCustomer() != 2) { |
|
|
return ResultUtils.error(XSS_PARAM_ERROR, "无权限切换账号"); |
|
|
return ResultUtils.error(XSS_PARAM_ERROR, "无权限切换账号"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取目标用户信息
|
|
|
|
|
|
User targetUser = userService.getById(targetUserId); |
|
|
User targetUser = userService.getById(targetUserId); |
|
|
if (ObjectUtil.isNull(targetUser)) { |
|
|
if (ObjectUtil.isNull(targetUser)) { |
|
|
return ResultUtils.error(ResultCode.XSS_PARAM_ERROR, "目标用户不存在"); |
|
|
return ResultUtils.error(ResultCode.XSS_PARAM_ERROR, "目标用户不存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 生成新的token
|
|
|
|
|
|
UserSession newSession = BeanUtils.copyProperties(targetUser, UserSession.class); |
|
|
UserSession newSession = BeanUtils.copyProperties(targetUser, UserSession.class); |
|
|
newSession.setUserId(targetUser.getId()); |
|
|
newSession.setUserId(targetUser.getId()); |
|
|
newSession.setTerminal(terminal); |
|
|
newSession.setTerminal(terminal); |
|
|
@ -299,8 +301,6 @@ public class UserController { |
|
|
vo.setRefreshTokenExpiresIn(jwtProperties.getRefreshTokenExpireIn()); |
|
|
vo.setRefreshTokenExpiresIn(jwtProperties.getRefreshTokenExpireIn()); |
|
|
vo.setUser(targetUser); |
|
|
vo.setUser(targetUser); |
|
|
|
|
|
|
|
|
// log.info("账号切换:从用户 {} 切换到用户 {}", currentSession.getUserId(), targetUserId);
|
|
|
|
|
|
|
|
|
|
|
|
return ResultUtils.success(vo); |
|
|
return ResultUtils.success(vo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -319,7 +319,6 @@ public class UserController { |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 取出可切换账号并移除目标ID
|
|
|
|
|
|
String switchableIdsStr = currentUser.getSwitchableAccountIds(); |
|
|
String switchableIdsStr = currentUser.getSwitchableAccountIds(); |
|
|
if (StrUtil.isBlank(switchableIdsStr)) { |
|
|
if (StrUtil.isBlank(switchableIdsStr)) { |
|
|
return ResultUtils.success("移除成功"); |
|
|
return ResultUtils.success("移除成功"); |
|
|
@ -333,7 +332,6 @@ public class UserController { |
|
|
|
|
|
|
|
|
String newIds = idList.stream().map(String::valueOf).collect(Collectors.joining(",")); |
|
|
String newIds = idList.stream().map(String::valueOf).collect(Collectors.joining(",")); |
|
|
|
|
|
|
|
|
// 更新到数据库
|
|
|
|
|
|
currentUser.setSwitchableAccountIds(newIds); |
|
|
currentUser.setSwitchableAccountIds(newIds); |
|
|
userService.updateById(currentUser); |
|
|
userService.updateById(currentUser); |
|
|
|
|
|
|
|
|
|