|  | @@ -0,0 +1,270 @@
 | 
	
		
			
				|  |  | +package com.ym.mec.web.controller.education;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  | +import com.microsvc.toolkit.common.webportal.exception.BizException;
 | 
	
		
			
				|  |  | +import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.ImGroupMemberDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.ImGroupNoticeDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.ImUserFriendDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.ImGroup;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.ImGroupMemberPlus;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.im.ClientEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.wrapper.ImGroupWrapper;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.vo.ImUserWrapper;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiImplicitParam;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiImplicitParams;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | +import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.springframework.http.HttpStatus;
 | 
	
		
			
				|  |  | +import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.util.Optional;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@RequestMapping("${app-config.url.web:}/eduImGroup")
 | 
	
		
			
				|  |  | +@Api(tags = "IM群服务")
 | 
	
		
			
				|  |  | +@RestController
 | 
	
		
			
				|  |  | +public class EduImGroupController extends BaseController {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Resource
 | 
	
		
			
				|  |  | +	private ImGroupService imGroupService;
 | 
	
		
			
				|  |  | +	@Resource
 | 
	
		
			
				|  |  | +	private ImUserFriendService imUserFriendService;
 | 
	
		
			
				|  |  | +	@Resource
 | 
	
		
			
				|  |  | +	private ImGroupNoticeService imGroupNoticeService;
 | 
	
		
			
				|  |  | +	@Resource
 | 
	
		
			
				|  |  | +	private SysUserService userLoginService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private ImGroupMemberPlusService imGroupMemberPlusService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation(value = "全体禁言/解除禁言")
 | 
	
		
			
				|  |  | +	@PostMapping("/muteAll")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<Object> muteAll(@RequestBody ImGroupWrapper.GroupMuteAll groupMuteAll) {
 | 
	
		
			
				|  |  | +		if (StringUtils.isEmpty(groupMuteAll.getGroupId()) || groupMuteAll.getMuteAll() == null){
 | 
	
		
			
				|  |  | +			throw new BizException("参数错误");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		imGroupService.muteAll(groupMuteAll);
 | 
	
		
			
				|  |  | +		return succeed();
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryGroupList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImGroup>> queryGroupList(String search, String groupType) {
 | 
	
		
			
				|  |  | +		return succeed(imGroupService.queryByUserId(userLoginService.getUserId(), search,groupType));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation("查询群列表-v2")
 | 
	
		
			
				|  |  | +    @GetMapping(value = "/queryGroupList/v2")
 | 
	
		
			
				|  |  | +    public HttpResponseResult<List<ImGroup>> queryGroupListV2(String search, String groupType, String musicGroupId, String classType) {
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(classType) && classType.equals("SINGLE")) {
 | 
	
		
			
				|  |  | +            classType = "NORMAL";
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return succeed(imGroupService.queryByUserIdV2(userLoginService.getUserId(), search,groupType,musicGroupId,classType));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群详情")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryGroupDetail")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<ImGroup> queryGroupDetail(String imGroupId) {
 | 
	
		
			
				|  |  | +		if (imGroupId.contains("S") || imGroupId.contains("I")){
 | 
	
		
			
				|  |  | +			imGroupId = imGroupId.substring(1);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +        ImGroup imGroup = imGroupService.get(imGroupId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (imGroup == null) {
 | 
	
		
			
				|  |  | +            return failed(HttpStatus.NO_CONTENT, "群组不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
 | 
	
		
			
				|  |  | +            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
 | 
	
		
			
				|  |  | +            .eq(ImGroupMemberPlus::getUserId, userLoginService.getUser().getId())
 | 
	
		
			
				|  |  | +            .last("limit 1").one();
 | 
	
		
			
				|  |  | +        if (admin == null) {
 | 
	
		
			
				|  |  | +            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
 | 
	
		
			
				|  |  | +            return failed(HttpStatus.NO_CONTENT, "群组不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +		// 设置默认头像
 | 
	
		
			
				|  |  | +		if (Objects.nonNull(imGroup) && Objects.nonNull(imGroup.getGroupType()) && StringUtils.isBlank(imGroup.getImg())) {
 | 
	
		
			
				|  |  | +			imGroup.setImg(imGroup.getGroupType().getAvatar());
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		return succeed(imGroup);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群详情(重构版)")
 | 
	
		
			
				|  |  | +	@ApiImplicitParams({
 | 
	
		
			
				|  |  | +		@ApiImplicitParam(name = "groupId", value = "群编号", required = true, dataType = "String")
 | 
	
		
			
				|  |  | +	})
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/getDetail/{groupId}")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<ImGroup> groupDetail(@PathVariable("groupId") String imGroupId) {
 | 
	
		
			
				|  |  | +		if (imGroupId.contains("S") || imGroupId.contains("I")){
 | 
	
		
			
				|  |  | +			imGroupId = imGroupId.substring(1);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +        ImGroup imGroup = imGroupService.get(imGroupId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (imGroup == null) {
 | 
	
		
			
				|  |  | +            return failed(HttpStatus.NO_CONTENT, "群组不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
 | 
	
		
			
				|  |  | +            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
 | 
	
		
			
				|  |  | +            .eq(ImGroupMemberPlus::getUserId, userLoginService.getUser().getId())
 | 
	
		
			
				|  |  | +            .last("limit 1").one();
 | 
	
		
			
				|  |  | +        if (admin == null) {
 | 
	
		
			
				|  |  | +            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
 | 
	
		
			
				|  |  | +            return failed(HttpStatus.NO_CONTENT, "群组不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +		return succeed(imGroupService.get(imGroupId));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群成员列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryGroupMemberList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImGroupMemberDto>> queryGroupMemberList(String imGroupId) {
 | 
	
		
			
				|  |  | +		return succeed(imGroupService.queryMemberById(imGroupId));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群学生列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryGroupStudentList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImGroupMemberDto>> queryGroupStudentList(String imGroupId) {
 | 
	
		
			
				|  |  | +		return succeed(imGroupService.queryMemberById(imGroupId).stream().filter(e -> StringUtils.isBlank(e.getRoleType())).collect(Collectors.toList()));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation("查询群学生列表v2")
 | 
	
		
			
				|  |  | +    @GetMapping(value = "/queryGroupStudentList/v2")
 | 
	
		
			
				|  |  | +    public HttpResponseResult<List<ImGroupMemberDto>> queryGroupStudentListV2(String imGroupId, String search, Integer subjectId, Boolean vipFlag) {
 | 
	
		
			
				|  |  | +        return succeed(imGroupService.queryMemberByIdV2(imGroupId,search,subjectId,vipFlag).stream().filter(e -> StringUtils.isBlank(e.getRoleType())).collect(Collectors.toList()));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群成员详情")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryGroupMemberDetail")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<ImGroupMemberDto> queryGroupMemberDetail(String imGroupId, Integer userId) {
 | 
	
		
			
				|  |  | +		return succeed(imGroupService.queryMember(imGroupId, userId));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询好友详情")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryFriendDetail")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<ImUserFriendDto> queryFriendDetail(Integer userId) {
 | 
	
		
			
				|  |  | +		ImUserFriendDto dto = imUserFriendService.queryFriendDetail(userLoginService.getUserId(), userId);
 | 
	
		
			
				|  |  | +		if (dto == null) {
 | 
	
		
			
				|  |  | +			dto = new ImUserFriendDto();
 | 
	
		
			
				|  |  | +			SysUser user = userLoginService.queryUserById(userId);
 | 
	
		
			
				|  |  | +			dto.setFriend(user);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			List<String> userTypes = Lists.newArrayList(user.getUserType().split(","));
 | 
	
		
			
				|  |  | +			if (userTypes.size() > 1
 | 
	
		
			
				|  |  | +				|| userTypes.contains(ClientEnum.TEACHER.getCode())
 | 
	
		
			
				|  |  | +				|| userTypes.contains(ClientEnum.SYSTEM.getCode())) {
 | 
	
		
			
				|  |  | +				// 增加用户身份数量 > 1 或者包含老师身份,统一使用实名
 | 
	
		
			
				|  |  | +				dto.setFriendNickname(Optional.ofNullable(user.getRealName()).filter(StringUtils::isNotBlank).orElse(user.getUsername()));
 | 
	
		
			
				|  |  | +			} else if (user.getUserType().contains("STUDENT") || user.getUserType().contains("SCHOOL")) {
 | 
	
		
			
				|  |  | +				dto.setFriendNickname(user.getUsername());
 | 
	
		
			
				|  |  | +			} else {
 | 
	
		
			
				|  |  | +				dto.setFriendNickname(user.getRealName());
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			dto.setFriendId(userId);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		return succeed(dto);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询好友详情(重构版)")
 | 
	
		
			
				|  |  | +	@ApiImplicitParams({
 | 
	
		
			
				|  |  | +		@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "Integer")
 | 
	
		
			
				|  |  | +	})
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/imUserFriend/getDetail/{userId}")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<ImUserWrapper.ImUserFriend> getImUserFriendDetail(@PathVariable("userId") Integer userId) {
 | 
	
		
			
				|  |  | +		ImUserFriendDto dto = imUserFriendService.queryFriendDetail(userLoginService.getUserId(), userId);
 | 
	
		
			
				|  |  | +		if (dto == null) {
 | 
	
		
			
				|  |  | +			dto = new ImUserFriendDto();
 | 
	
		
			
				|  |  | +			SysUser user = userLoginService.queryUserById(userId);
 | 
	
		
			
				|  |  | +			dto.setFriend(user);
 | 
	
		
			
				|  |  | +			if (user.getUserType().contains("STUDENT") || user.getUserType().contains("SCHOOL")) {
 | 
	
		
			
				|  |  | +				dto.setFriendNickname(user.getUsername());
 | 
	
		
			
				|  |  | +			} else {
 | 
	
		
			
				|  |  | +				dto.setFriendNickname(user.getRealName());
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			dto.setFriendId(userId);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// 返回数据结构封装
 | 
	
		
			
				|  |  | +		ImUserWrapper.ImUserFriend userFriend = ImUserWrapper.ImUserFriend.builder()
 | 
	
		
			
				|  |  | +			.id(dto.getId())
 | 
	
		
			
				|  |  | +			.userId(dto.getUserId().longValue())
 | 
	
		
			
				|  |  | +			.friendId(dto.getFriendId().longValue())
 | 
	
		
			
				|  |  | +			.friendAvatar(dto.getFriend().getAvatar())
 | 
	
		
			
				|  |  | +			.friendNickname(dto.getFriendNickname())
 | 
	
		
			
				|  |  | +			.memo(dto.getMemo())
 | 
	
		
			
				|  |  | +			.updateTime(dto.getUpdateTime())
 | 
	
		
			
				|  |  | +			.createTime(dto.getCreateTime())
 | 
	
		
			
				|  |  | +			.roleType(dto.getRoleType())
 | 
	
		
			
				|  |  | +			.friendType(dto.getRoleType())
 | 
	
		
			
				|  |  | +			.build();
 | 
	
		
			
				|  |  | +		return succeed(userFriend);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询好友列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryFriendList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImUserFriendDto>> queryFriendList(String search) {
 | 
	
		
			
				|  |  | +		return succeed(imUserFriendService.queryFriendListByUserId(userLoginService.getUserId(), search));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询好友列表(重构版)")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/imUserFriend/queryAll")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImUserWrapper.ImUserFriend>> queryImUserFriendList(String search) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// 好友关系列表
 | 
	
		
			
				|  |  | +		List<ImUserFriendDto> friendDtos = imUserFriendService.queryFriendListByUserId(userLoginService.getUserId(), search);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		List<ImUserWrapper.ImUserFriend> wrappers = Lists.newArrayList();
 | 
	
		
			
				|  |  | +		if (CollectionUtils.isNotEmpty(friendDtos)) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			// 封装返回数据结构
 | 
	
		
			
				|  |  | +			for (ImUserFriendDto item : friendDtos) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				wrappers.add(ImUserWrapper.ImUserFriend.builder()
 | 
	
		
			
				|  |  | +					.id(item.getId())
 | 
	
		
			
				|  |  | +					.userId(item.getUserId().longValue())
 | 
	
		
			
				|  |  | +					.friendId(item.getFriendId().longValue())
 | 
	
		
			
				|  |  | +					.friendAvatar(item.getFriend().getAvatar())
 | 
	
		
			
				|  |  | +					.friendNickname(item.getFriendNickname())
 | 
	
		
			
				|  |  | +					.memo(item.getMemo())
 | 
	
		
			
				|  |  | +					.roleType(item.getRoleType())
 | 
	
		
			
				|  |  | +					.friendType(item.getRoleType())
 | 
	
		
			
				|  |  | +					.updateTime(item.getUpdateTime())
 | 
	
		
			
				|  |  | +					.createTime(item.getCreateTime())
 | 
	
		
			
				|  |  | +					.build());
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		return succeed(wrappers);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询好友中的学生列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryFriendStudentList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<List<ImUserFriendDto>> queryFriendStudentList(String search) {
 | 
	
		
			
				|  |  | +		return succeed(imUserFriendService.queryFriendListByUserId(userLoginService.getUserId(), search).stream().filter(e -> StringUtils.isBlank(e.getTags()))
 | 
	
		
			
				|  |  | +				.collect(Collectors.toList()));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation("查询好友中的学生列表-v2")
 | 
	
		
			
				|  |  | +    @GetMapping(value = "/queryFriendStudentList/v2")
 | 
	
		
			
				|  |  | +    public HttpResponseResult<List<ImUserFriendDto>> queryFriendStudentListV2(String search, String musicGroupId, Integer subjectId, Boolean vipFlag) {
 | 
	
		
			
				|  |  | +        return succeed(imUserFriendService.queryFriendListByUserIdV2(userLoginService.getUserId(), search,musicGroupId,subjectId,vipFlag)
 | 
	
		
			
				|  |  | +                .stream().filter(e -> StringUtils.isBlank(e.getTags()))
 | 
	
		
			
				|  |  | +                .collect(Collectors.toList()));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@ApiOperation("查询群公告列表")
 | 
	
		
			
				|  |  | +	@GetMapping(value = "/queryNoticeList")
 | 
	
		
			
				|  |  | +	public HttpResponseResult<PageInfo<ImGroupNoticeDto>> queryNoticeList(ImGroupNoticeQueryInfo queryInfo) {
 | 
	
		
			
				|  |  | +		return succeed(imGroupNoticeService.queryPage(queryInfo));
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +}
 |