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 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.constraints.Max; | |
| 5 | +import jakarta.validation.constraints.Min; | |
| 4 | 6 | import jakarta.validation.constraints.NotNull; |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | import org.springframework.format.annotation.DateTimeFormat; |
| ... | ... | @@ -13,6 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ |
| 13 | 15 | @Data |
| 14 | 16 | public class KeFuMessageListReqVO { |
| 15 | 17 | |
| 18 | + private static final Integer PAGE_SIZE = 10; | |
| 19 | + | |
| 16 | 20 | @Schema(description = "会话编号", example = "12580") |
| 17 | 21 | @NotNull(message = "会话编号不能为空") |
| 18 | 22 | private Long conversationId; |
| ... | ... | @@ -21,4 +25,10 @@ public class KeFuMessageListReqVO { |
| 21 | 25 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 22 | 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 | 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 | 9 | import cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message.AppKeFuMessageSendReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; |
| 11 | 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 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -18,8 +20,12 @@ import org.springframework.validation.annotation.Validated; |
| 18 | 20 | import org.springframework.web.bind.annotation.*; |
| 19 | 21 | |
| 20 | 22 | import java.util.List; |
| 23 | +import java.util.Map; | |
| 21 | 24 | |
| 22 | 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 | 29 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 24 | 30 | |
| 25 | 31 | @Tag(name = "用户 APP - 客服消息") |
| ... | ... | @@ -30,6 +36,8 @@ public class AppKeFuMessageController { |
| 30 | 36 | |
| 31 | 37 | @Resource |
| 32 | 38 | private KeFuMessageService kefuMessageService; |
| 39 | + @Resource | |
| 40 | + private AdminUserApi adminUserApi; | |
| 33 | 41 | |
| 34 | 42 | @PostMapping("/send") |
| 35 | 43 | @Operation(summary = "发送客服消息") |
| ... | ... | @@ -52,8 +60,14 @@ public class AppKeFuMessageController { |
| 52 | 60 | @Operation(summary = "获得客服消息列表") |
| 53 | 61 | @PreAuthenticated |
| 54 | 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 | 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 | 1 | package cn.iocoder.yudao.module.promotion.controller.app.kefu.vo.message; |
| 2 | 2 | |
| 3 | 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 | 7 | import lombok.Data; |
| 5 | 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 | 15 | @Data |
| 13 | 16 | public class AppKeFuMessagePageReqVO { |
| 14 | 17 | |
| 18 | + private static final Integer PAGE_SIZE = 10; | |
| 19 | + | |
| 15 | 20 | @Schema(description = "会话编号", example = "12580") |
| 16 | 21 | private Long conversationId; |
| 17 | 22 | |
| ... | ... | @@ -19,4 +24,10 @@ public class AppKeFuMessagePageReqVO { |
| 19 | 24 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 20 | 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 | 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 | 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.kefu; |
| 2 | 2 | |
| 3 | 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 | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageListReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; |
| 7 | 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| ... | ... | @@ -28,11 +28,11 @@ public interface KeFuMessageMapper extends BaseMapperX<KeFuMessageDO> { |
| 28 | 28 | * @return 消息列表 |
| 29 | 29 | */ |
| 30 | 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 | 38 | default List<KeFuMessageDO> selectListByConversationIdAndUserTypeAndReadStatus(Long conversationId, Integer userType, | ... | ... |