package com.sckw.order.serivce;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.order.dao.KwpWantBuyTradingMapper;
import com.sckw.order.model.KwoWantBuyTrading;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc: 求购支付service
 * @author: yzc
 * @date: 2023-07-24 14:43
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class KwoWantBuyTradingService {

    private final KwpWantBuyTradingMapper kwpWantBuyTradingMapper;

    public void insertBatch(List<KwoWantBuyTrading> list) {
        kwpWantBuyTradingMapper.insertBatch(list);
    }

    public List<KwoWantBuyTrading> getByWantBuyId(Long wantBuyId) {
        LambdaQueryWrapper<KwoWantBuyTrading> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwoWantBuyTrading::getWantBuyId, wantBuyId).eq(KwoWantBuyTrading::getDelFlag, Global.NO);
        List<KwoWantBuyTrading> list = kwpWantBuyTradingMapper.selectList(wrapper);
        return CollectionUtils.emptyIfNull(list);
    }

    //根据wangtBuyId删除
    public Integer deleteByWantBuyid(Long wantBuyid){
        LambdaUpdateWrapper<KwoWantBuyTrading> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(KwoWantBuyTrading::getWantBuyId, wantBuyid).set(KwoWantBuyTrading::getDelFlag, Global.YES);
        return kwpWantBuyTradingMapper.update(null,wrapper);
    }

    //根据wangtBuyIds批量删除
    public void delTradingByWantBuyids(List<Long> ids)
    {
        LambdaUpdateWrapper<KwoWantBuyTrading> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(KwoWantBuyTrading::getWantBuyId, ids).eq(KwoWantBuyTrading::getDelFlag, Global.NO).set(KwoWantBuyTrading::getDelFlag, Global.YES);
        kwpWantBuyTradingMapper.update(null,wrapper);
    }



}
