Commit 0d7cb763ff135b289c58f7193254695c234afc4c
1 parent
43b5de51
feat(im): 增加好友申请的管理界面
Showing
7 changed files
with
185 additions
and
0 deletions
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/controller/admin/manager/friend/ImFriendRequestManagerController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.im.controller.admin.manager.friend; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 8 | +import cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo.ImFriendRequestManagerPageReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo.ImFriendRequestManagerRespVO; | ||
| 10 | +import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; | ||
| 11 | +import cn.iocoder.yudao.module.im.service.friend.ImFriendRequestService; | ||
| 12 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 13 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 14 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 15 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 16 | +import jakarta.annotation.Resource; | ||
| 17 | +import jakarta.validation.Valid; | ||
| 18 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 19 | +import org.springframework.validation.annotation.Validated; | ||
| 20 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 21 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 22 | +import org.springframework.web.bind.annotation.RestController; | ||
| 23 | + | ||
| 24 | +import java.util.Map; | ||
| 25 | +import java.util.Set; | ||
| 26 | +import java.util.stream.Stream; | ||
| 27 | + | ||
| 28 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; | ||
| 30 | + | ||
| 31 | +@Tag(name = "管理后台 - IM 好友申请管理") | ||
| 32 | +@RestController | ||
| 33 | +@RequestMapping("/im/manager/friend-request") | ||
| 34 | +@Validated | ||
| 35 | +public class ImFriendRequestManagerController { | ||
| 36 | + | ||
| 37 | + @Resource | ||
| 38 | + private ImFriendRequestService friendRequestService; | ||
| 39 | + @Resource | ||
| 40 | + private AdminUserApi adminUserApi; | ||
| 41 | + | ||
| 42 | + @GetMapping("/page") | ||
| 43 | + @Operation(summary = "获得好友申请分页") | ||
| 44 | + @PreAuthorize("@ss.hasPermission('im:manager:friend-request:query')") | ||
| 45 | + public CommonResult<PageResult<ImFriendRequestManagerRespVO>> getFriendRequestPage( | ||
| 46 | + @Valid ImFriendRequestManagerPageReqVO pageReqVO) { | ||
| 47 | + // 1. 分页查询 | ||
| 48 | + PageResult<ImFriendRequestDO> pageResult = friendRequestService.getFriendRequestPage(pageReqVO); | ||
| 49 | + if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 50 | + return success(PageResult.empty(pageResult.getTotal())); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + // 2.1 一次性批量查询发起方 + 接收方的昵称 | ||
| 54 | + Set<Long> userIds = convertSetByFlatMap(pageResult.getList(), | ||
| 55 | + request -> Stream.of(request.getFromUserId(), request.getToUserId())); | ||
| 56 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); | ||
| 57 | + // 2.2 转换为 VO,填充昵称 | ||
| 58 | + return success(BeanUtils.toBean(pageResult, ImFriendRequestManagerRespVO.class, vo -> { | ||
| 59 | + MapUtils.findAndThen(userMap, vo.getFromUserId(), | ||
| 60 | + user -> vo.setFromNickname(user.getNickname())); | ||
| 61 | + MapUtils.findAndThen(userMap, vo.getToUserId(), | ||
| 62 | + user -> vo.setToNickname(user.getNickname())); | ||
| 63 | + })); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | +} |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/controller/admin/manager/friend/vo/ImFriendManagerRespVO.java
| @@ -27,9 +27,18 @@ public class ImFriendManagerRespVO { | @@ -27,9 +27,18 @@ public class ImFriendManagerRespVO { | ||
| 27 | @Schema(description = "好友展示备注") | 27 | @Schema(description = "好友展示备注") |
| 28 | private String displayName; | 28 | private String displayName; |
| 29 | 29 | ||
| 30 | + @Schema(description = "添加来源", example = "1") | ||
| 31 | + private Integer addSource; // 参见 ImFriendAddSourceEnum 枚举类 | ||
| 32 | + | ||
| 30 | @Schema(description = "是否免打扰", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | 33 | @Schema(description = "是否免打扰", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") |
| 31 | private Boolean silent; | 34 | private Boolean silent; |
| 32 | 35 | ||
| 36 | + @Schema(description = "是否置顶联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | ||
| 37 | + private Boolean pinned; | ||
| 38 | + | ||
| 39 | + @Schema(description = "是否拉黑", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") | ||
| 40 | + private Boolean blocked; | ||
| 41 | + | ||
| 33 | @Schema(description = "好友状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | 42 | @Schema(description = "好友状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 34 | private Integer status; // 参见 CommonStatusEnum 枚举类 | 43 | private Integer status; // 参见 CommonStatusEnum 枚举类 |
| 35 | 44 |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/controller/admin/manager/friend/vo/ImFriendRequestManagerPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 8 | + | ||
| 9 | +import java.time.LocalDateTime; | ||
| 10 | + | ||
| 11 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 12 | + | ||
| 13 | +@Schema(description = "管理后台 - IM 好友申请分页 Request VO") | ||
| 14 | +@Data | ||
| 15 | +@EqualsAndHashCode(callSuper = true) | ||
| 16 | +public class ImFriendRequestManagerPageReqVO extends PageParam { | ||
| 17 | + | ||
| 18 | + @Schema(description = "发起方用户编号", example = "1024") | ||
| 19 | + private Long fromUserId; | ||
| 20 | + | ||
| 21 | + @Schema(description = "接收方用户编号", example = "2048") | ||
| 22 | + private Long toUserId; | ||
| 23 | + | ||
| 24 | + @Schema(description = "处理结果", example = "0") | ||
| 25 | + private Integer handleResult; // 参见 ImFriendRequestHandleResultEnum 枚举类 | ||
| 26 | + | ||
| 27 | + @Schema(description = "添加来源", example = "1") | ||
| 28 | + private Integer addSource; // 参见 ImFriendAddSourceEnum 枚举类 | ||
| 29 | + | ||
| 30 | + @Schema(description = "创建时间", example = "[2026-04-01 00:00:00, 2026-04-30 23:59:59]") | ||
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 32 | + private LocalDateTime[] createTime; | ||
| 33 | + | ||
| 34 | +} |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/controller/admin/manager/friend/vo/ImFriendRequestManagerRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.time.LocalDateTime; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - IM 好友申请 Response VO") | ||
| 9 | +@Data | ||
| 10 | +public class ImFriendRequestManagerRespVO { | ||
| 11 | + | ||
| 12 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 13 | + private Long id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "发起方用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 16 | + private Long fromUserId; | ||
| 17 | + | ||
| 18 | + @Schema(description = "发起方昵称", example = "张三") | ||
| 19 | + private String fromNickname; | ||
| 20 | + | ||
| 21 | + @Schema(description = "接收方用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | ||
| 22 | + private Long toUserId; | ||
| 23 | + | ||
| 24 | + @Schema(description = "接收方昵称", example = "李四") | ||
| 25 | + private String toNickname; | ||
| 26 | + | ||
| 27 | + @Schema(description = "申请理由", example = "我是芋艿") | ||
| 28 | + private String applyContent; | ||
| 29 | + | ||
| 30 | + @Schema(description = "发起方对接收方的备注") | ||
| 31 | + private String displayName; | ||
| 32 | + | ||
| 33 | + @Schema(description = "添加来源", example = "1") | ||
| 34 | + private Integer addSource; // 参见 ImFriendAddSourceEnum 枚举类 | ||
| 35 | + | ||
| 36 | + @Schema(description = "处理结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | ||
| 37 | + private Integer handleResult; // 参见 ImFriendRequestHandleResultEnum 枚举类 | ||
| 38 | + | ||
| 39 | + @Schema(description = "处理理由", example = "暂不通过") | ||
| 40 | + private String handleContent; | ||
| 41 | + | ||
| 42 | + @Schema(description = "处理时间") | ||
| 43 | + private LocalDateTime handleTime; | ||
| 44 | + | ||
| 45 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 46 | + private LocalDateTime createTime; | ||
| 47 | + | ||
| 48 | +} |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/dal/mysql/friend/ImFriendRequestMapper.java
| 1 | package cn.iocoder.yudao.module.im.dal.mysql.friend; | 1 | package cn.iocoder.yudao.module.im.dal.mysql.friend; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo.ImFriendRequestManagerPageReqVO; | ||
| 5 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; | 7 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; |
| 6 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 8 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 7 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| @@ -43,4 +45,14 @@ public interface ImFriendRequestMapper extends BaseMapperX<ImFriendRequestDO> { | @@ -43,4 +45,14 @@ public interface ImFriendRequestMapper extends BaseMapperX<ImFriendRequestDO> { | ||
| 43 | .eq(ImFriendRequestDO::getId, id).eq(ImFriendRequestDO::getHandleResult, handleResult)); | 45 | .eq(ImFriendRequestDO::getId, id).eq(ImFriendRequestDO::getHandleResult, handleResult)); |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 48 | + default PageResult<ImFriendRequestDO> selectPage(ImFriendRequestManagerPageReqVO reqVO) { | ||
| 49 | + return selectPage(reqVO, new LambdaQueryWrapperX<ImFriendRequestDO>() | ||
| 50 | + .eqIfPresent(ImFriendRequestDO::getFromUserId, reqVO.getFromUserId()) | ||
| 51 | + .eqIfPresent(ImFriendRequestDO::getToUserId, reqVO.getToUserId()) | ||
| 52 | + .eqIfPresent(ImFriendRequestDO::getHandleResult, reqVO.getHandleResult()) | ||
| 53 | + .eqIfPresent(ImFriendRequestDO::getAddSource, reqVO.getAddSource()) | ||
| 54 | + .betweenIfPresent(ImFriendRequestDO::getCreateTime, reqVO.getCreateTime()) | ||
| 55 | + .orderByDesc(ImFriendRequestDO::getId)); | ||
| 56 | + } | ||
| 57 | + | ||
| 46 | } | 58 | } |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/friend/ImFriendRequestService.java
| 1 | package cn.iocoder.yudao.module.im.service.friend; | 1 | package cn.iocoder.yudao.module.im.service.friend; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 3 | import cn.iocoder.yudao.module.im.controller.admin.friend.vo.request.ImFriendRequestApplyReqVO; | 4 | import cn.iocoder.yudao.module.im.controller.admin.friend.vo.request.ImFriendRequestApplyReqVO; |
| 5 | +import cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo.ImFriendRequestManagerPageReqVO; | ||
| 4 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; | 6 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; |
| 5 | 7 | ||
| 6 | import java.util.List; | 8 | import java.util.List; |
| @@ -53,4 +55,11 @@ public interface ImFriendRequestService { | @@ -53,4 +55,11 @@ public interface ImFriendRequestService { | ||
| 53 | */ | 55 | */ |
| 54 | ImFriendRequestDO getFriendRequest(Long id); | 56 | ImFriendRequestDO getFriendRequest(Long id); |
| 55 | 57 | ||
| 58 | + // ==================== 管理后台 ==================== | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 【管理后台】分页查询好友申请记录 | ||
| 62 | + */ | ||
| 63 | + PageResult<ImFriendRequestDO> getFriendRequestPage(ImFriendRequestManagerPageReqVO reqVO); | ||
| 64 | + | ||
| 56 | } | 65 | } |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/friend/ImFriendRequestServiceImpl.java
| @@ -5,8 +5,10 @@ import cn.hutool.core.bean.copier.CopyOptions; | @@ -5,8 +5,10 @@ import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import cn.hutool.core.util.ObjUtil; | 5 | import cn.hutool.core.util.ObjUtil; |
| 6 | import cn.hutool.extra.spring.SpringUtil; | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | import cn.iocoder.yudao.module.im.controller.admin.friend.vo.request.ImFriendRequestApplyReqVO; | 10 | import cn.iocoder.yudao.module.im.controller.admin.friend.vo.request.ImFriendRequestApplyReqVO; |
| 11 | +import cn.iocoder.yudao.module.im.controller.admin.manager.friend.vo.ImFriendRequestManagerPageReqVO; | ||
| 10 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendDO; | 12 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendDO; |
| 11 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; | 13 | import cn.iocoder.yudao.module.im.dal.dataobject.friend.ImFriendRequestDO; |
| 12 | import cn.iocoder.yudao.module.im.dal.mysql.friend.ImFriendRequestMapper; | 14 | import cn.iocoder.yudao.module.im.dal.mysql.friend.ImFriendRequestMapper; |
| @@ -200,6 +202,11 @@ public class ImFriendRequestServiceImpl implements ImFriendRequestService { | @@ -200,6 +202,11 @@ public class ImFriendRequestServiceImpl implements ImFriendRequestService { | ||
| 200 | return friendRequestMapper.selectById(id); | 202 | return friendRequestMapper.selectById(id); |
| 201 | } | 203 | } |
| 202 | 204 | ||
| 205 | + @Override | ||
| 206 | + public PageResult<ImFriendRequestDO> getFriendRequestPage(ImFriendRequestManagerPageReqVO reqVO) { | ||
| 207 | + return friendRequestMapper.selectPage(reqVO); | ||
| 208 | + } | ||
| 209 | + | ||
| 203 | /** | 210 | /** |
| 204 | * 校验申请可被「当前用户」处理:申请存在 + 未处理 + 操作人 = 接收方 | 211 | * 校验申请可被「当前用户」处理:申请存在 + 未处理 + 操作人 = 接收方 |
| 205 | */ | 212 | */ |