|
|
@@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -23,10 +24,6 @@ public class ImageRepository {
|
|
|
this.imageUrlMapper = imageUrlMapper;
|
|
|
}
|
|
|
|
|
|
- public void saveImageFile(ImageFile imageFile) {
|
|
|
- imageFileMapper.save(imageFile);
|
|
|
- }
|
|
|
-
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveImageFile(ImageFile imageFile, List<ImageUrl> imageUrls) {
|
|
|
imageFileMapper.save(imageFile);
|
|
|
@@ -35,6 +32,28 @@ public class ImageRepository {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public List<String> deleteImageFile(String imageFileId) {
|
|
|
+ List<String> objectIds = imageUrlMapper.findByImageFileId(imageFileId).stream()
|
|
|
+ .map(ImageUrl::getObjectId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ deleteImageFile0(imageFileId);
|
|
|
+ return objectIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteImageFile0(String imageFileId) {
|
|
|
+ imageUrlMapper.deleteByImageFileId(imageFileId);
|
|
|
+ imageFileMapper.deleteByImageFileId(imageFileId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ImageFile getImageFile(String imageFileId) {
|
|
|
+ return imageFileMapper.findByImageFileId(imageFileId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ImageUrl> getImageUrls(String imageFileId) {
|
|
|
+ return imageUrlMapper.findByImageFileId(imageFileId);
|
|
|
+ }
|
|
|
+
|
|
|
public List<ImageUrlDto> getImageUrls(List<String> imageFileIds) {
|
|
|
List<ImageUrlDto> list = new ArrayList<>();
|
|
|
for (String imageFileId : imageFileIds) {
|
|
|
@@ -45,12 +64,12 @@ public class ImageRepository {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- public List<ImageUrl> getImageUrls(String imageFileId) {
|
|
|
- return imageUrlMapper.findByImageFileId(imageFileId);
|
|
|
- }
|
|
|
-
|
|
|
public ImageUrlDto getImageUrl(String imageFileId) {
|
|
|
List<ImageUrl> list = imageUrlMapper.findByImageFileId(imageFileId);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
ImageUrlDto imageUrlDto = new ImageUrlDto(imageFileId);
|
|
|
for (ImageUrl imageUrl : list) {
|
|
|
String format = imageUrl.getFormat();
|
|
|
@@ -64,8 +83,4 @@ public class ImageRepository {
|
|
|
|
|
|
return imageUrlDto;
|
|
|
}
|
|
|
-
|
|
|
- public ImageFile getImageFile(String imageFileId) {
|
|
|
- return imageFileMapper.findByImageFileId(imageFileId);
|
|
|
- }
|
|
|
}
|