|
@@ -1,29 +1,46 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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.microsvc.toolkit.middleware.im.properties.ImConfigProperties;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.ImGroupNoticeDao;
|
|
|
import com.ym.mec.biz.dal.dto.ImGroupNoticeDto;
|
|
|
import com.ym.mec.biz.dal.entity.ImGroupNotice;
|
|
|
import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
|
|
|
+import com.ym.mec.biz.dal.wrapper.ImGroupNoticeWrapper;
|
|
|
import com.ym.mec.biz.service.ImGroupNoticeService;
|
|
|
+import com.ym.mec.biz.service.SysUserService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ImGroupNoticeServiceImpl extends BaseServiceImpl<Long, ImGroupNotice> implements ImGroupNoticeService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ImGroupNoticeDao imGroupNoticeDao;
|
|
|
+ @Resource
|
|
|
+ private ImPluginContext imPluginContext;
|
|
|
+ @Resource
|
|
|
+ private SysUserService sysUserService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, ImGroupNotice> getDAO() {
|
|
@@ -66,6 +83,18 @@ public class ImGroupNoticeServiceImpl extends BaseServiceImpl<Long, ImGroupNotic
|
|
|
imGroupNoticeDao.updateTop(imGroupNotice.getImGroupId(),false);
|
|
|
}
|
|
|
imGroupNoticeDao.update(imGroupNotice);
|
|
|
+ // 撤销群公告消息
|
|
|
+ ImGroupNotice notice = imGroupNoticeDao.get(imGroupNotice.getId());
|
|
|
+ revokeImGroupNoticeMessage(notice);
|
|
|
+
|
|
|
+ // 发送群公告消息
|
|
|
+ String messageSeqId = sendGroupCustomNoticeMessage(convertToImGroupNotice(notice));
|
|
|
+
|
|
|
+ // 更新群公告消息ID
|
|
|
+ if (StringUtils.isNotBlank(messageSeqId)) {
|
|
|
+ notice.setMessageSeqId(messageSeqId);
|
|
|
+ imGroupNoticeDao.update(notice);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -73,4 +102,123 @@ public class ImGroupNoticeServiceImpl extends BaseServiceImpl<Long, ImGroupNotic
|
|
|
return imGroupNoticeDao;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Long add(ImGroupNotice imGroupNotice) {
|
|
|
+ if(imGroupNotice.isIsTop()){
|
|
|
+ //置顶取消
|
|
|
+ imGroupNoticeDao.updateTop(imGroupNotice.getImGroupId(),false);
|
|
|
+ }
|
|
|
+ imGroupNoticeDao.insert(imGroupNotice);
|
|
|
+ // 发送群公告消息
|
|
|
+ String messageSeqId = sendGroupCustomNoticeMessage(convertToImGroupNotice(imGroupNotice));
|
|
|
+ // 更新群公告消息ID
|
|
|
+ if (StringUtils.isNotBlank(messageSeqId)) {
|
|
|
+ imGroupNotice.setMessageSeqId(messageSeqId);
|
|
|
+ imGroupNoticeDao.update(imGroupNotice);
|
|
|
+ }
|
|
|
+ return imGroupNotice.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void del(Long id) {
|
|
|
+ ImGroupNotice notice = imGroupNoticeDao.get(id);
|
|
|
+ if (notice == null) {
|
|
|
+ throw new BizException("该群公告已被删除");
|
|
|
+ }
|
|
|
+ imGroupNoticeDao.delete(id);
|
|
|
+ // 撤销群公告消息
|
|
|
+ revokeImGroupNoticeMessage(notice);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ImGroupNoticeDto getNotice(Long id) {
|
|
|
+ ImGroupNotice notice = imGroupNoticeDao.get(id);
|
|
|
+ if (notice == null) {
|
|
|
+ throw new BizException("该群公告已被删除");
|
|
|
+ }
|
|
|
+ ImGroupNoticeDto noticeDto = JSON.parseObject(JSON.toJSONString(notice), ImGroupNoticeDto.class);
|
|
|
+ SysUser sysUser = sysUserService.queryUserById(noticeDto.getOperatorId().intValue());
|
|
|
+ noticeDto.setUsername(sysUser.getRealName());
|
|
|
+ noticeDto.setAvatar(sysUser.getAvatar());
|
|
|
+ return noticeDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ImGroupNoticeWrapper.ImGroupNotice convertToImGroupNotice(ImGroupNotice imGroupNotice) {
|
|
|
+ ImGroupNoticeWrapper.ImGroupNotice notice = ImGroupNoticeWrapper.ImGroupNotice.builder()
|
|
|
+ .id(imGroupNotice.getId())
|
|
|
+ .groupId(imGroupNotice.getImGroupId())
|
|
|
+ .title(imGroupNotice.getTitle())
|
|
|
+ .content(imGroupNotice.getContent())
|
|
|
+ .topFlag(imGroupNotice.isIsTop())
|
|
|
+ .sentToNewMemberFlag(true)
|
|
|
+ .operatorId(imGroupNotice.getOperatorId())
|
|
|
+ .delFlag(imGroupNotice.isDelFlag())
|
|
|
+ .build();
|
|
|
+ return notice;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送群公告消息
|
|
|
+ *
|
|
|
+ * @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.getImGroupId())
|
|
|
+ .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.getImGroupId(),
|
|
|
+ imGroupNotice.getTitle(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|