package com.seer.teach.teacher.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.teacher.module.entity.ReadDurationsEntity;
import com.seer.teach.teacher.module.mapper.ReadDurationsMapper;
import com.seer.teach.teacher.service.ReadDurationsService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-09-20 20:02:07
 */
@Service
public class ReadDurationsServiceImpl extends ServiceImpl<ReadDurationsMapper, ReadDurationsEntity> implements ReadDurationsService {

    /**
     * 插入阅读时长记录
     *
     * @param userId 用户ID
     * @param bookId 书籍ID
     * @param chapterId 章节ID
     */
    @Override
    public void insertRecord(Integer userId, Integer bookId, Integer chapterId) {
        // 创建阅读时长实体对象
        ReadDurationsEntity duration = new ReadDurationsEntity();
        duration.setChapterId(chapterId);
        duration.setUserId(userId);
        duration.setBookId(bookId);
        duration.setStartTime(LocalDateTime.now());
        this.save(duration);
    }
}

