|
@@ -12,6 +12,7 @@ import com.fs.live.domain.LiveCompletionPointsRecord;
|
|
|
import com.fs.live.mapper.LiveCompletionPointsRecordMapper;
|
|
import com.fs.live.mapper.LiveCompletionPointsRecordMapper;
|
|
|
import com.fs.live.service.ILiveCompletionPointsRecordService;
|
|
import com.fs.live.service.ILiveCompletionPointsRecordService;
|
|
|
import com.fs.live.service.ILiveService;
|
|
import com.fs.live.service.ILiveService;
|
|
|
|
|
+import com.fs.live.service.ILiveWatchUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -44,9 +45,15 @@ public class LiveCompletionPointsRecordServiceImpl implements ILiveCompletionPoi
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
|
|
private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ILiveWatchUserService liveWatchUserService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 检查并创建完课记录(由定时任务调用)
|
|
* 检查并创建完课记录(由定时任务调用)
|
|
|
|
|
+ * @param liveId 直播间ID
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @param watchDuration 观看时长(可为null,为null时从数据库自动累计直播+回放时长)
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -78,26 +85,40 @@ public class LiveCompletionPointsRecordServiceImpl implements ILiveCompletionPoi
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. 获取视频总时长(秒)
|
|
|
|
|
|
|
+ // 3. 获取观看时长(如果为null,则从数据库累计直播+回放时长)
|
|
|
|
|
+ Long actualWatchDuration = watchDuration;
|
|
|
|
|
+ if (actualWatchDuration == null) {
|
|
|
|
|
+ // 自动累加直播和回放的观看时长
|
|
|
|
|
+ actualWatchDuration = liveWatchUserService.getTotalWatchDuration(liveId, userId);
|
|
|
|
|
+ log.debug("自动累计观看时长: liveId={}, userId={}, totalDuration={}",
|
|
|
|
|
+ liveId, userId, actualWatchDuration);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (actualWatchDuration == null || actualWatchDuration <= 0) {
|
|
|
|
|
+ log.debug("观看时长为0, liveId={}, userId={}", liveId, userId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 获取视频总时长(秒)
|
|
|
Long videoDuration = live.getDuration();
|
|
Long videoDuration = live.getDuration();
|
|
|
if (videoDuration == null || videoDuration <= 0) {
|
|
if (videoDuration == null || videoDuration <= 0) {
|
|
|
log.warn("直播间视频时长无效, liveId={}, duration={}", liveId, videoDuration);
|
|
log.warn("直播间视频时长无效, liveId={}, duration={}", liveId, videoDuration);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 计算完课比例
|
|
|
|
|
- BigDecimal watchRate = BigDecimal.valueOf(watchDuration)
|
|
|
|
|
|
|
+ // 5. 计算完课比例
|
|
|
|
|
+ BigDecimal watchRate = BigDecimal.valueOf(actualWatchDuration)
|
|
|
.multiply(BigDecimal.valueOf(100))
|
|
.multiply(BigDecimal.valueOf(100))
|
|
|
.divide(BigDecimal.valueOf(videoDuration), 2, RoundingMode.HALF_UP);
|
|
.divide(BigDecimal.valueOf(videoDuration), 2, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
- // 5. 判断是否达到完课标准
|
|
|
|
|
|
|
+ // 6. 判断是否达到完课标准
|
|
|
if (watchRate.compareTo(BigDecimal.valueOf(completionRate)) < 0) {
|
|
if (watchRate.compareTo(BigDecimal.valueOf(completionRate)) < 0) {
|
|
|
- log.debug("观看时长未达到完课标准, liveId={}, userId={}, watchRate={}%, required={}%",
|
|
|
|
|
- liveId, userId, watchRate, completionRate);
|
|
|
|
|
|
|
+ log.debug("观看时长未达到完课标准, liveId={}, userId={}, watchDuration={}, videoDuration={}, watchRate={}%, required={}%",
|
|
|
|
|
+ liveId, userId, actualWatchDuration, videoDuration, watchRate, completionRate);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 6. 检查今天是否已有完课记录
|
|
|
|
|
|
|
+ // 7. 检查今天是否已有完课记录
|
|
|
LocalDate today = LocalDate.now();
|
|
LocalDate today = LocalDate.now();
|
|
|
Date currentDate = Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
Date currentDate = Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
|
|
@@ -107,8 +128,8 @@ public class LiveCompletionPointsRecordServiceImpl implements ILiveCompletionPoi
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 7. 查询最近一次完课记录,计算连续天数
|
|
|
|
|
- LiveCompletionPointsRecord latestRecord = recordMapper.selectLatestByUser(liveId, userId);
|
|
|
|
|
|
|
+ // 7. 查询最近一次完课记录(不限直播间),计算连续天数
|
|
|
|
|
+ LiveCompletionPointsRecord latestRecord = recordMapper.selectLatestByUser(userId);
|
|
|
int continuousDays = 1;
|
|
int continuousDays = 1;
|
|
|
|
|
|
|
|
if (latestRecord != null) {
|
|
if (latestRecord != null) {
|
|
@@ -137,7 +158,7 @@ public class LiveCompletionPointsRecordServiceImpl implements ILiveCompletionPoi
|
|
|
LiveCompletionPointsRecord record = new LiveCompletionPointsRecord();
|
|
LiveCompletionPointsRecord record = new LiveCompletionPointsRecord();
|
|
|
record.setLiveId(liveId);
|
|
record.setLiveId(liveId);
|
|
|
record.setUserId(userId);
|
|
record.setUserId(userId);
|
|
|
- record.setWatchDuration(watchDuration);
|
|
|
|
|
|
|
+ record.setWatchDuration(actualWatchDuration);
|
|
|
record.setVideoDuration(videoDuration);
|
|
record.setVideoDuration(videoDuration);
|
|
|
record.setCompletionRate(watchRate);
|
|
record.setCompletionRate(watchRate);
|
|
|
record.setContinuousDays(continuousDays);
|
|
record.setContinuousDays(continuousDays);
|
|
@@ -151,8 +172,8 @@ public class LiveCompletionPointsRecordServiceImpl implements ILiveCompletionPoi
|
|
|
|
|
|
|
|
recordMapper.insertRecord(record);
|
|
recordMapper.insertRecord(record);
|
|
|
|
|
|
|
|
- log.info("创建完课记录成功, liveId={}, userId={}, continuousDays={}, points={}",
|
|
|
|
|
- liveId, userId, continuousDays, points);
|
|
|
|
|
|
|
+ log.info("创建完课记录成功, liveId={}, userId={}, watchDuration={}, videoDuration={}, watchRate={}%, continuousDays={}, points={}",
|
|
|
|
|
+ liveId, userId, actualWatchDuration, videoDuration, watchRate, continuousDays, points);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("检查并创建完课记录失败, liveId={}, userId={}", liveId, userId, e);
|
|
log.error("检查并创建完课记录失败, liveId={}, userId={}", liveId, userId, e);
|