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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.teacher.module.entity.TreasuryArticleReadDurationsEntity;
import com.seer.teach.teacher.module.mapper.TreasuryArticleReadDurationsMapper;
import com.seer.teach.teacher.service.TreasuryArticleReadDurationsService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-09-20 20:51:31
 */
@Service
public class TreasuryArticleReadDurationsServiceImpl extends ServiceImpl<TreasuryArticleReadDurationsMapper, TreasuryArticleReadDurationsEntity> implements TreasuryArticleReadDurationsService {

    /**
     * 异步插入文章阅读记录
     * 创建一个新的文章阅读时长记录，设置用户ID、文章ID和开始阅读时间，并保存到数据库中
     *
     * @param userId 用户ID
     * @param articleId 文章ID
     */
    @Async
    @Override
    public void insertRecord(Integer userId, Integer articleId) {
        // 创建文章阅读时长实体对象
        TreasuryArticleReadDurationsEntity duration = new TreasuryArticleReadDurationsEntity();
        duration.setArticleId(articleId);
        duration.setUserId(userId);
        duration.setStartTime(LocalDateTime.now());
        this.save(duration);
    }

}

