package com.yami.shop.api.controller.im; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.yami.shop.bean.model.*; import com.yami.shop.bean.param.im.*; import com.yami.shop.common.bean.AliOss; import com.yami.shop.common.bean.HuaWeiOss; import com.yami.shop.common.config.Constant; import com.yami.shop.common.response.ServerResponseEntity; import com.yami.shop.security.api.util.SecurityUtils; import com.yami.shop.service.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; /** * 用户聊天群组管理 * */ @RestController @RequestMapping("/p/imGroup") @Tag(name = "聊天群组管理") public class LuckImGroupController { @Autowired private ILuckImGroupService luckImGroupService; @Autowired private ILuckImGroupTypeService luckImGroupTypeService; @Autowired private ILuckImGroupMemberService luckImGroupMemberService; @Autowired private QRCodeService qrCodeService; @Autowired private SysConfigService sysConfigService; @Operation(summary = "获取所有群组类型") @GetMapping(value = "/getGroupTypes") public ServerResponseEntity> getGroupTypes() { List list = luckImGroupTypeService.list(new QueryWrapper().eq("status",1).orderByAsc("sort")); return ServerResponseEntity.success(list); } @Operation(summary = "获取群组列表") @GetMapping(value = "/getGroupList") public ServerResponseEntity> getGroupList(GetGroupListParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); Page groupList = luckImGroupService.getGroupList(params); return ServerResponseEntity.success(groupList); } @Operation(summary = "获取群组详情") @GetMapping(value = "/getGroupById") public ServerResponseEntity getGroupById(@RequestParam String groupId) { LuckImGroup groupInfo = luckImGroupService.getGroupById(groupId); return ServerResponseEntity.success(groupInfo); } @Operation(summary = "查看群成员") @GetMapping(value = "/getGroupMembers") public ServerResponseEntity> getGroupMembers(GetGroupMembersParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); List members = luckImGroupService.getGroupMembers(params); return ServerResponseEntity.success(members); } @Operation(summary = "查看群成员信息") @GetMapping(value = "/getGroupMemberInfo") public ServerResponseEntity getGroupMemberInfo(@RequestParam String groupId,@RequestParam String userId) { if (StringUtils.isBlank(userId)) { userId = SecurityUtils.getUser().getUserId(); } LuckImGroupMember member = luckImGroupMemberService.getOne(Wrappers.lambdaQuery(LuckImGroupMember.class) .eq(LuckImGroupMember::getGroupId, groupId) .eq(LuckImGroupMember::getUserId,userId)); return ServerResponseEntity.success(member); } @Operation(summary = "创建群组") @PostMapping(value = "/createGroup") public ServerResponseEntity createGroup(@RequestBody CreateGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.createGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "解散群组") @PostMapping(value = "/dissolveGroup") public ServerResponseEntity dissolveGroup(@RequestBody DissolveGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.dissolveGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "修改群组信息") @PostMapping(value = "/updateGroup") public ServerResponseEntity updateGroup(@RequestBody UpdateGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.updateGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "设置群组管理") @PostMapping(value = "/setGroupAdmin") public ServerResponseEntity setGroupAdmin(@RequestBody SetGroupAdminParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.setGroupAdmin(params); return ServerResponseEntity.success(); } @Operation(summary = "转让群组") @PostMapping(value = "/transferGroup") public ServerResponseEntity transferGroup(@RequestBody TransferGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.transferGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "申请加入群组") @PostMapping(value = "/joinGroup") public ServerResponseEntity joinGroup(@RequestBody JoinGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.joinGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "邀请加入群组") @PostMapping(value = "/inviteJoinGroup") public ServerResponseEntity inviteJoinGroup(@RequestBody InviteJoinGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.inviteJoinGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "群管理审核成员") @PostMapping(value = "/auditMember") public ServerResponseEntity auditMember(@RequestBody AuditMemberParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.auditMember(params); return ServerResponseEntity.success(); } @Operation(summary = "退出群组") @PostMapping(value = "/exitGroup") public ServerResponseEntity exitGroup(@RequestBody ExitGroupParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.exitGroup(params); return ServerResponseEntity.success(); } @Operation(summary = "提人出群组") @PostMapping(value = "/kickMember") public ServerResponseEntity kickMember(@RequestBody KickMemberParam params) { params.setSelfUserId(SecurityUtils.getUser().getUserId()); luckImGroupService.kickMember(params); return ServerResponseEntity.success(); } @Operation(summary = "生成群聊二维码") @GetMapping(value = "/createGroupQrCode") public ServerResponseEntity createGroupQrCode(@RequestParam String groupId) { HuaWeiOss aliOss = sysConfigService.getSysConfigObject(Constant.HUAWEI_OBS_CONFIG, HuaWeiOss.class); LuckImGroup luckImGroup = luckImGroupService.getOne(new QueryWrapper().eq("id", groupId)); if (StringUtils.isNotBlank(luckImGroup.getQrCode())){ return ServerResponseEntity.success(luckImGroup.getQrCode()); } String content = "/pages/im/chatInfo/chatInfo?groupId=" + groupId; String qrCodeUrl = qrCodeService.generateQRCodeUrl(content, aliOss); luckImGroupService.update(Wrappers.lambdaUpdate(LuckImGroup.class).set(LuckImGroup::getQrCode, qrCodeUrl).eq(LuckImGroup::getId, groupId)); return ServerResponseEntity.success(qrCodeUrl); } @Operation(summary = "设置群用户发言状态") @PostMapping(value = "/setBannedToPost") public ServerResponseEntity setBannedToPost(@RequestBody BannedToPostParam bannedToPostParam) { if (bannedToPostParam.getBannedType() == 0) { luckImGroupMemberService.update(Wrappers.lambdaUpdate(LuckImGroupMember.class) .set(LuckImGroupMember::getBannedToPost, bannedToPostParam.getBannedToPost()) .set(LuckImGroupMember::getUpdateTime, new Date()) .set(LuckImGroupMember::getAuditUserId, SecurityUtils.getUser().getUserId()) .eq(LuckImGroupMember::getGroupId, bannedToPostParam.getGroupId()) .eq(LuckImGroupMember::getUserId, bannedToPostParam.getUserId())); }else{ luckImGroupMemberService.update(Wrappers.lambdaUpdate(LuckImGroupMember.class) .set(LuckImGroupMember::getBannedToPost, bannedToPostParam.getBannedToPost()) .set(LuckImGroupMember::getUpdateTime, new Date()) .set(LuckImGroupMember::getAuditUserId, SecurityUtils.getUser().getUserId()) .eq(LuckImGroupMember::getGroupId, bannedToPostParam.getGroupId()) .eq(LuckImGroupMember::getRole,1)); luckImGroupService.update(Wrappers.lambdaUpdate(LuckImGroup.class) .set(LuckImGroup::getBannedToPost,bannedToPostParam.getBannedToPost()) .set(LuckImGroup::getUpdateTime, new Date()) .eq(LuckImGroup::getId, bannedToPostParam.getGroupId())); } return ServerResponseEntity.success(); } }