package jnpf.cultivate.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import jnpf.cultivate.mapper.FtbCultivateLearnTaskMapper;
import jnpf.cultivate.service.FtbCultivateLearnTaskInfoCountService;
import jnpf.cultivate.service.FtbCultivateLearnTaskListService;
import jnpf.cultivate.utils.CultivateLearnUtils;
import jnpf.model.cultivate.req.learn.QueryLearnTaskCountListReq;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskInfoCountListVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xuguilin
 * @create: 2024/9/9:14:50
 */
@Service
public class FtbCultivateLearnTaskInfoCountServiceImpl implements FtbCultivateLearnTaskInfoCountService {

    @Autowired
    private FtbCultivateLearnTaskMapper ftbCultivateLearnTaskInfoMapper;

    @Autowired
    private FtbCultivateLearnTaskListService ftbCultivateLearnTaskListService;


    @Autowired
    private CultivateLearnUtils cultivateLearnUtils;


    /**
     * 查询学习任务统计列表
     * @param req
     * @return
     */
    @Override
    public PageInfo<FtbCultivateLearnTaskInfoCountListVO> queryCountList(QueryLearnTaskCountListReq req) {
        if (StringUtils.isNotEmpty(req.getKeyWord())) {
            req.setKeyWord(req.getKeyWord().trim());
        }
        Page<FtbCultivateLearnTaskInfoCountListVO> queryPage = ftbCultivateLearnTaskInfoMapper.queryLearnCountList(Page.of(req.getCurrentPage(), req.getPageSize()), req);
        List<FtbCultivateLearnTaskInfoCountListVO> records = queryPage.getRecords();
        cultivateLearnUtils.fillLearnCountList(records);
        //构建分页返回数据
        PageInfo<FtbCultivateLearnTaskInfoCountListVO> pageInfo = new PageInfo<>();
        pageInfo.setList(records);
        pageInfo.setPageSize((int) queryPage.getSize());
        pageInfo.setPageNum((int) queryPage.getCurrent());
        pageInfo.setTotal((int) queryPage.getTotal());
        return pageInfo;
    }
}
