package vip.xiaonuo.purchase.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.purchase.entity.PurchasePay;
import vip.xiaonuo.purchase.mapper.PurchasePayMapper;
import vip.xiaonuo.purchase.param.PurchaseParam;
import vip.xiaonuo.purchase.param.PurchasePayParam;
import vip.xiaonuo.purchase.service.IPurchasePayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 采购应付账款 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-26
 */
@Service
public class PurchasePayServiceImpl extends ServiceImpl<PurchasePayMapper, PurchasePay> implements IPurchasePayService {

    @Autowired
    private PurchasePayMapper payMapper;

    @Override
    public Page<PurchasePay> listPay(PurchasePayParam purchasePayParam) {
        QueryWrapper<PurchasePay> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(purchasePayParam.getOrgId()), "org_id", purchasePayParam.getOrgId());
        String time = purchasePayParam.getTime();
        if ("".equals(time) || null == time) {
            queryWrapper.ge("create_time", DateUtil.beginOfYear(new Date()));
        } else {
            queryWrapper.between("create_time", time+"-01 00:00:00", time + "-31 23:59:59");
        }
        queryWrapper.orderByDesc("end_time");
        Page page = new Page<PurchasePay>(purchasePayParam.getPageNum(), purchasePayParam.getPageSize());
        return payMapper.selectPage(page, queryWrapper);
    }

}
