|
|
@@ -1,8 +1,7 @@
|
|
|
import cn.reghao.dfs.store.db.mapper.*;
|
|
|
import cn.reghao.dfs.store.model.constant.VideoUrlType;
|
|
|
import cn.reghao.dfs.store.model.dto.UploadingFile;
|
|
|
-import cn.reghao.dfs.store.model.po.ImageUrl;
|
|
|
-import cn.reghao.dfs.store.model.po.VideoUrl;
|
|
|
+import cn.reghao.dfs.store.model.po.*;
|
|
|
import cn.reghao.dfs.store.model.vo.ImageFileRet;
|
|
|
import cn.reghao.dfs.store.model.dto.UploadedFile;
|
|
|
import cn.reghao.dfs.store.service.FileUploadService;
|
|
|
@@ -10,7 +9,7 @@ import cn.reghao.dfs.store.service.media.ImageFileService;
|
|
|
import cn.reghao.dfs.store.service.media.MediaQuality;
|
|
|
import cn.reghao.jutil.jdk.http.util.UrlFormatter;
|
|
|
import cn.reghao.dfs.store.DfsStoreApplication;
|
|
|
-import cn.reghao.dfs.store.model.po.FileUrl;
|
|
|
+import cn.reghao.jutil.tool.id.IdGenerator;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.junit.Test;
|
|
|
@@ -42,10 +41,6 @@ public class ConsistentCheckTest {
|
|
|
FileUploadService fileUploadService;
|
|
|
@Autowired
|
|
|
ImageFileService imageFileService;
|
|
|
- @Autowired
|
|
|
- VideoUrlMapper videoUrlMapper;
|
|
|
- @Autowired
|
|
|
- ImageUrlMapper imageUrlMapper;
|
|
|
|
|
|
HttpClient client = HttpClient.newBuilder()
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
@@ -143,44 +138,113 @@ public class ConsistentCheckTest {
|
|
|
videoUrlMapper.save(videoUrl);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ FileInfoMapper fileInfoMapper;
|
|
|
@Autowired
|
|
|
FileUrlMapper fileUrlMapper;
|
|
|
+ @Autowired
|
|
|
+ VideoFileMapper videoFileMapper;
|
|
|
+ @Autowired
|
|
|
+ VideoUrlMapper videoUrlMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查 FileInfo 和 FileUrl 的一致性
|
|
|
+ * FileInfo 和 FileUrl 是 one-to-many 关系
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2022-08-14 下午2:30
|
|
|
+ */
|
|
|
@Test
|
|
|
- public void imgTest() {
|
|
|
- List<ImageUrl> list = imageUrlMapper.findAll();
|
|
|
- list.forEach(imageUrl -> {
|
|
|
- String fileId = imageUrl.getFileId();
|
|
|
- FileUrl fileUrl = fileUrlMapper.findFileUrl(fileId, 0, 0);
|
|
|
- String url = fileUrl.getUrl();
|
|
|
-
|
|
|
- imageUrlMapper.updateSetUrl(fileId, url);
|
|
|
- });
|
|
|
+ public void fileTest() {
|
|
|
+ int i = 0;
|
|
|
+ List<FileInfo> list = fileInfoMapper.findAll();
|
|
|
+ for (FileInfo fileInfo : list) {
|
|
|
+ String fileId = fileInfo.getFileId();
|
|
|
+ List<FileUrl> fileUrls = fileUrlMapper.findByFileId(fileId);
|
|
|
+ if (fileUrls.size() == 0) {
|
|
|
+ log.error("{} 没有 FileUrl", fileId);
|
|
|
+ } else if (fileUrls.size() > 1) {
|
|
|
+ log.error("{} 有 {} 个 FileUrl", fileId, fileUrls.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("{}", i++);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void vidTest() {
|
|
|
- List<VideoUrl> list = videoUrlMapper.findAll();
|
|
|
- list.forEach(videoUrl -> {
|
|
|
- String fileId = videoUrl.getFileId();
|
|
|
- FileUrl fileUrl = fileUrlMapper.findFileUrl(fileId, 0, 0);
|
|
|
- String url = fileUrl.getUrl();
|
|
|
-
|
|
|
- videoUrlMapper.updateSetUrl(fileId, url);
|
|
|
- });
|
|
|
+ public void videoFileTest() {
|
|
|
+ int i = 0;
|
|
|
+ List<FileUrl> list = fileUrlMapper.findAllVideoUrl();
|
|
|
+ for (FileUrl fileUrl : list) {
|
|
|
+ String fileId = fileUrl.getFileId();
|
|
|
+
|
|
|
+ VideoUrl videoUrl = videoUrlMapper.findByFileId(fileId);
|
|
|
+ if (videoUrl != null) {
|
|
|
+ String videoFileId = videoUrl.getVideoFileId();
|
|
|
+ videoUrlMapper.updateSetUrl(fileId, fileUrl.getUrl());
|
|
|
+
|
|
|
+ VideoFile videoFile = videoFileMapper.findByVideoFileId(videoFileId);
|
|
|
+ if (videoFile == null) {
|
|
|
+ log.error("{} 没有 VideoFile", fileId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("{} 没有 VideoUrl", fileId);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("{}", i++);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ IdGenerator idGenerator = new IdGenerator("image-file-id");
|
|
|
+ @Autowired
|
|
|
+ ImageFileMapper imageFileMapper;
|
|
|
+ @Autowired
|
|
|
+ ImageUrlMapper imageUrlMapper;
|
|
|
@Test
|
|
|
- public void uploadSmallImageTest() throws Exception {
|
|
|
- String filePath = "/home/reghao/Downloads/pic/banner/bg.jpg";
|
|
|
- File file = new File(filePath);
|
|
|
+ public void imageFileTest() {
|
|
|
+ int i = 0;
|
|
|
+ List<FileUrl> list = fileUrlMapper.findAllImageUrl();
|
|
|
+ for (FileUrl fileUrl : list) {
|
|
|
+ String fileId = fileUrl.getFileId();
|
|
|
+
|
|
|
+ ImageUrl imageUrl = imageUrlMapper.findByFileId(fileId);
|
|
|
+ if (imageUrl != null) {
|
|
|
+ if (imageUrl.getImageFileId() != null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- String filename = file.getName();
|
|
|
- long size = file.length();
|
|
|
- String contentType = "image/jpeg";
|
|
|
- InputStream inputStream = new FileInputStream(file);
|
|
|
+ String imageFileId = idGenerator.getUuid();
|
|
|
+ boolean horizontal = imageUrl.getWidth() > imageUrl.getHeight();
|
|
|
+ ImageFile imageFile = new ImageFile(imageFileId, horizontal);
|
|
|
+ imageFileMapper.save(imageFile);
|
|
|
+ imageUrlMapper.updateSetUrl(fileId, fileUrl.getUrl(), imageFileId);
|
|
|
+ /*ImageFile imageFile = imageFileMapper.findByImageFileId(imageFileId);
|
|
|
+ if (imageFile == null) {
|
|
|
+ log.info("{} 没有 ImageFile", fileId);
|
|
|
+ }*/
|
|
|
+ } else {
|
|
|
+ log.error("{} 没有 ImageUrl", fileId);
|
|
|
+ }
|
|
|
+ log.info("{}", i++);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- UploadingFile uploadingFile = new UploadingFile(filename, size, contentType, inputStream);
|
|
|
- UploadedFile uploadedFile = fileUploadService.put(uploadingFile);
|
|
|
- System.out.println(uploadedFile.getPathUrl().getUrl());
|
|
|
+ @Test
|
|
|
+ public void videoFileTest1() {
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ List<VideoFile> videoFiles = videoFileMapper.findAll();
|
|
|
+ for (VideoFile videoFile : videoFiles) {
|
|
|
+ String coverUrl = videoFile.getCoverUrl();
|
|
|
+ ImageUrl imageUrl = imageUrlMapper.findByUrl(coverUrl);
|
|
|
+ if (imageUrl != null) {
|
|
|
+ String imageFileId = imageUrl.getImageFileId();
|
|
|
+ } else {
|
|
|
+ log.error("{} 没有 ImageUrl", videoFile.getVideoFileId());
|
|
|
+ }
|
|
|
+
|
|
|
+ //log.info("{}", i++);
|
|
|
+ }
|
|
|
}
|
|
|
}
|