mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 11:40:05 +08:00
commit
2347bffeb1
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_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,43 @@
|
||||
package cn.iocoder.yudao.module.promotion.enums.kehu;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 消息类型枚举
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum KeFuMessageContentTypeEnum implements IntArrayValuable {
|
||||
|
||||
TEXT(1, "文本消息"),
|
||||
IMAGE(2, "图片消息"),
|
||||
VOICE(3, "语音消息"),
|
||||
VIDEO(4, "视频消息"),
|
||||
// 和正常消息隔离下
|
||||
PRODUCT(10, "商品消息"),
|
||||
ORDER(11, "订单消息");
|
||||
|
||||
private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(KeFuMessageContentTypeEnum::getType).toArray();
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.dataobject.kefu;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客服会话 DO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@TableName("promotion_kefu_conversation")
|
||||
@KeySequence("promotion_kefu_conversation_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KeFuConversationDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 会话所属用户
|
||||
*
|
||||
* 关联 {@link MemberUserRespDTO#getId()}
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 最后聊天时间
|
||||
*/
|
||||
private LocalDateTime lastMessageTime;
|
||||
/**
|
||||
* 最后聊天内容
|
||||
*/
|
||||
private String lastMessageContent;
|
||||
/**
|
||||
* 最后发送的消息类型
|
||||
*
|
||||
* 枚举 {@link KeFuMessageContentTypeEnum}
|
||||
*/
|
||||
private Integer lastMessageContentType;
|
||||
|
||||
//======================= 会话操作相关 =======================
|
||||
|
||||
/**
|
||||
* 管理端置顶
|
||||
*/
|
||||
private Boolean adminPinned;
|
||||
/**
|
||||
* 用户是否可见
|
||||
*
|
||||
* false - 可见,默认值
|
||||
* true - 不可见,用户删除时设置为 true
|
||||
*/
|
||||
private Boolean userDeleted;
|
||||
/**
|
||||
* 管理员是否可见
|
||||
*
|
||||
* false - 可见,默认值
|
||||
* true - 不可见,管理员删除时设置为 true
|
||||
*/
|
||||
private Boolean adminDeleted;
|
||||
|
||||
/**
|
||||
* 管理员未读消息数
|
||||
*
|
||||
* 用户发送消息时增加,管理员查看后扣减
|
||||
*/
|
||||
private Integer adminUnreadMessageCount;
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.dataobject.kefu;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.kehu.KeFuMessageContentTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 客服消息 DO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@TableName("promotion_kefu_message")
|
||||
@KeySequence("promotion_kefu_message_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KeFuMessageDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 会话编号
|
||||
*
|
||||
* 关联 {@link KeFuConversationDO#getId()}
|
||||
*/
|
||||
private Long conversationId;
|
||||
|
||||
/**
|
||||
* 发送人编号
|
||||
*
|
||||
* 存储的是用户编号
|
||||
*/
|
||||
private Long senderId;
|
||||
/**
|
||||
* 发送人类型
|
||||
*
|
||||
* 枚举,{@link UserTypeEnum}
|
||||
*/
|
||||
private Integer senderType;
|
||||
/**
|
||||
* 接收人编号
|
||||
*
|
||||
* 存储的是用户编号
|
||||
*/
|
||||
private Long receiverId;
|
||||
/**
|
||||
* 接收人类型
|
||||
*
|
||||
* 枚举,{@link UserTypeEnum}
|
||||
*/
|
||||
private Integer receiverType;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*
|
||||
* 枚举 {@link KeFuMessageContentTypeEnum}
|
||||
*/
|
||||
private Integer contentType;
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
private String content;
|
||||
|
||||
//======================= 消息相关状态 =======================
|
||||
|
||||
/**
|
||||
* 是/否已读
|
||||
*/
|
||||
private Boolean readStatus;
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package cn.iocoder.yudao.module.trade.controller.app.brokerage;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
@ -11,8 +10,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*;
|
||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert;
|
||||
import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
|
||||
@ -20,7 +17,6 @@ import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService;
|
||||
import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO;
|
||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -55,22 +51,16 @@ public class AppBrokerageUserController {
|
||||
@Resource
|
||||
private BrokerageWithdrawService brokerageWithdrawService;
|
||||
@Resource
|
||||
private TradeConfigService tradeConfigService;
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得个人分销信息")
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppBrokerageUserRespVO> getBrokerageUser() {
|
||||
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId()));
|
||||
// 获得交易中心配置
|
||||
TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig();
|
||||
// 如果是人人分佣 BrokerageUserDO 为 null 时,也有分销资格
|
||||
boolean brokerageEnabled = ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(), tradeConfig.getBrokerageEnabledCondition());
|
||||
Optional<BrokerageUserDO> user = Optional.ofNullable(brokerageUserService.getOrCreateBrokerageUser(getLoginUserId()));
|
||||
// 返回数据
|
||||
AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO()
|
||||
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(brokerageEnabled))
|
||||
.setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false))
|
||||
.setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0))
|
||||
.setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0));
|
||||
return success(respVO);
|
||||
|
@ -8,7 +8,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "应用 App - 绑定推广员 Request VO")
|
||||
@Data
|
||||
public class AppBrokerageUserBindReqVO extends PageParam {
|
||||
public class AppBrokerageUserBindReqVO {
|
||||
|
||||
@Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "推广员编号不能为空")
|
||||
|
@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokera
|
||||
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
|
||||
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
|
||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -67,6 +67,14 @@ public interface BrokerageUserService {
|
||||
*/
|
||||
BrokerageUserDO getBindBrokerageUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得或创建分销用户
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @return 分销用户
|
||||
*/
|
||||
BrokerageUserDO getOrCreateBrokerageUser(Long id);
|
||||
|
||||
/**
|
||||
* 更新用户佣金
|
||||
*
|
||||
@ -134,4 +142,5 @@ public interface BrokerageUserService {
|
||||
* @return 下级分销统计分页
|
||||
*/
|
||||
PageResult<AppBrokerageUserChildSummaryRespVO> getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
||||
@ -25,10 +26,10 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
|
||||
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@ -127,6 +128,18 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
|
||||
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
|
||||
if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
|
||||
tradeConfigService.getTradeConfig().getBrokerageEnabledCondition())) { // 人人分销的情况下,如果分销人为空则创建分销人
|
||||
brokerageUser = new BrokerageUserDO().setId(id).setBrokerageEnabled(true).setBrokeragePrice(0)
|
||||
.setBrokerageTime(LocalDateTime.now()).setFrozenPrice(0);
|
||||
brokerageUserMapper.insert(brokerageUser);
|
||||
}
|
||||
return brokerageUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateUserPrice(Long id, Integer price) {
|
||||
if (price > 0) {
|
||||
@ -184,7 +197,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
if (BrokerageEnabledConditionEnum.ALL.getCondition().equals(enabledCondition)) { // 人人分销:用户默认就有分销资格
|
||||
brokerageUser.setBrokerageEnabled(true).setBrokerageTime(LocalDateTime.now());
|
||||
}
|
||||
brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now());
|
||||
brokerageUserMapper.insert(fillBindUserData(bindUserId, brokerageUser));
|
||||
} else {
|
||||
brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(userId)));
|
||||
@ -294,18 +306,23 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
}
|
||||
|
||||
private void validateCanBindUser(BrokerageUserDO user, Long bindUserId) {
|
||||
// 校验要绑定的用户有无推广资格
|
||||
BrokerageUserDO bindUser = brokerageUserMapper.selectById(bindUserId);
|
||||
// 1.1 校验推广人是否存在
|
||||
MemberUserRespDTO bindUserInfo = memberUserApi.getUser(bindUserId);
|
||||
if (bindUserInfo == null) {
|
||||
throw exception(BROKERAGE_USER_NOT_EXISTS);
|
||||
}
|
||||
// 1.2 校验要绑定的用户有无推广资格
|
||||
BrokerageUserDO bindUser = getOrCreateBrokerageUser(bindUserId);
|
||||
if (bindUser == null || BooleanUtil.isFalse(bindUser.getBrokerageEnabled())) {
|
||||
throw exception(BROKERAGE_BIND_USER_NOT_ENABLED);
|
||||
}
|
||||
|
||||
// 校验绑定自己
|
||||
// 2. 校验绑定自己
|
||||
if (Objects.equals(user.getId(), bindUserId)) {
|
||||
throw exception(BROKERAGE_BIND_SELF);
|
||||
}
|
||||
|
||||
// 下级不能绑定自己的上级
|
||||
// 3. 下级不能绑定自己的上级
|
||||
for (int i = 0; i <= Short.MAX_VALUE; i++) {
|
||||
if (Objects.equals(bindUser.getBindUserId(), user.getId())) {
|
||||
throw exception(BROKERAGE_BIND_LOOP);
|
||||
|
@ -57,4 +57,12 @@ public interface MemberUserApi {
|
||||
* @return 用户信息
|
||||
*/
|
||||
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.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 实现类
|
||||
*
|
||||
@ -44,4 +47,12 @@ public class MemberUserApiImpl implements MemberUserApi {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ public class AppSocialUserController {
|
||||
|
||||
@PostMapping("/wxa-qrcode")
|
||||
@Operation(summary = "获得微信小程序码(base64 image)")
|
||||
public CommonResult<String> getWxQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
|
||||
byte[] wxQrcode = socialClientApi.getWxaQrcode(new SocialWxQrcodeReqDTO().setPath(reqVO.getPath()));
|
||||
public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) {
|
||||
byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class));
|
||||
return success(Base64.encode(wxQrcode));
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class SocialWxQrcodeReqDTO {
|
||||
|
||||
/**
|
||||
* 小程序版本
|
||||
*
|
||||
* 正式版为 "release";体验版为 "trial";开发版为 "develop"
|
||||
*/
|
||||
public static final String ENV_VERSION = "release";
|
||||
/**
|
||||
* 页面路径不能携带参数(参数请放在scene字段里)
|
||||
*/
|
||||
@ -51,10 +45,6 @@ public class SocialWxQrcodeReqDTO {
|
||||
*/
|
||||
@NotEmpty(message = "页面路径不能为空")
|
||||
private String path;
|
||||
/**
|
||||
* 要打开的小程序版本
|
||||
*/
|
||||
private String envVersion;
|
||||
/**
|
||||
* 二维码宽度
|
||||
*/
|
||||
|
@ -41,6 +41,7 @@ import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -60,6 +61,12 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
@Slf4j
|
||||
public class SocialClientServiceImpl implements SocialClientService {
|
||||
|
||||
/**
|
||||
* 小程序版本
|
||||
*/
|
||||
@Value("${yudao.wxa-code.env-version}")
|
||||
public String envVersion;
|
||||
|
||||
@Resource
|
||||
private AuthRequestFactory authRequestFactory;
|
||||
|
||||
@ -237,7 +244,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
ObjUtil.defaultIfEmpty(reqVO.getScene(), SocialWxQrcodeReqDTO.SCENE),
|
||||
reqVO.getPath(),
|
||||
ObjUtil.defaultIfNull(reqVO.getCheckPath(), SocialWxQrcodeReqDTO.CHECK_PATH),
|
||||
ObjUtil.defaultIfBlank(reqVO.getEnvVersion(), SocialWxQrcodeReqDTO.ENV_VERSION),
|
||||
envVersion,
|
||||
ObjUtil.defaultIfNull(reqVO.getWidth(), SocialWxQrcodeReqDTO.WIDTH),
|
||||
ObjUtil.defaultIfNull(reqVO.getAutoColor(), SocialWxQrcodeReqDTO.AUTO_COLOR),
|
||||
null,
|
||||
|
@ -171,6 +171,8 @@ yudao:
|
||||
order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址
|
||||
refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址
|
||||
demo: true # 开启演示模式
|
||||
wxa-code:
|
||||
env-version: release # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
|
||||
tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
|
||||
|
||||
justauth:
|
||||
|
@ -220,6 +220,8 @@ yudao:
|
||||
access-log: # 访问日志的配置项
|
||||
enable: false
|
||||
demo: false # 关闭演示模式
|
||||
wxa-code:
|
||||
env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
|
||||
tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
|
||||
|
||||
justauth:
|
||||
|
@ -177,6 +177,8 @@ yudao:
|
||||
license-url: https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE
|
||||
captcha:
|
||||
enable: true # 验证码的开关,默认为 true
|
||||
wxa-code:
|
||||
env-version: release # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"。默认为 release
|
||||
codegen:
|
||||
base-package: ${yudao.info.base-package}
|
||||
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||
|
Loading…
Reference in New Issue
Block a user