Browse Source

客服转接

master
La123123 19 hours ago
parent
commit
7562388cb5
  1. 43
      im-platform/src/main/java/com/bx/implatform/controller/UserController.java
  2. 6
      im-platform/src/main/java/com/bx/implatform/service/FriendService.java
  3. 6
      im-platform/src/main/java/com/bx/implatform/service/PrivateMessageService.java
  4. 11
      im-platform/src/main/java/com/bx/implatform/service/UserService.java
  5. 51
      im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
  6. 36
      im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
  7. 23
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

43
im-platform/src/main/java/com/bx/implatform/controller/UserController.java

@ -1,5 +1,8 @@
package com.bx.implatform.controller; package com.bx.implatform.controller;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.bx.implatform.dto.RegisterDTO;
import com.bx.implatform.entity.User; import com.bx.implatform.entity.User;
import com.bx.implatform.result.Result; import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils; import com.bx.implatform.result.ResultUtils;
@ -18,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import static com.bx.implatform.enums.ResultCode.XSS_PARAM_ERROR;
@Tag(name = "用户相关") @Tag(name = "用户相关")
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
@ -61,5 +66,43 @@ public class UserController {
public Result<List<UserVO>> findByName(@RequestParam String name) { public Result<List<UserVO>> findByName(@RequestParam String name) {
return ResultUtils.success(userService.findUserByName(name)); return ResultUtils.success(userService.findUserByName(name));
} }
@PostMapping("/getEnableChangeCustomer")
@Operation(summary = "获取可转接的客服", description = "转接客服")
public Result<List<User>> getEnableChangeCustomer() {
// 获取当前客服id、转接客服id、转接用户id
UserSession session = SessionContext.getSession();
Long userId = session.getUserId();
if(ObjectUtil.isNull(userId)){
return ResultUtils.error(XSS_PARAM_ERROR);
}
List<User> list = userService.getEnableChangeCustomerList(userId);
return ResultUtils.success(list);
}
@PostMapping("/changeCustomer")
@Operation(summary = "转接客服", description = "转接客服")
public Result register(@RequestBody JSONObject jsonObject) {
UserSession session = SessionContext.getSession();
// 获取当前客服id、转接客服id、转接用户id
Long customerId = session.getUserId();
Long targetId = jsonObject.getLong("targetId");
Long userId = jsonObject.getLong("userId");
if(ObjectUtil.isNull(customerId) || ObjectUtil.isNull(targetId) || ObjectUtil.isNull(userId)){
return ResultUtils.error(XSS_PARAM_ERROR);
}
userService.changeCustomer(customerId,targetId, userId);
return ResultUtils.success();
}
} }

6
im-platform/src/main/java/com/bx/implatform/service/FriendService.java

@ -78,4 +78,10 @@ public interface FriendService extends IService<Friend> {
*/ */
void setDnd(FriendDndDTO dto); void setDnd(FriendDndDTO dto);
/**
* 修改好友关系
* @param customerId 客服id
*/
void changeFriendRelation(Long customerId,Long targetId, Long userId);
} }

6
im-platform/src/main/java/com/bx/implatform/service/PrivateMessageService.java

@ -57,4 +57,10 @@ public interface PrivateMessageService extends IService<PrivateMessage> {
* @param friendId 好友id * @param friendId 好友id
*/ */
Long getMaxReadedId(Long friendId); Long getMaxReadedId(Long friendId);
/**
* 改变消息记录关系
* @param customerId 客服id
*/
void changeMessageRecord(Long customerId,Long targetId, Long userId);
} }

11
im-platform/src/main/java/com/bx/implatform/service/UserService.java

@ -97,5 +97,16 @@ public interface UserService extends IService<User> {
*/ */
void updateIpAndAddress(User user); void updateIpAndAddress(User user);
/**
* 转接客服
* @param customerId 客服id targetId 转接的客服id userId 转接的用户id
*/
void changeCustomer(Long customerId,Long targetId, Long userId);
/**
* 获取可转接的客服
* @param userId 用户id
* @return 客服列表
*/
List<User> getEnableChangeCustomerList(Long userId);
} }

51
im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java

