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

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

/**
 * 
 * 
 * @author wlf
 * @email sunlightcs@gmail.com
 * @date 2022-04-06 13:56:01
 */
@Mapper
public interface InvokeFrequencyDao extends BaseMapper<InvokeFrequencyEntity> {
    InvokeFrequencyEntity queryByUniqueKey(String uniqueKey);

    void updateByUniqueKey(InvokeFrequencyEntity invokeFrequencyEntity);

    String getRemark(String today, String invokeType);

    boolean insertOrUpdate(InvokeFrequencyEntity entity);

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

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