Commit eed4cf127e71b7917b196f26190248ac2d549b93

Authored by puhui999
1 parent 4ce2be72

MALL-KEFU: 完善管理端接口

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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  6 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
5 7 import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationRespVO;
6 8 import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
7 9 import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService;
... ... @@ -15,8 +17,11 @@ import org.springframework.validation.annotation.Validated;
15 17 import org.springframework.web.bind.annotation.*;
16 18  
17 19 import java.util.List;
  20 +import java.util.Map;
18 21  
19 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  24 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
20 25  
21 26 @Tag(name = "管理后台 - 客服会话")
22 27 @RestController
... ... @@ -26,6 +31,8 @@ public class KeFuConversationController {
26 31  
27 32 @Resource
28 33 private KeFuConversationService conversationService;
  34 + @Resource
  35 + private MemberUserApi memberUserApi;
29 36  
30 37 @PostMapping("/update-conversation-pinned")
31 38 @Operation(summary = "置顶客服会话")
... ... @@ -39,7 +46,7 @@ public class KeFuConversationController {
39 46 @Operation(summary = "删除客服会话")
40 47 @Parameter(name = "id", description = "编号", required = true)
41 48 @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')")
42   - public CommonResult<Boolean> deleteKefuConversation(@RequestParam("id") Long id) {
  49 + public CommonResult<Boolean> deleteConversation(@RequestParam("id") Long id) {
43 50 conversationService.deleteKefuConversation(id);
44 51 return success(true);
45 52 }
... ... @@ -47,8 +54,18 @@ public class KeFuConversationController {
47 54 @GetMapping("/list")
48 55 @Operation(summary = "获得客服会话列表")
49 56 @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')")
50   - public CommonResult<List<KeFuConversationRespVO>> getKefuConversationPage() {
51   - return success(BeanUtils.toBean(conversationService.getKefuConversationList(), KeFuConversationRespVO.class));
  57 + public CommonResult<List<KeFuConversationRespVO>> getConversationList() {
  58 + // 查询会话列表
  59 + List<KeFuConversationRespVO> respList = BeanUtils.toBean(conversationService.getKefuConversationList(),
  60 + KeFuConversationRespVO.class);
  61 +
  62 + // 拼接数据
  63 + Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(respList, KeFuConversationRespVO::getUserId));
  64 + respList.forEach(item->{
  65 + findAndThen(userMap, item.getUserId(), memberUser-> item.setUserAvatar(memberUser.getAvatar())
  66 + .setUserNickname(memberUser.getNickname()));
  67 + });
  68 + return success(respList);
52 69 }
53 70  
54 71 }
55 72 \ No newline at end of file
... ...
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
9 9 import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO;
10 10 import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
11 11 import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService;
  12 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  13 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
12 14 import io.swagger.v3.oas.annotations.Operation;
13 15 import io.swagger.v3.oas.annotations.Parameter;
14 16 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -18,7 +20,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
18 20 import org.springframework.validation.annotation.Validated;
19 21 import org.springframework.web.bind.annotation.*;
20 22  
  23 +import java.util.Map;
  24 +
21 25 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  26 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  27 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
  28 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
22 29 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
23 30  
24 31 @Tag(name = "管理后台 - 客服消息")
... ... @@ -29,11 +36,13 @@ public class KeFuMessageController {
29 36  
30 37 @Resource
31 38 private KeFuMessageService messageService;
  39 + @Resource
  40 + private AdminUserApi adminUserApi;
32 41  
33 42 @PostMapping("/send")
34 43 @Operation(summary = "发送客服消息")
35 44 @PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')")
36   - public CommonResult<Long> createKefuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) {
  45 + public CommonResult<Long> sendKeFuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) {
37 46 sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.ADMIN.getValue()); // 设置用户编号和类型
38 47 return success(messageService.sendKefuMessage(sendReqVO));
39 48 }
... ... @@ -42,18 +51,26 @@ public class KeFuMessageController {
42 51 @Operation(summary = "更新客服消息已读状态")
43 52 @Parameter(name = "conversationId", description = "会话编号", required = true)
44 53 @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
45   - public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
46   - messageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
  54 + public CommonResult<Boolean> updateKeFuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
  55 + messageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
47 56 return success(true);
48 57 }
49 58  
50   - // TODO @puhui999:这个应该是某个会话,上翻、下翻;不是传统的分页哈;
51 59 @GetMapping("/page")
52 60 @Operation(summary = "获得客服消息分页")
53 61 @PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')")
54   - public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
55   - PageResult<KeFuMessageDO> pageResult = messageService.getKefuMessagePage(pageReqVO);
56   - return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
  62 + public CommonResult<PageResult<KeFuMessageRespVO>> getKeFuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
  63 + // 获得数据
  64 + PageResult<KeFuMessageDO> pageResult = messageService.getKeFuMessagePage(pageReqVO);
  65 +
  66 + // 拼接数据
  67 + PageResult<KeFuMessageRespVO> result = BeanUtils.toBean(pageResult, KeFuMessageRespVO.class);
  68 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(filterList(result.getList(),
  69 + item -> UserTypeEnum.ADMIN.getValue().equals(item.getSenderType())), KeFuMessageRespVO::getSenderId));
  70 + result.getList().forEach(item->{
  71 + findAndThen(userMap, item.getSenderId(), adminUser -> item.setSenderAvatar(adminUser.getAvatar()));
  72 + });
  73 + return success(result);
57 74 }
58 75  
59 76 }
60 77 \ No newline at end of file
... ...
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 {
14 14  
15 15 @Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300")
16 16 private Long userId;
  17 + @Schema(description = "会话所属用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg")
  18 + private String userAvatar;
  19 + @Schema(description = "会话所属用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
  20 + private String userNickname;
17 21  
18 22 @Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED)
19 23 private LocalDateTime lastMessageTime;
... ...
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 {
18 18  
19 19 @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
20 20 private Long senderId;
  21 + @Schema(description = "发送人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg")
  22 + private String senderAvatar;
21 23  
22 24 @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
23 25 private Integer senderType;
... ...
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 {
43 43 @Parameter(name = "conversationId", description = "会话编号", required = true)
44 44 @PreAuthenticated
45 45 public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
46   - kefuMessageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue());
  46 + kefuMessageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue());
47 47 return success(true);
48 48 }
49 49  
... ... @@ -51,7 +51,7 @@ public class AppKeFuMessageController {
51 51 @Operation(summary = "获得客服消息分页")
52 52 @PreAuthenticated
53 53 public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) {
54   - PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKefuMessagePage(pageReqVO, getLoginUserId());
  54 + PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKeFuMessagePage(pageReqVO, getLoginUserId());
55 55 return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
56 56 }
57 57  
... ...
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 {
38 38 * @param userId 用户编号
39 39 * @param userType 用户类型
40 40 */
41   - void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType);
  41 + void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType);
