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

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

/**
 * 基金行情数据表（custody_fund_index_daily_quote_info）
 * 
 * @author chenyy K2511571
 * @date 2022-08-08 16:52:34
 */
@Mapper
public interface FundIndexDailyQuoteInfoDao extends BaseMapper<FundIndexDailyQuoteInfoEntity> {

    boolean insertOrUpdate(FundIndexDailyQuoteInfoEntity entity);

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

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