派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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 org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.qxueyou.scc.admin.classes.model.ClsClass;
import com.qxueyou.scc.admin.classes.service.IClassService;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.teach.live.dao.MediaLiveDAO;
import com.qxueyou.scc.teach.live.model.MediaVideoLive;
import com.qxueyou.scc.teach.live.service.IMediaLiveService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
@Api(tags="Ö±²¥½Ó¿Ú-ѧԱ¶Ë")
@RestController
@RequestMapping(value = "/stu/live")
public class StuLiveController {
    
    @Autowired
    IClassService classService;
    
    @Autowired
    IMediaLiveService liveService;
    
    @Autowired
    MediaLiveDAO dao;
    
    private final static short[] PUBLIC_LIVE_STATUS = new short[] {
            MediaVideoLive.STATUS_LIVE_LIVE,MediaVideoLive.STATUS_LIVE_PAUSE,
            MediaVideoLive.STATUS_LIVE_STOP,MediaVideoLive.STATUS_LIVE_REVIEW
    };
    
    /**
     * »ñȡֱ²¥Áбí
     * @param classId °à¼¶id
     * @return
     */
    @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"),
    })
    @GetMapping(value = "list")
    public Result list(String classId, Short status) {
        short[] _status = null;
        if(status == null || status == 0) {
            _status = PUBLIC_LIVE_STATUS;
        }else {
            _status = new short[]{status};
        }
        
        List<String> liveIds = getLiveIdLst(StringUtils.isEmpty(classId)?ClientUtils.getClassId():classId);
 
        List<MediaVideoLive> lives = liveService.readByStatus(liveIds,_status);
        
        List<Map<String,Object>> lst =QBeanUtils.listBean2ListMap(lives, CollectionUtils.newStringMap(
                "creator","creator",
                "startTime","startTime",
                "endTime","endTime",
                "updateTime","lastUpdateTime",
                "videoLiveId","videoLiveId",
                "name","name",
                "status","status",
                "hlsPullUrl","hlsPullUrl",
                "previewImgUrl","imgPath"
                ));
        
        //Ìí¼ÓÁÄÌìÊÒid
        if(lst!=null && lst.size()>0){
            for(Map<String,Object> map:lst) {
                map.put("chatroomId", dao.getChatRoomId((String)map.get("videoLiveId")));
            }    
        }
        
        return new Result(true, "success", CollectionUtils.newObjectMap("liveCount", lst==null?0:lst.size(), "liveLst",lst));
    }
 
    /**
     * »ñȡֱ²¥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 { //²éѯѧԱËùÔÚµÄÈ«²¿°à¼¶
            List<ClsClass> clsLst = classService.listMyClass();
            Set<String> ids = new HashSet<String>();
            for(ClsClass cls:clsLst) {
                ids.addAll(dao.getClassLives(cls.getClassId()));
            }
            liveIds.addAll(ids);
        }
        return liveIds;
    }
    
    /**
     * ²é¿´Ö±²¥Ã÷ϸ
     * @param liveId Ö±²¥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()
                ));
    }
}