package com.sunyard.chsm.mapper;

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

import java.util.List;

/**
 * @author liulu
 * @since 2024/10/29
 */
@Mapper
public interface ApplicationMapper extends BaseMapper<Application> {


    default Application selectByAppKey(String appKey) {
        List<Application> apps = selectList(new QueryWrapper<Application>().eq("app_key", appKey));
        if (CollectionUtils.isEmpty(apps)) {
            return null;
        }
        Assert.isTrue(apps.size() == 1, "app 数据异常");
        return apps.iterator().next();
    }

}
