update 工单,通知相关接口调试修改
This commit is contained in:
@@ -31,4 +31,11 @@ public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
|
||||
@MapKey("userEmail")
|
||||
Map<String, Map<String,Integer>> findUnReadNums(@Param("userEmails") List<String> userEmails);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前客服参与过的所有聊天室
|
||||
* @param userEmail
|
||||
* @return
|
||||
*/
|
||||
List<Long> findRoomIdsByCustomerEmail(@Param("userEmail") String userEmail);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ public interface ChatRoomMapper extends BaseMapper<ChatRoom> {
|
||||
|
||||
/**
|
||||
* 查询客服的聊天室列表
|
||||
* @param userEmail 客服邮箱
|
||||
* @param ids 要查询的聊天室集合
|
||||
* @return
|
||||
*/
|
||||
List<ChatRoomDto> findRoomList(@Param("userEmail") String userEmail, @Param("sendDateTime") LocalDateTime sendDateTime);
|
||||
List<ChatRoomDto> findRoomList(@Param("ids") List<Long> ids, @Param("sendDateTime") LocalDateTime sendDateTime);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.m2pool.chat.service.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.m2pool.chat.config.CustomWebSocketConfig;
|
||||
import com.m2pool.chat.dto.ChatRoomDto;
|
||||
import com.m2pool.chat.entity.ChatRoom;
|
||||
import com.m2pool.chat.mapper.ChatMessageMapper;
|
||||
@@ -26,8 +27,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> implements ChatRoomService {
|
||||
@@ -44,15 +48,21 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
||||
@Autowired
|
||||
private SimpUserRegistry userRegistry;
|
||||
|
||||
@Resource
|
||||
private CustomWebSocketConfig webSocketConfig;
|
||||
|
||||
@Override
|
||||
public TableDataInfo<ChatRoomDto> findRoomList(RoomPageVo roomPageVo) {
|
||||
String userEmail = SecurityUtils.getUsername();
|
||||
PageHelper.startPage(1, 20);
|
||||
List<Long> ids = chatMessageMapper.findRoomIdsByCustomerEmail(userEmail);
|
||||
List<ChatRoomDto> roomList = new ArrayList<>();
|
||||
if (ids.isEmpty()){
|
||||
return getDataTable(roomList);
|
||||
}
|
||||
//1.查找当前客服对应的聊天室
|
||||
List<ChatRoomDto> roomList = chatRoomMapper.findRoomList(userEmail,roomPageVo.getSendDateTime());
|
||||
roomList = chatRoomMapper.findRoomList(ids,roomPageVo.getSendDateTime());
|
||||
|
||||
|
||||
PageUtils.clearPage();
|
||||
// if (roomList.isEmpty()){
|
||||
// TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
// tableDataInfo.setCode(HttpStatus.ERROR);
|
||||
@@ -73,40 +83,69 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
||||
rspData.setTotalPage(pageInfo.getPages());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
private static final String EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$";
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public R<ChatRoomDto> findRoomByUserid(RoomVo roomVo) {
|
||||
Random random = new Random();
|
||||
//1.查询当前用户与对应用户是否已存在创建的聊天室
|
||||
String userEmail = roomVo.getEmail();
|
||||
ChatRoomDto roomByUserEmail = chatRoomMapper.findRoomByUserEmail(userEmail);
|
||||
//获取nacos中配置的客服邮箱列表,这个列表中的邮箱实际可能不是客服角色,但能够行驶客服角色功能
|
||||
List<String> customerEmails = new ArrayList<>(Arrays.asList(webSocketConfig.getDefaultCustomerEmail().split(",")));
|
||||
int i = random.nextInt(customerEmails.size());
|
||||
String email = customerEmails.get(i);
|
||||
customerEmails.removeIf(email1 -> !checkOnline(email1));
|
||||
System.out.println("bby-在线的客服"+customerEmails + "初始化分配的客服"+email+"聊天室信息"+roomByUserEmail);
|
||||
if(roomByUserEmail != null){
|
||||
if (checkOnline(roomByUserEmail.getUserEmail())) {
|
||||
//1.1 客服在线,并且在客服列表
|
||||
if (checkOnline(roomByUserEmail.getUserEmail()) && customerEmails.contains(roomByUserEmail.getUserEmail())) {
|
||||
roomByUserEmail.setCustomerIsOnline(true);
|
||||
} else{
|
||||
}
|
||||
// 1.2客服账号不在担任客服角色,选择使用nacos默认配置中的客服角色,并修改数据库中的聊天室信息为新的客服角色。
|
||||
if(!customerEmails.contains(roomByUserEmail.getUserEmail())){
|
||||
roomByUserEmail.setCustomerIsOnline(false);
|
||||
if (!customerEmails.isEmpty()){
|
||||
email = customerEmails.get(random.nextInt(customerEmails.size()));
|
||||
roomByUserEmail.setUserEmail(email);
|
||||
roomByUserEmail.setCustomerIsOnline(true);
|
||||
}
|
||||
chatRoomMapper.updateById(ChatRoom.builder().id(roomByUserEmail.getId()).userTwoEmail(email).build());
|
||||
}
|
||||
// 1.3客服不在线,不在线情况如果从nacos配置中获取到多个客服,选择一个在线的客服发送。
|
||||
if (!checkOnline(roomByUserEmail.getUserEmail())){
|
||||
roomByUserEmail.setCustomerIsOnline(false);
|
||||
if (!customerEmails.isEmpty()){
|
||||
roomByUserEmail.setCustomerIsOnline(true);
|
||||
email = customerEmails.get(random.nextInt(customerEmails.size()));
|
||||
roomByUserEmail.setUserEmail(email);
|
||||
}
|
||||
}
|
||||
return R.success(roomByUserEmail);
|
||||
}
|
||||
|
||||
//2.不存在创建一个聊天室
|
||||
List<SysUser> data = remoteUserService.getCSList().getData();
|
||||
if(Collections.isEmpty(data)){
|
||||
return R.fail("客服人数不足");
|
||||
List<String> emails = data.stream().map(SysUser::getEmail).collect(Collectors.toList());
|
||||
emails.removeIf(email1 -> !checkOnline(email1));
|
||||
//如果当前没有客服角色账号,使用nacos 默认配置中的客服角色
|
||||
if(Collections.isEmpty(emails)){
|
||||
emails = customerEmails;
|
||||
// 自己不能创建
|
||||
if(emails.contains( userEmail)){
|
||||
return R.fail("您作为管理员无法创建与自己的连接");
|
||||
}
|
||||
}
|
||||
Random random = new Random();
|
||||
SysUser sysUser = data.get(random.nextInt(data.size()));
|
||||
data.removeIf(datum -> !checkOnline(datum.getEmail()));
|
||||
boolean customerIsOnline = false;
|
||||
if (!data.isEmpty()){
|
||||
sysUser = data.get(random.nextInt(data.size()));
|
||||
|
||||
//有在线客服,再次分配给在线的客服
|
||||
if (!emails.isEmpty()){
|
||||
customerIsOnline = true;
|
||||
email = emails.get(random.nextInt(emails.size()));
|
||||
System.out.println("bby-最终分配的在线客服"+email);
|
||||
}
|
||||
ChatRoom build = ChatRoom.builder()
|
||||
.userOneEmail(userEmail)
|
||||
.userTwoEmail(sysUser.getEmail())
|
||||
.userTwoEmail(email)
|
||||
.build();
|
||||
int insert = chatRoomMapper.insert(build);
|
||||
if (insert > 0){
|
||||
@@ -128,6 +167,7 @@ public class ChatRoomServiceImpl extends ServiceImpl<ChatRoomMapper, ChatRoom> i
|
||||
.anyMatch(user -> user.getName().equals(email));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public R<String> updateRoom(CharRoomVo charRoomVo) {
|
||||
int i = chatRoomMapper.updateById(ChatRoom.builder().id(charRoomVo.getId()).flag(charRoomVo.getFlag()).build());
|
||||
|
||||
@@ -94,7 +94,6 @@ public class StompServiceImpl implements StompService {
|
||||
.eq(ChatRoom::getUserOneEmail, principal.getName())
|
||||
.eq(ChatRoom::getUserTwoEmail, userMessageVo.getEmail()));
|
||||
build.setRoomId(userMessageVo.getRoomId());
|
||||
System.out.println("发送消息,聊天室id"+userMessageVo.getRoomId()+"发送者邮箱"+principal.getName()+"接受者邮箱"+userMessageVo.getEmail());
|
||||
int serviceReadNum = chatRoom != null ? chatRoom.getServiceReadNum() : 0;
|
||||
build.setClientReadNum(serviceReadNum + 1);
|
||||
|
||||
@@ -230,9 +229,12 @@ public class StompServiceImpl implements StompService {
|
||||
public void customerCloseRoom(String userName){
|
||||
//目前配置只配置了一个客服,如果多个关闭消息,需同时发送多个客服
|
||||
System.out.println("当前配置的客服"+webSocketConfig.getDefaultCustomerEmail());
|
||||
messagingTemplate.convertAndSendToUser(
|
||||
webSocketConfig.getDefaultCustomerEmail(),
|
||||
Destination.QUEUE_CLOSE_ROOM + webSocketConfig.getDefaultCustomerEmail(),userName);
|
||||
String[] split = webSocketConfig.getDefaultCustomerEmail().split(",");
|
||||
for (String email : split) {
|
||||
messagingTemplate.convertAndSendToUser(
|
||||
email,
|
||||
Destination.QUEUE_CLOSE_ROOM + email, userName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: test
|
||||
active: prod
|
||||
|
||||
@@ -33,5 +33,12 @@
|
||||
AND is_read = false
|
||||
GROUP BY send_email
|
||||
</select>
|
||||
<select id="findRoomIdsByCustomerEmail" resultType="java.lang.Long">
|
||||
select room_id from chat_message where send_email = #{userEmail} group by room_id
|
||||
UNION
|
||||
select room_id from chat_message_history where send_email = #{userEmail} group by room_id
|
||||
UNION
|
||||
select id as room_id from chat_room where user_two_email = #{userEmail}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@@ -13,8 +13,15 @@
|
||||
FROM
|
||||
chat_room
|
||||
<where>
|
||||
user_two_email = #{userEmail} AND del = false
|
||||
del = false
|
||||
<choose>
|
||||
<when test="ids != null and ids.size() > 0">
|
||||
AND id IN
|
||||
<foreach item="id" index="index" collection="ids"
|
||||
open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</when>
|
||||
<when test="sendDateTime != null">
|
||||
AND last_user_send_time <![CDATA[ <= ]]> #{sendDateTime}
|
||||
</when>
|
||||
@@ -22,11 +29,11 @@
|
||||
AND last_user_send_time <![CDATA[ <= ]]> NOW()
|
||||
</otherwise>
|
||||
</choose>
|
||||
|
||||
</where>
|
||||
ORDER BY
|
||||
flag DESC,
|
||||
GREATEST( last_user_send_time, last_customer_send_time ) DESC
|
||||
LIMIT 20
|
||||
</select>
|
||||
<select id="findRoomByUserEmail" resultType="com.m2pool.chat.dto.ChatRoomDto">
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user