Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

liaoyongfei 4 anni fa
parent
commit
affd5933b2

+ 45 - 13
ymall/src/main/java/com/liangjian11/ymall/controller/video/VideoDoctorController.java

@@ -8,10 +8,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.liangjian11.ymall.model.Doctor;
 import com.liangjian11.ymall.model.UserAccount;
 import com.liangjian11.ymall.model.video.Video;
-import com.liangjian11.ymall.model.video.event.StreamTranscodeComplete;
 import com.liangjian11.ymall.service.DoctorService;
 import com.liangjian11.ymall.service.UserAccountService;
 import com.liangjian11.ymall.service.video.VideoService;
+import com.liangjian11.ymall.utils.MongoDBUtil;
 import com.liangjian11.ymall.utils.RequestUtil;
 import com.liangjian11.ymall.utils.ResultInfo;
 import com.liangjian11.ymall.utils.video.DTO.DoctorVideoDTO;
@@ -23,6 +23,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang.StringUtils;
+import org.bson.Document;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -51,16 +52,28 @@ public class VideoDoctorController {
   @Value("${domain.ymall}")
   private String domain;
 
-  public Doctor getUser(HttpServletRequest request) {
+  public String getUser(HttpServletRequest request) {
     String userId = null;
     Cookie[] cookies = request.getCookies();
-    for (Cookie cookie : cookies) {
-      if (cookie.getName().equals("loginTokenAccount")) {
-        userId = cookie.getValue();
+    if (cookies != null) {
+      for (Cookie cookie : cookies) {
+        if (cookie.getName().equals("loginTokenAccount")) {
+          userId = cookie.getValue();
+        }
+      }
+    } else {
+      String token = RequestUtil.getRequest().getHeader("token");
+      Document document = MongoDBUtil.queryVLoginTokenByToken(token);
+      if (!Objects.isNull(document)) {
+        Date expirationDate = (Date) document.get("ExpirationDate");
+        if (expirationDate.compareTo(new Date()) <= 0) {
+          return "timeout";
+        }
+        userId = (String) document.get("AccountId");
       }
     }
     if (!StringUtils.isEmpty(userId) && userAccountService.count(new QueryWrapper<UserAccount>().eq("id::varchar(100)", userId)) > 0) {
-      return doctorService.getDoctorByUserId(userId);
+      return userId;
     }
     return null;
   }
@@ -86,7 +99,14 @@ public class VideoDoctorController {
   @PostMapping("/UploadFileByDoctor")
   @ApiOperation(value = "上传视频归属到医生")
   public PageResultInfo UploadFileByDoctor(@ApiParam(value = "Video对象") @RequestBody DoctorVideoDTO dto) {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }
@@ -101,10 +121,10 @@ public class VideoDoctorController {
     video.setUserAccountID(doctor.getAccountID());
     video.setSource(2);
     video.setVideoId(dto.getVideoId());
-    if(dto.getVideoTitle().contains(".")){
-      video.setVideoTitle(dto.getVideoTitle().substring(0, dto.getVideoTitle().lastIndexOf(".")).replaceAll(" ",""));
-    }else{
-      video.setVideoTitle(dto.getVideoTitle().replaceAll(" ",""));
+    if (dto.getVideoTitle().contains(".")) {
+      video.setVideoTitle(dto.getVideoTitle().substring(0, dto.getVideoTitle().lastIndexOf(".")).replaceAll(" ", ""));
+    } else {
+      video.setVideoTitle(dto.getVideoTitle().replaceAll(" ", ""));
     }
     video.setVideoType("mp4");
     video.setVideoSize(dto.getVideoSize());
@@ -125,7 +145,13 @@ public class VideoDoctorController {
   @PostMapping("/GetMyVideoListByTranscoding")
   @ApiOperation(value = "获取医生作品列表 正在转码的列表")
   public PageResultInfo<List<Video>> GetMyVideoListByTranscoding(@ApiParam(value = "selectDTO对象") @RequestBody SelectDTO selectDTO) {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }
@@ -135,7 +161,13 @@ public class VideoDoctorController {
   @PostMapping("/GetMyVideoList")
   @ApiOperation(value = "获取医生作品列表")
   public PageResultInfo<List<Video>> GetMyVideoList(@ApiParam(value = "selectDTO对象") @RequestBody SelectDTO selectDTO) throws Exception {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }

+ 53 - 11
ymall/src/main/java/com/liangjian11/ymall/controller/video/VideoUserController.java

@@ -7,6 +7,7 @@ import com.liangjian11.ymall.model.UserAccount;
 import com.liangjian11.ymall.model.video.*;
 import com.liangjian11.ymall.service.UserAccountService;
 import com.liangjian11.ymall.service.video.*;
+import com.liangjian11.ymall.utils.MongoDBUtil;
 import com.liangjian11.ymall.utils.RequestUtil;
 import com.liangjian11.ymall.utils.video.DTO.DoctorDTO;
 import com.liangjian11.ymall.utils.video.DTO.PageResultInfo;
@@ -16,6 +17,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang.StringUtils;
+import org.bson.Document;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -49,14 +51,26 @@ public class VideoUserController {
   private VideoHotsearchService videoHotsearchService;
 
   public String getUser(HttpServletRequest request) {
-    String userId =null;
+    String userId = null;
     Cookie[] cookies = request.getCookies();
-    for (Cookie cookie : cookies) {
-      if (cookie.getName().equals("loginTokenAccount")) {
-        userId = cookie.getValue();
+    if (cookies != null) {
+      for (Cookie cookie : cookies) {
+        if (cookie.getName().equals("loginTokenAccount")) {
+          userId = cookie.getValue();
+        }
+      }
+    } else {
+      String token = RequestUtil.getRequest().getHeader("token");
+      Document document = MongoDBUtil.queryVLoginTokenByToken(token);
+      if (!Objects.isNull(document)) {
+        Date expirationDate = (Date) document.get("ExpirationDate");
+        if (expirationDate.compareTo(new Date()) <= 0) {
+          return "timeout";
+        }
+        userId = (String) document.get("AccountId");
       }
     }
-    if(!StringUtils.isEmpty(userId) && userAccountService.count(new QueryWrapper<UserAccount>().eq("id::varchar(100)",userId))>0){
+    if (!StringUtils.isEmpty(userId) && userAccountService.count(new QueryWrapper<UserAccount>().eq("id::varchar(100)", userId)) > 0) {
       return userId;
     }
     return null;
@@ -69,6 +83,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.listVideoByHome(userId, selectDTO);
   }
@@ -87,6 +103,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.listVideoByHomePage(userId, selectDTO);
   }
@@ -99,6 +117,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (video.getId() != null) {
       video = videoService.getPlayInfo(video.getId(), userId);
@@ -113,8 +133,10 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
-    if(!StringUtils.isEmpty(selectDTO.getName())){
+    if (!StringUtils.isEmpty(selectDTO.getName())) {
       VideoHotsearch videoHotsearch = new VideoHotsearch();
       videoHotsearch.setSuperiorName(selectDTO.getName());
       videoHotsearch.setSubordinateID(userId);
@@ -136,6 +158,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.getDoctorVideoPage(userId, selectDTO);
   }
@@ -154,6 +178,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoUserAttentionService.getUserFollowList(userId, selectDTO);
   }
@@ -164,6 +190,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.getMyLikeList(userId, selectDTO);
   }
@@ -175,10 +203,12 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     VideoStatisticsIntermediate oldPlayLog = videoStatisticsIntermediateService.getOne(new QueryWrapper<VideoStatisticsIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId));
-    VideoStatisticsIntermediate playLog =  null;
-    if(Objects.isNull(oldPlayLog)){
+    VideoStatisticsIntermediate playLog = null;
+    if (Objects.isNull(oldPlayLog)) {
       playLog = new VideoStatisticsIntermediate();
       playLog.setSuperiorID(video.getId());
       playLog.setSubordinateID(userId);
@@ -188,7 +218,7 @@ public class VideoUserController {
       playLog.setType(7);
       playLog.setCreateTime(new Date());
       playLog.setUpdateTime(playLog.getCreateTime());
-    }else{
+    } else {
       playLog = oldPlayLog;
       playLog.setUpdateTime(new Date());
     }
@@ -206,8 +236,10 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
-    if(videoLikeIntermediateService.count(new QueryWrapper<VideoLikeIntermediate>().eq("superior_id",video.getId()).eq("subordinate_id",userId))>0){
+    if (videoLikeIntermediateService.count(new QueryWrapper<VideoLikeIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId)) > 0) {
       return PageResultInfo.createFail("保存失败,已有用户点赞记录");
     }
     VideoLikeIntermediate likeLog = new VideoLikeIntermediate();
@@ -234,6 +266,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoLikeIntermediateService.remove(new QueryWrapper<VideoLikeIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId))) {
       return PageResultInfo.createSuccess("用户取消点赞成功", null);
@@ -249,6 +283,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     VideoStatisticsIntermediate shareLog = new VideoStatisticsIntermediate();
     shareLog.setSuperiorID(video.getId());
@@ -273,8 +309,10 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
-    if(videoUserAttentionService.count(new QueryWrapper<VideoUserAttention>().eq("superior_id",doctor.getId()).eq("subordinate_id",userId))>0){
+    if (videoUserAttentionService.count(new QueryWrapper<VideoUserAttention>().eq("superior_id", doctor.getId()).eq("subordinate_id", userId)) > 0) {
       return PageResultInfo.createFail("保存失败,已有用户关注该医生记录");
     }
     VideoUserAttention attentionLog = new VideoUserAttention();
@@ -300,6 +338,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoUserAttentionService.remove(new QueryWrapper<VideoUserAttention>().eq("superior_id", doctor.getId()).eq("subordinate_id", userId))) {
       return PageResultInfo.createSuccess("用户取关医生成功", null);
@@ -315,6 +355,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoCommentDTO.getVideoID() == null || StringUtils.isEmpty(videoCommentDTO.getContent())) {
       return PageResultInfo.createFail("缺少参数");

+ 13 - 0
ymall/src/main/java/com/liangjian11/ymall/utils/video/DTO/PageResultInfo.java

@@ -86,4 +86,17 @@ public class PageResultInfo<T> {
     return pageResultInfo;
   }
 
+
+  /**
+   * 创建token/cookies过期失败的消息提示
+   * @return
+   */
+  public static PageResultInfo createTimeOutFail(String message){
+    PageResultInfo pageResultInfo = new PageResultInfo();
+    pageResultInfo.setIsSuccess(false);
+    pageResultInfo.setResultCode(401);
+    pageResultInfo.setResultMsg(message);
+    return pageResultInfo;
+  }
+
 }