From 3970ced88b5b456f03fe277c254ca761f05492e0 Mon Sep 17 00:00:00 2001
From: yn147 <2270338776@qq.com>
Date: 星期四, 26 十月 2023 14:00:12 +0800
Subject: [PATCH] 直播是否发布门户

---
 src/main/java/com/qxueyou/scc/controller/VideoLiveController.java |  112 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 89 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/qxueyou/scc/controller/VideoLiveController.java b/src/main/java/com/qxueyou/scc/controller/VideoLiveController.java
index f18bac9..2caa80a 100644
--- a/src/main/java/com/qxueyou/scc/controller/VideoLiveController.java
+++ b/src/main/java/com/qxueyou/scc/controller/VideoLiveController.java
@@ -2,15 +2,22 @@
 
 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;
@@ -30,11 +37,14 @@
 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 {
@@ -54,7 +64,12 @@
 	
 	@Autowired
 	MediaLiveDAO dao;
-	
+
+	@Autowired
+    CommonDAO commonDAO;
+
+	@Autowired
+	private RedisCache redisCache;
 	/**
 	 * 鑾峰彇鐩存挱鍒楄〃
 	 * 
@@ -68,9 +83,9 @@
 	 */
 	@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, 
@@ -87,10 +102,19 @@
 						"pushUrl","rtmpPushUrl",
 						"hlsPullUrl","hlsPullUrl",
 						"previewImgUrl","previewImgUrl",
-						"courseId","courseId"
+						"courseId","courseId",
+						"portalStatus","portalStatus"
 						))));
 	}
 
+	@ApiOperation(value = "鑾峰彇宸茬粨鏉熺洿鎾垪琛�")
+	@GetMapping(value = "listvideo")
+	public Result listvideo() {
+
+		List<MediaVideoLive> data = liveService.listvideo("9");
+
+		return new Result(true, "success", CollectionUtils.newObjectMap("listVideo",data));
+	}
 	/**
 	 * 鏂板鐩存挱/鏇存柊鐩存挱
 	 * 
@@ -115,7 +139,7 @@
 	@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);
@@ -126,48 +150,90 @@
 		options.put("modetype", 6);
 		//灏唋ong绫诲瀷杞崲涓篠tring绫诲瀷
 		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-		simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
 		String startTime1 = simpleDateFormat.format(new Date(startTime));
 		String endTime1 = simpleDateFormat.format(new Date(endTime));
+        System.out.println(startTime1+"------"+endTime1);
 		//璋冪敤绗笁鏂圭洿鎾帴鍙�
 		String s = client.courseAdd(name, ClientUtils.getUserId(), startTime1, endTime1, ClientUtils.getUserName(), "222", options);
 		//json杞崲鎷垮埌courseId
 		JSONObject jsonObject = JSON.parseObject(s);
 		JSONObject data = jsonObject.getJSONObject("data");
-		String course_id = (String) data.get("course_id");
-//		System.out.println(Integer.parseInt(course_id));
-		if(Nature.s !=null) {
-			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(",")));
+		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(",")),portalStatus);
 			return new Result(true, "鎴愬姛", s);
 		}
-		return new Result(false);
+		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);
-		JSONObject data = jsonObject.getJSONObject("data");
-		String protocol = (String) data.get("url");
-		return new Result(true,"寮�鍚垚鍔�",protocol);
+		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 = "鍦ㄧ嚎鏃堕暱")
+    @ApiOperation(value = "淇敼鐩存挱鐘舵��")
+    @GetMapping(value = "updateLive")
+    public Result updateLive(Integer courseId)  {
+
+        MediaVideoLive revamp = liveService.revamp(courseId);
+        revamp.setStatus(MediaVideoLive.STATUS_LIVE_STOP);
+        commonDAO.update(revamp);
+
+        return new Result(true,"鍏抽棴鎴愬姛");
+    }
+
+    @ApiOperation(value = "鍦ㄧ嚎鏃堕暱")
 	@GetMapping(value = "onlineCommunication")
 	public Result onlineCommunication(String courseId,Integer page, Integer size) throws Exception {
 		MTCloud client = new MTCloud();
 		HashMap<Object,Object> options = new HashMap<Object, Object>();
 		options.put("ssl", false);
-		String res = client.courseVisitorList("3360573",10,1,options);
+		String res = client.courseVisitorList(courseId,page,size,options);
 		return new Result(true,"寮�鍚垚鍔�",res);
 	}
+
+//	@ApiOperation(value = "鏌ョ湅璇︽儏")
+//	@GetMapping(value = "detailLive")
+//	public Result detailLive(String liveId) {
+//		commonDAO.find
+//		return new Result(true,"寮�鍚垚鍔�",res);
+//	}
 	/**
 	 * 鏌ヨ鐩存挱璇︽儏
 	 * 

--
Gitblit v1.8.0