浏览代码

Merge remote-tracking branch 'origin/master_saas' into master_saas

zouxuan 2 年之前
父节点
当前提交
759159a185

+ 8 - 0
README.md

@@ -0,0 +1,8 @@
+
+#### 直播回调配置
+
+> 1、IM回调配置
+> 2、直播录制回调配置
+> 3、录制模板创建
+> 4、添加IM管理员帐号 `mec_admin`
+> 5、群自定义数据

+ 46 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/EGroupDefinedDataType.java

@@ -0,0 +1,46 @@
+package com.ym.mec.biz.dal.enums;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2023-03-20
+ */
+public enum EGroupDefinedDataType {
+
+    /**
+     * 主讲人状态
+     */
+    ANCHOR_STATUS("主讲人状态"), // "ONLINE":"OFFLINE"
+
+    /**
+     * 全局禁言
+     */
+    GLOBAL_BAN("全局禁言"), //  0允许 1不允许
+
+    ;
+    private String code;
+
+    private String msg;
+
+    EGroupDefinedDataType(String msg) {
+        this.msg = msg;
+        this.code = this.name();
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/vo/ImLiveBroadcastRoomVo.java

@@ -123,6 +123,17 @@ public class ImLiveBroadcastRoomVo implements Serializable {
     @ApiModelProperty(value = "禁言状态: 0 取消;1禁言")
     private Integer banStatus;
 
+    @ApiModelProperty("视频数量")
+    private Integer videoNum;
+
+    public Integer getVideoNum() {
+        return videoNum;
+    }
+
+    public void setVideoNum(Integer videoNum) {
+        this.videoNum = videoNum;
+    }
+
     public SysUserType getClientType() {
         return clientType;
     }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImLiveRoomBlackService.java

@@ -35,6 +35,8 @@ public interface ImLiveRoomBlackService extends IService<ImLiveRoomBlack> {
      */
     void add(Map<String, Object> param);
 
+    void setBlack(Integer userId, ImLiveBroadcastRoomVo roomVo);
+
     /**
      * 删除该用户从房间黑名单中移除
      *

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImLiveRoomVideoService.java

@@ -6,6 +6,7 @@ import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
 import com.ym.mec.biz.dal.vo.ImLiveRoomVideoVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 直播视频记录(ImLiveRoomVideo)表服务接口
@@ -18,5 +19,12 @@ public interface ImLiveRoomVideoService extends IService<ImLiveRoomVideo> {
     ImLiveRoomVideoDao getDao();
 
     List<ImLiveRoomVideoVo> queryList(String roomUid);
+
+    /**
+     * 直播间的视频数
+     *
+     * @param roomIdList 直播间id
+     */
+    Map<String,Integer> queryRoomUidCountMap(List<String> roomIdList);
 }
 

+ 59 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -34,6 +34,7 @@ import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoomData;
 import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoomMember;
 import com.ym.mec.biz.dal.entity.ImLiveRoomBlack;
 import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
+import com.ym.mec.biz.dal.enums.EGroupDefinedDataType;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 import com.ym.mec.biz.dal.page.LiveRoomGoodsOrderQueryInfo;
 import com.ym.mec.biz.dal.vo.*;
@@ -251,6 +252,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         // 直播房间统计信息
         getRoomData(room);
 
+
         // 直播间配置信息
         return room.userSig(userSig).liveRoomConfig(pluginService.getLiveRoomConfig());
     }
@@ -287,9 +289,12 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
     @Override
     public PageInfo<ImLiveBroadcastRoomVo> queryPage(Map<String, Object> param) {
         String os = WrapperUtil.toStr(param, "os");
-        if (StringUtils.isNotBlank(os) && os.equals("teacher")) {
+        if (StringUtils.isNotBlank(os) && os.toUpperCase(Locale.ROOT).equals("TEACHER")) {
             param.put("speakerId", getSysUser().getId());
             param.put("clientType", SysUserType.TEACHER.getCode());
+        } else if (StringUtils.isNotBlank(os) && os.toUpperCase(Locale.ROOT).equals("EDUCATION")) {
+            param.put("clientType", SysUserType.EDUCATION.getCode());
+            param.put("speakerId", getSysUser().getId());
         }
         Page<ImLiveBroadcastRoomVo> pageInfo = PageUtil.concatTimePage(param, "startTime", "endTime");
         // pageInfo.setDesc("a.created_time_");
@@ -315,6 +320,16 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             record.setRoomReservationNum(imLiveBroadcastRoomVos.get(0).getRoomReservationNum());
         }
 
+        // 查询直播间视频数
+        Map<String, Integer> uidCountMap = imLiveRoomVideoService.queryRoomUidCountMap(roomIdList);
+        for (ImLiveBroadcastRoomVo record : records) {
+            Integer count = uidCountMap.get(record.getRoomUid());
+            if (count == null) {
+                record.setVideoNum(0);
+            }
+            record.setVideoNum(count);
+        }
+
         return PageUtil.pageInfo(page);
     }
 
@@ -401,6 +416,10 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         roomConfig.setWhether_chat(whetherChat);
         obj.setRoomConfig(JSONObject.toJSONString(roomConfig));
         this.updateById(obj);
+
+
+        ImLiveBroadcastRoomVo roomVo = getImLiveBroadcastRoomVo(obj.getRoomUid());
+        setGroupDefinedData(roomVo,EGroupDefinedDataType.GLOBAL_BAN,whetherChat.toString());
     }
 
     /**
@@ -1153,7 +1172,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
                 .update(room);
 
         // 设置直播群组自定义数据
-        setGroupDefinedData(roomVo,false);
+        setGroupDefinedData(roomVo,EGroupDefinedDataType.ANCHOR_STATUS,"OFFLINE");
 
         return true;
     }
@@ -1200,16 +1219,16 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
                 .update();
 
         // 设置直播群组自定义数据
-        setGroupDefinedData(roomVo,true);
+        setGroupDefinedData(roomVo,EGroupDefinedDataType.ANCHOR_STATUS,"ONLINE");
 
         return roomVo;
     }
 
-    private void setGroupDefinedData( ImLiveBroadcastRoomVo roomVo,Boolean onlineStatus) {
+    private void setGroupDefinedData(ImLiveBroadcastRoomVo roomVo, EGroupDefinedDataType type, String value) {
         List<TencentRequest.ChatRoomGroupDefinedData> appDefinedData = new ArrayList<>();
         appDefinedData.add(TencentRequest.ChatRoomGroupDefinedData.builder()
-                                                                  .key("ANCHOR_STATUS")
-                                                                  .value(onlineStatus?"ONLINE":"OFFLINE")
+                                                                  .key(type.getCode())
+                                                                  .value(value)
                                                                   .build());
         try {
             livePluginContext.getPluginService(roomVo.getServiceProvider())
@@ -1235,6 +1254,18 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             log.info("opsRoom>>>> joinRoom error roomUid: {}", roomUid);
             return;
         }
+
+        // 判断用户机构是否有权限进入该直播间
+        SysUser sysUser = sysUserFeignService.queryUserById(userId);
+        if (Objects.isNull(sysUser)) {
+            log.info("opsRoom>>>> joinRoom user null error userId: {}", userId);
+            return;
+        }
+        if (!sysUser.getTenantId().equals(imLiveBroadcastRoomVo.getTenantId())) {
+            log.info("opsRoom>>>> joinRoom error tenant diff userId: {}, tenantId: {}", userId, sysUser.getTenantId());
+            throw new BizException("当前用户所在机构没有加入直播间的权限");
+        }
+
         //记录用户当前房间uid
         redissonClient.getBucket(LIVE_USER_ROOM.replace(USER_ID, userId.toString())).set(roomUid, 12L, TimeUnit.HOURS);
         //房间累计用户信息-指只要进入到该房间的用户都要记录
@@ -1572,6 +1603,18 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
             //推送直播开始消息
             this.sendRoomLiveState(sysUser, room, MessageTypeEnum.JIGUANG_LIVE_STARTED);
 
+            // 查询黑名单人员
+            List<ImLiveRoomBlack> blackList = imLiveRoomBlackService.lambdaQuery()
+                .eq(ImLiveRoomBlack::getRoomUid, room.getRoomUid())
+                .list();
+
+            ImLiveBroadcastRoomVo roomVo = getImLiveBroadcastRoomVo(room.getRoomUid());
+            if (CollectionUtils.isNotEmpty(blackList)) {
+                // 将黑名单人员踢出房间
+                for (ImLiveRoomBlack black : blackList) {
+                    imLiveRoomBlackService.setBlack(black.getUserId(),roomVo);
+                }
+            }
         } catch (Exception e) {
             log.error(">>>>>>>>>> createLiveRoom error roomUid:{} msg:{}", room.getRoomUid(), e.getMessage());
         }
@@ -1686,6 +1729,15 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         roomVo.setTotalLookNum(getNum.apply(this::getTotalUserCache, roomVo.getRoomUid()));
         //在房间观看用户数量
         roomVo.setLookNum(getNum.apply(this::getOnlineUserCache, roomVo.getRoomUid()));
+
+
+        // 直播视频数
+        List<ImLiveRoomVideoVo> imLiveRoomVideoVos = imLiveRoomVideoService.queryList(roomVo.getRoomUid());
+        if (CollectionUtils.isNotEmpty(imLiveRoomVideoVos)) {
+            roomVo.setVideoNum(imLiveRoomVideoVos.size());
+        } else {
+            roomVo.setVideoNum(0);
+        }
     }
 
     /**
@@ -1924,6 +1976,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         imLiveBroadcastRoom.setSpeakerStatus(liveRoom.getSpeakerStatus());
         imLiveBroadcastRoom.setPushStatus(liveRoom.getPushStatus());
         imLiveBroadcastRoom.setBanStatus(liveRoom.getBanStatus());
+        whetherChat(room.getId(), liveRoom.getBanStatus());
         // 不用前端传时间
         // imLiveBroadcastRoom.setLiveTotalTime(liveRoom.getLiveTotalTime());
 

+ 30 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveRoomBlackServiceImpl.java

@@ -96,18 +96,40 @@ public class ImLiveRoomBlackServiceImpl extends ServiceImpl<ImLiveRoomBlackDao,
             imLiveRoomBlack.setCreateTime(new Date());
             this.save(imLiveRoomBlack);
             ImLiveBroadcastRoomVo roomVo = imLiveBroadcastRoomService.queryRoomInfo(roomUid);
-            //发送消息到直播房间
-            this.sendBlackMsg(roomVo, userId, userId, ImRoomMessage.BLOCK_BLACK_USER);
-            //调用融云方法加入禁言
-            LivePluginService pluginService = livePluginContext.getPluginService(roomVo.getServiceProvider());
-            try {
-                pluginService.chatRoomUserGagCreate(userIdStr, roomUid, -1L);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+            if (roomVo == null) {
+                throw new BizException("直播房间不存在");
+            }
+            if (roomVo.getLiveState() != 1) {
+                log.info("直播房间未开播,不需要发送消息");
+                return;
             }
+            setBlack( userId, roomVo);
         });
     }
 
+    @Override
+    public void setBlack(Integer userId, ImLiveBroadcastRoomVo roomVo) {
+        //发送消息到直播房间
+        this.sendBlackMsg(roomVo, userId, userId, ImRoomMessage.BLOCK_BLACK_USER);
+        //调用融云方法加入禁言
+        LivePluginService pluginService = livePluginContext.getPluginService(roomVo.getServiceProvider());
+        try {
+
+            SysUser sysUser = sysUserFeignService.queryUserById(userId);
+            if (sysUser == null) {
+                log.error("用户不存在");
+                return;
+            }
+
+            // 注册主播用户信息到三方平台
+            pluginService.register(sysUser.getId().toString(), sysUser.getUsername(), sysUser.getAvatar());
+
+            pluginService.chatRoomUserGagCreate(userId.toString(), roomVo.getRoomUid(),-1L);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     /**
      * 删除该用户从房间黑名单中移除
      *

+ 27 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveRoomVideoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Maps;
 import com.ym.mec.biz.dal.dao.ImLiveRoomVideoDao;
 import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
 import com.ym.mec.biz.dal.vo.ImLiveRoomVideoVo;
@@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 直播视频记录(ImLiveRoomVideo)表服务实现类
@@ -32,5 +34,30 @@ public class ImLiveRoomVideoServiceImpl extends ServiceImpl<ImLiveRoomVideoDao,
         return baseMapper.queryVideoList(roomUid);
     }
 
+    /**
+     * 直播间的视频数
+     *
+     * @param roomIdList 直播间id
+     */
+    @Override
+    public Map<String, Integer> queryRoomUidCountMap(List<String> roomIdList) {
+        if (roomIdList == null || roomIdList.isEmpty()) {
+            return Maps.newHashMap();
+        }
+        List<ImLiveRoomVideo> list = this.lambdaQuery().in(ImLiveRoomVideo::getRoomUid, roomIdList).list();
+        Map<String, Integer> map = Maps.newHashMap();
+        for (ImLiveRoomVideo imLiveRoomVideo : list) {
+            String roomUid = imLiveRoomVideo.getRoomUid();
+            Integer count = map.get(roomUid);
+            if (count == null) {
+                count = 0;
+            }
+            map.put(roomUid, count + 1);
+        }
+        return map;
+
+
+    }
+
 }
 

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MemberRankSettingServiceImpl.java

