package com.sckw.payment.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sckw.payment.dao.KwpLedgerTradeUnitMapper;
import com.sckw.payment.model.KwpLedgerTradeUnit;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

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

/**
 * @author xucaiqin
 * @date 2023-07-13 17:32:40
 */
@Service
@AllArgsConstructor
public class KwpLedgerTradeUnitService {
    private final KwpLedgerTradeUnitMapper tradeUnitMapper;

    public void saveList(List<KwpLedgerTradeUnit> list) {
        if (!CollectionUtils.isEmpty(list)) {
            for (KwpLedgerTradeUnit kwpLedgerTradeUnit : list) {
                tradeUnitMapper.insert(kwpLedgerTradeUnit);
            }
        }
    }

    public void remove(Long tLedgerId) {
        KwpLedgerTradeUnit kwpLedgerTradeUnit = new KwpLedgerTradeUnit();
        kwpLedgerTradeUnit.setDelFlag(1);
        kwpLedgerTradeUnit.setUpdateTime(LocalDateTime.now());
        LambdaUpdateWrapper<KwpLedgerTradeUnit> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(KwpLedgerTradeUnit::getTLedgerId, tLedgerId);
        wrapper.eq(KwpLedgerTradeUnit::getDelFlag, 0);
        tradeUnitMapper.update(kwpLedgerTradeUnit, wrapper);
    }
}
