|
|
@@ -87,20 +87,20 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@GetMapping("/info")
|
|
|
public R getInfo(@RequestParam Long liveId) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
// 1. 获取用户积分余额
|
|
|
FsUser user = fsUserService.selectFsUserByUserId(userId);
|
|
|
Long integral = user != null && user.getIntegral() != null ? user.getIntegral() : 0L;
|
|
|
-
|
|
|
+
|
|
|
// 2. 获取完课记录列表(包含已领取和未领取)
|
|
|
List<LiveCompletionPointsRecord> records = completionPointsRecordService.getUserRecords(liveId, userId);
|
|
|
-
|
|
|
+
|
|
|
// 3. 统计信息
|
|
|
long totalPoints = records.stream()
|
|
|
.filter(r -> r.getReceiveStatus() == 1)
|
|
|
.mapToLong(LiveCompletionPointsRecord::getPointsAwarded)
|
|
|
.sum();
|
|
|
-
|
|
|
+
|
|
|
long unreceivedCount = records.stream()
|
|
|
.filter(r -> r.getReceiveStatus() == 0)
|
|
|
.count();
|
|
|
@@ -111,7 +111,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
result.put("totalDays", records.size()); // 累计看直播天数
|
|
|
result.put("unreceivedCount", unreceivedCount); // 未领取记录数
|
|
|
result.put("records", records); // 完课记录列表
|
|
|
-
|
|
|
+
|
|
|
return R.ok().put("data", result);
|
|
|
}
|
|
|
|
|
|
@@ -121,7 +121,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@PostMapping("/test/create")
|
|
|
public R testCreateRecord(@RequestParam Long liveId, @RequestParam(required = false) Long watchDuration) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 调用完课记录创建方法(watchDuration为null时会自动从数据库累计)
|
|
|
completionPointsRecordService.checkAndCreateCompletionRecord(liveId, userId, watchDuration);
|
|
|
@@ -139,7 +139,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@GetMapping("/remaining-time")
|
|
|
public R getRemainingTime(@RequestParam Long liveId) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 1. 获取直播间信息
|
|
|
Live live = liveService.selectLiveByLiveId(liveId);
|
|
|
@@ -149,7 +149,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
|
|
|
// 2. 查询当前用户和当前直播间的最近一次完课记录(不限制日期)
|
|
|
LiveCompletionPointsRecord record = completionPointsRecordMapper.selectLatestByUserAndLiveId(liveId, userId);
|
|
|
-
|
|
|
+
|
|
|
// 3. 如果没有记录,查询直播间配置并生成记录
|
|
|
if (record == null) {
|
|
|
record = completionPointsRecordService.createCompletionRecord(liveId, userId);
|
|
|
@@ -158,9 +158,9 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
// 4. 计算剩余时长
|
|
|
RemainingTimeVO vo = new RemainingTimeVO();
|
|
|
Long videoDuration = live.getDuration() != null ? live.getDuration() : 0L;
|
|
|
- Long watchDuration = record != null && record.getWatchDuration() != null
|
|
|
+ Long watchDuration = record != null && record.getWatchDuration() != null
|
|
|
? record.getWatchDuration() : 0L;
|
|
|
-
|
|
|
+
|
|
|
vo.setVideoDuration(videoDuration);
|
|
|
if (record != null) {
|
|
|
vo.setCompletionRate(record.getCompletionRate());
|
|
|
@@ -168,7 +168,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
vo.setWatchDuration(watchDuration);
|
|
|
vo.setRemainingTime(Math.max(0, videoDuration - watchDuration));
|
|
|
vo.setHasReceived(record != null && record.getReceiveStatus() != null && record.getReceiveStatus() == 1);
|
|
|
-
|
|
|
+
|
|
|
return R.ok().put("data", vo);
|
|
|
} catch (Exception e) {
|
|
|
return R.error("查询失败: " + e.getMessage());
|
|
|
@@ -183,7 +183,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@PostMapping("/update-watch-duration")
|
|
|
public R updateWatchDuration(@RequestParam Long liveId, @RequestParam Long watchDuration) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 1. 获取直播间信息
|
|
|
Live live = liveService.selectLiveByLiveId(liveId);
|
|
|
@@ -194,7 +194,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
// 2. 判断当前时间是否在直播期间(状态为2,直播中)
|
|
|
boolean isLiveInProgress = false;
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
-
|
|
|
+
|
|
|
if (live.getStatus() != null && live.getStatus() == 2) {
|
|
|
// status=2 表示直播中
|
|
|
isLiveInProgress = true;
|
|
|
@@ -210,20 +210,20 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
|
|
|
// 3. 查询当前直播间的完课记录(不限制日期)
|
|
|
LiveCompletionPointsRecord record = completionPointsRecordMapper.selectLatestByUserAndLiveId(liveId, userId);
|
|
|
-
|
|
|
+
|
|
|
// 4. 计算看课时长
|
|
|
Date updateTime = null;
|
|
|
if (record != null && record.getUpdateTime() != null) {
|
|
|
updateTime = record.getUpdateTime();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 判断更新时间与直播间开始时间的关系
|
|
|
- Date startTime = live.getStartTime() != null
|
|
|
+ Date startTime = live.getStartTime() != null
|
|
|
? java.sql.Timestamp.valueOf(live.getStartTime()) : null;
|
|
|
-
|
|
|
+
|
|
|
Date currentTime = new Date();
|
|
|
long timeDiff = 0L;
|
|
|
-
|
|
|
+
|
|
|
if (updateTime != null && startTime != null) {
|
|
|
if (updateTime.before(startTime)) {
|
|
|
// 更新时间小于直播间开始时间,使用直播间开始时间进行计算
|
|
|
@@ -236,7 +236,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
// 没有更新记录,使用直播间开始时间计算
|
|
|
timeDiff = (currentTime.getTime() - startTime.getTime()) / 1000; // 转换为秒
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 5. 如果请求传入的时间大于这个时间差,就使用计算出的看课时长,否则使用请求传入的时长
|
|
|
Long finalWatchDuration;
|
|
|
if (watchDuration > timeDiff) {
|
|
|
@@ -246,17 +246,17 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
// 否则使用请求传入的时长
|
|
|
finalWatchDuration = watchDuration;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 6. 更新完课记录中的看课时长
|
|
|
if (record == null) {
|
|
|
// 如果没有记录,先创建记录
|
|
|
record = completionPointsRecordService.createCompletionRecord(liveId, userId);
|
|
|
} else {
|
|
|
// 更新现有记录的看课时长
|
|
|
- Long currentWatchDuration = record.getWatchDuration() != null
|
|
|
+ Long currentWatchDuration = record.getWatchDuration() != null
|
|
|
? record.getWatchDuration() : 0L;
|
|
|
record.setWatchDuration(currentWatchDuration + finalWatchDuration);
|
|
|
-
|
|
|
+
|
|
|
// 重新计算完课比例
|
|
|
Long videoDuration = live.getDuration();
|
|
|
if (videoDuration != null && videoDuration > 0) {
|
|
|
@@ -268,15 +268,15 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
}
|
|
|
record.setCompletionRate(completionRate);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
completionPointsRecordMapper.updateRecord(record);
|
|
|
}
|
|
|
|
|
|
UpdateWatchDurationVO vo = new UpdateWatchDurationVO();
|
|
|
vo.setWatchDuration(finalWatchDuration);
|
|
|
- vo.setTotalWatchDuration(record != null && record.getWatchDuration() != null
|
|
|
+ vo.setTotalWatchDuration(record != null && record.getWatchDuration() != null
|
|
|
? record.getWatchDuration() : finalWatchDuration);
|
|
|
-
|
|
|
+
|
|
|
return R.ok().put("data", vo);
|
|
|
} catch (Exception e) {
|
|
|
return R.error("更新失败: " + e.getMessage());
|
|
|
@@ -294,11 +294,11 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@RepeatSubmit
|
|
|
public R receivePoints(@RequestParam Long liveId) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 1. 查询当前用户和当前直播间的最近一次完课记录(不限制日期)
|
|
|
LiveCompletionPointsRecord record = completionPointsRecordMapper.selectLatestByUserAndLiveId(liveId, userId);
|
|
|
-
|
|
|
+
|
|
|
if (record == null) {
|
|
|
return R.error("您还没有看课记录,无法领取积分");
|
|
|
}
|
|
|
@@ -361,7 +361,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
vo.setRecord(receivedRecord);
|
|
|
vo.setPoints(receivedRecord.getPointsAwarded());
|
|
|
vo.setContinuousDays(receivedRecord.getContinuousDays());
|
|
|
-
|
|
|
+
|
|
|
return R.ok().put("data", vo);
|
|
|
} catch (BaseException e) {
|
|
|
return R.error(e.getMessage());
|
|
|
@@ -377,13 +377,13 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
@GetMapping("/integral-logs")
|
|
|
public R getIntegralLogs(@RequestParam(required = false) Integer type) {
|
|
|
Long userId = Long.parseLong(getUserId());
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
FsUserIntegralLogs query = new FsUserIntegralLogs();
|
|
|
query.setUserId(userId);
|
|
|
-
|
|
|
+
|
|
|
List<FsUserIntegralLogs> logs = fsUserIntegralLogsService.selectFsUserIntegralLogsList(query);
|
|
|
-
|
|
|
+
|
|
|
// 如果指定了类型,进行过滤
|
|
|
if (type != null) {
|
|
|
if (type == 1) {
|
|
|
@@ -394,7 +394,7 @@ public class LiveCompletionPointsController extends AppBaseController {
|
|
|
logs.removeIf(log -> log.getIntegral() == null || log.getIntegral() >= 0);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return R.ok().put("data", logs);
|
|
|
} catch (Exception e) {
|
|
|
return R.error("查询失败: " + e.getMessage());
|