package com.sunyard.chsm.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunyard.chsm.model.entity.IpWhitelist;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author liulu
 * @since 2024/11/6
 */
@Mapper
public interface IpWhitelisttMapper extends BaseMapper<IpWhitelist> {

    default List<IpWhitelist> selectByAppIds(List<Long> appIds) {
        if (CollectionUtils.isEmpty(appIds)) {
            return Collections.emptyList();
        }
        return selectList(
                new LambdaQueryWrapper<IpWhitelist>()
                        .in(IpWhitelist::getAppId, appIds)
        );
    }

    default void deleteByAppId(Long appId) {
        delete(
                new LambdaQueryWrapper<IpWhitelist>()
                        .eq(IpWhitelist::getAppId, appId)
        );

    }
}
