From cdb20539ea71b38dcae6d6db69ff916233b2267e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 17 Jun 2024 17:37:09 +0800 Subject: [PATCH] =?UTF-8?q?MALL-KEFU:=20=E5=AE=8C=E5=96=84APP=E7=AB=AF?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=B6=88=E6=81=AF=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/mall-promotion-kefu.sql | 62 ++++++++++--------- .../app/kefu/AppKeFuMessageController.java | 10 ++- .../dal/mysql/kefu/KeFuMessageMapper.java | 9 ++- .../service/kefu/KeFuConversationService.java | 8 +++ .../kefu/KeFuConversationServiceImpl.java | 5 ++ .../service/kefu/KeFuMessageService.java | 10 +++ .../service/kefu/KeFuMessageServiceImpl.java | 14 +++++ 7 files changed, 81 insertions(+), 37 deletions(-) diff --git a/sql/mysql/mall-promotion-kefu.sql b/sql/mysql/mall-promotion-kefu.sql index e0b478f57..67054cbb1 100644 --- a/sql/mysql/mall-promotion-kefu.sql +++ b/sql/mysql/mall-promotion-kefu.sql @@ -1,37 +1,39 @@ DROP TABLE IF EXISTS `promotion_kefu_conversation`; CREATE TABLE `promotion_kefu_conversation` ( - `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '编号', - `user_id` BIGINT NOT NULL COMMENT '会话所属用户', - `last_message_time` DATETIME NOT NULL COMMENT '最后聊天时间', - `last_message_content` VARCHAR(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '最后聊天内容', - `last_message_content_type` INT NOT NULL COMMENT '最后发送的消息类型', - `admin_pinned` BIT(1) NOT NULL DEFAULT b'0' COMMENT '管理端置顶', - `user_deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '用户是否可见', - `admin_deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '管理员是否可见', - `admin_unread_message_count` INT NOT NULL COMMENT '管理员未读消息数', - `creator` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', - `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `updater` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', - `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `user_id` bigint NOT NULL COMMENT '会话所属用户', + `last_message_time` datetime NOT NULL COMMENT '最后聊天时间', + `last_message_content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '最后聊天内容', + `last_message_content_type` int NOT NULL COMMENT '最后发送的消息类型', + `admin_pinned` bit(1) NOT NULL DEFAULT b'0' COMMENT '管理端置顶', + `user_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '用户是否可见', + `admin_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '管理员是否可见', + `admin_unread_message_count` int NOT NULL COMMENT '管理员未读消息数', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '客服会话' ROW_FORMAT = Dynamic; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='客服会话'; DROP TABLE IF EXISTS `promotion_kefu_message`; CREATE TABLE `promotion_kefu_message` ( - `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '编号', - `conversation_id` BIGINT NOT NULL COMMENT '会话编号', - `sender_id` BIGINT NOT NULL COMMENT '发送人编号', - `sender_type` INT NOT NULL COMMENT '发送人类型', - `receiver_id` BIGINT NOT NULL COMMENT '接收人编号', - `receiver_type` INT NOT NULL COMMENT '接收人类型', - `content_type` INT NOT NULL COMMENT '消息类型', - `content` VARCHAR(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '消息', - `read_status` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否已读', - `creator` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', - `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `updater` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', - `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `conversation_id` bigint NOT NULL COMMENT '会话编号', + `sender_id` bigint NOT NULL COMMENT '发送人编号', + `sender_type` int NOT NULL COMMENT '发送人类型', + `receiver_id` bigint DEFAULT NULL COMMENT '接收人编号', + `receiver_type` int DEFAULT NULL COMMENT '接收人类型', + `content_type` int NOT NULL COMMENT '消息类型', + `content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '消息', + `read_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已读', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '客服消息' ROW_FORMAT = Dynamic; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='客服消息'; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java index d17990857..8b54c8db4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java @@ -5,9 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; @@ -16,14 +15,13 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -@Tag(name = "管理后台 - 客服消息") +@Tag(name = "用户 APP - 客服消息") @RestController @RequestMapping("/promotion/kefu-message") @Validated @@ -52,8 +50,8 @@ public class AppKeFuMessageController { @GetMapping("/page") @Operation(summary = "获得客服消息分页") @PreAuthenticated - public CommonResult> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) { - PageResult pageResult = kefuMessageService.getKefuMessagePage(pageReqVO); + public CommonResult> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) { + PageResult pageResult = kefuMessageService.getKefuMessagePage(pageReqVO, getLoginUserId()); return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java index 6a732cff0..3de68fe0f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -23,7 +24,7 @@ public interface KeFuMessageMapper extends BaseMapperX { default PageResult selectPage(KeFuMessagePageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(KeFuMessageDO::getConversationId, reqVO.getConversationId()) - .orderByDesc(KeFuMessageDO::getId)); + .orderByDesc(KeFuMessageDO::getCreateTime)); } default List selectListByConversationIdAndReadStatus(Long conversationId, Boolean readStatus) { @@ -37,4 +38,10 @@ public interface KeFuMessageMapper extends BaseMapperX { .in(KeFuMessageDO::getId, ids)); } + default PageResult selectPage(AppKeFuMessagePageReqVO pageReqVO){ + return selectPage(pageReqVO, new LambdaQueryWrapperX() + .eqIfPresent(KeFuMessageDO::getConversationId, pageReqVO.getConversationId()) + .orderByDesc(KeFuMessageDO::getCreateTime)); + } + } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java index c4bd59976..c99e74b5c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationService.java @@ -74,4 +74,12 @@ public interface KeFuConversationService { */ KeFuConversationDO validateKefuConversationExists(Long id); + /** + * 【会员】获得客服会话 + * + * @param userId 用户编号 + * @return 客服会话 + */ + KeFuConversationDO getConversationByUserId(Long userId); + } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java index 89af0eec7..0f6c185f3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuConversationServiceImpl.java @@ -104,4 +104,9 @@ public class KeFuConversationServiceImpl implements KeFuConversationService { return conversation; } + @Override + public KeFuConversationDO getConversationByUserId(Long userId) { + return conversationMapper.selectOne(KeFuConversationDO::getUserId, userId); + } + } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java index ad28df0b8..2563ada34 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageService.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.kefu; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; import jakarta.validation.Valid; @@ -45,4 +46,13 @@ public interface KeFuMessageService { */ PageResult getKefuMessagePage(KeFuMessagePageReqVO pageReqVO); + /** + * 【会员】获得客服消息分页 + * + * @param pageReqVO 请求 + * @param userId 用户编号 + * @return 客服消息分页 + */ + PageResult getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId); + } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java index b7617bf32..22339e608 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/kefu/KeFuMessageServiceImpl.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessagePageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; @@ -21,6 +22,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @@ -131,6 +133,18 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { return keFuMessageMapper.selectPage(pageReqVO); } + @Override + public PageResult getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) { + // 1. 获得客服会话 + KeFuConversationDO conversation = conversationService.getConversationByUserId(userId); + if (conversation == null) { + return PageResult.empty(); + } + // 2. 设置会话编号 + pageReqVO.setConversationId(conversation.getId()); + return keFuMessageMapper.selectPage(pageReqVO); + } + private KeFuMessageServiceImpl getSelf() { return SpringUtil.getBean(getClass()); }