package com.jwipc.order.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
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 com.jwipc.order.entity.PurchaseOrder;
import com.jwipc.order.mapper.PurchaseOrderMapper;
import com.jwipc.order.model.po.PurchaseOrderPO;
import com.jwipc.order.model.query.OrderBatchPrintQuery;
import com.jwipc.order.model.query.PurchaseOrderQuery;
import com.jwipc.order.service.IPurchaseOrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

import static com.baomidou.dynamic.datasource.support.DdConstants.SLAVE;

/**
 * <p>
 * 采购订单 服务实现类
 * </p>
 *
 * @author zhangjie
 * @since 2024-03-05
 */
@Service
public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, PurchaseOrder>
        implements IPurchaseOrderService
{

    @Override
    public List<PurchaseOrderPO> orderList(PurchaseOrderQuery query, Page<PurchaseOrder> page) {
        if (page == null) {
            return baseMapper.orderList(query);
        }
        return baseMapper.orderList(query, page);
    }

    @Override
    public List<PurchaseOrder> findBatchPrintListCheck(OrderBatchPrintQuery query) {
        return baseMapper.findBatchPrintListCheck(query);
    }

    @Override
    @DS(SLAVE)
    public List<PurchaseOrder> findBatchPrintList(Page<PurchaseOrder> page, OrderBatchPrintQuery query) {
        if (Objects.isNull(query)) {
            return baseMapper.findBatchPrintList(query);
        }
        return baseMapper.findBatchPrintList(page, query);
    }
    @Override
    public PurchaseOrder getIdByCode(String purchaseGroupCode) {
        return baseMapper.getIdByCode(purchaseGroupCode);
    }

    @Override
    @DS(SLAVE)
    public List<PurchaseOrderPO> findByPage(Page<PurchaseOrderPO> page, LambdaQueryWrapper<PurchaseOrder> queryWrapper,PurchaseOrderQuery query) {
        return baseMapper.findList(page,queryWrapper,query);
    }

    @Override
    @DS(SLAVE)
    public List<PurchaseOrderPO> findAll(LambdaQueryWrapper<PurchaseOrder> queryWrapper,PurchaseOrderQuery query) {
        return baseMapper.findList(queryWrapper,query);
    }

    @Override
    @DS(SLAVE)
    public List<PurchaseOrderPO> supplierConfirmOrderList() {
        return baseMapper.supplierConfirmOrderList();
    }


    @Override
    @DS(SLAVE)
    public List<PurchaseOrderPO> findMonthNGconfirmOrderList(PurchaseOrderQuery query) {
        return baseMapper.findMonthNGconfirmOrderList(query);
    }

    @Override
    public Integer findQualifiedSupplier(String supplierCode) {
        return baseMapper.findQualifiedSupplier(supplierCode);
    }


    @Override
    public List<String> findAccountStatementByOrderCode(Long id) {
        return this.baseMapper.findAccountStatementByOrderCode(id);
    }
}