@@ -381,6 +381,7 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
                 filter(e -> Arrays.stream(e.getOrganId().split(",")).collect(Collectors.toList()).contains(sysUser.getOrganId().toString())).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(activityDtos)){
             succeed.setMsg("当前分部暂未开通活动");
+            succeed.setData(2);
             return succeed;
         }
         if(memberPayParamDto.getLiveGoodsId() == 1 || memberPayParamDto.getLiveGoodsId() == 5){

+ 1 - 0
mec-biz/src/main/resources/config/mybatis/ImLiveBroadcastRoomMapper.xml

@@ -74,6 +74,7 @@
                 AND (
                 a.`id_` LIKE CONCAT('%', #{param.search},'%')
                 OR a.`room_title_` LIKE CONCAT('%', #{param.search},'%')
+                OR a.`live_remark_` LIKE CONCAT('%', #{param.search},'%')
                 )
             </if>
             <if test="param.tenantId != null ">

+ 24 - 0
mec-im/src/main/java/com/ym/controller/UserController.java

@@ -22,9 +22,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import static com.ym.mec.common.controller.BaseController.succeed;
+
 @RestController
 @RequestMapping("/user")
 public class UserController {
@@ -61,6 +64,19 @@ public class UserController {
     }
 
 
+
+    /**
+     * 监听融云用户状态变更
+     *
+     * @param userState List<ImUserState>
+     */
+    @PostMapping(value = "/update/statusImUser")
+    public Object updateStatusImUser(@RequestBody List<ImUserState> userState) {
+        log.info("statusImUser >>>>> : {}", JSONObject.toJSONString(userState));
+        imLiveBroadcastRoomService.opsRoom(userState);
+        return succeed();
+    }
+
     @ApiOperation("腾讯im 回调接口")
     @PostMapping(value = "/tencentImCallback")
     public TencentImCallbackResult tencentImCallback(@RequestBody String body, HttpServletRequest request) {
@@ -126,6 +142,10 @@ public class UserController {
 
         TencentData.CallbackStreamStateEvent event = TencentData.CallbackStreamStateEvent.from(body);
 
+        List<ImUserState> userState = new ArrayList<>();
+        ImUserState imUserState = new ImUserState();
+        userState.add(imUserState);
+        imUserState.setUserid(getSpeakerId(event.getStreamId()).toString());
         // 断流事件通知
         if (event.getEventType() == 0) {
 
@@ -134,6 +154,7 @@ public class UserController {
                 // 更新直播推流时长
                 imLiveBroadcastRoomService.updateLiveRoomPushStreamTime(event);
             }
+            imUserState.setStatus("3");
 
             // 自动关闭录制
             imLiveBroadcastRoomService.closeLive(getRoomUid(event.getStreamId()), getSpeakerId(event.getStreamId()));
@@ -143,8 +164,11 @@ public class UserController {
         if (event.getEventType() == 1) {
             // 自动开启录制
             imLiveBroadcastRoomService.startLive(getRoomUid(event.getStreamId()), getSpeakerId(event.getStreamId()), null);
+
+            imUserState.setStatus("0");
         }
 
+        imLiveBroadcastRoomService.opsRoom(userState);
         return TencentData.StreamEventCallbackResult.builder().code(0).build();
     }
 

+ 32 - 0
mec-student/src/main/java/com/ym/mec/student/controller/StudentImLiveRoomVideoController.java

@@ -0,0 +1,32 @@
+package com.ym.mec.student.controller;
+
+import com.ym.mec.biz.dal.vo.ImLiveRoomVideoVo;
+import com.ym.mec.biz.service.ImLiveRoomVideoService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Api(tags = "直播回放录像记录表")
+@RestController
+@RequestMapping("/imLiveRoomVideo")
+public class StudentImLiveRoomVideoController extends BaseController {
+
+    /**
+     * 服务对象
+     */
+    @Resource
+    private ImLiveRoomVideoService imLiveRoomVideoService;
+
+    @ApiOperation("查询该机构目前推广的直播间")
+    @GetMapping(value = "/queryList")
+    public HttpResponseResult<List<ImLiveRoomVideoVo>> queryList(String roomUid) {
+        return succeed(imLiveRoomVideoService.queryList(roomUid));
+    }
+}

+ 4 - 0
mec-teacher/pom.xml

@@ -65,6 +65,10 @@
 			<artifactId>easy-captcha</artifactId>
 			<version>1.6.2</version>
 		</dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
     </dependencies>
 	<build>
 		<plugins>

+ 18 - 1
mec-web/src/main/java/com/ym/mec/web/controller/ImLiveBroadcastRoomController.java

@@ -98,7 +98,7 @@ public class ImLiveBroadcastRoomController extends BaseController {
     @GetMapping("/queryRoom")
     public HttpResponseResult<ImLiveBroadcastRoomVo> queryRoomAndCheck(@ApiParam(value = "房间uid", required = true) String roomUid,
                                                                        @ApiParam(value = "用户id", required = true) Integer userId) {
-        return succeed(imLiveBroadcastRoomService.queryRoomAndCheck(roomUid, userId, null));
+        return succeed(imLiveBroadcastRoomService.queryRoomAndCheck(roomUid, userId, 3));
     }
 
     @ApiOperation("学生端-查询房间信息")
@@ -150,6 +150,14 @@ public class ImLiveBroadcastRoomController extends BaseController {
         return succeed();
     }
 
+
+    @ApiOperation("关闭直播间")
+    @GetMapping(value = "/roomDestroy")
+    public HttpResponseResult<Object> roomDestroy(@ApiParam(value = "房间Uid", required = true) String roomUid) {
+        imLiveBroadcastRoomService.roomDestroy(roomUid);
+        return succeed();
+    }
+
     @ApiImplicitParams({
             @ApiImplicitParam(name = "id", dataType = "Integer", value = "房间id"),
     })
@@ -270,5 +278,14 @@ public class ImLiveBroadcastRoomController extends BaseController {
         imLiveBroadcastRoomService.userWhetherMic(roomUid,userId,whetherMicStatus);
         return succeed();
     }
+
+
+    @ApiOperation("设置是否允许连麦")
+    @GetMapping("/whetherMic")
+    public HttpResponseResult<Object> whetherMic(@ApiParam(value = "房间uid", required = true) String roomUid,
+                                                 @ApiParam(value = "是否连麦 0:是 1否", required = true) Integer whetherMic) {
+        imLiveBroadcastRoomService.whetherMic(roomUid,whetherMic);
+        return succeed();
+    }
 }
 

+ 1 - 2
mec-student/src/main/java/com/ym/mec/student/controller/ImLiveRoomVideoController.java → mec-web/src/main/java/com/ym/mec/web/controller/ImLiveRoomVideoController.java

@@ -1,6 +1,5 @@
-package com.ym.mec.student.controller;
+package com.ym.mec.web.controller;
 
-import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
 import com.ym.mec.biz.dal.vo.ImLiveRoomVideoVo;
 import com.ym.mec.biz.service.ImLiveRoomVideoService;
 import com.ym.mec.common.controller.BaseController;