package cn.ezhizao.project.business.service.impl;

import java.util.List;
import javax.annotation.Resource;

import cn.ezhizao.project.business.domain.BizOutsourcedOrder;
import cn.ezhizao.project.business.domain.BizReturnReceiptDetail;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.ezhizao.project.business.mapper.BizOutsourcedOrderDetailMapper;
import cn.ezhizao.project.business.domain.BizOutsourcedOrderDetail;
import cn.ezhizao.project.business.service.IBizOutsourcedOrderDetailService;

/**
 * 外协单从Service业务层处理
 *
 * @author ezhizao
 * @date 2024-04-26
 */
@Service
public class BizOutsourcedOrderDetailServiceImpl  extends ServiceImpl<BizOutsourcedOrderDetailMapper, BizOutsourcedOrderDetail> implements IBizOutsourcedOrderDetailService
{
    @Resource
    private BizOutsourcedOrderDetailMapper bizOutsourcedOrderDetailMapper;

    /**
     * 查询外协单从列表
     *
     * @param bizOutsourcedOrderDetail 外协单从
     * @return 外协单从
     */
    @Override
    public List<BizOutsourcedOrderDetail> getList(BizOutsourcedOrderDetail bizOutsourcedOrderDetail)
    {
        return bizOutsourcedOrderDetailMapper.getList(bizOutsourcedOrderDetail);
    }

    /**
     * 物理删除
     * @param bizOutsourcedOrderDetail
     * @return 删除结果
     */
    @Override
    public int physicalDelete(BizOutsourcedOrderDetail bizOutsourcedOrderDetail){ return bizOutsourcedOrderDetailMapper.physicalDelete(bizOutsourcedOrderDetail); }

    @Override
    public List<BizOutsourcedOrderDetail> batchSave(List<BizOutsourcedOrderDetail> outsourcedOrderDetails, BizOutsourcedOrder bizOutsourcedOrder) {
        outsourcedOrderDetails.forEach(detail -> {
            detail.setId(null);
            detail.setMasterId(bizOutsourcedOrder.getId());
            detail.setFormDate(bizOutsourcedOrder.getFormDate());
            detail.setFormCode(bizOutsourcedOrder.getFormCode());
            detail.setSupplierId(bizOutsourcedOrder.getSupplierId());
            detail.setSupplierName(bizOutsourcedOrder.getSupplierName());
            detail.setDeliveryMethod(bizOutsourcedOrder.getDeliveryMethod());
            detail.setPackagingMethod(bizOutsourcedOrder.getPackagingMethod());
            detail.setTenantId(bizOutsourcedOrder.getTenantId());
        });
        saveBatch(outsourcedOrderDetails);
        return outsourcedOrderDetails;
    }
    @Override
    public List<BizOutsourcedOrderDetail> updateOrSave(List<BizOutsourcedOrderDetail> outsourcedOrderDetails, BizOutsourcedOrder bizOutsourcedOrder) {
        outsourcedOrderDetails.forEach(detail -> {
            detail.setMasterId(bizOutsourcedOrder.getId());
            detail.setFormDate(bizOutsourcedOrder.getFormDate());
            detail.setFormCode(bizOutsourcedOrder.getFormCode());
            detail.setSupplierId(bizOutsourcedOrder.getSupplierId());
            detail.setSupplierName(bizOutsourcedOrder.getSupplierName());
            detail.setDeliveryMethod(bizOutsourcedOrder.getDeliveryMethod());
            detail.setPackagingMethod(bizOutsourcedOrder.getPackagingMethod());
            detail.setTenantId(bizOutsourcedOrder.getTenantId());
            detail.setNewCarrierCount(detail.getCarrierNum());
        });
        return outsourcedOrderDetails;
    }
    public  boolean saveBatch(List<BizOutsourcedOrderDetail> outsourcedOrderDetails, BizOutsourcedOrder bizOutsourcedOrder) {
        return saveOrUpdateBatch(outsourcedOrderDetails);
    }
    /**
     * 查询外协单从列表
     *
     * @param bizOutsourcedOrderDetail 外协单从表
     * @return 外协单从
     */
    @Override
    public List<BizOutsourcedOrderDetail> getListForReceipt(BizOutsourcedOrderDetail bizOutsourcedOrderDetail)
    {
        return bizOutsourcedOrderDetailMapper.getListForReceipt(bizOutsourcedOrderDetail);
    }
    /**
     * 查询所有外协单从列表
     *
     * @param bizOutsourcedOrderDetail 外协单从表
     * @return 外协单从
     */
    @Override
    public List<BizOutsourcedOrderDetail> getListForAllReceipt(BizOutsourcedOrderDetail bizOutsourcedOrderDetail)
    {
        return bizOutsourcedOrderDetailMapper.getListForAllReceipt(bizOutsourcedOrderDetail);
    }
    @Override
    public List<BizOutsourcedOrderDetail> getFinishedReturnList(BizOutsourcedOrderDetail bizOutsourcedOrderDetail) {
        return bizOutsourcedOrderDetailMapper.getFinishedReturnList(bizOutsourcedOrderDetail);
    }


    @Override
    public int removeByMasterIds(List<Long> ids) {
        return bizOutsourcedOrderDetailMapper.removeByMasterIds(ids);
    }

    @Override
    public List<BizOutsourcedOrderDetail> getFinishedOutsourceDetailList(BizOutsourcedOrderDetail bizOutsourcedOrderDetail)
    {
        return bizOutsourcedOrderDetailMapper.getFinishedOutsourceDetailList(bizOutsourcedOrderDetail);
    }

}
