mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-24 02:09:35 +08:00
fixed: 课时进度判断
This commit is contained in:
parent
bd0bebb311
commit
d7ae1358b7
2
pom.xml
2
pom.xml
@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package xyz.playedu.api.listener;
|
package xyz.playedu.api.listener;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@ -14,6 +15,7 @@ import xyz.playedu.api.service.UserCourseRecordService;
|
|||||||
* @create 2023/3/20 17:41
|
* @create 2023/3/20 17:41
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class UserCourseHourFinishedListener {
|
public class UserCourseHourFinishedListener {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -30,6 +32,7 @@ public class UserCourseHourFinishedListener {
|
|||||||
public void userCourseProgressUpdate(UserCourseHourFinishedEvent evt) {
|
public void userCourseProgressUpdate(UserCourseHourFinishedEvent evt) {
|
||||||
Integer hourCount = hourService.getCountByCourseId(evt.getCourseId());
|
Integer hourCount = hourService.getCountByCourseId(evt.getCourseId());
|
||||||
Integer finishedCount = userCourseHourRecordService.getFinishedHourCount(evt.getUserId(), evt.getCourseId());
|
Integer finishedCount = userCourseHourRecordService.getFinishedHourCount(evt.getUserId(), evt.getCourseId());
|
||||||
|
log.info("UserCourseHourFinishedListener courseId={} userId={} hourCount={} finishedCount={}", evt.getCourseId(), evt.getUserId(), hourCount, finishedCount);
|
||||||
userCourseRecordService.storeOrUpdate(evt.getUserId(), evt.getCourseId(), hourCount, finishedCount);
|
userCourseRecordService.storeOrUpdate(evt.getUserId(), evt.getCourseId(), hourCount, finishedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
public interface UserCourseHourRecordService extends IService<UserCourseHourRecord> {
|
public interface UserCourseHourRecordService extends IService<UserCourseHourRecord> {
|
||||||
UserCourseHourRecord find(Integer userId, Integer courseId, Integer hourId);
|
UserCourseHourRecord find(Integer userId, Integer courseId, Integer hourId);
|
||||||
|
|
||||||
UserCourseHourRecord storeOrUpdate(Integer userId, Integer courseId, Integer hourId, Integer duration, Integer totalDuration);
|
void storeOrUpdate(Integer userId, Integer courseId, Integer hourId, Integer duration, Integer totalDuration);
|
||||||
|
|
||||||
Integer getFinishedHourCount(Integer userId, Integer courseId);
|
Integer getFinishedHourCount(Integer userId, Integer courseId);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package xyz.playedu.api.service.impl;
|
package xyz.playedu.api.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||||
@ -30,12 +29,12 @@ public class UserCourseHourRecordServiceImpl extends ServiceImpl<UserCourseHourR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserCourseHourRecord storeOrUpdate(Integer userId, Integer courseId, Integer hourId, Integer duration, Integer totalDuration) {
|
public void storeOrUpdate(Integer userId, Integer courseId, Integer hourId, Integer duration, Integer totalDuration) {
|
||||||
UserCourseHourRecord record = find(userId, courseId, hourId);
|
UserCourseHourRecord record = find(userId, courseId, hourId);
|
||||||
|
|
||||||
// 已看完
|
// 记录存在 && 已看完 => 跳过处理
|
||||||
if (record != null && record.getIsFinished() == 1) {
|
if (record != null && record.getIsFinished() == 1) {
|
||||||
return record;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否看完
|
// 是否看完
|
||||||
@ -55,28 +54,20 @@ public class UserCourseHourRecordServiceImpl extends ServiceImpl<UserCourseHourR
|
|||||||
insertRecord.setUpdatedAt(new Date());
|
insertRecord.setUpdatedAt(new Date());
|
||||||
|
|
||||||
save(insertRecord);
|
save(insertRecord);
|
||||||
|
} else if (record.getFinishedDuration() < duration) {
|
||||||
|
UserCourseHourRecord updateRecord = new UserCourseHourRecord();
|
||||||
|
updateRecord.setId(record.getId());
|
||||||
|
updateRecord.setTotalDuration(totalDuration);
|
||||||
|
updateRecord.setFinishedDuration(duration);
|
||||||
|
updateRecord.setIsFinished(isFinished ? 1 : 0);
|
||||||
|
updateRecord.setFinishedAt(finishedAt);
|
||||||
|
|
||||||
record = insertRecord;
|
updateById(updateRecord);
|
||||||
} else {
|
|
||||||
// 未看完 && 大于存在的观看记录时长
|
|
||||||
if (record.getFinishedDuration() < duration) {
|
|
||||||
UserCourseHourRecord updateRecord = new UserCourseHourRecord();
|
|
||||||
updateRecord.setId(record.getId());
|
|
||||||
updateRecord.setTotalDuration(totalDuration);
|
|
||||||
updateRecord.setFinishedDuration(duration);
|
|
||||||
updateRecord.setIsFinished(isFinished ? 1 : 0);
|
|
||||||
updateRecord.setFinishedAt(finishedAt);
|
|
||||||
|
|
||||||
updateById(updateRecord);
|
|
||||||
record = updateRecord;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
ctx.publishEvent(new UserCourseHourFinishedEvent(this, record.getUserId(), record.getCourseId(), record.getHourId()));
|
ctx.publishEvent(new UserCourseHourFinishedEvent(this, userId, courseId, hourId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return record;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user