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

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

/**
 * 
 * 
 * @author lyb
 * @email k0051582@gmail.com
 * @date 2022-07-25 16:29:56
 */
@Mapper
public interface DataDictionaryZxFndBasicInfoCyDao extends BaseMapper<DataDictionaryZxFndBasicInfoCyEntity> {

    boolean insertOrUpdate(DataDictionaryZxFndBasicInfoCyEntity entity);

    String queryKeyByValue(@Param("value") String value);

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

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