mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
学员真实学习时长记录
This commit is contained in:
@@ -4,10 +4,10 @@ import xyz.playedu.api.domain.UserLearnDurationRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_records】的数据库操作Service
|
||||
* @createDate 2023-03-20 16:41:12
|
||||
*/
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_records】的数据库操作Service
|
||||
* @createDate 2023-03-20 16:41:12
|
||||
*/
|
||||
public interface UserLearnDurationRecordService extends IService<UserLearnDurationRecord> {
|
||||
|
||||
void store(Integer userId, Integer courseId, Integer hourId, Long startTime, Long endTime);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.UserLearnDurationStats;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_stats】的数据库操作Service
|
||||
* @createDate 2023-03-22 13:55:29
|
||||
*/
|
||||
public interface UserLearnDurationStatsService extends IService<UserLearnDurationStats> {
|
||||
void storeOrUpdate(Integer userId, Long startTime, Long endTime);
|
||||
}
|
||||
@@ -1,20 +1,42 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import xyz.playedu.api.domain.UserLearnDurationRecord;
|
||||
import xyz.playedu.api.service.UserLearnDurationRecordService;
|
||||
import xyz.playedu.api.mapper.UserLearnDurationRecordMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_records】的数据库操作Service实现
|
||||
* @createDate 2023-03-20 16:41:12
|
||||
*/
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_records】的数据库操作Service实现
|
||||
* @createDate 2023-03-20 16:41:12
|
||||
*/
|
||||
@Service
|
||||
public class UserLearnDurationRecordServiceImpl extends ServiceImpl<UserLearnDurationRecordMapper, UserLearnDurationRecord>
|
||||
implements UserLearnDurationRecordService{
|
||||
implements UserLearnDurationRecordService {
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void store(Integer userId, Integer courseId, Integer hourId, Long startTime, Long endTime) {
|
||||
// 处理日期
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String date = simpleDateFormat.format(new Date(endTime));
|
||||
|
||||
UserLearnDurationRecord record = new UserLearnDurationRecord();
|
||||
record.setUserId(userId);
|
||||
record.setCourseId(courseId);
|
||||
record.setHourId(hourId);
|
||||
record.setStartAt(new Date(startTime));
|
||||
record.setEndAt(new Date(endTime));
|
||||
record.setDuration((int) (endTime - startTime));
|
||||
record.setCreatedDate(simpleDateFormat.parse(date));
|
||||
|
||||
save(record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import xyz.playedu.api.domain.UserLearnDurationStats;
|
||||
import xyz.playedu.api.service.UserLearnDurationStatsService;
|
||||
import xyz.playedu.api.mapper.UserLearnDurationStatsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_stats】的数据库操作Service实现
|
||||
* @createDate 2023-03-22 13:55:29
|
||||
*/
|
||||
@Service
|
||||
public class UserLearnDurationStatsServiceImpl extends ServiceImpl<UserLearnDurationStatsMapper, UserLearnDurationStats>
|
||||
implements UserLearnDurationStatsService {
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void storeOrUpdate(Integer userId, Long startTime, Long endTime) {
|
||||
// 处理日期
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String date = simpleDateFormat.format(new Date(endTime));
|
||||
// duration
|
||||
Long duration = endTime - startTime;
|
||||
|
||||
UserLearnDurationStats stats = getOne(query().getWrapper().eq("user_id", userId).eq("created_date", date));
|
||||
if (stats == null) {
|
||||
UserLearnDurationStats newStats = new UserLearnDurationStats();
|
||||
newStats.setUserId(userId);
|
||||
newStats.setDuration(Math.toIntExact(duration));
|
||||
newStats.setCreatedDate(simpleDateFormat.parse(date));
|
||||
save(newStats);
|
||||
return;
|
||||
}
|
||||
|
||||
UserLearnDurationStats newStats = new UserLearnDurationStats();
|
||||
newStats.setId(stats.getId());
|
||||
newStats.setDuration((int) (stats.getDuration() + duration));
|
||||
updateById(newStats);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user