import cn.reghao.dfs.store.DfsStoreApplication; import cn.reghao.dfs.store.db.mapper.*; import cn.reghao.dfs.store.db.repository.ObjectRepository; import cn.reghao.dfs.store.model.po.*; import cn.reghao.dfs.store.model.vo.ImageObject; import cn.reghao.jutil.media.ImageOps; import cn.reghao.oss.api.dto.ObjectMeta; import cn.reghao.oss.api.rest.UploadFileRet; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; /** * @author reghao * @date 2023-03-22 16:19:12 */ @Slf4j @ActiveProfiles("dev") @SpringBootTest(classes = DfsStoreApplication.class) @RunWith(SpringRunner.class) public class MediaFileTest { @Autowired VideoFileMapper videoFileMapper; @Autowired VideoUrlMapper videoUrlMapper; @Autowired FileMetaMapper fileMetaMapper; @Autowired ImageFileMapper imageFileMapper; @Autowired ImageUrlMapper imageUrlMapper; @Autowired ObjectRepository objectRepository; @Test public void videoUrlTest() { List list = imageFileMapper.findAll1(); Set ids = list.stream().map(ImageObject::getImageFileId).collect(Collectors.toSet()); List list1 = imageUrlMapper.findAll1(); //Set ids = list1.stream().map(ImageObject::getImageFileId).collect(Collectors.toSet()); List notExist = new ArrayList<>(); list1.forEach(imageObject -> { if (!ids.contains(imageObject.getImageFileId())) { notExist.add(imageObject); } }); List imageFiles = new ArrayList<>(); /*for (ImageObject imageObject : notExist) { String imageFileId = imageObject.getImageFileId(); String objectId = imageObject.getObjectId(); ObjectMeta objectMeta = objectRepository.getObjectMetaById(objectId); if (objectMeta == null) { log.error("object {} not exist", objectId); continue; } String absolutePath = objectMeta.getAbsolutePath(); File file = new File(absolutePath); if (!file.exists()) { log.error("file {} not exist", absolutePath); continue; } try { ImageOps.Size size = ImageOps.info(file); int width = size.getWidth(); int height = size.getHeight(); ImageFile imageFile = new ImageFile(imageFileId, width, height); imageFiles.add(imageFile); if (imageFiles.size() > 10_000) { imageFileMapper.saveAll(imageFiles); log.info("持久化 {} 个 ImageFile", imageFiles.size()); imageFiles.clear(); } } catch (Exception e) { e.printStackTrace(); } } if (imageFiles.size() > 0) { imageFileMapper.saveAll(imageFiles); log.info("持久化 {} 个 ImageFile", imageFiles.size()); imageFiles.clear(); }*/ } }