package com.qianwen.smartman.modules.system.service.impl;
|
|
import java.io.IOException;
|
import java.util.List;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.common.utils.Lambda;
|
import com.qianwen.smartman.common.utils.PictureUtil;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import com.qianwen.smartman.modules.system.dto.GalleryItemDTO;
|
import com.qianwen.smartman.modules.system.entity.GalleryItem;
|
import com.qianwen.smartman.modules.system.mapper.GalleryItemMapper;
|
import com.qianwen.smartman.modules.system.service.IGalleryItemService;
|
|
@Service
|
public class GalleryItemServiceImpl extends BaseServiceImpl<GalleryItemMapper, GalleryItem> implements IGalleryItemService {
|
private final OssBuilder ossBuilder;
|
|
|
public GalleryItemServiceImpl(final OssBuilder ossBuilder) {
|
this.ossBuilder = ossBuilder;
|
}
|
|
@Override // org.springblade.modules.system.service.IGalleryItemService
|
@Transactional
|
public GalleryItem save(MultipartFile file, GalleryItemDTO galleryItemDTO) throws IOException {
|
GalleryItem galleryItem = new GalleryItem();
|
galleryItem.setGalleryId(galleryItemDTO.getGalleryId());
|
galleryItem.setThumbnail(PictureUtil.compressBase64(file.getBytes(), 10L));
|
BladeFile bladeFile = this.ossBuilder.visualTemplate().putFile(file.getOriginalFilename(), file);
|
galleryItem.setName(bladeFile.getName());
|
galleryItem.setOriginalName(bladeFile.getOriginalName());
|
galleryItem.setLink(bladeFile.getName());
|
galleryItem.setExtension(PictureUtil.getSuffix(file));
|
save(galleryItem);
|
return galleryItem;
|
}
|
|
@Override // org.springblade.modules.system.service.IGalleryItemService
|
public boolean remove(List<String> ids) {
|
List<GalleryItem> galleryItems = list(Lambda.in((v0) -> {
|
return v0.getId();
|
}, ids));
|
galleryItems.forEach(item -> {
|
this.ossBuilder.template().removeFile(item.getName());
|
});
|
return removeByIds(Func.toLongList(ids));
|
}
|
}
|