| | |
| | | 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; |
| | |
| | | @Component |
| | | public class deleteSync { |
| | | |
| | | private final SysOssMapper baseMapper; |
| | | private final ISysOssService ossService; |
| | | private final SysOssMapper ossMapper; |
| | | private final Boundary boundary; |
| | | |
| | | public deleteSync(SysOssMapper baseMapper, Boundary boundary) { |
| | | this.baseMapper = baseMapper; |
| | | 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 { |
| | | // System.out.println("同步删除......"); |
| | | // List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(1)); |
| | | // |
| | | // if (ids.size() == 0) { |
| | | // return; |
| | | // } |
| | | // for (Long ossId : ids) { |
| | | // baseMapper.deleteById(ossId); |
| | | // HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete", |
| | | // String.valueOf(ossId)); |
| | | // } |
| | | // } |
| | | |
| | | @Scheduled(cron = "0 */10 * * * ?") |
| | | public void remove() throws IOException { |
| | | System.out.println("同步删除......"); |
| | | List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(1)); |
| | | |
| | | System.out.println("self delete......"); |
| | | List<Long> ids = ossMapper.getWillDeleted(LocalDateTime.now().minusDays(1)); |
| | | if (ids.size() == 0) { |
| | | return; |
| | | } |
| | | for (Long ossId : ids) { |
| | | baseMapper.deleteById(ossId); |
| | | HttpUtils.sendDeleteRequest(boundary.getVideo() + "/resource/synchronization/delete", |
| | | String.valueOf(ossId)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 每小时删除2天之前的文件信息,因为上面的同步删除并不能保证事务 |
| | | * |
| | | * @throws IOException |
| | | */ |
| | | @Scheduled(cron = "0 0 * * * ?") |
| | | public void removeOssTable() throws IOException { |
| | | log.error("每小时定时删除超过2天的数据库文件信息......"); |
| | | List<Long> ids = baseMapper.getWillDeleted(LocalDateTime.now().minusDays(2)); |
| | | if (ids.size() == 0) { |
| | | return; |
| | | } |
| | | // 删除对应文件 |
| | | OssClient ossClient = OssFactory.instance(); |
| | | for (Long ossId : ids) { |
| | | SysOss sysOss = baseMapper.selectById(ossId); |
| | | if (Objects.nonNull(sysOss)) { |
| | | ossClient.delete(sysOss.getFileName()); |
| | | } |
| | | } |
| | | baseMapper.deleteIds(ids); |
| | | ossService.deleteByIds(ids); |
| | | } |
| | | } |