package com.friday.custody.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.friday.custody.entity.InvestorBankInfoEntity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 
 * 
 * @author lyb
 * @email k0051582@gmail.com
 * @date 2022-03-04 16:12:06
 */
@Mapper
public interface InvestorBankInfoDao extends BaseMapper<InvestorBankInfoEntity> {

    default Set<String> queryUniqueKeyList(List<String> rawUniqueKeyList){
        if (CollectionUtils.isEmpty(rawUniqueKeyList)){
            return null;
        }
        LambdaQueryWrapper<InvestorBankInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(InvestorBankInfoEntity::getUniqueKey).in(InvestorBankInfoEntity::getUniqueKey, rawUniqueKeyList);
        List<InvestorBankInfoEntity> entityList = this.selectList(queryWrapper);
        Set<String> result = entityList.stream().map(t -> t.getUniqueKey()).collect(Collectors.toSet());
        return result;
    }

    default int deleteByUniqueKeys(Set<String> uniqueKeySet){
        LambdaQueryWrapper<InvestorBankInfoEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.in(InvestorBankInfoEntity::getUniqueKey, uniqueKeySet);
        return delete(queryWrapper);
    }
}
