xw před 1 dnem
rodič
revize
1a48332c01

+ 0 - 39
fs-live-app/src/main/java/com/fs/app/controller/live/LivePersonalizedPushController.java

@@ -1,39 +0,0 @@
-package com.fs.app.controller.live;
-
-import com.fs.common.core.controller.BaseController;
-import com.fs.common.core.domain.R;
-import com.fs.live.param.LiveWatchProgressParam;
-import com.fs.live.service.ILivePersonalizedPushService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 直播个性化推送Controller
- *
- * @author fs
- * @date 2025-01-19
- */
-@Api(tags = "直播录播进度上报")
-@RestController
-@RequestMapping("/app/live/replay")
-@Slf4j
-public class LivePersonalizedPushController extends BaseController {
-
-    @Autowired
-    private ILivePersonalizedPushService personalizedPushService;
-
-    /**
-     * 上报观看进度并获取需要展示的任务
-     */
-    @ApiOperation("上报观看进度")
-    @PostMapping("/reportProgress")
-    public R reportProgress(@RequestBody LiveWatchProgressParam param) {
-        return personalizedPushService.reportProgressAndGetTasks(param);
-    }
-}

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

@@ -295,9 +295,10 @@ public class LiveController extends AppBaseController {
 	@GetMapping("/currentActivities")
 	@Transactional
 	@Login
-	public R currentActivities(Long liveId) {
-/*		String userId = getUserId();
-		return liveService.currentActivities(liveId,userId);*/
+	public R currentActivities(Long liveId, Long currentProgress, Integer replayFlag) {
+		if (replayFlag != null && replayFlag == 1 && currentProgress != null) {
+			return liveFacadeService.currentActivitiesWithProgress(liveId, getUserId(), currentProgress, replayFlag);
+		}
 		return liveFacadeService.currentActivities(liveId,getUserId());
 	}
 
@@ -313,10 +314,10 @@ public class LiveController extends AppBaseController {
 
 	@Autowired
 	private WxMaProperties properties;
-	
+
 	@Autowired
 	private RedisCache redisCache;
-	
+
 	@ApiOperation("微信直播间urlScheme")
 	@GetMapping("/getAppletScheme")
 	public R getAppletScheme(@RequestParam(value = "liveId") Long liveId,@RequestParam(value = "companyUserId") Long companyUserId) {
@@ -337,37 +338,37 @@ public class LiveController extends AppBaseController {
 			String param = "liveId=" + liveId + "&companyUserId=" + companyUser.getUserId() + "&companyId=" + companyUser.getCompanyId() ;
 			String appId = properties.getConfigs().get(0).getAppid();
 			String secret = properties.getConfigs().get(0).getSecret();
-			
+
 			// 从 Redis 缓存中获取 access_token
 			String cacheKey = "wx:access_token:" + appId;
 			String access_token = redisCache.getCacheObject(cacheKey);
-			
+
 			// 如果缓存中没有或已过期,则重新获取
 			if (StringUtils.isEmpty(access_token)) {
 				String rspStr = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&" + "appid=" + appId + "&secret=" + secret);
 				JSONObject obj = JSONObject.parseObject(rspStr);
 				access_token = obj.getString("access_token");
-				
+
 				// 检查是否获取成功
 				if (StringUtils.isEmpty(access_token)) {
 					log.error("获取微信 access_token 失败: {}", obj);
 					return R.error("获取微信 access_token 失败");
 				}
-				
+
 				// 将 access_token 存入 Redis,缓存时间为 7200 秒
 				redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
 				log.info("微信 access_token 已刷新并缓存,appId: {}", appId);
 			} else {
 				log.debug("从 Redis 缓存中获取 access_token,appId: {}", appId);
 			}
-			
+
 			JSONObject jump_wxaObj = new JSONObject();
 			// 跳转直播间
 			jump_wxaObj.put("page_url", "pages_course/living.html?" + param);
 			String paramStr = jump_wxaObj.toJSONString();
 			String postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
 			JSONObject obj = JSONObject.parseObject(postStr);
-			
+
 			// 如果 access_token 失效,清除缓存并重新获取
 			if (obj != null && (obj.getInteger("errcode") != null && obj.getInteger("errcode") == 40001)) {
 				log.warn("access_token 已失效,清除缓存并重新获取,appId: {}", appId);
@@ -383,7 +384,7 @@ public class LiveController extends AppBaseController {
 					obj = JSONObject.parseObject(postStr);
 				}
 			}
-			
+
 			//response.addHeader("Access-Control-Allow-Origin", "*");
 			return R.ok().put("result", obj);
 		} catch (Exception e) {

+ 4 - 0
fs-user-app/src/main/java/com/fs/app/facade/LiveFacadeService.java

@@ -17,6 +17,10 @@ public interface LiveFacadeService {
 
     R currentActivities(Long liveId, String userId);
 
+    /**录播
+     */
+    R currentActivitiesWithProgress(Long liveId, String userId, Long currentProgress, Integer replayFlag);
+
     R drawClaim(LotteryPO lottery);
 
     R redClaim(RedPO red);

+ 43 - 11
fs-user-app/src/main/java/com/fs/app/facade/impl/LiveFacadeServiceImpl.java

@@ -14,6 +14,7 @@ import com.fs.common.core.redis.RedisCache;
 import com.fs.live.domain.*;
 import com.fs.framework.aspectj.lock.DistributeLock;
 import com.fs.live.param.CouponPO;
+import com.fs.live.param.LiveWatchProgressParam;
 import com.fs.live.param.LotteryPO;
 import com.fs.live.param.RedPO;
 import com.fs.live.service.*;
@@ -52,10 +53,13 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
 
     @Autowired
     private ILiveLotteryConfService liveLotteryConfService;
-    
+
     @Autowired
     private ILiveCompletionPointsRecordService completionPointsRecordService;
 
+    @Autowired
+    private ILivePersonalizedPushService personalizedPushService;
+
     @Override
     public R liveList(PageRequest pageRequest) {
         int start = (pageRequest.getCurrentPage() - 1) * pageRequest.getPageSize();
@@ -132,32 +136,32 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
         if(liveVo.getIsShow() == 2) {
             return R.error("直播未开放");
         }
-        
+
         // 查询用户今天是否已领取完课奖励
         if (userId != null) {
             try {
-                List<LiveCompletionPointsRecord> unreceivedRecords = 
+                List<LiveCompletionPointsRecord> unreceivedRecords =
                     completionPointsRecordService.getUserUnreceivedRecords(id, userId);
-                
+
                 // 判断是否有未领取的奖励,如果有则说明今天还未领取
                 // 如果没有未领取的,再查询是否有已领取的记录
                 if (unreceivedRecords != null && !unreceivedRecords.isEmpty()) {
                     liveVo.setTodayRewardReceived(false);
                 } else {
                     // 查询所有记录(包括已领取和未领取)
-                    List<LiveCompletionPointsRecord> allRecords = 
+                    List<LiveCompletionPointsRecord> allRecords =
                         completionPointsRecordService.getUserRecords(id, userId);
-                    
+
                     if (allRecords != null && !allRecords.isEmpty()) {
                         // 检查最近一条记录是否是今天的且已领取
                         LiveCompletionPointsRecord latestRecord = allRecords.get(0);
                         Date today = new Date();
                         Date recordDate = latestRecord.getCurrentCompletionDate();
-                        
+
                         // 判断是否为同一天
-                        boolean isSameDay = recordDate != null && 
+                        boolean isSameDay = recordDate != null &&
                             isSameDay(recordDate, today);
-                        
+
                         if (isSameDay && latestRecord.getReceiveStatus() == 1) {
                             liveVo.setTodayRewardReceived(true);
                         } else {
@@ -174,10 +178,10 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
         } else {
             liveVo.setTodayRewardReceived(false);
         }
-        
+
         return R.ok().put("data", liveVo);
     }
-    
+
     /**
      * 判断两个日期是否为同一天
      */
@@ -226,6 +230,34 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
                 .put("topMsg", liveMsg);
     }
 
+    @Override
+    public R currentActivitiesWithProgress(Long liveId, String userId, Long currentProgress, Integer replayFlag) {
+        try {
+            LiveWatchProgressParam param = new LiveWatchProgressParam();
+            param.setLiveId(liveId);
+            param.setUserId(Long.parseLong(userId));
+            param.setCurrentProgress(currentProgress);
+            param.setReplayFlag(replayFlag);
+
+            R personalizedResult = personalizedPushService.reportProgressAndGetTasks(param);
+
+            R originalResult = currentActivities(liveId, userId);
+
+            // 合并结果,增加个性化推送的任务
+            if (personalizedResult != null && personalizedResult.get("code").equals(200)) {
+                originalResult.put("personalizedTasks", personalizedResult.get("tasks"));
+            } else {
+                originalResult.put("personalizedTasks", new ArrayList<>());
+            }
+
+            return originalResult;
+
+        } catch (Exception e) {
+            log.error("获取录播个性化推送失败,liveId: {}, userId: {}", liveId, userId, e);
+            return currentActivities(liveId, userId);
+        }
+    }
+
     @Override
     @DistributeLock(keyExpression = "#red.redId +'_'+#red.userId", scene = "red_claim", waitTime = 1000, errorMsg = "红包领取失败")
     public R redClaim(RedPO red) {