Browse Source

MALL-KEFU: 完善管理端接口

puhui999 8 months ago
parent
commit
eed4cf127e

+ 20 - 3
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<Boolean> deleteKefuConversation(@RequestParam("id") Long id) {
+    public CommonResult<Boolean> 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<List<KeFuConversationRespVO>> getKefuConversationPage() {
-        return success(BeanUtils.toBean(conversationService.getKefuConversationList(), KeFuConversationRespVO.class));
+    public CommonResult<List<KeFuConversationRespVO>> getConversationList() {
+        // 查询会话列表
+        List<KeFuConversationRespVO> respList = BeanUtils.toBean(conversationService.getKefuConversationList(),
+                KeFuConversationRespVO.class);
+
+        // 拼接数据
+        Map<Long, MemberUserRespDTO> 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);
     }
 
 }

+ 24 - 7
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<Long> createKefuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) {
+    public CommonResult<Long> 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<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
-        messageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
+    public CommonResult<Boolean> 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<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
-        PageResult<KeFuMessageDO> pageResult = messageService.getKefuMessagePage(pageReqVO);
-        return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
+    public CommonResult<PageResult<KeFuMessageRespVO>> getKeFuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
+        // 获得数据
+        PageResult<KeFuMessageDO> pageResult = messageService.getKeFuMessagePage(pageReqVO);
+
+        // 拼接数据
+        PageResult<KeFuMessageRespVO> result = BeanUtils.toBean(pageResult, KeFuMessageRespVO.class);
+        Map<Long, AdminUserRespDTO> 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);
     }
 
 }

+ 4 - 0
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;

+ 2 - 0
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;

+ 2 - 2
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<Boolean> 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<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) {
-        PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKefuMessagePage(pageReqVO, getLoginUserId());
+        PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKeFuMessagePage(pageReqVO, getLoginUserId());
         return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
     }
 

+ 3 - 3
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<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO);
+    PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO);
 
     /**
      * 【会员】获得客服消息分页
@@ -55,6 +55,6 @@ public interface KeFuMessageService {
      * @param userId    用户编号
      * @return 客服消息分页
      */
-    PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId);
+    PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId);
 
 }

+ 3 - 3
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<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO) {
+    public PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) {
         return keFuMessageMapper.selectPage(pageReqVO);
     }
 
     @Override
-    public PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) {
+    public PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) {
         // 1. 获得客服会话
         KeFuConversationDO conversation = conversationService.getConversationByUserId(userId);
         if (conversation == null) {

+ 4 - 0
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;
 
 }