@ -37,6 +37,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -51,6 +52,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
private final PrivateMessageMapper privateMessageMapper; private final PrivateMessageMapper privateMessageMapper;
private final UserMapper userMapper; private final UserMapper userMapper;
private final IMClient imClient; private final IMClient imClient;
private final FriendMapper friendMapper;
@Override @Override
public List<Friend> findAllFriends() { public List<Friend> findAllFriends() {
@ -152,6 +154,55 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
sendSyncDndMessage(dto.getFriendId(), dto.getIsDnd()); sendSyncDndMessage(dto.getFriendId(), dto.getIsDnd());
} }
@Override
public void changeFriendRelation(Long customerId, Long targetId, Long userId) {
LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery();
wrapper.eq(Friend::getUserId, customerId);
wrapper.eq(Friend::getFriendId, userId);
Friend friend = this.getOne(wrapper);
LambdaQueryWrapper<Friend> wrapperAnother = Wrappers.lambdaQuery();
wrapper.eq(Friend::getUserId, userId);
wrapper.eq(Friend::getFriendId, customerId);
Friend friendAnother = this.getOne(wrapperAnother);
if (Objects.isNull(friend) || Objects.isNull(friendAnother)) {
throw new GlobalException("用户不存在");
}
// 删除原有关系
List<Long> ids = new ArrayList<>();
ids.add(friend.getId());
ids.add(friendAnother.getId());
this.baseMapper.deleteByIds(ids);
//获取转移目标客服对象
User user = userMapper.selectById(targetId);
if(Objects.isNull(user)){
throw new GlobalException("转移目标客服不存在");
}
//新增关系
List<Friend> friendsList = new ArrayList<>();
Friend friendNew = new Friend();
friendNew.setUserId(targetId);
friendNew.setFriendId(userId);
friendNew.setFriendNickName(friend.getFriendNickName());
friendNew.setDeleted(false);
friendsList.add(friendNew);
Friend friendNewAnother = new Friend();
friendNewAnother.setUserId(userId);
friendNewAnother.setFriendId(targetId);
friendNewAnother.setFriendNickName(user.getNickName());
friendNewAnother.setFriendHeadImage(user.getHeadImageThumb());
friendNewAnother.setDeleted(false);
friendsList.add(friendNewAnother);
friendMapper.insert(friendsList);
}
/** /**
* 单向解除好友关系 * 单向解除好友关系
* *

36
im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java

@ -30,6 +30,7 @@ import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -228,4 +229,39 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
sendMessage.setSendResult(false); sendMessage.setSendResult(false);
imClient.sendPrivateMessage(sendMessage); imClient.sendPrivateMessage(sendMessage);
} }
@Override
public void changeMessageRecord(Long customerId, Long targetId, Long userId) {
List<PrivateMessage> list = new ArrayList<>();
//获取原有消息记录
LambdaQueryWrapper<PrivateMessage> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PrivateMessage::getSendId, customerId).eq(PrivateMessage::getRecvId, userId);
List<PrivateMessage> messages1 = this.list(wrapper);
//修改发送对象
if(!messages1.isEmpty()) {
for (PrivateMessage message : messages1) {
message.setSendId(targetId);
}
}
//获取原有消息记录
LambdaQueryWrapper<PrivateMessage> wrapperAnother = new LambdaQueryWrapper<>();
wrapper.eq(PrivateMessage::getSendId, userId).eq(PrivateMessage::getRecvId, customerId);
List<PrivateMessage> messages2 = this.list(wrapperAnother);
//修改接收对象
if(!messages2.isEmpty()) {
for (PrivateMessage message : messages2) {
message.setRecvId(targetId);
}
}
list.addAll(messages1);
list.addAll(messages2);
if(!list.isEmpty()) {
baseMapper.updateById(list);
}
}
} }

23
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -22,6 +22,7 @@ import com.bx.implatform.exception.GlobalException;
import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.mapper.UserMapper;
import com.bx.implatform.service.FriendService; import com.bx.implatform.service.FriendService;
import com.bx.implatform.service.GroupMemberService; import com.bx.implatform.service.GroupMemberService;
import com.bx.implatform.service.PrivateMessageService;
import com.bx.implatform.service.UserService; import com.bx.implatform.service.UserService;
import com.bx.implatform.session.SessionContext; import com.bx.implatform.session.SessionContext;
import com.bx.implatform.session.UserSession; import com.bx.implatform.session.UserSession;
@ -51,6 +52,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
private final JwtProperties jwtProperties; private final JwtProperties jwtProperties;
private final IMClient imClient; private final IMClient imClient;
private final SensitiveFilterUtil sensitiveFilterUtil; private final SensitiveFilterUtil sensitiveFilterUtil;
private final PrivateMessageService privateMessageService;
// @Override // @Override
// public LoginVO login(LoginDTO dto) { // public LoginVO login(LoginDTO dto) {
@ -298,7 +300,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
user.setSex(vo.getSex()); user.setSex(vo.getSex());
user.setSignature(vo.getSignature()); user.setSignature(vo.getSignature());
user.setHeadImage(vo.getHeadImage()); user.setHeadImage(vo.getHeadImage());
user.setHeadImageThumb(vo.getHeadImageThumb()); user.setHeadImageThumb(vo.getHeadImage());
this.updateById(user); this.updateById(user);
log.info("用户信息更新,用户:{}}", user); log.info("用户信息更新,用户:{}}", user);
} }
@ -348,4 +350,23 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
.set(User::getLastLoginIp, ip) .set(User::getLastLoginIp, ip)
.set(User::getIpAddress, address)); .set(User::getIpAddress, address));
} }
@Override
public void changeCustomer(Long customerId, Long targetId, Long userId) {
// 更新好友关系
friendService.changeFriendRelation(customerId, targetId, userId);
//变更消息记录
privateMessageService.changeMessageRecord(customerId, targetId, userId);
}
@Override
public List<User> getEnableChangeCustomerList(Long userId) {
LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.ne(User::getId, userId);
queryWrapper.eq(User::getIsCustomer, 2);
return this.list(queryWrapper);
}
} }

Loading…
Cancel
Save