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