xiangpei
2024-11-13 37e189c3e7f8ae4468afbfd1abf9a83d4128a627
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
52
53
54
55
56
57
package org.dromara.system.sync;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.dromara.system.domain.SysOss;
import org.dromara.system.domain.properties.Boundary;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.mapper.SysOssMapper;
import org.dromara.system.uitil.HttpUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
 
@Component
public class deleteSync {
 
    private final SysOssMapper baseMapper;
    private final Boundary boundary;
 
    public deleteSync(SysOssMapper baseMapper, Boundary boundary) {
        this.baseMapper = baseMapper;
        this.boundary = boundary;
    }
 
 
//    @Scheduled(cron = "0 */10 * * * ?")
    public void remove() throws IOException {
        System.out.println("同步删除......");
        List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(1));
 
        if (ids.size() == 0) {
            return;
        }
        for (Long ossId : ids) {
            HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete",
                String.valueOf(ossId));
        }
    }
 
 
    /**
     * 每小时删除30天之前的文件信息,确保上面的定时任务不会因为停电关机等原因导致文件未被删除
     *
     * @throws IOException
     */
//    @Scheduled(cron = "0 0 * * * ?")
    public void removeOssTable() throws IOException {
        System.out.println("每小时定时删除超过30天的数据库文件信息......");
        List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(30));
        if (ids.size() == 0) {
            return;
        }
        baseMapper.deleteBatchIds(ids);
    }
}