package com.friday.custody.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.friday.custody.entity.FundValueTableDataInfoEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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-02-16 10:32:28
 */
@Mapper
public interface FundValueTableDataInfoDao extends BaseMapper<FundValueTableDataInfoEntity> {


    default List<FundValueTableDataInfoEntity> selectByUniqueKey(FundValueTableDataInfoEntity entity){
        LambdaQueryWrapper<FundValueTableDataInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FundValueTableDataInfoEntity::getUniqueKey, entity.getUniqueKey());
        return selectList(queryWrapper);
    }

    /**
     * 查询唯一主键是否存在，用于区分更新/插入
     * @param uniqueKeyList
     * @return
     */
    default Set<String> queryUniqueKeyList(List<String> uniqueKeyList){
        LambdaQueryWrapper<FundValueTableDataInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(FundValueTableDataInfoEntity::getUniqueKey).in(FundValueTableDataInfoEntity::getUniqueKey, uniqueKeyList);
        List<FundValueTableDataInfoEntity> entityList = this.selectList(queryWrapper);
        Set<String> result = entityList.stream().map(t -> t.getUniqueKey()).collect(Collectors.toSet());
        return result;
    }
}
