package com.sckw.payment.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sckw.payment.dao.KwpLedgerLogisticsUnitMapper;
import com.sckw.payment.model.KwpLedgerLogisticsUnit;
import com.sckw.payment.model.KwpLedgerTradeUnit;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author xucaiqin
 * @date 2023-07-13 17:32:34
 */
@Service
@AllArgsConstructor
public class KwpLedgerLogisticsUnitService {
    private final KwpLedgerLogisticsUnitMapper logisticsUnitMapper;

    public void saveList(List<KwpLedgerLogisticsUnit> logisticsUnits) {
        if (!CollectionUtils.isEmpty(logisticsUnits)) {
            for (KwpLedgerLogisticsUnit logisticsUnit : logisticsUnits) {
                logisticsUnitMapper.insert(logisticsUnit);
            }
        }
    }

    public void remove(Long lLedgerId) {
        KwpLedgerLogisticsUnit logisticsUnit = new KwpLedgerLogisticsUnit();
        logisticsUnit.setDelFlag(1);
        logisticsUnit.setUpdateTime(LocalDateTime.now());
        LambdaUpdateWrapper<KwpLedgerLogisticsUnit> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(KwpLedgerLogisticsUnit::getLLedgerId, lLedgerId);
        wrapper.eq(KwpLedgerLogisticsUnit::getDelFlag, 0);
        logisticsUnitMapper.update(logisticsUnit, wrapper);
    }
}
