|
|
|
@ -1,7 +1,10 @@ |
|
|
|
package com.bx.implatform.controller; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.bx.implatform.dto.LoginDTO; |
|
|
|
import com.bx.implatform.dto.RegisterDTO; |
|
|
|
import com.bx.implatform.entity.User; |
|
|
|
import com.bx.implatform.result.Result; |
|
|
|
@ -24,9 +27,8 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.bx.imcommon.util.JwtUtil; |
|
|
|
import com.bx.implatform.config.props.JwtProperties; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.bx.implatform.enums.ResultCode.XSS_PARAM_ERROR; |
|
|
|
|
|
|
|
@ -133,6 +135,109 @@ public class UserController { |
|
|
|
return ResultUtils.success(result); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/addAccounts") |
|
|
|
@Operation(summary = "客服登录", description = "客服登录") |
|
|
|
public Result<LoginVO> addAccounts(@Valid @RequestBody LoginDTO dto) { |
|
|
|
LoginVO vo = userService.addAccounts(dto); |
|
|
|
return ResultUtils.success(vo); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/getSwitchableAccounts") |
|
|
|
@Operation(summary = "获取可切换的账号列表", description = "获取当前客服可切换的账号列表") |
|
|
|
public Result<Map<String, Object>> getSwitchableAccounts() { |
|
|
|
UserSession session = SessionContext.getSession(); |
|
|
|
Long userId = session.getUserId(); |
|
|
|
|
|
|
|
if (ObjectUtil.isNull(userId)) { |
|
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前用户信息
|
|
|
|
User currentUser = userService.getById(userId); |
|
|
|
if (currentUser == null) { |
|
|
|
return ResultUtils.error(XSS_PARAM_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
// 获取可切换的账号ID列表(逗号分隔的字符串,如 "13,14")
|
|
|
|
String switchableIdsStr = currentUser.getSwitchableAccountIds(); |
|
|
|
List<Map<String, Object>> switchableUsers = new ArrayList<>(); |
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(switchableIdsStr)) { |
|
|
|
String[] idArray = switchableIdsStr.split(","); |
|
|
|
List<Long> ids = Arrays.stream(idArray) |
|
|
|
.filter(StrUtil::isNotBlank) |
|
|
|
.map(Long::parseLong) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (!ids.isEmpty()) { |
|
|
|
List<User> users = userService.listByIds(ids); |
|
|
|
// 过滤掉被封禁的账号
|
|
|
|
users = users.stream() |
|
|
|
.filter(u -> !Boolean.TRUE.equals(u.getIsBanned())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
switchableUsers = users.stream().map(user -> { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("id", user.getId()); |
|
|
|
map.put("userName", user.getUserName()); |
|
|
|
map.put("nickName", user.getNickName()); |
|
|
|
map.put("headImage", user.getHeadImage()); |
|
|
|
map.put("headImageThumb", user.getHeadImageThumb()); |
|
|
|
return map; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.put("switchableUsers", switchableUsers); |
|
|
|
|
|
|
|
// 获取当前用户的 unique_token
|
|
|
|
String currentUserUniqueToken = currentUser.getUniqueToken(); |
|
|
|
|
|
|
|
// 构建查询条件
|
|
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>() |
|
|
|
.eq(User::getIsCustomer, 2) |
|
|
|
.ne(User::getId, userId) |
|
|
|
.eq(User::getIsBanned, 0); |
|
|
|
|
|
|
|
// 添加 unique_token 条件
|
|
|
|
if (StrUtil.isNotBlank(currentUserUniqueToken)) { |
|
|
|
// 当前用户有 unique_token,只查询相同 unique_token 的客服
|
|
|
|
queryWrapper.eq(User::getUniqueToken, currentUserUniqueToken); |
|
|
|
} else { |
|
|
|
// 当前用户没有 unique_token,只查询也没有 unique_token 的客服
|
|
|
|
queryWrapper.isNull(User::getUniqueToken).or().eq(User::getUniqueToken, ""); |
|
|
|
} |
|
|
|
|
|
|
|
List<User> availableUsers = userService.list(queryWrapper); |
|
|
|
|
|
|
|
// 获取已添加的ID集合
|
|
|
|
Set<Long> existingIds = new HashSet<>(); |
|
|
|
if (StrUtil.isNotBlank(switchableIdsStr)) { |
|
|
|
Arrays.stream(switchableIdsStr.split(",")) |
|
|
|
.filter(StrUtil::isNotBlank) |
|
|
|
.map(Long::parseLong) |
|
|
|
.forEach(existingIds::add); |
|
|
|
} |
|
|
|
|
|
|
|
// 标记是否已添加
|
|
|
|
List<Map<String, Object>> availableUsersList = availableUsers.stream().map(user -> { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("id", user.getId()); |
|
|
|
map.put("userName", user.getUserName()); |
|
|
|
map.put("nickName", user.getNickName()); |
|
|
|
map.put("headImage", user.getHeadImage()); |
|
|
|
// map.put("headImageThumb", user.getHeadImageThumb());
|
|
|
|
map.put("isAdded", existingIds.contains(user.getId())); |
|
|
|
return map; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
result.put("availableUsers", availableUsersList); |
|
|
|
|
|
|
|
return ResultUtils.success(result); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/changeCustomer") |
|
|
|
@Operation(summary = "转接客服", description = "转接客服") |
|
|
|
public Result register(@RequestBody JSONObject jsonObject) { |
|
|
|
|