package cn.iocoder.yudao.module.system.dal.mysql.storage; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.dal.dataobject.storage.SystemStorageBlobDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.Collection; import java.util.List; /** * 文件主表 Mapper * * @author 芋道源码 */ @Mapper public interface SystemStorageBlobMapper extends BaseMapperX { default SystemStorageBlobDO selectByUidFilename(String uidFilename) { return selectOne(SystemStorageBlobDO::getUidFilename, uidFilename); } default SystemStorageBlobDO selectByUidFilenameAndResourceKey(String uidFilename, String resourceKey) { return selectOne(new LambdaQueryWrapperX() .eq(SystemStorageBlobDO::getUidFilename, uidFilename) .eq(SystemStorageBlobDO::getResourceKey, resourceKey)); } default List selectExistingUidFilenames(Collection fileNames) { if (fileNames == null || fileNames.isEmpty()) { return List.of(); } return selectList(new LambdaQueryWrapperX() .in(SystemStorageBlobDO::getUidFilename, fileNames) .select(SystemStorageBlobDO::getUidFilename)) .stream().map(SystemStorageBlobDO::getUidFilename).toList(); } /** * 查询孤儿blob(未被 system_storage_attachment 关联的记录),按ID范围分批查询 * 用于定时清理任务 */ @Select("SELECT b.* FROM system_storage_blob b " + "LEFT JOIN system_storage_attachment a ON a.storage_blob_id = b.id AND a.deleted = 0 " + "WHERE a.id IS NULL AND b.id > #{lastId} " + "ORDER BY b.id LIMIT #{limit}") List selectOrphanBlobsByIdRange(@Param("lastId") long lastId, @Param("limit") int limit); }