mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
MALL-KEFU: 新增客服相关操作接口
This commit is contained in:
parent
0be9c67aa6
commit
127a98a934
37
sql/mysql/mall-promotion-kefu.sql
Normal file
37
sql/mysql/mall-promotion-kefu.sql
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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 '是否删除',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '客服会话' ROW_FORMAT = Dynamic;
|
||||||
|
|
||||||
|
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 '是否删除',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '客服消息' ROW_FORMAT = Dynamic;
|
@ -125,4 +125,10 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode DIY_PAGE_NOT_EXISTS = new ErrorCode(1_013_018_000, "装修页面不存在");
|
ErrorCode DIY_PAGE_NOT_EXISTS = new ErrorCode(1_013_018_000, "装修页面不存在");
|
||||||
ErrorCode DIY_PAGE_NAME_USED = new ErrorCode(1_013_018_001, "装修页面名称({})已经被使用");
|
ErrorCode DIY_PAGE_NAME_USED = new ErrorCode(1_013_018_001, "装修页面名称({})已经被使用");
|
||||||
|
|
||||||
|
// ========== 客服会话 1-013-019-000 ==========
|
||||||
|
ErrorCode KEFU_CONVERSATION_NOT_EXISTS = new ErrorCode(1_013_019_000, "客服会话不存在");
|
||||||
|
|
||||||
|
// ========== 客服消息 1-013-020-000 ==========
|
||||||
|
ErrorCode KEFU_MESSAGE_NOT_EXISTS = new ErrorCode(1_013_020_000, "客服消息不存在");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationRespVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 客服会话")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/promotion/kefu-conversation")
|
||||||
|
@Validated
|
||||||
|
public class KeFuConversationController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuConversationService conversationService;
|
||||||
|
|
||||||
|
@PostMapping("/update-pinned")
|
||||||
|
@Operation(summary = "置顶客服会话")
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:update')")
|
||||||
|
public CommonResult<Boolean> updatePinned(@Valid @RequestBody KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
||||||
|
conversationService.updatePinned(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除客服会话")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')")
|
||||||
|
public CommonResult<Boolean> deleteKefuConversation(@RequestParam("id") Long id) {
|
||||||
|
conversationService.deleteKefuConversation(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "获得客服会话列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')")
|
||||||
|
public CommonResult<List<KeFuConversationRespVO>> getKefuConversationPage() {
|
||||||
|
return success(BeanUtils.toBean(conversationService.getKefuConversationList(), KeFuConversationRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu;
|
||||||
|
|
||||||
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import jakarta.validation.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 客服消息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/promotion/kefu-message")
|
||||||
|
@Validated
|
||||||
|
public class KeFuMessageController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuMessageService messageService;
|
||||||
|
|
||||||
|
@PostMapping("/send")
|
||||||
|
@Operation(summary = "发送客服消息")
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')")
|
||||||
|
public CommonResult<Long> createKefuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) {
|
||||||
|
return success(messageService.sendKefuMessage(sendReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update-read-status")
|
||||||
|
@Operation(summary = "更新客服消息已读状态")
|
||||||
|
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')")
|
||||||
|
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
||||||
|
messageService.updateKefuMessageReadStatus(conversationId, getLoginUserId());
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得客服消息分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')")
|
||||||
|
public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
|
||||||
|
PageResult<KeFuMessageDO> pageResult = messageService.getKefuMessagePage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 客服会话 Response VO")
|
||||||
|
@Data
|
||||||
|
public class KeFuConversationRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24988")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED,example = "2024-01-01 00:00:00")
|
||||||
|
private LocalDateTime lastMessageTime;
|
||||||
|
|
||||||
|
@Schema(description = "最后聊天内容", requiredMode = Schema.RequiredMode.REQUIRED,example = "嗨,您好啊")
|
||||||
|
private String lastMessageContent;
|
||||||
|
|
||||||
|
@Schema(description = "最后发送的消息类型", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
|
||||||
|
private Integer lastMessageContentType;
|
||||||
|
|
||||||
|
@Schema(description = "管理端置顶", requiredMode = Schema.RequiredMode.REQUIRED,example = "false")
|
||||||
|
private Boolean adminPinned;
|
||||||
|
|
||||||
|
@Schema(description = "用户是否可见", requiredMode = Schema.RequiredMode.REQUIRED,example = "true")
|
||||||
|
private Boolean userDeleted;
|
||||||
|
|
||||||
|
@Schema(description = "管理员是否可见", requiredMode = Schema.RequiredMode.REQUIRED,example = "true")
|
||||||
|
private Boolean adminDeleted;
|
||||||
|
|
||||||
|
@Schema(description = "管理员未读消息数", requiredMode = Schema.RequiredMode.REQUIRED,example = "6")
|
||||||
|
private Integer adminUnreadMessageCount;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED,example = "2024-01-01 00:00:00")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 客服会话置顶 Request VO")
|
||||||
|
@Data
|
||||||
|
public class KeFuConversationUpdatePinnedReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
|
@NotNull(message = "会话编号,不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "管理端置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
|
||||||
|
@NotNull(message = "管理端置顶,不能为空")
|
||||||
|
private Boolean adminPinned;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 客服消息分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class KeFuMessagePageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", example = "12580")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 客服消息 Response VO")
|
||||||
|
@Data
|
||||||
|
public class KeFuMessageRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
@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 = "29124")
|
||||||
|
private Long receiverId;
|
||||||
|
|
||||||
|
@Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
private Integer receiverType;
|
||||||
|
|
||||||
|
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Integer contentType;
|
||||||
|
|
||||||
|
@Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Boolean readStatus;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 发送客服消息 Request VO")
|
||||||
|
@Data
|
||||||
|
public class KeFuMessageSendReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
|
||||||
|
@NotNull(message = "会话编号不能为空")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
@Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
|
||||||
|
@NotNull(message = "发送人编号不能为空")
|
||||||
|
private Long senderId;
|
||||||
|
|
||||||
|
@Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "发送人类型不能为空")
|
||||||
|
private Integer senderType;
|
||||||
|
|
||||||
|
@Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29124")
|
||||||
|
@NotNull(message = "接收人编号不能为空")
|
||||||
|
private Long receiverId;
|
||||||
|
|
||||||
|
@Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@NotNull(message = "接收人类型不能为空")
|
||||||
|
private Integer receiverType;
|
||||||
|
|
||||||
|
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "消息类型不能为空")
|
||||||
|
private Integer contentType;
|
||||||
|
|
||||||
|
@Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "消息不能为空")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
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.app.kefu.vo.conversation.AppKeFuConversationRespVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
|
@Tag(name = "用户 APP - 客户会话")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/promotion/kefu-conversation")
|
||||||
|
@Validated
|
||||||
|
public class AppKeFuConversationController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuConversationService conversationService;
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得客服会话")
|
||||||
|
@PreAuthenticated
|
||||||
|
public CommonResult<AppKeFuConversationRespVO> getDiyPage() {
|
||||||
|
return success(BeanUtils.toBean(conversationService.getOrCreateConversation(getLoginUserId()), AppKeFuConversationRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu;
|
||||||
|
|
||||||
|
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.AppKeFuMessageSendReqVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
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 = "管理后台 - 客服消息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/promotion/kefu-message")
|
||||||
|
@Validated
|
||||||
|
public class AppKeFuMessageController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuMessageService kefuMessageService;
|
||||||
|
|
||||||
|
@PostMapping("/send")
|
||||||
|
@Operation(summary = "发送客服消息")
|
||||||
|
@PreAuthenticated
|
||||||
|
public CommonResult<Long> createKefuMessage(@Valid @RequestBody AppKeFuMessageSendReqVO sendReqVO) {
|
||||||
|
return success(kefuMessageService.sendKefuMessage(BeanUtils.toBean(sendReqVO, KeFuMessageSendReqVO.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update-read-status")
|
||||||
|
@Operation(summary = "更新客服消息已读状态")
|
||||||
|
@Parameter(name = "conversationId", description = "会话编号", required = true)
|
||||||
|
@PreAuthenticated
|
||||||
|
public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) {
|
||||||
|
kefuMessageService.updateKefuMessageReadStatus(conversationId, getLoginUserId());
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得客服消息分页")
|
||||||
|
@PreAuthenticated
|
||||||
|
public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) {
|
||||||
|
PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKefuMessagePage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.conversation;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 客服会话 Response VO")
|
||||||
|
@Data
|
||||||
|
public class AppKeFuConversationRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24988")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED,example = "2024-01-01 00:00:00")
|
||||||
|
private LocalDateTime lastMessageTime;
|
||||||
|
|
||||||
|
@Schema(description = "最后聊天内容", requiredMode = Schema.RequiredMode.REQUIRED,example = "嗨,您好啊")
|
||||||
|
private String lastMessageContent;
|
||||||
|
|
||||||
|
@Schema(description = "最后发送的消息类型", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
|
||||||
|
private Integer lastMessageContentType;
|
||||||
|
|
||||||
|
@Schema(description = "管理端置顶", requiredMode = Schema.RequiredMode.REQUIRED,example = "false")
|
||||||
|
private Boolean adminPinned;
|
||||||
|
|
||||||
|
@Schema(description = "用户是否可见", requiredMode = Schema.RequiredMode.REQUIRED,example = "true")
|
||||||
|
private Boolean userDeleted;
|
||||||
|
|
||||||
|
@Schema(description = "管理员是否可见", requiredMode = Schema.RequiredMode.REQUIRED,example = "true")
|
||||||
|
private Boolean adminDeleted;
|
||||||
|
|
||||||
|
@Schema(description = "管理员未读消息数", requiredMode = Schema.RequiredMode.REQUIRED,example = "6")
|
||||||
|
private Integer adminUnreadMessageCount;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED,example = "2024-01-01 00:00:00")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 客服消息分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class AppKeFuMessagePageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", example = "12580")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 客服消息 Response VO")
|
||||||
|
@Data
|
||||||
|
public class AppKeFuMessageRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
@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 = "29124")
|
||||||
|
private Long receiverId;
|
||||||
|
|
||||||
|
@Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
private Integer receiverType;
|
||||||
|
|
||||||
|
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Integer contentType;
|
||||||
|
|
||||||
|
@Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
private Boolean readStatus;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "用户 App - 发送客服消息 Request VO")
|
||||||
|
@Data
|
||||||
|
public class AppKeFuMessageSendReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23202")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12580")
|
||||||
|
@NotNull(message = "会话编号不能为空")
|
||||||
|
private Long conversationId;
|
||||||
|
|
||||||
|
@Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571")
|
||||||
|
@NotNull(message = "发送人编号不能为空")
|
||||||
|
private Long senderId;
|
||||||
|
|
||||||
|
@Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "发送人类型不能为空")
|
||||||
|
private Integer senderType;
|
||||||
|
|
||||||
|
@Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "29124")
|
||||||
|
@NotNull(message = "接收人编号不能为空")
|
||||||
|
private Long receiverId;
|
||||||
|
|
||||||
|
@Schema(description = "接收人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||||
|
@NotNull(message = "接收人类型不能为空")
|
||||||
|
private Integer receiverType;
|
||||||
|
|
||||||
|
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "消息类型不能为空")
|
||||||
|
private Integer contentType;
|
||||||
|
|
||||||
|
@Schema(description = "消息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "消息不能为空")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
@ -61,15 +61,15 @@ public class KeFuConversationDO extends BaseDO {
|
|||||||
/**
|
/**
|
||||||
* 用户是否可见
|
* 用户是否可见
|
||||||
*
|
*
|
||||||
* true - 可见,默认值
|
* false - 可见,默认值
|
||||||
* false - 不可见,用户删除时设置为 false
|
* true - 不可见,用户删除时设置为 true
|
||||||
*/
|
*/
|
||||||
private Boolean userDeleted;
|
private Boolean userDeleted;
|
||||||
/**
|
/**
|
||||||
* 管理员是否可见
|
* 管理员是否可见
|
||||||
*
|
*
|
||||||
* true - 可见,默认值
|
* false - 可见,默认值
|
||||||
* false - 不可见,管理员删除时设置为 false
|
* true - 不可见,管理员删除时设置为 true
|
||||||
*/
|
*/
|
||||||
private Boolean adminDeleted;
|
private Boolean adminDeleted;
|
||||||
|
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.dal.mysql.kefu;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服会话 Mapper
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface KeFuConversationMapper extends BaseMapperX<KeFuConversationDO> {
|
||||||
|
|
||||||
|
default List<KeFuConversationDO> selectListWithSort() {
|
||||||
|
return selectList(new LambdaQueryWrapperX<KeFuConversationDO>()
|
||||||
|
.eq(KeFuConversationDO::getAdminDeleted, Boolean.FALSE)
|
||||||
|
.orderByDesc(KeFuConversationDO::getAdminPinned) // 置顶优先
|
||||||
|
.orderByDesc(KeFuConversationDO::getCreateTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void updateAdminUnreadMessageCountByConversationId(Long id, Integer count) {
|
||||||
|
LambdaUpdateWrapper<KeFuConversationDO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(KeFuConversationDO::getId, id);
|
||||||
|
if (count != null && count > 0) { // 情况一:会员发送消息时增加管理员的未读消息数
|
||||||
|
updateWrapper.setSql("admin_unread_message_count = admin_unread_message_count + 1");
|
||||||
|
} else { // 情况二:管理员已读后重置
|
||||||
|
updateWrapper.set(KeFuConversationDO::getAdminUnreadMessageCount, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.dal.mysql.kefu;
|
||||||
|
|
||||||
|
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.dal.dataobject.kefu.KeFuMessageDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服消息 Mapper
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> {
|
||||||
|
|
||||||
|
default PageResult<KeFuMessageDO> selectPage(KeFuMessagePageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<KeFuMessageDO>()
|
||||||
|
.eqIfPresent(KeFuMessageDO::getConversationId, reqVO.getConversationId())
|
||||||
|
.orderByDesc(KeFuMessageDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<KeFuMessageDO> selectListByConversationIdAndReceiverIdAndReadStatus(Long conversationId, Long receiverId, Boolean readStatus) {
|
||||||
|
return selectList(new LambdaQueryWrapper<KeFuMessageDO>()
|
||||||
|
.eq(KeFuMessageDO::getConversationId, conversationId)
|
||||||
|
.eq(KeFuMessageDO::getReceiverId, receiverId)
|
||||||
|
.eq(KeFuMessageDO::getReadStatus, readStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void updateReadStstusBatchByIds(Collection<Long> ids, Boolean readStatus) {
|
||||||
|
update(new LambdaUpdateWrapper<KeFuMessageDO>()
|
||||||
|
.in(KeFuMessageDO::getId, ids)
|
||||||
|
.set(KeFuMessageDO::getReadStatus, readStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.service.kefu;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服会话 Service 接口
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
public interface KeFuConversationService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除客服会话
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteKefuConversation(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服会话置顶
|
||||||
|
*
|
||||||
|
* @param updateReqVO 请求
|
||||||
|
*/
|
||||||
|
void updatePinned(KeFuConversationUpdatePinnedReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话客服消息冗余信息
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @param lastMessageTime 最后聊天时间
|
||||||
|
* @param lastMessageContent 最后聊天内容
|
||||||
|
* @param lastMessageContentType 最后聊天内容类型
|
||||||
|
*/
|
||||||
|
void updateConversationMessage(Long id, LocalDateTime lastMessageTime, String lastMessageContent, Integer lastMessageContentType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新管理员未读消息数
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @param count 数量:0 则重置 1 则消息数加一
|
||||||
|
*/
|
||||||
|
void updateAdminUnreadMessageCountByConversationId(Long id, Integer count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话对于管理员是否可见
|
||||||
|
*
|
||||||
|
* @param adminDeleted 管理员是否可见
|
||||||
|
*/
|
||||||
|
void updateConversationAdminDeleted(Long id, Boolean adminDeleted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得客服会话列表
|
||||||
|
*
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
|
List<KeFuConversationDO> getKefuConversationList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得或创建会话
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @return 客服会话
|
||||||
|
*/
|
||||||
|
KeFuConversationDO getOrCreateConversation(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验客服会话是否存在
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 客服会话
|
||||||
|
*/
|
||||||
|
KeFuConversationDO validateKefuConversationExists(Long id);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.service.kefu;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuConversationDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.mysql.kefu.KeFuConversationMapper;
|
||||||
|
import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.KEFU_CONVERSATION_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服会话 Service 实现类
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class KeFuConversationServiceImpl implements KeFuConversationService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuConversationMapper conversationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteKefuConversation(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateKefuConversationExists(id);
|
||||||
|
|
||||||
|
// 只有管理员端可以删除会话,也不真的删,只是管理员端看不到啦
|
||||||
|
conversationMapper.updateById(new KeFuConversationDO().setId(id).setAdminDeleted(Boolean.TRUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePinned(KeFuConversationUpdatePinnedReqVO updateReqVO) {
|
||||||
|
// 只有管理员端可以置顶会话
|
||||||
|
conversationMapper.updateById(new KeFuConversationDO().setId(updateReqVO.getId()).setAdminPinned(updateReqVO.getAdminPinned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateConversationMessage(Long id, LocalDateTime lastMessageTime, String lastMessageContent, Integer lastMessageContentType) {
|
||||||
|
conversationMapper.updateById(new KeFuConversationDO().setId(id).setLastMessageTime(lastMessageTime)
|
||||||
|
.setLastMessageContent(lastMessageContent).setLastMessageContentType(lastMessageContentType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAdminUnreadMessageCountByConversationId(Long id, Integer count) {
|
||||||
|
conversationMapper.updateAdminUnreadMessageCountByConversationId(id, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateConversationAdminDeleted(Long id, Boolean adminDeleted) {
|
||||||
|
conversationMapper.updateById(new KeFuConversationDO().setId(id).setAdminDeleted(adminDeleted));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<KeFuConversationDO> getKefuConversationList() {
|
||||||
|
return conversationMapper.selectListWithSort();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeFuConversationDO getOrCreateConversation(Long userId) {
|
||||||
|
KeFuConversationDO conversation = conversationMapper.selectOne(KeFuConversationDO::getUserId, userId);
|
||||||
|
if (conversation == null) { // 没有历史会话则初始化一个新会话
|
||||||
|
conversation = new KeFuConversationDO().setUserId(userId).setLastMessageTime(LocalDateTime.now())
|
||||||
|
.setLastMessageContent("").setLastMessageContentType(KeFuMessageContentTypeEnum.TEXT.getType())
|
||||||
|
.setAdminPinned(Boolean.FALSE).setUserDeleted(Boolean.FALSE).setAdminDeleted(Boolean.FALSE)
|
||||||
|
.setAdminUnreadMessageCount(0);
|
||||||
|
conversationMapper.insert(conversation);
|
||||||
|
}
|
||||||
|
return conversation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeFuConversationDO validateKefuConversationExists(Long id) {
|
||||||
|
KeFuConversationDO conversationDO = conversationMapper.selectById(id);
|
||||||
|
if (conversationDO == null) {
|
||||||
|
throw exception(KEFU_CONVERSATION_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return conversationDO;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
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.dal.dataobject.kefu.KeFuMessageDO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服消息 Service 接口
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
public interface KeFuMessageService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送客服消息
|
||||||
|
*
|
||||||
|
* @param sendReqVO 信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long sendKefuMessage(@Valid KeFuMessageSendReqVO sendReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新消息已读状态
|
||||||
|
*
|
||||||
|
* @param conversationId 会话编号
|
||||||
|
* @param receiverId 用户编号
|
||||||
|
*/
|
||||||
|
void updateKefuMessageReadStatus(Long conversationId, Long receiverId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得客服消息分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 客服消息分页
|
||||||
|
*/
|
||||||
|
PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.service.kefu;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
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.dal.dataobject.kefu.KeFuConversationDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.dal.mysql.kefu.KeFuMessageMapper;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getFirst;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客服消息 Service 实现类
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class KeFuMessageServiceImpl implements KeFuMessageService {
|
||||||
|
|
||||||
|
private static final String KEFU_MESSAGE_TYPE = "kefu_message_type"; // 客服消息类型
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeFuMessageMapper messageMapper;
|
||||||
|
@Resource
|
||||||
|
private KeFuConversationService conversationService;
|
||||||
|
@Resource
|
||||||
|
private AdminUserApi adminUserApi;
|
||||||
|
@Resource
|
||||||
|
private MemberUserApi memberUserApi;
|
||||||
|
@Resource
|
||||||
|
private WebSocketSenderApi webSocketSenderApi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Long sendKefuMessage(KeFuMessageSendReqVO sendReqVO) {
|
||||||
|
// 1.1 校验会话是否存在
|
||||||
|
KeFuConversationDO conversation = conversationService.validateKefuConversationExists(sendReqVO.getConversationId());
|
||||||
|
// 1.2 校验接收人是否存在
|
||||||
|
validateReceiverExist(sendReqVO.getReceiverId(), sendReqVO.getReceiverType());
|
||||||
|
|
||||||
|
// 2.1 保存消息
|
||||||
|
KeFuMessageDO kefuMessage = BeanUtils.toBean(sendReqVO, KeFuMessageDO.class);
|
||||||
|
messageMapper.insert(kefuMessage);
|
||||||
|
// 2.2 更新会话消息冗余
|
||||||
|
conversationService.updateConversationMessage(kefuMessage.getConversationId(), LocalDateTime.now(),
|
||||||
|
kefuMessage.getContent(), kefuMessage.getContentType());
|
||||||
|
// 2.3 更新管理员未读消息数
|
||||||
|
if (UserTypeEnum.ADMIN.getValue().equals(kefuMessage.getReceiverType())) {
|
||||||
|
conversationService.updateAdminUnreadMessageCountByConversationId(kefuMessage.getConversationId(), 1);
|
||||||
|
}
|
||||||
|
// 2.4 会员用户发送消息时,如果管理员删除过会话则进行恢复
|
||||||
|
if (UserTypeEnum.MEMBER.getValue().equals(kefuMessage.getSenderType()) && Boolean.TRUE.equals(conversation.getAdminDeleted())) {
|
||||||
|
conversationService.updateConversationAdminDeleted(kefuMessage.getConversationId(), Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 发送消息
|
||||||
|
getSelf().sendAsyncMessage(sendReqVO.getReceiverType(), sendReqVO.getReceiverId(), kefuMessage);
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
return kefuMessage.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateKefuMessageReadStatus(Long conversationId, Long receiverId) {
|
||||||
|
// 1.1 校验会话是否存在
|
||||||
|
conversationService.validateKefuConversationExists(conversationId);
|
||||||
|
// 1.2 查询接收人所有的未读消息
|
||||||
|
List<KeFuMessageDO> messageList = messageMapper.selectListByConversationIdAndReceiverIdAndReadStatus(
|
||||||
|
conversationId, receiverId, Boolean.FALSE);
|
||||||
|
// 1.3 情况一:没有未读消息
|
||||||
|
if (CollUtil.isEmpty(messageList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.1 情况二:更新未读消息状态为已读
|
||||||
|
messageMapper.updateReadStstusBatchByIds(convertSet(messageList, KeFuMessageDO::getId), Boolean.TRUE);
|
||||||
|
// 2.2 更新管理员未读消息数
|
||||||
|
KeFuMessageDO message = getFirst(messageList);
|
||||||
|
assert message != null;
|
||||||
|
if (UserTypeEnum.ADMIN.getValue().equals(message.getReceiverType())) {
|
||||||
|
conversationService.updateAdminUnreadMessageCountByConversationId(conversationId, 0);
|
||||||
|
}
|
||||||
|
// 2.3 发送消息通知发送者,接收者已读 -> 发送者更新发送的消息状态
|
||||||
|
getSelf().sendAsyncMessage(message.getSenderType(), message.getSenderId(), "keFuMessageReadStatusChange");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateReceiverExist(Long receiverId, Integer receiverType) {
|
||||||
|
if (UserTypeEnum.ADMIN.getValue().equals(receiverType)) {
|
||||||
|
adminUserApi.validateUser(receiverId);
|
||||||
|
}
|
||||||
|
if (UserTypeEnum.MEMBER.getValue().equals(receiverType)) {
|
||||||
|
memberUserApi.validateUser(receiverId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void sendAsyncMessage(Integer userType, Long userId, Object content) {
|
||||||
|
webSocketSenderApi.sendObject(userType, userId, KEFU_MESSAGE_TYPE, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO) {
|
||||||
|
return messageMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeFuMessageServiceImpl getSelf() {
|
||||||
|
return SpringUtil.getBean(getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -57,4 +57,12 @@ public interface MemberUserApi {
|
|||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
MemberUserRespDTO getUserByMobile(String mobile);
|
MemberUserRespDTO getUserByMobile(String mobile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验用户是否存在
|
||||||
|
*
|
||||||
|
* @param id 用户编号
|
||||||
|
*/
|
||||||
|
void validateUser(Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ import jakarta.annotation.Resource;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_MOBILE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员用户的 API 实现类
|
* 会员用户的 API 实现类
|
||||||
*
|
*
|
||||||
@ -44,4 +47,12 @@ public class MemberUserApiImpl implements MemberUserApi {
|
|||||||
return MemberUserConvert.INSTANCE.convert2(userService.getUserByMobile(mobile));
|
return MemberUserConvert.INSTANCE.convert2(userService.getUserByMobile(mobile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validateUser(Long id) {
|
||||||
|
MemberUserDO user = userService.getUser(id);
|
||||||
|
if (user == null) {
|
||||||
|
throw exception(USER_MOBILE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user