Commit 866b38535eb3fb333ef8fdd8c140cedc37266f59
1 parent
9c4afeb7
【代码评审】MALL:review 客服的实现
Showing
9 changed files
with
23 additions
and
15 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/WebSocketMessageTypeConstants.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.enums; |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * websocket 消息类型枚举类 | |
| 4 | + * Promotion 的 WebSocket 消息类型枚举类 | |
| 5 | 5 | * |
| 6 | 6 | * @author HUIHUI |
| 7 | 7 | */ |
| 8 | 8 | public interface WebSocketMessageTypeConstants { |
| 9 | 9 | |
| 10 | - //======================= mall 客服 ======================= | |
| 10 | + // ======================= mall 客服 ======================= | |
| 11 | 11 | |
| 12 | 12 | String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型 |
| 13 | 13 | String KEFU_MESSAGE_ADMIN_READ = "kefu_message_read_status_change"; // 客服消息管理员已读 | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/kehu/KeFuMessageContentTypeEnum.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuConversationController.java
| ... | ... | @@ -31,7 +31,7 @@ public class KeFuConversationController { |
| 31 | 31 | @Operation(summary = "置顶客服会话") |
| 32 | 32 | @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')") |
| 33 | 33 | public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) { |
| 34 | - conversationService.updateAdminPinned(updateReqVO); | |
| 34 | + conversationService.updateConversationPinnedByAdmin(updateReqVO); | |
| 35 | 35 | return success(true); |
| 36 | 36 | } |
| 37 | 37 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/KeFuMessageController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.kefu; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| ... | ... | @@ -37,7 +36,7 @@ public class KeFuMessageController { |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | 38 | @PutMapping("/update-read-status") |
| 40 | - @Operation(summary = "更新会员客服消息已读状态") | |
| 39 | + @Operation(summary = "更新客服消息已读状态") | |
| 41 | 40 | @Parameter(name = "conversationId", description = "会话编号", required = true) |
| 42 | 41 | @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')") |
| 43 | 42 | public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java
| ... | ... | @@ -33,7 +33,7 @@ public class AppKeFuMessageController { |
| 33 | 33 | @PostMapping("/send") |
| 34 | 34 | @Operation(summary = "发送客服消息") |
| 35 | 35 | @PreAuthenticated |
| 36 | - public CommonResult<Long> createKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) { | |
| 36 | + public CommonResult<Long> sendKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) { | |
| 37 | 37 | sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.MEMBER.getValue()); // 设置用户编号和类型 |
| 38 | 38 | return success(kefuMessageService.sendKefuMessage(sendReqVO)); |
| 39 | 39 | } |
| ... | ... | @@ -43,6 +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 | + // TODO @puhui999:需要传递 userId;万一用户模拟一个 conversationId | |
| 46 | 47 | kefuMessageService.updateKefuMessageReadStatus(conversationId); |
| 47 | 48 | return success(true); |
| 48 | 49 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessageSendReqVO.java
| ... | ... | @@ -9,14 +9,10 @@ import lombok.Data; |
| 9 | 9 | @Data |
| 10 | 10 | public class AppKeFuMessageSendReqVO { |
| 11 | 11 | |
| 12 | + // TODO @puhui999:应该没有传递编号哈 | |
| 12 | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202") |
| 13 | 14 | private Long id; |
| 14 | 15 | |
| 15 | - @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571") | |
| 16 | - private Long senderId; | |
| 17 | - @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 18 | - private Integer senderType; | |
| 19 | - | |
| 20 | 16 | @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 21 | 17 | @NotNull(message = "消息类型不能为空") |
| 22 | 18 | private Integer contentType; |
| ... | ... | @@ -24,4 +20,11 @@ public class AppKeFuMessageSendReqVO { |
| 24 | 20 | @NotEmpty(message = "消息不能为空") |
| 25 | 21 | private String content; |
| 26 | 22 | |
| 23 | + // ========== 后端设置的参数,前端无需传递 ========== | |
| 24 | + | |
| 25 | + @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571", hidden = true) | |
| 26 | + private Long senderId; | |
| 27 | + @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1", hidden = true) | |
| 28 | + private Integer senderType; | |
| 29 | + | |
| 27 | 30 | } |
| 28 | 31 | \ No newline at end of file | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuConversationMapper.java
| ... | ... | @@ -22,12 +22,14 @@ public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO> |
| 22 | 22 | .orderByDesc(KeFuConversationDO::getCreateTime)); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | + // TODO @puhui999:这个不用单独搞个方法哈。Service 直接 new 一个对象,然后调用 update 方法。 | |
| 25 | 26 | default void updateAdminUnreadMessageCountWithZero(Long id) { |
| 26 | 27 | update(new LambdaUpdateWrapper<KeFuConversationDO>() |
| 27 | 28 | .eq(KeFuConversationDO::getId, id) |
| 28 | 29 | .set(KeFuConversationDO::getAdminUnreadMessageCount, 0)); |
| 29 | 30 | } |
| 30 | 31 | |
| 32 | + // TODO @puhui999:改成 updateAdminUnreadMessageCountIncrement 增加 | |
| 31 | 33 | default void updateAdminUnreadMessageCount(Long id) { |
| 32 | 34 | update(new LambdaUpdateWrapper<KeFuConversationDO>() |
| 33 | 35 | .eq(KeFuConversationDO::getId, id) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java
| ... | ... | @@ -25,7 +25,7 @@ public interface KeFuConversationService { |
| 25 | 25 | * |
| 26 | 26 | * @param updateReqVO 请求 |
| 27 | 27 | */ |
| 28 | - void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO); | |
| 28 | + void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO); | |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 更新会话客服消息冗余信息 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java
| ... | ... | @@ -40,7 +40,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | @Override |
| 43 | - public void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO) { | |
| 43 | + public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) { | |
| 44 | 44 | conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned())); |
| 45 | 45 | } |
| 46 | 46 | |
| ... | ... | @@ -54,11 +54,12 @@ public class KeFuConversationServiceImpl implements KeFuConversationService { |
| 54 | 54 | .setLastMessageTime(kefuMessage.getCreateTime()).setLastMessageContent(kefuMessage.getContent()) |
| 55 | 55 | .setLastMessageContentType(kefuMessage.getContentType())); |
| 56 | 56 | |
| 57 | - // 2.2 更新管理员未读消息数 | |
| 57 | + // 2.1 更新管理员未读消息数 | |
| 58 | 58 | if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())) { |
| 59 | 59 | conversationMapper.updateAdminUnreadMessageCount(kefuMessage.getConversationId()); |
| 60 | 60 | } |
| 61 | - // 2.4 会员用户发送消息时,如果管理员删除过会话则进行恢复 | |
| 61 | + // 2.2 会员用户发送消息时,如果管理员删除过会话则进行恢复 | |
| 62 | + // TODO @puhui999:其实不用判断用户类型;只要be已删除,就恢复! | |
| 62 | 63 | if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType()) |
| 63 | 64 | && Boolean.TRUE.equals(conversation.getAdminDeleted())) { |
| 64 | 65 | updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE); |
| ... | ... | @@ -106,6 +107,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService { |
| 106 | 107 | |
| 107 | 108 | @Override |
| 108 | 109 | public KeFuConversationDO getConversationByUserId(Long userId) { |
| 110 | + // TODO @puhui999:service 不写 dao 的逻辑哈 | |
| 109 | 111 | return conversationMapper.selectOne(KeFuConversationDO::getUserId, userId); |
| 110 | 112 | } |
| 111 | 113 | ... | ... |