| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package cn.reghao.tnb.file.app.service;
- import cn.reghao.tnb.file.app.config.PathUrl;
- import cn.reghao.tnb.file.app.db.mapper.FileUrlMapper;
- import cn.reghao.tnb.file.app.db.mapper.FileUserMapper;
- import cn.reghao.tnb.file.app.model.po.FileUrl;
- import cn.reghao.tnb.file.app.model.vo.TmpFile;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.io.FileUtils;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.*;
- import java.nio.file.attribute.BasicFileAttributes;
- import java.util.List;
- /**
- * @author reghao
- * @date 2022-05-23 23:42:06
- */
- @Slf4j
- @Service
- @Deprecated
- public class TmpFileUrlService {
- private final FileUserMapper fileUserMapper;
- private final FileUrlMapper fileUrlMapper;
- private final FileUrlService fileUrlService;
- public TmpFileUrlService(FileUserMapper fileUserMapper, FileUrlMapper fileUrlMapper, FileUrlService fileUrlService) {
- this.fileUserMapper = fileUserMapper;
- this.fileUrlMapper = fileUrlMapper;
- this.fileUrlService = fileUrlService;
- }
- public void start() {
- List<TmpFile> list = fileUserMapper.findTmpFile();
- for (TmpFile tmpFile : list) {
- String sha256sum = tmpFile.getSha256sum();
- long fileSize = tmpFile.getSize();
- String uploadId = tmpFile.getUploadId();
- String suffix = tmpFile.getSuffix();
- String fileId = tmpFile.getFileId();
- try {
- PathUrl pathUrl = fileUrlService.genVideoPathAndUrl(sha256sum, uploadId, fileSize, fileId, suffix);
- String blockId = pathUrl.getBlockId();
- String filePath = pathUrl.getFilePath();
- String url = pathUrl.getUrl();
- String path = pathUrl.getPath();
- List<FileUrl> list1 = fileUrlMapper.findByFileId(fileId);
- if (list1.isEmpty()) {
- continue;
- }
- FileUrl fileUrl = list1.get(0);
- String url1 = fileUrl.getUrl();
- String filePath1;
- if (url.contains("group")) {
- filePath1 = url1.replace("//static.reghao.cn/group0/node0", "/root/mnt");
- } else {
- filePath1 = url1.replace("//static.reghao.cn", "/root/mnt");
- }
- File source = new File(filePath1);
- File dest = new File(filePath);
- if (source.exists()) {
- FileUtils.copyFile(source, new File(filePath), true);
- fileUrlMapper.updateSetFileUrl(fileId, blockId, filePath);
- } else {
- log.error("source file {} not exist", filePath);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- log.info("start 执行完成...");
- }
- public void start1() {
- fileUrlMapper.findAll().forEach(fileUrl -> {
- String url = fileUrl.getUrl();
- String filePath;
- if (url.contains("group")) {
- filePath = url.replace("//static.reghao.cn/group0/node0", "/root/mnt");
- } else {
- filePath = url.replace("//static.reghao.cn", "/root/mnt");
- }
- File file = new File(filePath);
- if (!file.exists()) {
- log.error("{} not exist", filePath);
- } else {
- log.info("{} exist", filePath);
- }
- });
- log.info("start1 执行完成...");
- }
- }
|