From eed4cf127e71b7917b196f26190248ac2d549b93 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 1 Jul 2024 17:20:24 +0800 Subject: [PATCH] =?UTF-8?q?MALL-KEFU:=20=E5=AE=8C=E5=96=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=AB=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kefu/KeFuConversationController.java | 23 ++++++++++++-- .../admin/kefu/KeFuMessageController.java | 31 ++++++++++++++----- .../conversation/KeFuConversationRespVO.java | 4 +++ .../kefu/vo/message/KeFuMessageRespVO.java | 2 ++ .../app/kefu/AppKeFuMessageController.java | 4 +-- .../service/kefu/KeFuMessageService.java | 6 ++-- .../service/kefu/KeFuMessageServiceImpl.java | 6 ++-- .../system/api/user/dto/AdminUserRespDTO.java | 4 +++ 8 files changed, 62 insertions(+), 18 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java index 55042f547..3d1d10db5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.promotion.controller.admin.kefu; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO; import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService; @@ -15,8 +17,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; @Tag(name = "管理后台 - 客服会话") @RestController @@ -26,6 +31,8 @@ public class KeFuConversationController { @Resource private KeFuConversationService conversationService; + @Resource + private MemberUserApi memberUserApi; @PostMapping("/update-conversation-pinned") @Operation(summary = "置顶客服会话") @@ -39,7 +46,7 @@ public class KeFuConversationController { @Operation(summary = "删除客服会话") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')") - public CommonResult deleteKefuConversation(@RequestParam("id") Long id) { + public CommonResult deleteConversation(@RequestParam("id") Long id) { conversationService.deleteKefuConversation(id); return success(true); } @@ -47,8 +54,18 @@ public class KeFuConversationController { @GetMapping("/list") @Operation(summary = "获得客服会话列表") @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')") - public CommonResult> getKefuConversationPage() { - return success(BeanUtils.toBean(conversationService.getKefuConversationList(), KeFuConversationRespVO.class)); + public CommonResult> getConversationList() { + // 查询会话列表 + List respList = BeanUtils.toBean(conversationService.getKefuConversationList(), + KeFuConversationRespVO.class); + + // 拼接数据 + Map userMap = memberUserApi.getUserMap(convertSet(respList, KeFuConversationRespVO::getUserId)); + respList.forEach(item->{ + findAndThen(userMap, item.getUserId(), memberUser-> item.setUserAvatar(memberUser.getAvatar()) + .setUserNickname(memberUser.getNickname())); + }); + return success(respList); } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java index a5f543d79..4cbc296b6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java @@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMe import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -18,7 +20,12 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.Map; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - 客服消息") @@ -29,11 +36,13 @@ public class KeFuMessageController { @Resource private KeFuMessageService messageService; + @Resource + private AdminUserApi adminUserApi; @PostMapping("/send") @Operation(summary = "发送客服消息") @PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')") - public CommonResult createKefuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) { + public CommonResult sendKeFuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) { sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.ADMIN.getValue()); // 设置用户编号和类型 return success(messageService.sendKefuMessage(sendReqVO)); } @@ -42,18 +51,26 @@ public class KeFuMessageController { @Operation(summary = "更新客服消息已读状态") @Parameter(name = "conversationId", description = "会话编号", required = true) @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')") - public CommonResult updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { - messageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); + public CommonResult updateKeFuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { + messageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); return success(true); } - // TODO @puhui999:这个应该是某个会话,上翻、下翻;不是传统的分页哈; @GetMapping("/page") @Operation(summary = "获得客服消息分页") @PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')") - public CommonResult> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) { - PageResult pageResult = messageService.getKefuMessagePage(pageReqVO); - return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); + public CommonResult> getKeFuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) { + // 获得数据 + PageResult pageResult = messageService.getKeFuMessagePage(pageReqVO); + + // 拼接数据 + PageResult result = BeanUtils.toBean(pageResult, KeFuMessageRespVO.class); + Map userMap = adminUserApi.getUserMap(convertSet(filterList(result.getList(), + item -> UserTypeEnum.ADMIN.getValue().equals(item.getSenderType())), KeFuMessageRespVO::getSenderId)); + result.getList().forEach(item->{ + findAndThen(userMap, item.getSenderId(), adminUser -> item.setSenderAvatar(adminUser.getAvatar())); + }); + return success(result); } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationRespVO.java index 9f499e09e..98cd5acd8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/conversation/KeFuConversationRespVO.java @@ -14,6 +14,10 @@ public class KeFuConversationRespVO { @Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300") private Long userId; + @Schema(description = "会话所属用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg") + private String userAvatar; + @Schema(description = "会话所属用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + private String userNickname; @Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime lastMessageTime; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageRespVO.java index 41f9c52f6..248160dd9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageRespVO.java @@ -18,6 +18,8 @@ public class KeFuMessageRespVO { @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571") private Long senderId; + @Schema(description = "发送人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg") + private String senderAvatar; @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer senderType; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java index a38f68686..2c99c75cb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java @@ -43,7 +43,7 @@ public class AppKeFuMessageController { @Parameter(name = "conversationId", description = "会话编号", required = true) @PreAuthenticated public CommonResult updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { - kefuMessageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue()); + kefuMessageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue()); return success(true); } @@ -51,7 +51,7 @@ public class AppKeFuMessageController { @Operation(summary = "获得客服消息分页") @PreAuthenticated public CommonResult> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) { - PageResult pageResult = kefuMessageService.getKefuMessagePage(pageReqVO, getLoginUserId()); + PageResult pageResult = kefuMessageService.getKeFuMessagePage(pageReqVO, getLoginUserId()); return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java index fae4566cb..8af4f128e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java @@ -38,7 +38,7 @@ public interface KeFuMessageService { * @param userId 用户编号 * @param userType 用户类型 */ - void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType); + void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType); /** * 获得客服消息分页 @@ -46,7 +46,7 @@ public interface KeFuMessageService { * @param pageReqVO 分页查询 * @return 客服消息分页 */ - PageResult getKefuMessagePage(KeFuMessagePageReqVO pageReqVO); + PageResult getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO); /** * 【会员】获得客服消息分页 @@ -55,6 +55,6 @@ public interface KeFuMessageService { * @param userId 用户编号 * @return 客服消息分页 */ - PageResult getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId); + PageResult getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId); } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java index cf79c53d1..45d49041e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java @@ -89,7 +89,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { @Override @Transactional(rollbackFor = Exception.class) - public void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType) { + public void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType) { // 1.1 校验会话是否存在 KeFuConversationDO conversation = conversationService.validateKefuConversationExists(conversationId); // 1.2 如果是会员端处理已读,需要传递 userId;万一用户模拟一个 conversationId @@ -136,12 +136,12 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { } @Override - public PageResult getKefuMessagePage(KeFuMessagePageReqVO pageReqVO) { + public PageResult getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) { return keFuMessageMapper.selectPage(pageReqVO); } @Override - public PageResult getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) { + public PageResult getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) { // 1. 获得客服会话 KeFuConversationDO conversation = conversationService.getConversationByUserId(userId); if (conversation == null) { diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/AdminUserRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/AdminUserRespDTO.java index ac13c3a8b..d86f3e548 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/AdminUserRespDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/AdminUserRespDTO.java @@ -40,5 +40,9 @@ public class AdminUserRespDTO { * 手机号码 */ private String mobile; + /** + * 用户头像 + */ + private String avatar; }