From 0b2decafc90b69a83c26310329c2d17f49b1019e Mon Sep 17 00:00:00 2001 From: yyb <1416014977@qq.com> Date: Wed, 25 Jun 2025 16:31:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=B7=A5=E5=8D=95=EF=BC=8C=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- m2pool-auth/src/main/resources/bootstrap.yml | 2 +- .../common/security/auth/AuthLogic.java | 3 + .../src/main/resources/bootstrap.yml | 2 +- .../m2pool/chat/mapper/ChatMessageMapper.java | 9 +- .../m2pool/chat/mapper/ChatRoomMapper.java | 4 +- .../service/impl/ChatRoomServiceImpl.java | 72 +++++++--- .../chat/service/impl/StompServiceImpl.java | 10 +- .../src/main/resources/bootstrap.yml | 2 +- .../mapper/chat/ChatMessageMapper.xml | 9 +- .../resources/mapper/chat/ChatRoomMapper.xml | 11 +- .../controller/ManageBroadcastController.java | 16 ++- .../controller/ManageUserController.java | 5 + .../com/m2pool/manage/dto/ManageUserDto.java | 5 +- .../service/ManageBroadcastService.java | 9 ++ .../impl/ManageBroadcastServiceImpl.java | 28 +++- .../mapper/manage/ManageBroadcastMapper.xml | 3 +- .../pool/controller/TicketController.java | 10 +- .../com/m2pool/pool/dto/PowerLineDto.java | 5 + .../pool/service/impl/PoolServiceImpl.java | 79 +++++++---- .../java/com/m2pool/pool/utils/NodeRpc.java | 123 +++++++++++------- .../com/m2pool/pool/utils/PowerUnitUtils.java | 59 +++++++++ .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- 23 files changed, 356 insertions(+), 114 deletions(-) diff --git a/m2pool-auth/src/main/resources/bootstrap.yml b/m2pool-auth/src/main/resources/bootstrap.yml index 027b4e3..9f96606 100644 --- a/m2pool-auth/src/main/resources/bootstrap.yml +++ b/m2pool-auth/src/main/resources/bootstrap.yml @@ -1,3 +1,3 @@ spring: profiles: - active: test \ No newline at end of file + active: prod diff --git a/m2pool-common/common-security/src/main/java/com/m2pool/common/security/auth/AuthLogic.java b/m2pool-common/common-security/src/main/java/com/m2pool/common/security/auth/AuthLogic.java index 56c57d1..1c34bb0 100644 --- a/m2pool-common/common-security/src/main/java/com/m2pool/common/security/auth/AuthLogic.java +++ b/m2pool-common/common-security/src/main/java/com/m2pool/common/security/auth/AuthLogic.java @@ -215,6 +215,7 @@ public class AuthLogic { { if (requiresRoles.logical() == Logical.AND) { + checkRoleAnd(requiresRoles.value()); } else @@ -248,6 +249,8 @@ public class AuthLogic { public void checkRoleOr(String... roles) { Set roleList = getRoleList(); + System.out.println("从token获取的role"+roleList +"需要的权限"+roles); + for (String role : roles) { if (hasRole(roleList, role)) diff --git a/m2pool-gateway/src/main/resources/bootstrap.yml b/m2pool-gateway/src/main/resources/bootstrap.yml index 027b4e3..9f96606 100644 --- a/m2pool-gateway/src/main/resources/bootstrap.yml +++ b/m2pool-gateway/src/main/resources/bootstrap.yml @@ -1,3 +1,3 @@ spring: profiles: - active: test \ No newline at end of file + active: prod diff --git a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatMessageMapper.java b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatMessageMapper.java index 4f690b0..b224a46 100644 --- a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatMessageMapper.java +++ b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatMessageMapper.java @@ -31,4 +31,11 @@ public interface ChatMessageMapper extends BaseMapper { @MapKey("userEmail") Map> findUnReadNums(@Param("userEmails") List userEmails); -} \ No newline at end of file + + /** + * 查询当前客服参与过的所有聊天室 + * @param userEmail + * @return + */ + List findRoomIdsByCustomerEmail(@Param("userEmail") String userEmail); +} diff --git a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatRoomMapper.java b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatRoomMapper.java index 5bfd676..b87a78b 100644 --- a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatRoomMapper.java +++ b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/mapper/ChatRoomMapper.java @@ -16,10 +16,10 @@ public interface ChatRoomMapper extends BaseMapper { /** * 查询客服的聊天室列表 - * @param userEmail 客服邮箱 + * @param ids 要查询的聊天室集合 * @return */ - List findRoomList(@Param("userEmail") String userEmail, @Param("sendDateTime") LocalDateTime sendDateTime); + List findRoomList(@Param("ids") List ids, @Param("sendDateTime") LocalDateTime sendDateTime); diff --git a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/ChatRoomServiceImpl.java b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/ChatRoomServiceImpl.java index a8d33f0..051cff7 100644 --- a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/ChatRoomServiceImpl.java +++ b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/ChatRoomServiceImpl.java @@ -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 implements ChatRoomService { @@ -44,15 +48,21 @@ public class ChatRoomServiceImpl extends ServiceImpl i @Autowired private SimpUserRegistry userRegistry; + @Resource + private CustomWebSocketConfig webSocketConfig; @Override public TableDataInfo findRoomList(RoomPageVo roomPageVo) { String userEmail = SecurityUtils.getUsername(); - PageHelper.startPage(1, 20); + List ids = chatMessageMapper.findRoomIdsByCustomerEmail(userEmail); + List roomList = new ArrayList<>(); + if (ids.isEmpty()){ + return getDataTable(roomList); + } //1.查找当前客服对应的聊天室 - List 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 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 findRoomByUserid(RoomVo roomVo) { + Random random = new Random(); //1.查询当前用户与对应用户是否已存在创建的聊天室 String userEmail = roomVo.getEmail(); ChatRoomDto roomByUserEmail = chatRoomMapper.findRoomByUserEmail(userEmail); + //获取nacos中配置的客服邮箱列表,这个列表中的邮箱实际可能不是客服角色,但能够行驶客服角色功能 + List 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 data = remoteUserService.getCSList().getData(); - if(Collections.isEmpty(data)){ - return R.fail("客服人数不足"); + List 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 i .anyMatch(user -> user.getName().equals(email)); } + @Override public R updateRoom(CharRoomVo charRoomVo) { int i = chatRoomMapper.updateById(ChatRoom.builder().id(charRoomVo.getId()).flag(charRoomVo.getFlag()).build()); diff --git a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/StompServiceImpl.java b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/StompServiceImpl.java index 5adbd67..80b61b5 100644 --- a/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/StompServiceImpl.java +++ b/m2pool-modules/m2pool-chat/src/main/java/com/m2pool/chat/service/impl/StompServiceImpl.java @@ -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); + } } } diff --git a/m2pool-modules/m2pool-chat/src/main/resources/bootstrap.yml b/m2pool-modules/m2pool-chat/src/main/resources/bootstrap.yml index 027b4e3..9f96606 100644 --- a/m2pool-modules/m2pool-chat/src/main/resources/bootstrap.yml +++ b/m2pool-modules/m2pool-chat/src/main/resources/bootstrap.yml @@ -1,3 +1,3 @@ spring: profiles: - active: test \ No newline at end of file + active: prod diff --git a/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatMessageMapper.xml b/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatMessageMapper.xml index 61d8ab6..247be6c 100644 --- a/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatMessageMapper.xml +++ b/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatMessageMapper.xml @@ -33,5 +33,12 @@ AND is_read = false GROUP BY send_email + - \ No newline at end of file + diff --git a/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatRoomMapper.xml b/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatRoomMapper.xml index 15ff1a0..eaaee2b 100644 --- a/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatRoomMapper.xml +++ b/m2pool-modules/m2pool-chat/src/main/resources/mapper/chat/ChatRoomMapper.xml @@ -13,8 +13,15 @@ FROM chat_room - user_two_email = #{userEmail} AND del = false + del = false + + AND id IN + + #{id} + + AND last_user_send_time #{sendDateTime} @@ -22,11 +29,11 @@ AND last_user_send_time NOW() - ORDER BY flag DESC, GREATEST( last_user_send_time, last_customer_send_time ) DESC + LIMIT 20