package com.tourism.webadmin.app.website.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import com.tourism.common.core.exception.MyRuntimeException;
import com.tourism.common.core.object.MyPageData;
import com.tourism.common.core.object.MyRelationParam;
import com.tourism.common.core.object.TokenData;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.webadmin.app.website.dto.DelMessageDto;
import com.tourism.webadmin.app.website.dto.InteractionMessageDto;
import com.tourism.webadmin.app.website.dto.MessageDTO;
import com.tourism.webadmin.app.website.dto.SystemMessageDTO;
import com.tourism.webadmin.app.website.service.TourGroupService;
import com.tourism.webadmin.app.website.service.TourMemberService;
import com.tourism.webadmin.app.website.service.TourMessageService;
import com.tourism.webadmin.app.website.vo.GroupMessageVo;
import com.tourism.webadmin.app.website.vo.InteractionListVo;
import com.tourism.webadmin.back.dao.TourImMessageMapper;
import com.tourism.webadmin.back.model.TourImGroup;
import com.tourism.webadmin.back.model.TourImMember;
import com.tourism.webadmin.back.model.TourImMessage;
import com.tourism.webadmin.back.model.TourUser;
import com.tourism.webadmin.back.model.constant.IsTrue;
import com.tourism.webadmin.back.model.constant.NoticeType;
import com.tourism.webadmin.back.service.*;
import com.tourism.webadmin.enums.GroupRole;
import com.tourism.webadmin.enums.SystemDefaultHead;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;
@Service
public class TourMessageServiceImpl extends ServiceImpl<TourImMessageMapper, TourImMessage> implements TourMessageService {

    @Autowired
    private TourUserService tourUserService;
    @Autowired
    private TourImGroupService tourImGroupService;
    @Autowired
    private TourImMessageMapper baseMapper;
    @Autowired
    private TourImMemberService tourImMemberService;
    @Autowired
    private TourImMessageMapper tourImMessageMapper;
    @Autowired
    private TourImMessageService messageService;
//    @Autowired
//    private AESUtils aesUtil;
    @Autowired
    private TourMemberService tourMemberService;
    @Autowired
    private TourGroupService tourGroupService;
    @Autowired
    private TourismProjectTravelNotesWriteService tourismProjectTravelNotesWriteService;

    /**
     *  分页查询群组消息
     * @param pageSize
     * @return {@link List }<{@link GroupMessageVo }>
     */

    @Override
    public HashMap<String,Object> getMessageByGroupId(Long messageId,TourImGroup group,Integer pageSize,String searchMessage) {
        HashMap<String, Object> resultMap = new HashMap<>();

        //默认15条
        pageSize=pageSize==null||pageSize<=0? 15:pageSize;

        //时间排序查询当前登录用户可查看的全部消息
        List<TourImMessage> tourImMessages = tourImMessageMapper.getMessageByGroupId(messageId,pageSize,group.getId(),searchMessage,TokenData.takeFromRequest().getUserId());
        Integer count = tourImMessageMapper.getMessageByGroupIdCount(messageId,pageSize,group.getId(),searchMessage,TokenData.takeFromRequest().getUserId());

        Collections.reverse(tourImMessages);

        //全部消息发送人ID
        Set<Long> collect = tourImMessages.stream().map(TourImMessage::getCreateUserId).collect(Collectors.toSet());

        List<TourUser> tourUsers =new ArrayList<>();
        //类型转换为返回结果集
        List<GroupMessageVo> list = BeanUtil.copyToList(tourImMessages, GroupMessageVo.class);

        //消息是否为空
        if(!collect.isEmpty()){
            //查询群聊全部用户
            ArrayList<String> ids = new ArrayList<>();
            ids.add(group.getId().toString());
            Map<String, Set<TourUser>> userByGroupId = tourMemberService.getUserByGroupId(ids);
            //群聊全部用户
            Set<TourUser> groupUser = userByGroupId.get(group.getId().toString());

            //消息发送人 账号信息
            Map<Long, TourUser> userMap = new HashMap<>();

            // userId ->member
            Map<Long, TourImMember> groupMemberMap = getGroupMemberMap(group.getId());

            //查询用户信息
            tourUsers=tourUserService.getBaseMapper().selectBatchIds(collect);
            for (TourUser tourUser : tourUsers) {
                userMap.put(tourUser.getUserId(),tourUser);
            }

            //返回发送消息人的头像和昵称
            for (GroupMessageVo groupMessageVo : list) {
                //获取群聊里是否有这个人
                //获取用户会话
                TourImMember tourImMember = groupMemberMap.get(Long.valueOf(groupMessageVo.getCreateUserId()));

                //创建人
                TourUser tourUser = userMap.get(Long.valueOf(groupMessageVo.getCreateUserId()));

                if(tourUser==null){
                    continue;
                }
                if(tourImMember==null){
                    //这个人没在群里
                    groupMessageVo.setIsExistence("1");
                    groupMessageVo.setHeadImageUrl(tourUser.getHeadImageUrl());
                    groupMessageVo.setShowName(tourUser.getShowName());
                }else {
                    //这个人在群
                    groupMessageVo.setIsExistence("0");
                    groupMessageVo.setHeadImageUrl(tourUser.getHeadImageUrl());
                    groupMessageVo.setShowName(tourImMember.getGroupNickname());
                    if(ObjectUtil.isEmpty(tourImMember.getGroupNickname())){
                        groupMessageVo.setShowName(tourUser.getShowName());
                    }
                }
            }
        }

        //对消息发送人进行加密
        for (GroupMessageVo groupMessageVo : list) {
//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
        }
        resultMap.put("data",list);
        resultMap.put("count",count);
        return resultMap;
    }


