Commit a2e9eccee73f8ed8038d8959aee5ce42f360a336
1 parent
9bb10523
【功能完善】商城: 客服消息
Showing
4 changed files
with
43 additions
and
8 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/kefu/vo/message/KeFuMessageListReqVO.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message; | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.constraints.Max; | ||
| 5 | +import jakarta.validation.constraints.Min; | ||
| 4 | import jakarta.validation.constraints.NotNull; | 6 | import jakarta.validation.constraints.NotNull; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import org.springframework.format.annotation.DateTimeFormat; | 8 | import org.springframework.format.annotation.DateTimeFormat; |
| @@ -13,6 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | @@ -13,6 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||
| 13 | @Data | 15 | @Data |
| 14 | public class KeFuMessageListReqVO { | 16 | public class KeFuMessageListReqVO { |
| 15 | 17 | ||
| 18 | + private static final Integer PAGE_SIZE = 10; | ||
| 19 | + | ||
| 16 | @Schema(description = "会话编号", example = "12580") | 20 | @Schema(description = "会话编号", example = "12580") |
| 17 | @NotNull(message = "会话编号不能为空") | 21 | @NotNull(message = "会话编号不能为空") |
| 18 | private Long conversationId; | 22 | private Long conversationId; |
| @@ -21,4 +25,10 @@ public class KeFuMessageListReqVO { | @@ -21,4 +25,10 @@ public class KeFuMessageListReqVO { | ||
| 21 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | 25 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 22 | private LocalDateTime createTime; | 26 | private LocalDateTime createTime; |
| 23 | 27 | ||
| 28 | + @Schema(description = "每页条数,最大值为 100", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | ||
| 29 | + @NotNull(message = "每页条数不能为空") | ||
| 30 | + @Min(value = 1, message = "每页条数最小值为 1") | ||
| 31 | + @Max(value = 100, message = "每页条数最大值为 100") | ||
| 32 | + private Integer pageSize = PAGE_SIZE; | ||
| 33 | + | ||
| 24 | } | 34 | } |
| 25 | \ No newline at end of file | 35 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/AppKeFuMessageController.java
| @@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuM | @@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuM | ||
| 9 | import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; | 9 | import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; |
| 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; |
| 11 | import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; | 11 | import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; |
| 12 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 13 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 12 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | import io.swagger.v3.oas.annotations.Parameter; | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -18,8 +20,12 @@ import org.springframework.validation.annotation.Validated; | @@ -18,8 +20,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 18 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| 19 | 21 | ||
| 20 | import java.util.List; | 22 | import java.util.List; |
| 23 | +import java.util.Map; | ||
| 21 | 24 | ||
| 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 26 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | ||
| 23 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 29 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 24 | 30 | ||
| 25 | @Tag(name = "用户 APP - 客服消息") | 31 | @Tag(name = "用户 APP - 客服消息") |
| @@ -30,6 +36,8 @@ public class AppKeFuMessageController { | @@ -30,6 +36,8 @@ public class AppKeFuMessageController { | ||
| 30 | 36 | ||
| 31 | @Resource | 37 | @Resource |
| 32 | private KeFuMessageService kefuMessageService; | 38 | private KeFuMessageService kefuMessageService; |
| 39 | + @Resource | ||
| 40 | + private AdminUserApi adminUserApi; | ||
| 33 | 41 | ||
| 34 | @PostMapping("/send") | 42 | @PostMapping("/send") |
| 35 | @Operation(summary = "发送客服消息") | 43 | @Operation(summary = "发送客服消息") |
| @@ -52,8 +60,14 @@ public class AppKeFuMessageController { | @@ -52,8 +60,14 @@ public class AppKeFuMessageController { | ||
| 52 | @Operation(summary = "获得客服消息列表") | 60 | @Operation(summary = "获得客服消息列表") |
| 53 | @PreAuthenticated | 61 | @PreAuthenticated |
| 54 | public CommonResult<List<KeFuMessageRespVO>> getKefuMessageList(@Valid AppKeFuMessagePageReqVO pageReqVO) { | 62 | public CommonResult<List<KeFuMessageRespVO>> getKefuMessageList(@Valid AppKeFuMessagePageReqVO pageReqVO) { |
| 55 | - List<KeFuMessageDO> pageResult = kefuMessageService.getKeFuMessageList(pageReqVO, getLoginUserId()); | ||
| 56 | - return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); | 63 | + List<KeFuMessageDO> list = kefuMessageService.getKeFuMessageList(pageReqVO, getLoginUserId()); |
| 64 | + | ||
| 65 | + // 拼接数据 | ||
| 66 | + List<KeFuMessageRespVO> result = BeanUtils.toBean(list, KeFuMessageRespVO.class); | ||
| 67 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(filterList(result, | ||
| 68 | + item -> UserTypeEnum.ADMIN.getValue().equals(item.getSenderType())), KeFuMessageRespVO::getSenderId)); | ||
| 69 | + result.forEach(item -> findAndThen(userMap, item.getSenderId(), user -> item.setSenderAvatar(user.getAvatar()))); | ||
| 70 | + return success(result); | ||
| 57 | } | 71 | } |
| 58 | 72 | ||
| 59 | } | 73 | } |
| 60 | \ No newline at end of file | 74 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/kefu/vo/message/AppKeFuMessagePageReqVO.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message; | 1 | package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.constraints.Max; | ||
| 5 | +import jakarta.validation.constraints.Min; | ||
| 6 | +import jakarta.validation.constraints.NotNull; | ||
| 4 | import lombok.Data; | 7 | import lombok.Data; |
| 5 | import org.springframework.format.annotation.DateTimeFormat; | 8 | import org.springframework.format.annotation.DateTimeFormat; |
| 6 | 9 | ||
| @@ -12,6 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | @@ -12,6 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||
| 12 | @Data | 15 | @Data |
| 13 | public class AppKeFuMessagePageReqVO { | 16 | public class AppKeFuMessagePageReqVO { |
| 14 | 17 | ||
| 18 | + private static final Integer PAGE_SIZE = 10; | ||
| 19 | + | ||
| 15 | @Schema(description = "会话编号", example = "12580") | 20 | @Schema(description = "会话编号", example = "12580") |
| 16 | private Long conversationId; | 21 | private Long conversationId; |
| 17 | 22 | ||
| @@ -19,4 +24,10 @@ public class AppKeFuMessagePageReqVO { | @@ -19,4 +24,10 @@ public class AppKeFuMessagePageReqVO { | ||
| 19 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | 24 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 20 | private LocalDateTime createTime; | 25 | private LocalDateTime createTime; |
| 21 | 26 | ||
| 27 | + @Schema(description = "每页条数,最大值为 100", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | ||
| 28 | + @NotNull(message = "每页条数不能为空") | ||
| 29 | + @Min(value = 1, message = "每页条数最小值为 1") | ||
| 30 | + @Max(value = 100, message = "每页条数最大值为 100") | ||
| 31 | + private Integer pageSize = PAGE_SIZE; | ||
| 32 | + | ||
| 22 | } | 33 | } |
| 23 | \ No newline at end of file | 34 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/kefu/KeFuMessageMapper.java
| 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.kefu; | 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.kefu; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageListReqVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageListReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; |
| 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| @@ -28,11 +28,11 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> { | @@ -28,11 +28,11 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> { | ||
| 28 | * @return 消息列表 | 28 | * @return 消息列表 |
| 29 | */ | 29 | */ |
| 30 | default List<KeFuMessageDO> selectList(KeFuMessageListReqVO reqVO) { | 30 | default List<KeFuMessageDO> selectList(KeFuMessageListReqVO reqVO) { |
| 31 | - return selectList(new LambdaQueryWrapperX<KeFuMessageDO>() | ||
| 32 | - .eqIfPresent(KeFuMessageDO::getConversationId, reqVO.getConversationId()) | ||
| 33 | - .ltIfPresent(KeFuMessageDO::getCreateTime, reqVO.getCreateTime()) | ||
| 34 | - .orderByDesc(KeFuMessageDO::getCreateTime) | ||
| 35 | - .last("limit 10")); // TODO @puhui999:使用 limitN 哈。然后 10 通过 reqVO 传递。 | 31 | + return selectList(new QueryWrapperX<KeFuMessageDO>() |
| 32 | + .eqIfPresent("conversation_id", reqVO.getConversationId()) | ||
| 33 | + .ltIfPresent("create_time", reqVO.getCreateTime()) | ||
| 34 | + .orderByDesc("create_time") | ||
| 35 | + .limitN(reqVO.getPageSize())); | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType, | 38 | default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType, |