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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.admin.request.MaterialDocDataParseLogsPageReq;
import com.seer.teach.admin.service.AdminMaterialDocDataParseLogService;
import com.seer.teach.teacher.module.entity.MaterialDocDataParseLog;
import com.seer.teach.teacher.module.mapper.MaterialDocParseLogMapper;
import com.seer.teach.teacher.service.MaterialDocDataParseLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 教材文档数据解析日志服务实现类
 */
@RequiredArgsConstructor
@Service
public class AdminMaterialDocDataParseLogServiceImpl implements AdminMaterialDocDataParseLogService {


    private final MaterialDocDataParseLogService materialDocDataParseLogService;

    @Override
    public IPage<MaterialDocDataParseLog> pageMaterialDocDataParseLogs(MaterialDocDataParseLogsPageReq req) {
        IPage<MaterialDocDataParseLog> page = new Page<>(req.getPageNo(), req.getPageSize());
        LambdaQueryWrapper<MaterialDocDataParseLog> queryWrapper = new LambdaQueryWrapper<>();
        // 如果指定了文档ID，则按文档ID查询
        if (Objects.nonNull(req.getDocId())) {
            queryWrapper.eq(MaterialDocDataParseLog::getDocId, req.getDocId());
        }
        queryWrapper.orderByDesc(MaterialDocDataParseLog::getId);

        return materialDocDataParseLogService.page(page,queryWrapper);
    }
}