    /**
     *
     * 获取群聊  key userId  value tourImMember
     * @param groupId
     * @return {@link Map }<{@link String },{@link TourImMember }>
     */

    public Map<Long,TourImMember> getGroupMemberMap(Long groupId) {
        //获取群聊全部会话 包括删除的
        List<TourImMember> list = tourImMemberService.list(Wrappers.<TourImMember>lambdaQuery().eq(TourImMember::getGroupId, groupId));

        //用户集合
        Set<Long> ids = list.stream().map(TourImMember::getUserId).collect(Collectors.toSet());

        List<TourUser> users = tourUserService.getBaseMapper().selectBatchIds(ids);

        // userMap
        HashMap<Long, TourUser> userMap = new HashMap<>();
        for (TourUser user : users) {
            userMap.put(user.getUserId(),user);
        }

        HashMap<Long, TourImMember> map = new HashMap<>();
        for (TourImMember tourImMember : list) {
            map.put(tourImMember.getUserId(), tourImMember);
        }
        return map;
    }
    /**
     *   删除消息
     * @param params
     * @return boolean
     */

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delMessage(DelMessageDto params) {
        //登录账户
        Long userId = TokenData.takeFromRequest().getUserId();
        //查询消息
        List<TourImMessage> list = baseMapper.selectBatchIds(params.getMessageId());
        if(ObjectUtil.isEmpty(list)){
            return true;
        }
        for (TourImMessage message : list) {
            //将当前用户加入到删除列表
            message.setDeletedByUsers(message.getDeletedByUsers()+userId+",");
        }
        return this.updateBatchById(list);
    }

    /**
     *  撤回消息
     * @param params
     * @return boolean
     */

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean withdrawMessage(DelMessageDto params) {
        //登录账户
        Long userId = TokenData.takeFromRequest().getUserId();
        //查询消息
        List<TourImMessage> list = baseMapper.selectBatchIds(params.getMessageId());
        if(ObjectUtil.isEmpty(list)){
            return true;
        }
        for (TourImMessage tourImMessage : list) {
            //判断消息发送人是否是自己
            if(!tourImMessage.getCreateUserId().equals(userId)){
                continue;
            }
            long between = DateUtil.between(tourImMessage.getCreateTime(), new Date(), DateUnit.MS);
            //判断消息的创建时间是否超过 两分钟
            if(between>1000*60*2){
                continue;
            }
            tourImMessage.setRevocationTag(IsTrue.TRUE);
        }
        return updateBatchById(list);
    }

