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.KwpWantBuyAddressMapper;
import com.sckw.order.model.KwoWantBuyAddress;
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:42
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class KwoWantBuyAddressService {

    private final KwpWantBuyAddressMapper kwpWantBuyAddress;

    public List<KwoWantBuyAddress> getByAddressId(Long addressId) {
        LambdaQueryWrapper<KwoWantBuyAddress> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(KwoWantBuyAddress::getWantBuyId, addressId).eq(KwoWantBuyAddress::getDelFlag, Global.NO);
        List<KwoWantBuyAddress> list = kwpWantBuyAddress.selectList(wrapper);
        return CollectionUtils.emptyIfNull(list);
    }

    public void delAddressByWantBuyIds(List<Long> wantBuyIds) {
        LambdaUpdateWrapper<KwoWantBuyAddress> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(KwoWantBuyAddress::getWantBuyId, wantBuyIds).eq(KwoWantBuyAddress::getDelFlag, Global.NO)
                        .set(KwoWantBuyAddress::getDelFlag, Global.YES);
        kwpWantBuyAddress.update(null,wrapper);
    }

}
