|
|
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Repository;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -18,9 +19,11 @@ import java.util.stream.Collectors;
|
|
|
@Repository
|
|
|
public class ImageRepository {
|
|
|
private final ImageFileMapper imageFileMapper;
|
|
|
+ private final ObjectRepository objectRepository;
|
|
|
|
|
|
- public ImageRepository(ImageFileMapper imageFileMapper) {
|
|
|
+ public ImageRepository(ImageFileMapper imageFileMapper, ObjectRepository objectRepository) {
|
|
|
this.imageFileMapper = imageFileMapper;
|
|
|
+ this.objectRepository = objectRepository;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -28,17 +31,29 @@ public class ImageRepository {
|
|
|
imageFileMapper.saveAll(imageFiles);
|
|
|
}
|
|
|
|
|
|
- public List<String> deleteImageFile(String imageFileId) {
|
|
|
+ public void deleteByImageFileIds(List<String> imageFileIds) {
|
|
|
+ imageFileIds.forEach(this::deleteImageFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteImageFile(String imageFileId) {
|
|
|
List<String> objectIds = imageFileMapper.findByImageFileId(imageFileId).stream()
|
|
|
.map(ImageFile::getObjectId)
|
|
|
.collect(Collectors.toList());
|
|
|
- deleteImageFile0(imageFileId);
|
|
|
- return objectIds;
|
|
|
+ deleteImageFile0(imageFileId, objectIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByObjectNames(List<String> imageObjectNames) {
|
|
|
+ List<FileMeta> fileMetas = objectRepository.getByObjectNames(imageObjectNames);
|
|
|
+ fileMetas.forEach(fileMeta -> {
|
|
|
+ String objectId = fileMeta.getObjectId();
|
|
|
+ deleteImageFile(objectId);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void deleteImageFile0(String imageFileId) {
|
|
|
+ public void deleteImageFile0(String imageFileId, List<String> objectIds) {
|
|
|
imageFileMapper.deleteByImageFileId(imageFileId);
|
|
|
+ objectRepository.deleteByObjectIds(objectIds);
|
|
|
}
|
|
|
|
|
|
public List<ImageFile> findImageFiles(String imageFileId) {
|