From 63c8bc319fd02d9f39b729f136fb3af01c773de1 Mon Sep 17 00:00:00 2001
From: yn147 <2270338776@qq.com>
Date: 星期六, 25 十一月 2023 14:27:14 +0800
Subject: [PATCH] 学籍导入、班级

---
 src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java |   81 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java b/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
index bdf1177..ca7e119 100644
--- a/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
+++ b/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
@@ -1,10 +1,18 @@
 package com.qxueyou.scc.stucontroller;
 
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.qxueyou.scc.base.dao.CommonDAO;
+import com.qxueyou.scc.base.model.Pager;
+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 com.qxueyou.scc.teach.student.model.StuStudent;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -27,6 +35,9 @@
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 
+import javax.servlet.http.HttpServletRequest;
+
+@Slf4j
 @Api(tags="鐩存挱鎺ュ彛-瀛﹀憳绔�")
 @RestController
 @CrossOrigin
@@ -41,6 +52,12 @@
 	
 	@Autowired
 	MediaLiveDAO dao;
+
+	@Autowired
+	RedisCache redisCache;
+
+	@Autowired
+	CommonDAO commonDAO;
 	
 	private final static short[] PUBLIC_LIVE_STATUS = new short[] {
 			MediaVideoLive.STATUS_LIVE_LIVE,MediaVideoLive.STATUS_LIVE_PAUSE,
@@ -120,31 +137,77 @@
 	 * @return
 	 */
 	@GetMapping(value = "view")
-	public Result view(String couresId,String userId,String userName) throws Exception {
-
-
+	public Result view(String couresId, String userId, String userName, String logId, HttpServletRequest request) throws Exception {
+		String redisLiveUrl = redisCache.getCacheObject("LIVE_URL" + userId);
+		AccessLog accessLog=new AccessLog();
+		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(couresId);
+			accessLog.setEnterTime(new Date());
+			accessLog.setType("guangxi");
+			accessLog.setName(userName);
+			accessLog.setIp(ip);
+			accessLog.setIpAttribution(cityInfo);
+			accessLog.setCreateTime(new Date());
+			accessLog.setUpdateTime(new Date());
+			commonDAO.save(accessLog);
+		}
+		if (!StringUtils.isEmpty(redisLiveUrl)){
+			return new Result(true, "success",CollectionUtils.newObjectMap("url",redisLiveUrl,"log",accessLog.getLogId()));
+		}
 		MTCloud client = new MTCloud();
-
+		String userRole = null;
 		HashMap<Object,Object> options = new HashMap<Object, Object>();
 		if(userId.equals("")){
 			userId= randomId();
 		}
+        if(userName.equals("") || userName==null){
+            userName= "娓稿";
+            userRole=MTCloud.ROLE_GUEST;
+        }else {
+			userRole=MTCloud.ROLE_USER;
+		}
+		options.put("ssl", true);
+		String res = client.courseAccess(couresId,userId,userName,userRole, 10000, options);
 
-		String res = client.courseAccess(couresId,userId,userName, MTCloud.ROLE_USER, 10000, options);
 		JSONObject jsonObject = JSON.parseObject(res);
-
 
 		if(jsonObject.getString("code").equals("0")){
 			JSONObject data = jsonObject.getJSONObject("data");
-
 			String liveUrl = (String) data.get("liveUrl");
-
-			return new Result(true, "success",liveUrl);
+			StringBuffer redisLiveKey = new StringBuffer("LIVE_URL");
+			redisLiveKey.append(userId);
+			redisCache.setCacheObject(redisLiveKey.toString(),liveUrl,5, TimeUnit.MINUTES);
+			return new Result(true, "success",CollectionUtils.newObjectMap("url",liveUrl,"log",accessLog.getLogId()));
 		}
 
 		return new Result(false, jsonObject.getString("msg"));
 	}
 
+	@ApiOperation(value = "绂诲紑璺紨鐩存挱闂�")
+	@GetMapping(value = "leaveRoadShow")
+	public Result enterIntoRoadShow(String logId)  {
+//		System.out.println(logId);
+		if(!StringUtils.isEmpty(logId)){
+			StringBuffer hql=new StringBuffer("from AccessLog where logId=?");
+			List<Object> args = CollectionUtils.newList(logId);
+			AccessLog accessLogs = commonDAO.findUnique(hql.toString(), args, AccessLog.class);
+//			System.out.println(accessLogs);
+			accessLogs.setLeaveTime(new Date());
+			accessLogs.setUpdateTime(new Date());
+			commonDAO.update(accessLogs);
+			return new Result(true,"閫�鍑烘垚鍔�");
+		}
+		return new Result(false,"logId涓嶈兘涓虹┖");
+	}
+
+
 	public  String randomId() {
 			Random random=new Random();
 			String str="";

--
Gitblit v1.8.0