package cd.casic.ci.process.process.service.history.impl;

import cd.casic.ci.process.dto.req.history.PipelineHistoryQueryReq;
import cd.casic.ci.process.process.dao.history.PipPipelineHisInstanceDao;
import cd.casic.ci.process.process.dataObject.history.PipPipelineHisInstance;
import cd.casic.ci.process.process.service.history.PipelineHistoryService;
import cd.casic.framework.commons.pojo.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class PipelineHistoryServiceImpl extends ServiceImpl<PipPipelineHisInstanceDao, PipPipelineHisInstance> implements PipelineHistoryService {
    @Resource
    private PipPipelineHisInstanceDao pipelineHisInstanceDao;
    @Override
    public PageResult<PipPipelineHisInstance> getPageByPipelineId(PipelineHistoryQueryReq req) {
        LambdaQueryWrapper<PipPipelineHisInstance> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PipPipelineHisInstance::getPipelineId,req.getPipelineId());
        wrapper.orderByDesc(PipPipelineHisInstance::getCreateTime);
        Page<PipPipelineHisInstance> page = pipelineHisInstanceDao.selectPage(new Page<>(req.getPageNo(),req.getPageSize()), wrapper);
        return new PageResult<PipPipelineHisInstance>(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}
