package cn.iocoder.yudao.module.supplier.service.impl;

import cn.iocoder.yudao.module.supplier.entity.BaseSupplierAccount;
import cn.iocoder.yudao.module.supplier.mapper.BaseSupplierAccountMapper;
import cn.iocoder.yudao.module.supplier.service.BaseSupplierAccountService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 供应商关联账户 Service 实现类
 *
 * @author pqz
 */
@Service
@Validated
public class BaseSupplierAccountServiceImpl extends ServiceImpl<BaseSupplierAccountMapper, BaseSupplierAccount> implements BaseSupplierAccountService {


    /**
     * @param supplierId 供应商id
     * @param list       List<BaseSupplierAccount> 实体
     * @return void
     * @author PQZ
     * @date 9:45 2024/9/12
     **/
    @Override
    public void saveBaseSupplierAccount(String supplierId, List<BaseSupplierAccount> list) {
        /*1、删除原有供应商银行账户*/
        removeBySupplierId(supplierId);
        /*2、保存新账户*/
        list.forEach(item -> {
            item.setId(null);
            item.setSupplierId(supplierId);
        });
        saveBatch(list);
    }

    /**
     * 通过供应商id删除供应商
     *
     * @param supplierId 供应商id
     * @author PQZ
     * @date 9:54 2024/9/12
     **/
    @Override
    public void removeBySupplierId(String supplierId) {
        LambdaQueryWrapper<BaseSupplierAccount> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BaseSupplierAccount::getSupplierId,supplierId);
        remove(lambdaQueryWrapper);
    }

    /**
     * 根据供应商id查询银行账户
     *
     * @param supplierId 供应商id
     * @return java.util.List<cn.iocoder.yudao.module.supplier.entity.BaseSupplierAccount>
     * @author PQZ
     * @date 9:59 2024/9/12
     **/
    @Override
    public List<BaseSupplierAccount> listBySupplierId(String supplierId) {
        LambdaQueryWrapper<BaseSupplierAccount> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BaseSupplierAccount::getSupplierId,supplierId);
        return list(lambdaQueryWrapper);
    }
}