liyong
3 天以前 d62a74c14a4002c0f401c94976fba8cc77cda6e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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<SystemStorageBlobDO> {
 
    default SystemStorageBlobDO selectByUidFilename(String uidFilename) {
        return selectOne(SystemStorageBlobDO::getUidFilename, uidFilename);
    }
 
    default SystemStorageBlobDO selectByUidFilenameAndResourceKey(String uidFilename, String resourceKey) {
        return selectOne(new LambdaQueryWrapperX<SystemStorageBlobDO>()
                .eq(SystemStorageBlobDO::getUidFilename, uidFilename)
                .eq(SystemStorageBlobDO::getResourceKey, resourceKey));
    }
 
    default List<String> selectExistingUidFilenames(Collection<String> fileNames) {
        if (fileNames == null || fileNames.isEmpty()) {
            return List.of();
        }
        return selectList(new LambdaQueryWrapperX<SystemStorageBlobDO>()
                .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<SystemStorageBlobDO> selectOrphanBlobsByIdRange(@Param("lastId") long lastId, @Param("limit") int limit);
 
}