package com.sunxung.factoring.service.purchcontractmanagement.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.purchcontractmanagement.PurchContractPaymentCondition;
import com.sunxung.factoring.mapper.purchcontractmanagement.PurchContractPaymentConditionMapper;
import com.sunxung.factoring.service.purchcontractmanagement.PurchContractPaymentConditionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description : 采购合同付款条件信息service实现类
 * @Author : JiaYf
 * @Date: 2021-09-15 14:46
 */
@Service
public class PurchContractPaymentConditionServiceImpl extends ServiceImpl<PurchContractPaymentConditionMapper, PurchContractPaymentCondition>
        implements PurchContractPaymentConditionService {

    @Override
    public List<PurchContractPaymentCondition> findByPurchContId(Long purchContId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("purch_contract_basic_info_id", purchContId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void add(Long purchId, List<PurchContractPaymentCondition> paymentConditionList) {
        if (paymentConditionList != null && paymentConditionList.size() > 0) {
            for (int i = 0; i < paymentConditionList.size(); i++) {
                paymentConditionList.get(i).setSerialNumber(i + 1);
                paymentConditionList.get(i).setPurchContractBasicInfoId(purchId);
                baseMapper.insert(paymentConditionList.get(i));
            }
        }
    }

}
