package com.backendsys.modules.common.utils;

import com.backendsys.exception.CustException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public class MybatisUtil {
    /**
     * 判断记录是否存在 (抛出异常)
     */
    public static <T, M extends BaseMapper> void checkExists(M mapper, String key, T value, String message) {
        Long count = mapper.selectCount(new QueryWrapper<>().eq(key, value));
        if (count == 0) {
            throw new CustException(message);
        }
    }
    /**
     * 判断记录是否存在 (返回Boolean)
     */
    public static <T, M extends BaseMapper> Boolean checkExists(M mapper, String key, T value) {
        Long count = mapper.selectCount(new QueryWrapper<>().eq(key, value));
        return count == 0;
    }
}
