package org.jeecg.modules.projectManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.projectManagement.entity.FdProjectFileInvoice;
import org.jeecg.modules.projectManagement.mapper.FdProjectFileInvoiceMapper;
import org.jeecg.modules.projectManagement.service.IFdProjectFileInvoiceService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Description: 支付信息
 * @author： jeecg-boot
 * @date：   2020-07-21
 * @version： V1.0
 */
@Service
public class FdProjectFileInvoiceServiceImpl extends ServiceImpl<FdProjectFileInvoiceMapper, FdProjectFileInvoice> implements IFdProjectFileInvoiceService {

    @Resource
    IFdProjectFileInvoiceService iFdProjectFileInvoiceService;

    @Override
    public void addAll(List<FdProjectFileInvoice> fdProjectFileInvoiceList) {
        if(fdProjectFileInvoiceList!=null&&fdProjectFileInvoiceList.size()>0){
            //删除旧数据
            LambdaQueryWrapper<FdProjectFileInvoice> fdProjectFileInvoiceLambdaQueryWrapper=new LambdaQueryWrapper<>();
            fdProjectFileInvoiceLambdaQueryWrapper.eq(FdProjectFileInvoice::getDelFlag,"0");
            fdProjectFileInvoiceLambdaQueryWrapper.eq(FdProjectFileInvoice::getProjectFileId,fdProjectFileInvoiceList.get(0).getProjectFileId());
            FdProjectFileInvoice fdProjectFileInvoice=new FdProjectFileInvoice();
            fdProjectFileInvoice.setDelFlag("1");
            iFdProjectFileInvoiceService.update(fdProjectFileInvoice,fdProjectFileInvoiceLambdaQueryWrapper);
            //保存
            Integer sort=1;
            for(FdProjectFileInvoice invoice:fdProjectFileInvoiceList){
                invoice.setId(null);
                invoice.setCreateBy(null);
                invoice.setCreateTime(null);
                invoice.setSort(sort);
                sort++;
            }
            iFdProjectFileInvoiceService.saveBatch(fdProjectFileInvoiceList);
        }

    }
}
