Ver código fonte

1、调整留存记录,视频排序记录

yys 5 dias atrás
pai
commit
d0234fa997

+ 7 - 3
fs-service/src/main/java/com/fs/course/mapper/FsUserVideoMapper.java

@@ -146,7 +146,7 @@ public interface FsUserVideoMapper
             "<if test = ' maps.keyword!=null and maps.keyword != \"\" '> " +
             "and v.title like CONCAT('%',#{maps.keyword},'%') " +
             "</if>" +
-            " order by RAND() "+
+            " order by v.create_time desc "+
             "</script>"})
     List<FsUserVideoListUVO> selectFsUserVideoListUVO(@Param("maps") FsUserVideoListUParam param);
 
@@ -264,7 +264,11 @@ public interface FsUserVideoMapper
     @Select({"<script> " +
             "select v.video_id as id,v.talent_id as talentId,t.user_id as userId,v.title,v.description as msg,t.nick_name as username,t.avatar as headImg, " +
             "v.thumbnail as cover,v.url as src,v.likes as likeNum,v.comments as smsNum,v.favorite_num as favoriteNum," +
-            "v.create_time,v.views as playNumber,v.product_id,p.img_url,p.package_name,v.upload_type,v.shares,v.add_num,v.is_audit,v.fail_reason,v.status from fs_user_video v " +
+            "v.create_time,v.views as playNumber,v.product_id,p.img_url,p.package_name,v.upload_type,v.shares,v.add_num,v.is_audit,v.fail_reason,v.status" +
+            "<if test = 'userId != null'> " +
+            ",CASE WHEN EXISTS (SELECT 1 FROM fs_user_talent_follow tf WHERE tf.talent_id = v.talent_id AND tf.user_id = #{userId}) THEN '1' ELSE '0' END as isFollow " +
+            "</if> " +
+            "from fs_user_video v " +
             "left join fs_user_talent t on t.talent_id = v.talent_id " +
             " left join fs_package p on p.package_id = v.product_id " +
             "where v.is_del = 0 and (" +
@@ -276,7 +280,7 @@ public interface FsUserVideoMapper
             " order by v.create_time" +
             "</if>" +
             "</script>"})
-    List<FsUserVideoListUVO> selectFsUserVideoListUVOByUser(@Param("talentId") Long talentId, @Param("oneSelf") boolean oneSelf);
+    List<FsUserVideoListUVO> selectFsUserVideoListUVOByUser(@Param("talentId") Long talentId, @Param("oneSelf") boolean oneSelf, @Param("userId") Long userId);
 
     // 评论数加一
     int addCommentCount(Long videoId);

+ 1 - 1
fs-service/src/main/java/com/fs/course/service/impl/FsUserVideoServiceImpl.java

