mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【代码评审】MALL:review 客服的实现
This commit is contained in:
parent
9c4afeb7ba
commit
866b38535e
@ -1,13 +1,13 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.enums;
|
package cn.iocoder.yudao.module.promotion.enums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* websocket 消息类型枚举类
|
* Promotion 的 WebSocket 消息类型枚举类
|
||||||
*
|
*
|
||||||
* @author HUIHUI
|
* @author HUIHUI
|
||||||
*/
|
*/
|
||||||
public interface WebSocketMessageTypeConstants {
|
public interface WebSocketMessageTypeConstants {
|
||||||
|
|
||||||
//======================= mall 客服 =======================
|
// ======================= mall 客服 =======================
|
||||||
|
|
||||||
String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型
|
String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型
|
||||||
String KEFU_MESSAGE_ADMIN_READ = "kefu_message_read_status_change"; // 客服消息管理员已读
|
String KEFU_MESSAGE_ADMIN_READ = "kefu_message_read_status_change"; // 客服消息管理员已读
|
||||||
|
@ -20,6 +20,7 @@ public enum KeFuMessageContentTypeEnum implements IntArrayValuable {
|
|||||||
VOICE(3, "语音消息"),
|
VOICE(3, "语音消息"),
|
||||||
VIDEO(4, "视频消息"),
|
VIDEO(4, "视频消息"),
|
||||||
SYSTEM(5, "系统消息"),
|
SYSTEM(5, "系统消息"),
|
||||||
|
|
||||||
// ========== 商城特殊消息 ==========
|
// ========== 商城特殊消息 ==========
|
||||||
PRODUCT(10, "商品消息"),
|
PRODUCT(10, "商品消息"),
|
||||||
ORDER(11, "订单消息");
|
ORDER(11, "订单消息");
|
||||||
|
@ -31,7 +31,7 @@ public class KeFuConversationController {
|
|||||||
@Operation(summary = "置顶客服会话")
|
@Operation(summary = "置顶客服会话")
|
||||||
@PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
|
||||||
public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
public CommonResult<Boolean> updateConversationPinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
||||||
conversationService.updateAdminPinned(updateReqVO);
|
conversationService.updateConversationPinnedByAdmin(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
@ -37,7 +36,7 @@ public class KeFuMessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update-read-status")
|
@PutMapping("/update-read-status")
|
||||||
@Operation(summary = "更新会员客服消息已读状态")
|
@Operation(summary = "更新客服消息已读状态")
|
||||||
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
|
||||||
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
||||||
|
@ -33,7 +33,7 @@ public class AppKeFuMessageController {
|
|||||||
@PostMapping("/send")
|
@PostMapping("/send")
|
||||||
@Operation(summary = "发送客服消息")
|
@Operation(summary = "发送客服消息")
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<Long> createKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
|
public CommonResult<Long> sendKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
|
||||||
sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.MEMBER.getValue()); // 设置用户编号和类型
|
sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.MEMBER.getValue()); // 设置用户编号和类型
|
||||||
return success(kefuMessageService.sendKefuMessage(sendReqVO));
|
return success(kefuMessageService.sendKefuMessage(sendReqVO));
|
||||||
}
|
}
|
||||||
@ -43,6 +43,7 @@ public class AppKeFuMessageController {
|
|||||||
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
||||||
|
// TODO @puhui999:需要传递 userId;万一用户模拟一个 conversationId
|
||||||
kefuMessageService.updateKefuMessageReadStatus(conversationId);
|
kefuMessageService.updateKefuMessageReadStatus(conversationId);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,10 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class AppKeFuMessageSendReqVO {
|
public class AppKeFuMessageSendReqVO {
|
||||||
|
|
||||||
|
// TODO @puhui999:应该没有传递编号哈
|
||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
|
|
||||||
private Long senderId;
|
|
||||||
@Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
|
||||||
private Integer senderType;
|
|
||||||
|
|
||||||
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
@NotNull(message = "消息类型不能为空")
|
@NotNull(message = "消息类型不能为空")
|
||||||
private Integer contentType;
|
private Integer contentType;
|
||||||
@ -24,4 +20,11 @@ public class AppKeFuMessageSendReqVO {
|
|||||||
@NotEmpty(message = "消息不能为空")
|
@NotEmpty(message = "消息不能为空")
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
|
// ========== 后端设置的参数,前端无需传递 ==========
|
||||||
|
|
||||||
|
@Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571", hidden = true)
|
||||||
|
private Long senderId;
|
||||||
|
@Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1", hidden = true)
|
||||||
|
private Integer senderType;
|
||||||
|
|
||||||
}
|
}
|
@ -22,12 +22,14 @@ public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO>
|
|||||||
.orderByDesc(KeFuConversationDO::getCreateTime));
|
.orderByDesc(KeFuConversationDO::getCreateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:这个不用单独搞个方法哈。Service 直接 new 一个对象,然后调用 update 方法。
|
||||||
default void updateAdminUnreadMessageCountWithZero(Long id) {
|
default void updateAdminUnreadMessageCountWithZero(Long id) {
|
||||||
update(new LambdaUpdateWrapper<KeFuConversationDO>()
|
update(new LambdaUpdateWrapper<KeFuConversationDO>()
|
||||||
.eq(KeFuConversationDO::getId, id)
|
.eq(KeFuConversationDO::getId, id)
|
||||||
.set(KeFuConversationDO::getAdminUnreadMessageCount, 0));
|
.set(KeFuConversationDO::getAdminUnreadMessageCount, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:改成 updateAdminUnreadMessageCountIncrement 增加
|
||||||
default void updateAdminUnreadMessageCount(Long id) {
|
default void updateAdminUnreadMessageCount(Long id) {
|
||||||
update(new LambdaUpdateWrapper<KeFuConversationDO>()
|
update(new LambdaUpdateWrapper<KeFuConversationDO>()
|
||||||
.eq(KeFuConversationDO::getId, id)
|
.eq(KeFuConversationDO::getId, id)
|
||||||
|
@ -25,7 +25,7 @@ public interface KeFuConversationService {
|
|||||||
*
|
*
|
||||||
* @param updateReqVO 请求
|
* @param updateReqVO 请求
|
||||||
*/
|
*/
|
||||||
void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO);
|
void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新会话客服消息冗余信息
|
* 更新会话客服消息冗余信息
|
||||||
|
@ -40,7 +40,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateAdminPinned(KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
public void updateConversationPinnedByAdmin(KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
||||||
conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned()));
|
conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,11 +54,12 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
|
|||||||
.setLastMessageTime(kefuMessage.getCreateTime()).setLastMessageContent(kefuMessage.getContent())
|
.setLastMessageTime(kefuMessage.getCreateTime()).setLastMessageContent(kefuMessage.getContent())
|
||||||
.setLastMessageContentType(kefuMessage.getContentType()));
|
.setLastMessageContentType(kefuMessage.getContentType()));
|
||||||
|
|
||||||
// 2.2 更新管理员未读消息数
|
// 2.1 更新管理员未读消息数
|
||||||
if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())) {
|
if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())) {
|
||||||
conversationMapper.updateAdminUnreadMessageCount(kefuMessage.getConversationId());
|
conversationMapper.updateAdminUnreadMessageCount(kefuMessage.getConversationId());
|
||||||
}
|
}
|
||||||
// 2.4 会员用户发送消息时,如果管理员删除过会话则进行恢复
|
// 2.2 会员用户发送消息时,如果管理员删除过会话则进行恢复
|
||||||
|
// TODO @puhui999:其实不用判断用户类型;只要be已删除,就恢复!
|
||||||
if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())
|
if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType())
|
||||||
&& Boolean.TRUE.equals(conversation.getAdminDeleted())) {
|
&& Boolean.TRUE.equals(conversation.getAdminDeleted())) {
|
||||||
updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE);
|
updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE);
|
||||||
@ -106,6 +107,7 @@ public class KeFuConversationServiceImpl implements KeFuConversationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeFuConversationDO getConversationByUserId(Long userId) {
|
public KeFuConversationDO getConversationByUserId(Long userId) {
|
||||||
|
// TODO @puhui999:service 不写 dao 的逻辑哈
|
||||||
return conversationMapper.selectOne(KeFuConversationDO::getUserId, userId);
|
return conversationMapper.selectOne(KeFuConversationDO::getUserId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user