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.FundOpenInfoEntity;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * 基金产品开放信息表（fund_open_info）
 * 
 * @author chenyy K2511571
 * @date 2022-11-02 17:52:04
 */
@Mapper
public interface FundOpenInfoDao extends BaseMapper<FundOpenInfoEntity> {

    default Set<String> queryUniqueKeyList(List<String> uniqueKeyList){
        LambdaQueryWrapper<FundOpenInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(FundOpenInfoEntity::getUniqueKey).in(FundOpenInfoEntity::getUniqueKey, uniqueKeyList);
        List<FundOpenInfoEntity> 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<FundOpenInfoEntity> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.in(FundOpenInfoEntity::getUniqueKey, uniqueKeySet);
        return delete(queryWrapper);
    }
}