    /**
     *
     *  设置消息已读
     * @param groupId
     * @return boolean
     */

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateRead(Long groupId) {
        Long userId = TokenData.takeFromRequest().getUserId();
        //查询登录账户群未读消息列表
        List<TourImMessage> list = lambdaQuery().eq(TourImMessage::getGroupId, groupId)
                .notLike(TourImMessage::getReadByUsers, userId).list();
        if(ObjectUtil.isEmpty(list)) return true;

        //登录账户加入到消息已读字段中
        for (TourImMessage tourImMessage : list) {
            tourImMessage.setReadByUsers(tourImMessage.getReadByUsers()+","+userId);
        }
        return updateBatchById(list);
    }

    @Override
    public void topUpGroupMessage(Long messageId) {
        Long userId = TokenData.takeFromRequest().getUserId();
        TourImMessage byId = getById(messageId);
        if(byId==null||userId==null) return;
        TourImGroup group = tourImGroupService.getById(byId.getGroupId());
        if(IsTrue.FALSE==group.getBannedStatus()){
            return;
        }
        LambdaQueryChainWrapper<TourImMember> query = tourImMemberService.lambdaQuery().eq(TourImMember::getUserId, userId).eq(TourImMember::getGroupId, group.getId());
        TourImMember one = tourImMemberService.getOne(query);
        //状态为删除 、 不是管理员都不能操作
        if(one==null||one.getDataState().equals(-1)||GroupRole.ORDINARY_MEMBERS.getCode().equals(one.getGroupRole())){
            return;
        }
        byId.setIsTop(IsTrue.TRUE);
        updateById(byId);
    }

    @Override
    @Transactional
    public void clearGroupMessage(Long groupId) {
        Long userId = TokenData.takeFromRequest().getUserId();
        TourImGroup byId = tourImGroupService.getById(groupId);
        if(byId==null||userId==null) return;
        //查询群聊群不消息
        List<TourImMessage> list = lambdaQuery().eq(TourImMessage::getGroupId, groupId).notLike(TourImMessage::getDeletedByUsers,userId).list();
        //将登录账户加入到删除消息字段
        for (TourImMessage tourImMessage : list) {
            tourImMessage.setDeletedByUsers(tourImMessage.getDeletedByUsers()+userId+",");
        }
        updateBatchById(list);
    }

