mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	MALL-KEFU: 完善管理端接口
This commit is contained in:
		| @ -2,6 +2,8 @@ package cn.iocoder.yudao.module.promotion.controller.admin.kefu; | |||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||||
|  | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | ||||||
|  | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | ||||||
| import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.conversation.KeFuConversationRespVO; | 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.controller.admin.kefu.vo.conversation.KeFuConversationUpdatePinnedReqVO; | ||||||
| import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService; | import cn.iocoder.yudao.module.promotion.service.kefu.KeFuConversationService; | ||||||
| @ -15,8 +17,11 @@ import org.springframework.validation.annotation.Validated; | |||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | ||||||
|  |  | ||||||
| @Tag(name = "管理后台 - 客服会话") | @Tag(name = "管理后台 - 客服会话") | ||||||
| @RestController | @RestController | ||||||
| @ -26,6 +31,8 @@ public class KeFuConversationController { | |||||||
|  |  | ||||||
|     @Resource |     @Resource | ||||||
|     private KeFuConversationService conversationService; |     private KeFuConversationService conversationService; | ||||||
|  |     @Resource | ||||||
|  |     private MemberUserApi memberUserApi; | ||||||
|  |  | ||||||
|     @PostMapping("/update-conversation-pinned") |     @PostMapping("/update-conversation-pinned") | ||||||
|     @Operation(summary = "置顶客服会话") |     @Operation(summary = "置顶客服会话") | ||||||
| @ -39,7 +46,7 @@ public class KeFuConversationController { | |||||||
|     @Operation(summary = "删除客服会话") |     @Operation(summary = "删除客服会话") | ||||||
|     @Parameter(name = "id", description = "编号", required = true) |     @Parameter(name = "id", description = "编号", required = true) | ||||||
|     @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')") |     @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:delete')") | ||||||
|     public CommonResult<Boolean> deleteKefuConversation(@RequestParam("id") Long id) { |     public CommonResult<Boolean> deleteConversation(@RequestParam("id") Long id) { | ||||||
|         conversationService.deleteKefuConversation(id); |         conversationService.deleteKefuConversation(id); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
| @ -47,8 +54,18 @@ public class KeFuConversationController { | |||||||
|     @GetMapping("/list") |     @GetMapping("/list") | ||||||
|     @Operation(summary = "获得客服会话列表") |     @Operation(summary = "获得客服会话列表") | ||||||
|     @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')") |     @PreAuthorize("@ss.hasPermission('promotion:kefu-conversation:query')") | ||||||
|     public CommonResult<List<KeFuConversationRespVO>> getKefuConversationPage() { |     public CommonResult<List<KeFuConversationRespVO>> getConversationList() { | ||||||
|         return success(BeanUtils.toBean(conversationService.getKefuConversationList(), KeFuConversationRespVO.class)); |         // 查询会话列表 | ||||||
|  |         List<KeFuConversationRespVO> respList = BeanUtils.toBean(conversationService.getKefuConversationList(), | ||||||
|  |                 KeFuConversationRespVO.class); | ||||||
|  |  | ||||||
|  |         // 拼接数据 | ||||||
|  |         Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(respList, KeFuConversationRespVO::getUserId)); | ||||||
|  |         respList.forEach(item->{ | ||||||
|  |             findAndThen(userMap, item.getUserId(), memberUser-> item.setUserAvatar(memberUser.getAvatar()) | ||||||
|  |                     .setUserNickname(memberUser.getNickname())); | ||||||
|  |         }); | ||||||
|  |         return success(respList); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @ -9,6 +9,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMe | |||||||
| import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; | import cn.iocoder.yudao.module.promotion.controller.admin.kefu.vo.message.KeFuMessageSendReqVO; | ||||||
| import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; | import cn.iocoder.yudao.module.promotion.dal.dataobject.kefu.KeFuMessageDO; | ||||||
| import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; | import cn.iocoder.yudao.module.promotion.service.kefu.KeFuMessageService; | ||||||
|  | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||||||
|  | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| import io.swagger.v3.oas.annotations.Parameter; | import io.swagger.v3.oas.annotations.Parameter; | ||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | import io.swagger.v3.oas.annotations.tags.Tag; | ||||||
| @ -18,7 +20,12 @@ import org.springframework.security.access.prepost.PreAuthorize; | |||||||
| import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
|  | import java.util.Map; | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||||||
|  | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | ||||||
| import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||||||
|  |  | ||||||
| @Tag(name = "管理后台 - 客服消息") | @Tag(name = "管理后台 - 客服消息") | ||||||
| @ -29,11 +36,13 @@ public class KeFuMessageController { | |||||||
|  |  | ||||||
|     @Resource |     @Resource | ||||||
|     private KeFuMessageService messageService; |     private KeFuMessageService messageService; | ||||||
|  |     @Resource | ||||||
|  |     private AdminUserApi adminUserApi; | ||||||
|  |  | ||||||
|     @PostMapping("/send") |     @PostMapping("/send") | ||||||
|     @Operation(summary = "发送客服消息") |     @Operation(summary = "发送客服消息") | ||||||
|     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')") |     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:send')") | ||||||
|     public CommonResult<Long> createKefuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) { |     public CommonResult<Long> sendKeFuMessage(@Valid @RequestBody KeFuMessageSendReqVO sendReqVO) { | ||||||
|         sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.ADMIN.getValue()); // 设置用户编号和类型 |         sendReqVO.setSenderId(getLoginUserId()).setSenderType(UserTypeEnum.ADMIN.getValue()); // 设置用户编号和类型 | ||||||
|         return success(messageService.sendKefuMessage(sendReqVO)); |         return success(messageService.sendKefuMessage(sendReqVO)); | ||||||
|     } |     } | ||||||
| @ -42,18 +51,26 @@ public class KeFuMessageController { | |||||||
|     @Operation(summary = "更新客服消息已读状态") |     @Operation(summary = "更新客服消息已读状态") | ||||||
|     @Parameter(name = "conversationId", description = "会话编号", required = true) |     @Parameter(name = "conversationId", description = "会话编号", required = true) | ||||||
|     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')") |     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:update')") | ||||||
|     public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { |     public CommonResult<Boolean> updateKeFuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { | ||||||
|         messageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); |         messageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @puhui999:这个应该是某个会话,上翻、下翻;不是传统的分页哈; |  | ||||||
|     @GetMapping("/page") |     @GetMapping("/page") | ||||||
|     @Operation(summary = "获得客服消息分页") |     @Operation(summary = "获得客服消息分页") | ||||||
|     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')") |     @PreAuthorize("@ss.hasPermission('promotion:kefu-message:query')") | ||||||
|     public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) { |     public CommonResult<PageResult<KeFuMessageRespVO>> getKeFuMessagePage(@Valid KeFuMessagePageReqVO pageReqVO) { | ||||||
|         PageResult<KeFuMessageDO> pageResult = messageService.getKefuMessagePage(pageReqVO); |         // 获得数据 | ||||||
|         return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); |         PageResult<KeFuMessageDO> pageResult = messageService.getKeFuMessagePage(pageReqVO); | ||||||
|  |  | ||||||
|  |         // 拼接数据 | ||||||
|  |         PageResult<KeFuMessageRespVO> result = BeanUtils.toBean(pageResult, KeFuMessageRespVO.class); | ||||||
|  |         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(filterList(result.getList(), | ||||||
|  |                 item -> UserTypeEnum.ADMIN.getValue().equals(item.getSenderType())), KeFuMessageRespVO::getSenderId)); | ||||||
|  |         result.getList().forEach(item->{ | ||||||
|  |             findAndThen(userMap, item.getSenderId(), adminUser -> item.setSenderAvatar(adminUser.getAvatar())); | ||||||
|  |         }); | ||||||
|  |         return success(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @ -14,6 +14,10 @@ public class KeFuConversationRespVO { | |||||||
|  |  | ||||||
|     @Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300") |     @Schema(description = "会话所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "8300") | ||||||
|     private Long userId; |     private Long userId; | ||||||
|  |     @Schema(description = "会话所属用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg") | ||||||
|  |     private String userAvatar; | ||||||
|  |     @Schema(description = "会话所属用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | ||||||
|  |     private String userNickname; | ||||||
|  |  | ||||||
|     @Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED) |     @Schema(description = "最后聊天时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||||||
|     private LocalDateTime lastMessageTime; |     private LocalDateTime lastMessageTime; | ||||||
|  | |||||||
| @ -18,6 +18,8 @@ public class KeFuMessageRespVO { | |||||||
|  |  | ||||||
|     @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571") |     @Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24571") | ||||||
|     private Long senderId; |     private Long senderId; | ||||||
|  |     @Schema(description = "发送人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://yudao.com/images/avatar.jpg") | ||||||
|  |     private String senderAvatar; | ||||||
|  |  | ||||||
|     @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |     @Schema(description = "发送人类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||||||
|     private Integer senderType; |     private Integer senderType; | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ public class AppKeFuMessageController { | |||||||
|     @Parameter(name = "conversationId", description = "会话编号", required = true) |     @Parameter(name = "conversationId", description = "会话编号", required = true) | ||||||
|     @PreAuthenticated |     @PreAuthenticated | ||||||
|     public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { |     public CommonResult<Boolean> updateKefuMessageReadStatus(@RequestParam("conversationId") Long conversationId) { | ||||||
|         kefuMessageService.updateKefuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue()); |         kefuMessageService.updateKeFuMessageReadStatus(conversationId, getLoginUserId(), UserTypeEnum.MEMBER.getValue()); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -51,7 +51,7 @@ public class AppKeFuMessageController { | |||||||
|     @Operation(summary = "获得客服消息分页") |     @Operation(summary = "获得客服消息分页") | ||||||
|     @PreAuthenticated |     @PreAuthenticated | ||||||
|     public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) { |     public CommonResult<PageResult<KeFuMessageRespVO>> getKefuMessagePage(@Valid AppKeFuMessagePageReqVO pageReqVO) { | ||||||
|         PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKefuMessagePage(pageReqVO, getLoginUserId()); |         PageResult<KeFuMessageDO> pageResult = kefuMessageService.getKeFuMessagePage(pageReqVO, getLoginUserId()); | ||||||
|         return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); |         return success(BeanUtils.toBean(pageResult, KeFuMessageRespVO.class)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ public interface KeFuMessageService { | |||||||
|      * @param userId         用户编号 |      * @param userId         用户编号 | ||||||
|      * @param userType       用户类型 |      * @param userType       用户类型 | ||||||
|      */ |      */ | ||||||
|     void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType); |     void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获得客服消息分页 |      * 获得客服消息分页 | ||||||
| @ -46,7 +46,7 @@ public interface KeFuMessageService { | |||||||
|      * @param pageReqVO 分页查询 |      * @param pageReqVO 分页查询 | ||||||
|      * @return 客服消息分页 |      * @return 客服消息分页 | ||||||
|      */ |      */ | ||||||
|     PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO); |     PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 【会员】获得客服消息分页 |      * 【会员】获得客服消息分页 | ||||||
| @ -55,6 +55,6 @@ public interface KeFuMessageService { | |||||||
|      * @param userId    用户编号 |      * @param userId    用户编号 | ||||||
|      * @return 客服消息分页 |      * @return 客服消息分页 | ||||||
|      */ |      */ | ||||||
|     PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId); |     PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId); | ||||||
|  |  | ||||||
| } | } | ||||||
| @ -89,7 +89,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void updateKefuMessageReadStatus(Long conversationId, Long userId, Integer userType) { |     public void updateKeFuMessageReadStatus(Long conversationId, Long userId, Integer userType) { | ||||||
|         // 1.1 校验会话是否存在 |         // 1.1 校验会话是否存在 | ||||||
|         KeFuConversationDO conversation = conversationService.validateKefuConversationExists(conversationId); |         KeFuConversationDO conversation = conversationService.validateKefuConversationExists(conversationId); | ||||||
|         // 1.2 如果是会员端处理已读,需要传递 userId;万一用户模拟一个 conversationId |         // 1.2 如果是会员端处理已读,需要传递 userId;万一用户模拟一个 conversationId | ||||||
| @ -136,12 +136,12 @@ public class KeFuMessageServiceImpl implements KeFuMessageService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PageResult<KeFuMessageDO> getKefuMessagePage(KeFuMessagePageReqVO pageReqVO) { |     public PageResult<KeFuMessageDO> getKeFuMessagePage(KeFuMessagePageReqVO pageReqVO) { | ||||||
|         return keFuMessageMapper.selectPage(pageReqVO); |         return keFuMessageMapper.selectPage(pageReqVO); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PageResult<KeFuMessageDO> getKefuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) { |     public PageResult<KeFuMessageDO> getKeFuMessagePage(AppKeFuMessagePageReqVO pageReqVO, Long userId) { | ||||||
|         // 1. 获得客服会话 |         // 1. 获得客服会话 | ||||||
|         KeFuConversationDO conversation = conversationService.getConversationByUserId(userId); |         KeFuConversationDO conversation = conversationService.getConversationByUserId(userId); | ||||||
|         if (conversation == null) { |         if (conversation == null) { | ||||||
|  | |||||||
| @ -40,5 +40,9 @@ public class AdminUserRespDTO { | |||||||
|      * 手机号码 |      * 手机号码 | ||||||
|      */ |      */ | ||||||
|     private String mobile; |     private String mobile; | ||||||
|  |     /** | ||||||
|  |      * 用户头像 | ||||||
|  |      */ | ||||||
|  |     private String avatar; | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999