|  |  | 
 |  |  |  | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.concurrent.TimeUnit; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.alibaba.fastjson.JSONArray; | 
 |  |  | import com.alibaba.fastjson.JSONObject; | 
 |  |  | import com.hankcs.hanlp.corpus.tag.Nature; | 
 |  |  | import com.qxueyou.scc.base.dao.CommonDAO; | 
 |  |  | import com.qxueyou.scc.config.IpUtils; | 
 |  |  | import com.qxueyou.scc.sdk.MTCloud; | 
 |  |  | import com.qxueyou.scc.teach.live.model.AccessLog; | 
 |  |  | import com.qxueyou.scc.teach.live.utils.RedisCache; | 
 |  |  | import io.swagger.models.auth.In; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.http.HttpRequest; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import com.qxueyou.scc.admin.classes.model.ClsClass; | 
 |  |  | 
 |  |  | import io.swagger.annotations.ApiOperation; | 
 |  |  | import springfox.documentation.spring.web.json.Json; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletRequest; | 
 |  |  |  | 
 |  |  | import static com.hankcs.hanlp.corpus.tag.Nature.r; | 
 |  |  | import static com.hankcs.hanlp.corpus.tag.Nature.s; | 
 |  |  |  | 
 |  |  | @Api(tags="直播管理接口") | 
 |  |  | @RestController | 
 |  |  | @Slf4j | 
 |  |  | @CrossOrigin(origins="*",maxAge=3600) | 
 |  |  | @RequestMapping(value = "/admin/videoLive") | 
 |  |  | public class VideoLiveController { | 
 |  |  | 
 |  |  |  | 
 |  |  |    @Autowired | 
 |  |  |     CommonDAO commonDAO; | 
 |  |  | 	 | 
 |  |  |  | 
 |  |  |    @Autowired | 
 |  |  |    private RedisCache redisCache; | 
 |  |  |    /** | 
 |  |  |     * 获取直播列表 | 
 |  |  |     *  | 
 |  |  | 
 |  |  |     */ | 
 |  |  |    @ApiOperation(value = "获取创建人的直播列表") | 
 |  |  |    @GetMapping(value = "list") | 
 |  |  |    public Result list(String keyword, Integer pageNum, Integer pageSize) { | 
 |  |  |    public Result list(String keyword,String portalStatus, Integer pageNum, Integer pageSize) { | 
 |  |  |        | 
 |  |  |       List<MediaVideoLive> data = liveService.listOfMine(keyword, pageNum, pageSize); | 
 |  |  |       List<MediaVideoLive> data = liveService.listOfMine(keyword,portalStatus, pageNum, pageSize); | 
 |  |  |       int count = liveService.listCountOfMine(keyword); | 
 |  |  |  | 
 |  |  |       return new Result(true, "success", CollectionUtils.newObjectMap("videoLiveCount", count,  | 
 |  |  | 
 |  |  |                   "pushUrl","rtmpPushUrl", | 
 |  |  |                   "hlsPullUrl","hlsPullUrl", | 
 |  |  |                   "previewImgUrl","previewImgUrl", | 
 |  |  |                   "courseId","courseId" | 
 |  |  |                   "courseId","courseId", | 
 |  |  |                   "portalStatus","portalStatus" | 
 |  |  |                   )))); | 
 |  |  |    } | 
 |  |  |  | 
 |  |  | 
 |  |  |    @ApiOperation(value = "创建编辑直播") | 
 |  |  |    @PostMapping(value = "addOrUpdate") | 
 |  |  |    public Result addOrUpdate(String videoLiveId, String name, String content,String teacherId,String teacherName,String subjectId, | 
 |  |  |          String subjectName,String definition,String imgPath, long startTime,long endTime, boolean isPlayBack, String classIds) throws Exception { | 
 |  |  |          String subjectName,String definition,String imgPath, long startTime,long endTime, boolean isPlayBack, String classIds,String portalStatus) throws Exception { | 
 |  |  |       MTCloud client = new MTCloud(); | 
 |  |  |       HashMap<Object,Object> options = new HashMap<Object,Object>(); | 
 |  |  |       options.put("barrage", 1); | 
 |  |  | 
 |  |  |       //json转换拿到courseId | 
 |  |  |       JSONObject jsonObject = JSON.parseObject(s); | 
 |  |  |       JSONObject data = jsonObject.getJSONObject("data"); | 
 |  |  | //      System.out.println(Integer.parseInt(course_id)); | 
 |  |  |       if(jsonObject.getString("code").equals("0")) { | 
 |  |  |             String course_id = (String) data.get("course_id"); | 
 |  |  |          liveService.add(name, content,teacherId,teacherName,subjectId,subjectName,definition,imgPath, new Date(startTime), new Date(endTime),Integer.parseInt(course_id), isPlayBack, StringUtils.isEmpty(classIds)?null:CollectionUtils.newList(String.class,classIds.split(","))); | 
 |  |  |          liveService.add(name, content,teacherId,teacherName,subjectId,subjectName,definition,imgPath, new Date(startTime), new Date(endTime),Integer.parseInt(course_id), isPlayBack, StringUtils.isEmpty(classIds)?null:CollectionUtils.newList(String.class,classIds.split(",")),portalStatus); | 
 |  |  |          return new Result(true, "成功", s); | 
 |  |  |       } | 
 |  |  |       return new Result(false,jsonObject.getString("msg")); | 
 |  |  | 
 |  |  |  | 
 |  |  |    @ApiOperation(value = "开启直播") | 
 |  |  |    @GetMapping(value = "OpenLive") | 
 |  |  |    public Result OpenLive(int courseId) throws Exception { | 
 |  |  |    public Result OpenLive(Integer courseId, String logId, HttpServletRequest request) throws Exception { | 
 |  |  |       MTCloud client = new MTCloud(); | 
 |  |  |       String redisUrl = redisCache.getCacheObject("ZCR" + courseId); | 
 |  |  |       AccessLog accessLog = new AccessLog(); | 
 |  |  |  | 
 |  |  |       HashMap<Object,Object> options = new HashMap<Object, Object>(); | 
 |  |  |       options.put("ssl", false); | 
 |  |  |  | 
 |  |  |       String res = client.courseLogin(ClientUtils.getUserId(),MTCloud.ACCOUNT_TYPE_THIRD, options); | 
 |  |  |       System.out.println(res); | 
 |  |  |       JSONObject jsonObject = JSON.parseObject(res); | 
 |  |  |       if(jsonObject.getString("code").equals("0")){ | 
 |  |  |             JSONObject data = jsonObject.getJSONObject("data"); | 
 |  |  |             String protocol = (String) data.get("url"); | 
 |  |  |             return new Result(true,"开启成功",protocol); | 
 |  |  |         } | 
 |  |  |       return new Result(false,jsonObject.getString("msg")); | 
 |  |  |       if (StringUtils.isEmpty(logId)) { | 
 |  |  |          String ip = IpUtils.getIpAddr(request); | 
 |  |  |          String cityInfo = null; | 
 |  |  |          try { | 
 |  |  |             cityInfo = IpUtils.getCityInfo(ip); | 
 |  |  |          } catch (Exception e) { | 
 |  |  |             log.error("获取ip归属地信息失败!"); | 
 |  |  |          } | 
 |  |  |          accessLog.setCourseId(courseId.toString()); | 
 |  |  |          accessLog.setEnterTime(new Date()); | 
 |  |  |          accessLog.setType("videoLive"); | 
 |  |  |          accessLog.setName(ClientUtils.getUserName()); | 
 |  |  |          accessLog.setIp(ip); | 
 |  |  |          accessLog.setIpAttribution(cityInfo); | 
 |  |  |          accessLog.setCreateTime(new Date()); | 
 |  |  |          accessLog.setUpdateTime(new Date()); | 
 |  |  |          //访问留痕 | 
 |  |  |          commonDAO.save(accessLog); | 
 |  |  |       } | 
 |  |  |       if (StringUtils.isEmpty(redisUrl)) { | 
 |  |  |          HashMap<Object, Object> options = new HashMap<Object, Object>(); | 
 |  |  |          options.put("ssl", false); | 
 |  |  |          String res = client.courseLogin(ClientUtils.getUserId(), MTCloud.ACCOUNT_TYPE_THIRD, options); | 
 |  |  |          JSONObject jsonObject = JSON.parseObject(res); | 
 |  |  |          if (jsonObject.getString("code").equals("0")) { | 
 |  |  |             JSONObject data = jsonObject.getJSONObject("data"); | 
 |  |  |             String protocol = (String) data.get("url"); | 
 |  |  |             redisCache.setCacheObject("ZCR" + courseId, protocol, 1, TimeUnit.DAYS); | 
 |  |  |             return new Result(true,"suc", CollectionUtils.newObjectMap("url", protocol, "log", accessLog.getLogId())); | 
 |  |  |          } | 
 |  |  |       } | 
 |  |  |       return new Result(true,"suc",CollectionUtils.newObjectMap("url", redisUrl, "log", accessLog.getLogId())); | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |     @ApiOperation(value = "修改直播状态") |