派生自 projectDept/qhighschool

胡仁荣
2023-08-04 2174b22bbbb45284765a23b8189df59583c65d29
src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
@@ -6,9 +6,12 @@
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;
@@ -31,6 +34,8 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
@Slf4j
@Api(tags="直播接口-学员端")
@@ -132,26 +137,29 @@
    * @return
    */
   @GetMapping(value = "view")
   public Result view(String couresId,String userId,String userName,String logId) throws Exception {
      AccessLog log=new AccessLog();
   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归属地信息失败!");
//         }
         log.setCourseId(couresId);
         log.setEnterTime(new Date());
         log.setType("guangxi");
         log.setName(userName);
//         log.setIp(ip);
//         log.setIpAttribution(cityInfo);
         commonDAO.save(log);
      }else {
         String liveUrl = redisCache.getCacheObject("LIVE_URL" + userId);
         return new Result(true, "success",liveUrl);
         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;
@@ -170,19 +178,35 @@
      JSONObject jsonObject = JSON.parseObject(res);
      if(jsonObject.getString("code").equals("0")){
         JSONObject data = jsonObject.getJSONObject("data");
         String liveUrl = (String) data.get("liveUrl");
         StringBuffer redisLiveUrl = new StringBuffer("LIVE_URL");
         redisLiveUrl=redisLiveUrl.append(userId);
         redisCache.setCacheObject(redisLiveUrl.toString(),liveUrl,5, TimeUnit.MINUTES);
         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="";