package com.jwipc.order.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jwipc.order.entity.DeliveryOrderDetail;
import com.jwipc.order.mapper.DeliveryOrderDetailMapper;
import com.jwipc.order.model.po.DeliveryOrderDetailPO;
import com.jwipc.order.model.query.DeliveryOrderDetailQuery;
import com.jwipc.order.service.IDeliveryOrderDetailService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

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

/**
 * <p>
 * 送货单明细 服务实现类
 * </p>
 *
 * @author zhangjie
 * @since 2024-03-06
 */
@Service
@DS(SLAVE)
public class DeliveryOrderDetailServiceImpl extends ServiceImpl<DeliveryOrderDetailMapper, DeliveryOrderDetail>
        implements IDeliveryOrderDetailService
{

    @Override
    public List<DeliveryOrderDetailPO> findForList(Page<DeliveryOrderDetailPO> orderDetailPOPage,
                                                   DeliveryOrderDetailQuery query)
    {
        return this.baseMapper.findForList(orderDetailPOPage, query);
    }

    @Override
    public List<DeliveryOrderDetailPO> findForList(DeliveryOrderDetailQuery query) {
        return this.baseMapper.findForList(query);
    }


    @Override
    public BigDecimal findCountByMaterialCodeAndFactory(String materialCode, String factory,Integer status,int delFlag) {
        final BigDecimal count = this.baseMapper.findCountByMaterialCodeAndFactory(materialCode,
                factory, status, delFlag);
        return Objects.isNull(count)?BigDecimal.ZERO:count;
    }

    @Override
    public BigDecimal findCountByPurchaseDetail(String purchaseOrderCode, String purchaseOrderRow, int status,int delFlag) {
        final BigDecimal count = baseMapper.findCountByPurchaseDetail(purchaseOrderCode,
                purchaseOrderRow, status, delFlag);
        return Objects.isNull(count)?BigDecimal.ZERO:count;
    }
    @Override
    public BigDecimal findSendNumBySuplierCodeAndMaterialCode(String effectiveDate, String supplierCode, String materialCode,int delFlag) {
        final BigDecimal sum = baseMapper.findSendNumBySuplierCodeAndMaterialCode(effectiveDate, supplierCode,
                materialCode, delFlag);
        return Objects.isNull(sum)?BigDecimal.ZERO:sum;
    }

    @Override
    public BigDecimal findSendNumByOrderId(@Param("orderId") String orderId) {
        final BigDecimal sum = baseMapper.findSendNumByOrderId(orderId);
        return Objects.isNull(sum)?BigDecimal.ZERO:sum;
    }
}
