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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.salescontractmanagement.SalesContractPaymentCondition;
import com.sunxung.factoring.mapper.salescontractmanagement.SalesContractPaymentConditionMapper;
import com.sunxung.factoring.service.salescontractmanagement.SalesContractPaymentConditionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description : 销售合同付款条件service实现类
 * @Author : L.Jia
 * @Date: 2021-09-14 10:58
 */
@Service
public class SalesContractPaymentConditionServiceImpl extends ServiceImpl<SalesContractPaymentConditionMapper, SalesContractPaymentCondition>
        implements SalesContractPaymentConditionService {


    @Override
    public List<SalesContractPaymentCondition> findByBasicInfoId(Long basicInfoId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sales_contract_basic_info_id", basicInfoId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(Long basicInfoId, List<SalesContractPaymentCondition> paymentConditionList) {
        if (paymentConditionList != null && paymentConditionList.size() > 0) {
            for (int i = 0; i < paymentConditionList.size(); i++) {
                paymentConditionList.get(i).setSerialNumber(i + 1);
                paymentConditionList.get(i).setSalesContractBasicInfoId(basicInfoId);
                baseMapper.insert(paymentConditionList.get(i));
            }
        }
    }
}
