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 liveIds = getLiveIdLst(StringUtils.isEmpty(classId)?ClientUtils.getClassId():classId); List lives = liveService.readByStatus(liveIds,_status); List> 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 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 getLiveIdLst(String classId) { List liveIds = new ArrayList(5); //»ñÈ¡°à¼¶ÁÐ±í¼°°à¼¶ËùÔÚÖ±²¥Áбí if(StringUtils.isNotEmpty(classId)) { liveIds = dao.getClassLives(classId); }else { //²éѯѧԱËùÔÚµÄÈ«²¿°à¼¶ List clsLst = classService.listMyClass(); Set ids = new HashSet(); 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() )); } }