@@ -381,7 +381,7 @@ public class FsUserVideoServiceImpl implements IFsUserVideoService {
 
     @Override
     public List<FsUserVideoListUVO> selectFsUserVideoListUVOByUser(Long talentId, boolean oneSelf, Long userId) {
-        List<FsUserVideoListUVO> list = fsUserVideoMapper.selectFsUserVideoListUVOByUser(talentId, oneSelf);
+        List<FsUserVideoListUVO> list = fsUserVideoMapper.selectFsUserVideoListUVOByUser(talentId, oneSelf, userId);
         if (list != null && !list.isEmpty() && userId != null) {
             list = selectLikesAndFavorites(userId, list);
         }

+ 10 - 4
fs-service/src/main/java/com/fs/live/service/ILiveConsoleOpLogService.java

@@ -4,11 +4,12 @@ import com.fs.live.domain.LiveConsoleOpLog;
 import com.fs.live.domain.LiveConsoleOpLogUser;
 import com.fs.live.domain.LiveCoupon;
 import com.fs.live.vo.LiveConsoleOpLogRecordVo;
+import com.fs.live.vo.LiveUserRewardRecordsVo;
 
 import java.util.List;
 
 /**
- * 直播??控台操作留存 Service
+ * 鐩存挱涓�帶鍙版搷浣滅暀瀛� Service
  */
 public interface ILiveConsoleOpLogService {
 
@@ -17,12 +18,12 @@ public interface ILiveConsoleOpLogService {
     LiveConsoleOpLog saveLog(Long liveId, Integer opType, Integer handleType, Long bizId, String bizName);
 
     /**
-     * ?齱???????棺???齱??д?????????????÷??????м??
+     * 鎶藉�缁撶畻鐣欏瓨锛氬悓涓€鎶藉�浠呭啓鍏ヤ竴鏉★紝閲嶅�璋冪敤杩斿洖宸叉湁璁板綍
      */
     LiveConsoleOpLog saveLotterySettleLog(Long liveId, Integer handleType, Long lotteryId, String bizName);
 
     /**
-     * \u7ea2\u5305\u7ed3\u7b97\u7559\u5b58\uff1a\u540c\u4e00\u7ea2\u5305\u4ec5\u5199\u5165\u4e00\u6761\uff0c\u91cd\u590d\u8c03\u7528\u8fd4\u56de\u5df2\u6709\u8bb0\u5f55
+     * 绾㈠寘缁撶畻鐣欏瓨锛氬悓涓€绾㈠寘浠呭啓鍏ヤ竴鏉★紝閲嶅�璋冪敤杩斿洖宸叉湁璁板綍
      */
     LiveConsoleOpLog saveRedSettleLog(Long liveId, Integer handleType, Long redId, String bizName);
 
@@ -37,7 +38,12 @@ public interface ILiveConsoleOpLogService {
     void bindOpLogUser(Long opLogId, Long liveId, Long userId, Long couponUserId);
 
     /**
-     * 查???用户在指定直播间的留存记录(含领取/结束状态)
+     * 鏌ヨ�鐢ㄦ埛鍦ㄦ寚瀹氱洿鎾�棿鐨勭暀瀛樿�褰曪紙鍚��鍙�/缁撴潫鐘舵€侊級
      */
     List<LiveConsoleOpLogRecordVo> listUserOpLogRecords(Long liveId, Long userId);
+
+    /**
+     * 鏌ヨ�鐢ㄦ埛鍦ㄦ寚瀹氱洿鎾�棿鐨勭暀瀛樿�褰曪紙鍚�椂闀夸俊鎭�級
+     */
+    LiveUserRewardRecordsVo getUserRewardRecords(Long liveId, Long userId);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/live/service/ILiveWatchUserService.java

@@ -158,6 +158,11 @@ public interface ILiveWatchUserService {
      */
     Long getTotalWatchDuration(Long liveId, Long userId);
 
+    /**
+     * 获取用户观看时长(秒),优先取 DB 与 Redis 较大值
+     */
+    Long getUserWatchDuration(Long liveId, Long userId);
+
     /**
      * 批量更新直播间观看用户
      * @param liveWatchUsers 需要更新的观看用户列表

+ 43 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveConsoleOpLogServiceImpl.java

@@ -5,6 +5,7 @@ import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.DictUtils;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.live.domain.Live;
 import com.fs.live.domain.LiveConsoleOpLog;
 import com.fs.live.domain.LiveConsoleOpLogUser;
 import com.fs.live.domain.LiveCoupon;
@@ -19,7 +20,10 @@ import com.fs.live.service.ILiveConsoleOpLogService;
 import com.fs.live.service.ILiveCouponIssueService;
 import com.fs.live.service.ILiveLotteryConfService;
 import com.fs.live.service.ILiveRedConfService;
+import com.fs.live.service.ILiveService;
+import com.fs.live.service.ILiveWatchUserService;
 import com.fs.live.vo.LiveConsoleOpLogRecordVo;
+import com.fs.live.vo.LiveUserRewardRecordsVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -33,6 +37,8 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 
 /**
  * 直播中控台操作留存 Service 实现
@@ -63,6 +69,12 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
     @Autowired
     private LiveCouponMapper liveCouponMapper;
 
+    @Autowired
+    private ILiveService liveService;
+
+    @Autowired
+    private ILiveWatchUserService liveWatchUserService;
+
     @Override
     public List<LiveConsoleOpLog> selectLiveConsoleOpLogList(LiveConsoleOpLog liveConsoleOpLog) {
         return liveConsoleOpLogMapper.selectLiveConsoleOpLogList(liveConsoleOpLog);
@@ -210,6 +222,37 @@ public class LiveConsoleOpLogServiceImpl implements ILiveConsoleOpLogService {
         return result;
     }
 
+    @Override
+    public LiveUserRewardRecordsVo getUserRewardRecords(Long liveId, Long userId) {
+        LiveUserRewardRecordsVo vo = new LiveUserRewardRecordsVo();
+        vo.setRecords(listUserOpLogRecords(liveId, userId));
+        vo.setLiveDuration(resolveLiveDuration(liveId));
+        vo.setWatchDuration(liveWatchUserService.getUserWatchDuration(liveId, userId));
+        return vo;
+    }
+
+    private Long resolveLiveDuration(Long liveId) {
+        if (liveId == null) {
+            return 0L;
+        }
+        Live live = liveService.selectLiveByLiveId(liveId);
+        if (live == null) {
+            return 0L;
+        }
+        if (live.getDuration() != null && live.getDuration() > 0) {
+            return live.getDuration();
+        }
+        if (live.getVideoDuration() != null && live.getVideoDuration() > 0) {
+            return live.getVideoDuration();
+        }
+        if (live.getStartTime() != null) {
+            LocalDateTime endTime = live.getFinishTime() != null ? live.getFinishTime() : LocalDateTime.now();
+            long seconds = ChronoUnit.SECONDS.between(live.getStartTime(), endTime);
+            return Math.max(seconds, 0L);
+        }
+        return 0L;
+    }
+
     /**
      * 状态优先级:已领取 > 已结束 > 待领取
      */

+ 17 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveWatchUserServiceImpl.java

@@ -1320,4 +1320,21 @@ public class LiveWatchUserServiceImpl implements ILiveWatchUserService {
         }
     }
 
+    @Override
+    public Long getUserWatchDuration(Long liveId, Long userId) {
+        Long total = getTotalWatchDuration(liveId, userId);
+        long dbDuration = total != null ? total : 0L;
+        try {
+            String hashKey = "live:watch:duration:hash:" + liveId;
+            Object redisValue = redisCache.hashGet(hashKey, String.valueOf(userId));
+            if (redisValue != null) {
+                long redisDuration = Long.parseLong(redisValue.toString());
+                return Math.max(dbDuration, redisDuration);
+            }
+        } catch (Exception e) {
+            log.debug("读取 Redis 观看时长失败: liveId={}, userId={}", liveId, userId, e);
+        }
+        return dbDuration;
+    }
+
 }

+ 21 - 0
fs-service/src/main/java/com/fs/live/vo/LiveUserRewardRecordsVo.java

@@ -0,0 +1,21 @@
+package com.fs.live.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * App 端用户直播间奖品留存查询结果
+ */
+@Data
+public class LiveUserRewardRecordsVo {
+
+    /** 留存记录列表 */
+    private List<LiveConsoleOpLogRecordVo> records;
+
+    /** 开播总时长(秒) */
+    private Long liveDuration;
+
+    /** 用户观看时长(秒,直播+回放,取 DB 与 Redis 较大值) */
+    private Long watchDuration;
+}

+ 0 - 8
fs-user-app/src/main/java/com/fs/app/controller/VideoController.java

@@ -40,8 +40,6 @@ public class VideoController extends  AppBaseController{
     @Autowired
     private IFsUserVideoViewService videoViewService;
 
-    @Autowired
-    private IRecommendationService recommendationService;
     @Autowired
     private IFsUserVideoTagsService fsUserVideoTagsService;
 
@@ -57,12 +55,6 @@ public class VideoController extends  AppBaseController{
         //添加假数据
 //        list = videoService.addNum(list);
         PageInfo<FsUserVideoListUVO> listPageInfo=new PageInfo<>(list);
-        if (param.getUserId() != null) {
-            // 对分页后的数据进行推荐排序
-            list = recommendationService.recommendVideos(param.getUserId(), list);
-             //更新PageInfo中的列表
-            listPageInfo.setList(list);
-        }
         if (param.getVideoId() != null && param.getPageNum()==1) {
             // 获取该 videoId 对应的视频数据
             FsUserVideoListUVO video = videoService.getVideoById(param.getVideoId());

+ 2 - 2
fs-user-app/src/main/java/com/fs/app/controller/live/LiveController.java

@@ -412,7 +412,7 @@ public class LiveController extends AppBaseController {
 	/**
 	 * 查询当前用户在当前直播间的奖品留存记录
 	 * @param liveId 直播间ID
-	 * @return 留存记录列表(含待领取/已领取/已结束状态
+	 * @return 留存记录及开播/观看时长(秒
 	 */
 	@Login
 	@ApiOperation("查询我的直播间奖品记录")
@@ -420,7 +420,7 @@ public class LiveController extends AppBaseController {
 	public R myRewardRecords(@RequestParam Long liveId) {
 		try {
 			Long userId = Long.valueOf(getUserId());
-			return R.ok().put("data", liveConsoleOpLogService.listUserOpLogRecords(liveId, userId));
+			return R.ok().put("data", liveConsoleOpLogService.getUserRewardRecords(liveId, userId));
 		} catch (Exception e) {
 			log.error("查询奖品留存记录失败, liveId={}, userId={}", liveId, getUserId(), e);
 			return R.error("查询奖品记录失败: " + e.getMessage());