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

import java.util.List;

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


    default AppCert selectBySN(String sn) {
        Assert.hasText(sn, "证书序列号不能为空");
        List<AppCert> certs = selectList(new LambdaQueryWrapper<AppCert>()
                .eq(AppCert::getSerialNumber, sn)
        );
        if (CollectionUtils.isEmpty(certs)) {
            return null;
        }
        return certs.iterator().next();
    }


}
