|  | @@ -2,6 +2,11 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  | +import com.microsvc.toolkit.middleware.im.ImPluginContext;
 | 
	
		
			
				|  |  | +import com.microsvc.toolkit.middleware.im.message.ETencentMessage;
 | 
	
		
			
				|  |  | +import com.microsvc.toolkit.middleware.im.message.MessageWrapper;
 | 
	
		
			
				|  |  | +import com.microsvc.toolkit.middleware.im.message.TencentRequest;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.ImGroupDao;
 | 
	
	
		
			
				|  | @@ -10,13 +15,14 @@ import com.yonge.cooleshow.biz.dal.dto.ImGroupNoticeDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ImGroup;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ImGroupNotice;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.ImGroupNoticeService;
 | 
	
		
			
				|  |  | -import com.yonge.toolset.mybatis.support.PageUtil;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupNoticeWrapper;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.page.PageInfo;
 | 
	
		
			
				|  |  | -import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +import com.yonge.toolset.mybatis.support.PageUtil;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
	
		
			
				|  | @@ -39,6 +45,8 @@ public class ImGroupNoticeServiceImpl extends ServiceImpl<ImGroupNoticeDao, ImGr
 | 
	
		
			
				|  |  |      private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private ImGroupDao imGroupDao;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private ImPluginContext imPluginContext;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public ImGroupNoticeDao getDao() {
 | 
	
	
		
			
				|  | @@ -59,6 +67,27 @@ public class ImGroupNoticeServiceImpl extends ServiceImpl<ImGroupNoticeDao, ImGr
 | 
	
		
			
				|  |  |              baseMapper.updateTopFlag(imGroupNotice.getGroupId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          baseMapper.insert(imGroupNotice);
 | 
	
		
			
				|  |  | +        // 发送群公告消息
 | 
	
		
			
				|  |  | +        String messageSeqId = sendGroupCustomNoticeMessage(convertToImGroupNotice(imGroupNotice));
 | 
	
		
			
				|  |  | +        // 更新群公告消息ID
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(messageSeqId)) {
 | 
	
		
			
				|  |  | +            imGroupNotice.setMessageSeqId(messageSeqId);
 | 
	
		
			
				|  |  | +            baseMapper.updateById(imGroupNotice);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ImGroupNoticeWrapper.ImGroupNotice convertToImGroupNotice(ImGroupNotice imGroupNotice) {
 | 
	
		
			
				|  |  | +        ImGroupNoticeWrapper.ImGroupNotice notice = ImGroupNoticeWrapper.ImGroupNotice.builder()
 | 
	
		
			
				|  |  | +                .id(imGroupNotice.getId())
 | 
	
		
			
				|  |  | +                .groupId(imGroupNotice.getGroupId())
 | 
	
		
			
				|  |  | +                .title(imGroupNotice.getTitle())
 | 
	
		
			
				|  |  | +                .content(imGroupNotice.getContent())
 | 
	
		
			
				|  |  | +                .topFlag(imGroupNotice.getTopFlag())
 | 
	
		
			
				|  |  | +                .sentToNewMemberFlag(imGroupNotice.getSentToNewMemberFlag())
 | 
	
		
			
				|  |  | +                .operatorId(imGroupNotice.getOperatorId())
 | 
	
		
			
				|  |  | +                .delFlag(imGroupNotice.getDelFlag())
 | 
	
		
			
				|  |  | +                .build();
 | 
	
		
			
				|  |  | +        return notice;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -69,6 +98,8 @@ public class ImGroupNoticeServiceImpl extends ServiceImpl<ImGroupNoticeDao, ImGr
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          this.checkAdmin(imGroupNotice.getGroupId());
 | 
	
		
			
				|  |  |          baseMapper.deleteById(noticeId);
 | 
	
		
			
				|  |  | +        // 撤销群公告消息
 | 
	
		
			
				|  |  | +        revokeImGroupNoticeMessage(imGroupNotice);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -94,8 +125,18 @@ public class ImGroupNoticeServiceImpl extends ServiceImpl<ImGroupNoticeDao, ImGr
 | 
	
		
			
				|  |  |          if(imGroupNotice.getTopFlag() != null && Boolean.TRUE.equals(imGroupNotice.getTopFlag())){
 | 
	
		
			
				|  |  |              baseMapper.updateTopFlag(imGroupNotice.getGroupId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          baseMapper.updateById(imGroupNotice);
 | 
	
		
			
				|  |  | +        // 撤销群公告消息
 | 
	
		
			
				|  |  | +        ImGroupNotice notice = baseMapper.selectById(imGroupNotice.getId());
 | 
	
		
			
				|  |  | +        revokeImGroupNoticeMessage(notice);
 | 
	
		
			
				|  |  | +        // 发送群公告消息
 | 
	
		
			
				|  |  | +        String messageSeqId = sendGroupCustomNoticeMessage(convertToImGroupNotice(notice));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 更新群公告消息ID
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotBlank(messageSeqId)) {
 | 
	
		
			
				|  |  | +            notice.setMessageSeqId(messageSeqId);
 | 
	
		
			
				|  |  | +            baseMapper.updateById(notice);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public Long checkAdmin(String groupId){
 | 
	
	
		
			
				|  | @@ -110,5 +151,65 @@ public class ImGroupNoticeServiceImpl extends ServiceImpl<ImGroupNoticeDao, ImGr
 | 
	
		
			
				|  |  |          return sysUser.getId();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 发送群公告消息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param notice   ImGroupNoticeWrapper.ImGroupNotice
 | 
	
		
			
				|  |  | +     * @return 消息ID
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private String sendGroupCustomNoticeMessage(ImGroupNoticeWrapper.ImGroupNotice notice) {
 | 
	
		
			
				|  |  | +        String messageSeqId;
 | 
	
		
			
				|  |  | +        // 发送群公告消息
 | 
	
		
			
				|  |  | +        ImGroupNoticeWrapper.CustomGroupNotice customGroupNotice = ImGroupNoticeWrapper.CustomGroupNotice.builder()
 | 
	
		
			
				|  |  | +                .businessID("TC_GROUP_NOTICE")
 | 
	
		
			
				|  |  | +                .msgId(String.valueOf(notice.getId()))
 | 
	
		
			
				|  |  | +                .msgTitle(notice.getTitle())
 | 
	
		
			
				|  |  | +                .msgContent(notice.getContent())
 | 
	
		
			
				|  |  | +                .build();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        TencentRequest.MessageBody messageBody = TencentRequest.MessageBody.builder()
 | 
	
		
			
				|  |  | +                .msgType(ETencentMessage.TIMCustomElem.name())
 | 
	
		
			
				|  |  | +                .msgContent(TencentRequest.CustomMessageBody.builder()
 | 
	
		
			
				|  |  | +                        .data(customGroupNotice.jsonString())
 | 
	
		
			
				|  |  | +                        .desc("群公告")
 | 
	
		
			
				|  |  | +                        .build())
 | 
	
		
			
				|  |  | +                .build();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            // 发送群公告消息
 | 
	
		
			
				|  |  | +            messageSeqId = imPluginContext.getPluginService().sendGroupMessage(MessageWrapper.GroupMessage.builder()
 | 
	
		
			
				|  |  | +                    .senderId(notice.getOperatorId().toString())
 | 
	
		
			
				|  |  | +                    .groupId(notice.getGroupId())
 | 
	
		
			
				|  |  | +                    .tencentMessage(messageBody)
 | 
	
		
			
				|  |  | +                    .build());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("群公告消息发送失败, messageId={}, groupId={}, title={}, ", notice.getId(), notice.getGroupId(),
 | 
	
		
			
				|  |  | +                    notice.getTitle(), e);
 | 
	
		
			
				|  |  | +            throw com.microsvc.toolkit.common.webportal.exception.BizException.from("群公告消息发送失败");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return messageSeqId;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 撤销群公告消息
 | 
	
		
			
				|  |  | +     * @param imGroupNotice ImGroupNotice
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void revokeImGroupNoticeMessage(ImGroupNotice imGroupNotice) {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            if (StringUtils.isNotBlank(imGroupNotice.getMessageSeqId())) {
 | 
	
		
			
				|  |  | +                imPluginContext.getPluginService().recallGroupMessage(MessageWrapper.RecallGroupMessage.builder()
 | 
	
		
			
				|  |  | +                        .groupId(imGroupNotice.getGroupId())
 | 
	
		
			
				|  |  | +                        .reason("群公告消息撤销")
 | 
	
		
			
				|  |  | +                        .messageSeqs(Lists.newArrayList(
 | 
	
		
			
				|  |  | +                                TencentRequest.GroupMessageSeq.builder().messageSeq(Integer.parseInt(imGroupNotice.getMessageSeqId())).build()
 | 
	
		
			
				|  |  | +                        ))
 | 
	
		
			
				|  |  | +                        .build());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("撤销群公告消息失败, messageId={}, groupId={}, title={}, ", imGroupNotice.getId(), imGroupNotice.getGroupId(),
 | 
	
		
			
				|  |  | +                    imGroupNotice.getTitle(), e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |