派生自 projectDept/qhighschool

EricsHu
2023-04-10 5196a1d1e00ced009a2d4e8ea0aa5f3bb7cefe33
src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
@@ -1,11 +1,10 @@
package com.qxueyou.scc.stucontroller;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qxueyou.scc.sdk.MTCloud;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -27,7 +26,7 @@
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags="直播接口-学员端")
@Api(tags="直播接口-学员端")
@RestController
@RequestMapping(value = "/stu/live")
public class StuLiveController {
@@ -47,14 +46,14 @@
   };
   
   /**
    * 获取直播列表
    * @param classId 班级id
    * 获取直播列表
    * @param classId 班级id
    * @return
    */
   @ApiOperation(value = "获取直播列表", notes = "")
   @ApiOperation(value = "获取直播列表", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "直播状态(2正在直播,5直播中的暂停状态,9停止直播,3回放)", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "直播状态(2正在直播,5直播中的暂停状态,9停止直播,3回放)", required = true, paramType="query", dataType = "String"),
    })
   @GetMapping(value = "list")
   public Result list(String classId, Short status) {
@@ -81,7 +80,7 @@
            "previewImgUrl","imgPath"
            ));
      
      //添加聊天室id
      //添加聊天室id
      if(lst!=null && lst.size()>0){
         for(Map<String,Object> map:lst) {
            map.put("chatroomId", dao.getChatRoomId((String)map.get("videoLiveId")));
@@ -92,17 +91,17 @@
   }
   /**
    * 获取直播id
    * 获取直播id
    * @param classId
    * @return
    */
   private List<String> getLiveIdLst(String classId) {
      List<String> liveIds = new ArrayList<String>(5);
      //获取班级列表及班级所在直播列表
      //获取班级列表及班级所在直播列表
      if(StringUtils.isNotEmpty(classId)) {
         liveIds = dao.getClassLives(classId);
      }else { //查询学员所在的全部班级
      }else { //查询学员所在的全部班级
         List<ClsClass> clsLst = classService.listMyClass();
         Set<String> ids = new HashSet<String>();
         for(ClsClass cls:clsLst) {
@@ -114,23 +113,28 @@
   }
   
   /**
    * 查看直播明细
    * @param liveId 直播id
    * 查看直播明细
    * @param couresId 直播id
    * @return
    */
   @GetMapping(value = "view")
   public Result view(String liveId) {
      MediaVideoLive live = liveService.read(liveId);
      return new Result(true, "success", CollectionUtils.newObjectMap(
            "startTime",live.getStartTime(),
            "endTime",live.getEndTime(),
            "name",live.getName(),
            "hlsPullUrl",live.getHlsPullUrl(),
            "imgPath",live.getPreviewImgUrl(),
            "chatroomId",dao.getChatRoomId(liveId),
            "remark",live.getRemark()
            ));
   public Result view(String couresId) throws Exception {
      MTCloud client = new MTCloud();
      HashMap<Object,Object> options = new HashMap<Object, Object>();
      String res = client.courseAccess(couresId, ClientUtils.getUserId(), ClientUtils.getUserName(), MTCloud.ROLE_USER, 10000, options);
      JSONObject jsonObject = JSON.parseObject(res);
      JSONObject data = jsonObject.getJSONObject("data");
      String liveUrl = (String) data.get("liveUrl");
      System.out.println(liveUrl);
      return new Result(true, "success",liveUrl);
   }
}