xiangpei
2025-02-17 035dae7be5cf8a7a4a13cecb5dc9cde9fcda07e6
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
58
59
60
61
62
63
64
65
66
67
68
69
package org.dromara.system.sync;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.factory.OssFactory;
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.service.ISysOssService;
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;
import java.util.Objects;
 
@Slf4j
@Component
public class deleteSync {
 
    private final ISysOssService ossService;
    private final SysOssMapper ossMapper;
    private final Boundary boundary;
 
    public deleteSync(ISysOssService ossService, SysOssMapper ossMapper, Boundary boundary) {
        this.ossService = ossService;
        this.ossMapper = ossMapper;
        this.boundary = boundary;
    }
 
//    @Scheduled(cron = "0 */10 * * * ?")
//    public void remove() throws IOException {
//        log.error("同步删除......");
//        List<SysOss> list = new LambdaQueryChainWrapper<>(baseMapper)
//            .le(SysOss::getCreateTime, LocalDateTime.now().minusDays(1L))
//            .list();
//        if (list.size() == 0)
//            return;
//
//        for (SysOss vo : list) {
//            OssClient storage = OssFactory.instance(vo.getService());
//            storage.delete(vo.getUrl());
//            HttpResponse httpResponse = HttpUtils.sendDeleteRequest(this.boundary.getVideo() + "/resource/synchronization/delete",
//                String.valueOf(vo.getOssId()));
//            if (httpResponse.getStatusLine().getStatusCode() == 200) {
//                baseMapper.deleteId(vo.getOssId());
//            }
//        }
//    }
 
    @Scheduled(cron = "0 */10 * * * ?")
    public void remove() throws IOException {
        System.out.println("self delete......");
        List<Long> ids = ossMapper.getWillDeleted(LocalDateTime.now().minusDays(1));
        if (ids.size() == 0) {
            return;
        }
        ossService.deleteByIds(ids);
    }
 
}