package com.ozs.plan.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ozs.plan.doman.MonthlyReconciliation;
import com.ozs.plan.doman.vo.requestVo.MonthlyReconciliationPageReqVo;
import com.ozs.plan.mapper.MonthlyReconciliationMapper;
import com.ozs.plan.service.MonthlyReconciliationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MonthlyReconciliationServiceImpl extends ServiceImpl<MonthlyReconciliationMapper, MonthlyReconciliation> implements MonthlyReconciliationService {

    @Autowired
    private MonthlyReconciliationMapper monthlyReconciliationMapper;

    @Override
    public IPage<MonthlyReconciliation> queryPage(MonthlyReconciliationPageReqVo vo) {
        int pageNum = Integer.parseInt(vo.getPageNum().toString());
        int pageSize = Integer.parseInt(vo.getPageSize().toString());
        vo.setProjectName(StringUtils.isBlank(vo.getProjectName()) ? null : vo.getProjectName());
        vo.setPurchaseServices(StringUtils.isBlank(vo.getPurchaseServices()) ? null : vo.getPurchaseServices());
        vo.setWarnStatus(StringUtils.isBlank(vo.getWarnStatus()) ? null : vo.getWarnStatus());
        Page<MonthlyReconciliation> page = PageHelper.startPage(pageNum, pageSize)
                .doSelectPage(() -> monthlyReconciliationMapper.query(vo));
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<MonthlyReconciliation> monthlyReconciliationPage =
                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize);
        monthlyReconciliationPage.setRecords(page.getResult());
        monthlyReconciliationPage.setTotal(page.getTotal());
        return monthlyReconciliationPage;
    }

}