    @Override
    public MyPageData getMessageByGroupIdPage(TourImGroup group, Integer pageNum, Integer pageSize, String searchMessage,Integer messageType) {
        //分页
        if (pageNum == null){
            pageNum = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
//        PageMethod.startPage(pageNum, pageSize);
        //条件查询历史
        List<TourImMessage> tourImMessages = tourImMessageMapper.selectList(new LambdaQueryWrapper<TourImMessage>()
                .eq(TourImMessage::getGroupId, group.getId())
                        .eq(messageType != null,TourImMessage::getMessageType, messageType)
                        .eq(TourImMessage::getMessageType,0)
                        .notLike(TourImMessage::getDeletedByUsers,"%"+TokenData.takeFromRequest().getUserId()+"%")
                .orderByDesc(TourImMessage::getCreateTime)
        );
        tourImMessages =tourImMessages.stream().filter(item->{
            String content = item.getMessageContent();
            SystemMessageDTO messageDTO = JSON.parseObject(content, SystemMessageDTO.class);
            if (messageDTO.getMessageContent().indexOf(searchMessage)>-1){
                return true;
            }
            return false;
        }).collect(Collectors.toList());
        if (tourImMessages.size() > pageSize){
            tourImMessages = tourImMessages.subList((pageNum - 1) * pageSize,pageSize);
        }
        int batchSize = tourImMessages instanceof Page ? 0 : 1000;
        //构建字典翻译
        messageService.buildRelationForDataList(tourImMessages, MyRelationParam.normal(), batchSize);
        //转换vo
        MyPageData<GroupMessageVo> groupMessageVoMyPageData = MyPageUtil.makeResponseData(tourImMessages, GroupMessageVo.class);
        //获取分页数据
        List<GroupMessageVo> dataList = groupMessageVoMyPageData.getDataList();
        List<String> collect = dataList.stream().map(GroupMessageVo::getCreateUserId).collect(Collectors.toList());
        List<TourUser> tourUsers =new ArrayList<>();
        //消息是否为空
        if(!collect.isEmpty()){

            Map<Long, TourImMember> groupMemberMap = getGroupMemberMap(group.getId());

            //查询用户信息
            tourUsers=tourUserService.getBaseMapper().selectBatchIds(collect);
            HashMap<Long, TourUser> userMap = new HashMap<>();
            for (TourUser tourUser : tourUsers) {
                userMap.put(tourUser.getUserId(),tourUser);
            }
            //返回发送消息人的头像和昵称
            for (GroupMessageVo groupMessageVo : dataList) {

                TourUser tourUser = userMap.get(Long.valueOf(groupMessageVo.getCreateUserId()));
                //获取用户会话
                TourImMember tourImMember = groupMemberMap.get(Long.valueOf(groupMessageVo.getCreateUserId()));

                //发送消息的人不存在
                if(tourUser==null){
                    continue;
                }
                groupMessageVo.setHeadImageUrl(tourUser.getHeadImageUrl());
                if(tourImMember==null){
                    //这个人没在群里
                    groupMessageVo.setIsExistence("1");
                    groupMessageVo.setShowName(tourUser.getShowName());
                }else {
                    //这个人在群
                    groupMessageVo.setIsExistence("0");
                    groupMessageVo.setShowName(tourImMember.getGroupNickname());
                    if(ObjectUtil.isEmpty(tourImMember.getGroupNickname())){
                        groupMessageVo.setShowName(tourUser.getShowName());
                    }
                }
            }
        }

        //对消息发送人进行加密
        for (GroupMessageVo groupMessageVo : dataList) {
//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
        }
        groupMessageVoMyPageData.setDataList(dataList);
        return groupMessageVoMyPageData;
    }


    /**
     *  修改公告
     * @param param
     * @return boolean
     */

    @Override
    public boolean updateAnnouncement(TourImMessage param,Long userId) {

        if(ObjectUtil.isEmpty(param.getGroupId())){
            return false;
        }
        TourImGroup group = tourGroupService.getById(param.getGroupId());
        if(group==null) {
            return false;
        }
        if(ObjectUtil.isEmpty(param.getMessageContent())){
          return false;
        }
        List<TourImMessage> list = lambdaQuery().eq(TourImMessage::getGroupId, param.getGroupId()).eq(TourImMessage::getIsTop, 1).list();
        MessageDTO messageDTO = new MessageDTO();
        messageDTO.setMessageContent( param.getMessageContent());
        if(ObjectUtil.isEmpty(list)) {
            //  没有公告
            TourImMessage insert = new TourImMessage();
            insert.setNoticeType(NoticeType.NOTICE_GROUP);
            insert.setIsTop(IsTrue.TRUE);
            //加入已读
            insert.setReadByUsers(userId.toString());
            insert.setGroupId(param.getGroupId());
            insert.setMessageContent(JSONUtil.toJsonStr(messageDTO));
            insert.setCreateTime(new Date());
            insert.setCreateUserId(userId);
            insert.setUpdateUserId(userId);
            insert.setUpdateTime(new Date());

            insert.setMessageType(0);
            return save(insert);
        }
        TourImMessage message = list.get(0);
        //清空已读
        message.setMessageContent(JSONUtil.toJsonStr(messageDTO));
        message.setReadByUsers(userId.toString());
        message.setCreateTime(new Date());
        message.setCreateUserId(userId);
        message.setUpdateUserId(userId);
        message.setUpdateTime(new Date());

        return updateById(message);
    }


    @Override
    public MyPageData<InteractionListVo> getInteractionList(String noticeType, Long userId, Integer pageNum,Integer pageSize) {
        if(ObjectUtil.isEmpty(noticeType)) return new MyPageData<InteractionListVo>();
        ArrayList<String> types = new ArrayList<>();
        //赞誉收藏  5-->5.7
        //提及-->10.11
        //收到的评论--> 7-->6
        //发出的评论--> 8-->6
        if(noticeType.equals("5")){//赞与收藏
            types.add("5");//点赞
            types.add("7");//收藏通知
        }else if(noticeType.equals("6")){//提及
            types.add("10");//评论区艾特
            types.add("11");//
        }else if(noticeType.equals("7")||noticeType.equals("8")){//收到的评论//发出的评论
            types.add("6");//评论通知
        }else {
            //查询全部
            types.add("5");//点赞
            types.add("6");//评论通知
            types.add("7");//收藏通知
            types.add("10");//评论区艾特
            types.add("11");//文章内艾特通知
        }
//        开启分页
//        PageMethod.startPage(pageNum==null?1:pageNum, pageSize==null?10:pageSize);
        //构建查询条件
        LambdaQueryWrapper<TourImMessage> query = Wrappers.<TourImMessage>lambdaQuery().in(TourImMessage::getNoticeType, types);
        //全部类型的数据
        List<TourImMessage> list = this.list(query);

        if(ObjectUtil.isEmpty(list)){
            return new MyPageData<InteractionListVo>();
        }
        //转为结果集合
        List<InteractionListVo> interactionListVos = MyModelUtil.copyCollectionTo(list, InteractionListVo.class);
        Set<InteractionListVo> interactionSetVos = interactionListVos.stream().filter(item -> {
            String messageContent = item.getMessageContent();
            InteractionMessageDto interactionMessageDto = JSON.parseObject(messageContent, InteractionMessageDto.class);
            item.setBusinessId(interactionMessageDto.getId());
            item.setBusinessType(interactionMessageDto.getType());
            item.setHeadImage(SystemDefaultHead.INTERACT_USERID_OR_GROUPID.getHead());
            //评论ID
            item.setReviewId(interactionMessageDto.getReviewId());
            if (noticeType.equals("8")) {
                if (item.getCreateUserId().toString().equals(userId.toString())) {
                    return true;
                }
            }
            if (interactionMessageDto.getGetUserId().toString().equals(userId.toString())) {
                return true;
            }
            return false;
        }).collect(Collectors.toSet());

//        for (InteractionListVo interactionListVo : interactionListVos) {
//            InteractionMessageDto bean = JSONUtil.toBean(interactionListVo.getMessageContent(), InteractionMessageDto.class);
//            //业务ID
//            interactionListVo.setBusinessId(bean.getId());
//            //业务类型
//            interactionListVo.setBusinessType(bean.getType());
//            //接收人为自己的消息
//            if(bean.getGetUserId().equals(userId.toString())){
//                vo.add(interactionListVo);
//            }
//            if(noticeType.equals("8")){
//                //发出的评论
//                if(interactionListVo.getCreateUserId().equals(userId.toString())){
//                    vo.add(interactionListVo);
//                }
//            }
//        }
        //操作人IDS
        Set<String> userList = interactionSetVos.stream().map(InteractionListVo::getCreateUserId).collect(Collectors.toSet());
        if(ObjectUtil.isEmpty(userList))return new MyPageData<InteractionListVo>();

        List<TourUser> tourUsers = tourUserService.getBaseMapper().selectBatchIds(userList);
        HashMap<String, TourUser> userMap = new HashMap<>();
        for (TourUser tourUser : tourUsers) {
            userMap.put(tourUser.getUserId().toString(),tourUser);
        }

//        //业务类型 ->类型ID
//        Map<String, List<String>> collect = vo.stream().collect(Collectors.toMap(InteractionListVo::getBusinessType, each -> Collections.singletonList(each.getBusinessType()), (value1, value2) -> {
//            List<String> union = new ArrayList<>(value1);
//            union.addAll(value2);
//            return union;
//        }));
//        //业务ID ->业务对象
//        HashMap<String, Object> map = new HashMap<>();
//        //设置业务封面
//        if(!ObjectUtil.isNotEmpty(vo)){
//            collect.forEach((k,v)->{
//                if(k.equals(BusinessType.TRAVELNOTES.getCode())){
//                    //游记
//                    List<TourismProjectTravelNotesWrite> tour = tourismProjectTravelNotesWriteService.getBaseMapper().selectBatchIds(v);
//                    for (TourismProjectTravelNotesWrite write : tour) {
//                        map.put(write.getId().toString(),write.getTravelNotesBanner());
//                    }
//                }
//                //其他业务
//
//            });
//        }

        for (InteractionListVo interactionListVo : interactionSetVos) {
            //设置发送者头像和名称
            TourUser tourUser = userMap.get(interactionListVo.getCreateUserId());
            if(tourUser!=null){
                interactionListVo.setHeadImage(tourUser.getHeadImageUrl());
                interactionListVo.setShowName(tourUser.getShowName());
            }

            String jsonString = interactionListVo.getMessageContent();

            InteractionMessageDto bean = JSONUtil.toBean(jsonString, InteractionMessageDto.class);

            //设置封面
            interactionListVo.setImageUrl(bean.getImageUrl());
//            if(interactionListVo.equals(BusinessType.TRAVELNOTES.getCode())){
//                //游记
//                Object o = map.get(interactionListVo.getBusinessId());
//                TourismProjectTravelNotesWrite business = (TourismProjectTravelNotesWrite) o;
//                //设置封面
//                interactionListVo.setImageUrl(business.getTourismUrl());
//            }
            //其他业务
        }
        ArrayList<InteractionListVo> interactionPageList = new ArrayList<>(interactionSetVos);
        if(pageSize>interactionPageList.size()){
            pageSize=interactionPageList.size();
        }
        List<InteractionListVo> listVos = interactionPageList.subList((pageNum - 1) * pageSize, pageSize);
        MyPageData<InteractionListVo> listVoMyPageData = new MyPageData<>();
        listVoMyPageData.setDataList(listVos);
        listVoMyPageData.setTotalCount(Long.valueOf(interactionSetVos.size()));
        return  listVoMyPageData;
    }

    @Override
    public List<GroupMessageVo> getLatestMessage(String groupId, String messageId) {
        List<TourImMessage> list = list(Wrappers.<TourImMessage>lambdaQuery()
                .eq(TourImMessage::getId, messageId)
                .eq(TourImMessage::getGroupId, groupId));
        if(ObjectUtil.isEmpty(list)){
            return new ArrayList<>();
        }
        //消息之后的全部消息
        List<TourImMessage> result = list(Wrappers.<TourImMessage>lambdaQuery()
                .eq(TourImMessage::getGroupId, groupId)
                .ge(TourImMessage::getCreateTime, list.get(0).getCreateTime()));
        if(result==null){
            return new ArrayList<>();
        }

        Set<Long> collect = result.stream().map(TourImMessage::getCreateUserId).collect(Collectors.toSet());

        List<GroupMessageVo> groupMessageVos = BeanUtil.copyToList(result, GroupMessageVo.class);

        LambdaQueryWrapper<TourImMember> query = Wrappers.<TourImMember>lambdaQuery().in(TourImMember::getUserId, collect)
                .eq(TourImMember::getGroupId, groupId);
        List<TourImMember> list1 = tourMemberService.list(query);

        HashMap<String, TourImMember> map = new HashMap<>();
        for (TourImMember tourImMember : list1) {
            map.put(tourImMember.getUserId().toString(),tourImMember);
        }
        //全部发消息用户
        List<TourUser> tourUsers = tourUserService.getBaseMapper().selectBatchIds(collect);
        //处理头像和名称
        for (GroupMessageVo vo : groupMessageVos) {
            String createUserId = vo.getCreateUserId();
            TourImMember tourImMember = map.get(createUserId);
            List<TourUser> ls = tourUsers.stream().filter(o -> o.getUserId().toString().equals(createUserId)).collect(Collectors.toList());
            if(tourImMember==null){
                //没在群
                if(!ObjectUtil.isEmpty(ls)){
                    vo.setShowName(ls.get(0).getShowName());
                    vo.setHeadImageUrl(ls.get(0).getHeadImageUrl());
                }
            }else {
                //在群
                if(!ObjectUtil.isEmpty(tourImMember.getGroupNickname())){
                    //有群备注
                    vo.setShowName(tourImMember.getGroupNickname());
                }else {
                    //没有
                    if(!ObjectUtil.isEmpty(ls)){
                        vo.setShowName(ls.get(0).getShowName());
                    }
                }
                if(!ObjectUtil.isEmpty(ls)){
                    vo.setHeadImageUrl(ls.get(0).getHeadImageUrl());
                }
            }
        }
        //对消息发送人进行加密
        for (GroupMessageVo groupMessageVo : groupMessageVos) {
//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
        }
        return groupMessageVos.stream().filter(o -> !o.getId().equals(messageId)).collect(Collectors.toList());
    }
}

