package com.friday.custody.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.friday.custody.entity.CustShareDetailInfoEntity;
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-03-21 10:45:51
 */
@Mapper
public interface CustShareDetailInfoDao extends BaseMapper<CustShareDetailInfoEntity> {

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