Browse Source

Merge branch 'zx_online_0910' of http://git.dayaedu.com/yonge/cooleshow into develop-new

zouxuan 6 months ago
parent
commit
6ed662a5fe

+ 13 - 15
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupNoticeController.java

@@ -8,19 +8,11 @@ import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.utils.validator.ValidationKit;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import org.springframework.beans.factory.annotation.Autowired;
+import io.swagger.annotations.*;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import javax.validation.Valid;
 import java.util.Map;
 
@@ -37,12 +29,12 @@ public class ImGroupNoticeController extends BaseController {
     /**
      * 服务对象
      */
-    @Autowired
+    @Resource
     private ImGroupNoticeService imGroupNoticeService;
 
     @ApiOperation("新增群公告")
     @PostMapping(value = "/create")
-    public HttpResponseResult create(@Valid @RequestBody ImGroupNotice imGroupNotice, BindingResult bindingResult){
+    public HttpResponseResult<Object> create(@Valid @RequestBody ImGroupNotice imGroupNotice, BindingResult bindingResult){
         ValidationKit.ignoreFields(bindingResult,"id");
         imGroupNoticeService.create(imGroupNotice);
         return succeed();
@@ -50,14 +42,20 @@ public class ImGroupNoticeController extends BaseController {
 
     @ApiOperation("删除群公告")
     @PostMapping(value = "/del/{noticeId}")
-    public HttpResponseResult del(@ApiParam(value = "群公告编号", required = true) @PathVariable("noticeId") Long noticeId){
+    public HttpResponseResult<Object> del(@ApiParam(value = "群公告编号", required = true) @PathVariable("noticeId") Long noticeId){
         imGroupNoticeService.del(noticeId);
         return succeed();
     }
 
+    @ApiOperation("获取群公告")
+    @GetMapping(value = "/get/{noticeId}")
+    public HttpResponseResult<ImGroupNotice> get(@ApiParam(value = "群公告编号", required = true) @PathVariable("noticeId") Long noticeId){
+        return succeed(imGroupNoticeService.getById(noticeId));
+    }
+
     @ApiOperation("修改群公告")
     @PostMapping(value = "/update")
-    public HttpResponseResult modify(@Valid @RequestBody ImGroupNotice imGroupNotice){
+    public HttpResponseResult<Object> modify(@Valid @RequestBody ImGroupNotice imGroupNotice){
         imGroupNoticeService.modify(imGroupNotice);
         return succeed();
     }

+ 12 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/ImGroupNotice.java

@@ -64,6 +64,18 @@ public class ImGroupNotice implements Serializable {
     @ApiModelProperty(value = "修改时间;")
     private Date updateTime;
 
+    @TableField("message_seq_id_")
+    @ApiModelProperty(value = "消息编号;")
+    private String messageSeqId;
+
+    public String getMessageSeqId() {
+        return messageSeqId;
+    }
+
+    public void setMessageSeqId(String messageSeqId) {
+        this.messageSeqId = messageSeqId;
+    }
+
     public Long getId() {
         return id;
     }

+ 105 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupNoticeServiceImpl.java

@@ -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);
+        }
+    }
+
 }
 

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/MusicSheetServiceImpl.java

@@ -2477,7 +2477,7 @@ public class MusicSheetServiceImpl extends ServiceImpl<MusicSheetDao, MusicSheet
         query.setDelFlag(true);
         query.setPage(1);
         query.setAudioPlayTypeFlag(false);
-        if (sourceType == SourceTypeEnum.PLATFORM) {
+        if (sourceType == null || sourceType == SourceTypeEnum.PLATFORM) {
             query.setApplicationId(applicationId);
         } else {
             query.setApplicationId(Long.parseLong(sysConfigService.findConfigValue(SysConfigConstant.CBS_TENANT_APP_ID)));

+ 32 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/ImGroupNoticeWrapper.java

@@ -10,6 +10,7 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 
+import java.io.Serializable;
 import java.util.Date;
 import java.util.Optional;
 
@@ -102,4 +103,35 @@ public class ImGroupNoticeWrapper {
                         
 	}
 
+
+    @Data
+    @Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ApiModel(" 自定义群公告")
+    public static class CustomGroupNotice implements Serializable {
+
+        @ApiModelProperty("业务ID")
+        private String businessID;
+
+        @ApiModelProperty("群公告ID")
+        private String msgId;
+
+        @ApiModelProperty("群公告标题")
+        private String msgTitle;
+
+        @ApiModelProperty("群公告内容")
+        private String msgContent;
+
+        public String jsonString() {
+            return JSON.toJSONString(this);
+        }
+
+        public String getBusinessID() {
+            return Optional.ofNullable(businessID).orElse("TC_GROUP_NOTICE");
+        }
+    }
+
+
+
 }

+ 1 - 1
pom.xml

@@ -24,7 +24,7 @@
 		<redisson.version>3.11.5</redisson.version>
 		<maven.test.skip>true</maven.test.skip>
 		<cbs.version>1.0.15</cbs.version>
-		<microsvc.version>1.0.8</microsvc.version>
+		<microsvc.version>1.0.8-RC1</microsvc.version>
 	</properties>