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.CryptoServiceDeviceGroup;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

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

/**
 * @author liulu
 * @since 2024/11/1
 */
@Mapper
public interface CryptoServiceDeviceGroupMapper extends BaseMapper<CryptoServiceDeviceGroup> {


    default CryptoServiceDeviceGroup selectByServiceId(Long id) {
        Assert.notNull(id, "id不能为空");
        List<CryptoServiceDeviceGroup> list = selectList(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().eq(CryptoServiceDeviceGroup::getServiceId, id));
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.iterator().next();
    }

    default List<CryptoServiceDeviceGroup> selectByServiceIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().
                in(CryptoServiceDeviceGroup::getServiceId, ids));
    }

    default void deleteByServiceId(Long id) {
        Assert.notNull(id, "id不能为空");
        delete(new LambdaQueryWrapper<CryptoServiceDeviceGroup>().eq(CryptoServiceDeviceGroup::getServiceId, id));
    }


}