42 42  
43 43 /**
44 44 * 获得客服消息分页
... ... @@ -46,7 +46,7 @@ public interface KeFuMessageService {
46 46 * @param pageReqVO 分页查询
47 47 * @return 客服消息分页
48 48 */
49   - PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO);
  49 + PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO);
50 50  
51 51 /**
52 52 * 【会员】获得客服消息分页
... ... @@ -55,6 +55,6 @@ public interface KeFuMessageService {
55 55 * @param userId 用户编号
56 56 * @return 客服消息分页
57 57 */
58   - PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId);
  58 + PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId);
59 59  
60 60 }
61 61 \ No newline at end of file
... ...
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 {
89 89  
90 90 @Override
91 91 @Transactional(rollbackFor = Exception.class)
92   - public void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType) {
  92 + public void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType) {
93 93 // 1.1 校验会话是否存在
94 94 KeFuConversationDO conversation = conversationService.validateKefuConversationExists(conversationId);
95 95 // 1.2 如果是会员端处理已读,需要传递 userId;万一用户模拟一个 conversationId
... ... @@ -136,12 +136,12 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
136 136 }
137 137  
138 138 @Override
139   - public PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO) {
  139 + public PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) {
140 140 return keFuMessageMapper.selectPage(pageReqVO);
141 141 }
142 142  
143 143 @Override
144   - public PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) {
  144 + public PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) {
145 145 // 1. 获得客服会话
146 146 KeFuConversationDO conversation = conversationService.getConversationByUserId(userId);
147 147 if (conversation == null) {
... ...
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 {
40 40 * 手机号码
41 41 */
42 42 private String mobile;
  43 + /**
  44 + * 用户头像
  45 + */
  46 + private String avatar;
43 47  
44 48 }
... ...