|
@@ -8,8 +8,11 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
+import com.ruoyi.system.domain.ZbFile;
|
|
|
import com.ruoyi.system.domain.grallery.ZbPicToPic;
|
|
|
import com.ruoyi.system.domain.grallery.ZbZip;
|
|
|
import com.ruoyi.system.dto.PicToPicDto;
|
|
@@ -20,7 +23,10 @@ import com.ruoyi.system.service.IZbFileService;
|
|
|
import com.ruoyi.system.service.IZbPicToPicService;
|
|
|
import com.ruoyi.system.service.IZbZipService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -38,6 +44,7 @@ import java.util.zip.ZipOutputStream;
|
|
|
* @author ruoyi
|
|
|
* @date 2020-12-02
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicToPic> implements IZbPicToPicService {
|
|
@@ -99,13 +106,18 @@ public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicTo
|
|
|
String pathname = timeFormat + RandomUtil.randomString(20) + ".zip";
|
|
|
|
|
|
File file = new File(profile + File.separator + pathname);
|
|
|
+ //检查或者创建父级文件夹
|
|
|
FileUtils.checkOrCreateParentDir(file);
|
|
|
+ ZipOutputStream zipOutputStream = null;
|
|
|
try {
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
|
- ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
|
|
|
+ zipOutputStream = new ZipOutputStream(fileOutputStream);
|
|
|
for (MultipartFile multipartFile : files) {
|
|
|
String originalFilename = multipartFile.getOriginalFilename();
|
|
|
- zipOutputStream.putNextEntry(new ZipEntry(originalFilename));
|
|
|
+ if (originalFilename != null) {
|
|
|
+ ZipEntry zipEntry = new ZipEntry(originalFilename);
|
|
|
+ zipOutputStream.putNextEntry(zipEntry);
|
|
|
+ }
|
|
|
zipOutputStream.write(multipartFile.getBytes());
|
|
|
zipOutputStream.flush();
|
|
|
}
|
|
@@ -113,9 +125,16 @@ public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicTo
|
|
|
zipOutputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if (zipOutputStream != null){
|
|
|
+ try {
|
|
|
+ zipOutputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
fileService.upload(file);
|
|
|
-
|
|
|
ZbZip zbZip = new ZbZip();
|
|
|
zbZip.setFileIds(CollectionUtil.join(upload.stream().map(UploadResult::getFileId).collect(Collectors.toList()), ","));
|
|
|
zbZip.setFileNum(files.length);
|
|
@@ -128,6 +147,76 @@ public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicTo
|
|
|
return zbZip;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 后台删除图来图往
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public AjaxResult removeZbPicToPic(Long id) {
|
|
|
+ //先去查询zb_pic_to_pic表信息
|
|
|
+ PicToPicDto picToPicDto = getDetailById(id);
|
|
|
+ if (ObjectUtil.isNotEmpty(picToPicDto)){
|
|
|
+ //获取压缩包id
|
|
|
+ Long zipId = picToPicDto.getZipId();
|
|
|
+ //查询压缩包信息
|
|
|
+ ZbZip zbZip = zbZipService.getById(zipId);
|
|
|
+ if (ObjectUtil.isNotEmpty(zbZip)){
|
|
|
+ //获取附件表ids
|
|
|
+ String fileIds = zbZip.getFileIds();
|
|
|
+ //获取附件表信息
|
|
|
+ String[] fileIdsArr = fileIds.split(",");
|
|
|
+ //先查询,再删除
|
|
|
+ List<ZbFile> zbFiles = zbFileService.selectByIds(fileIdsArr);
|
|
|
+ //删除附件表信息
|
|
|
+ Integer integer = zbFileService.deleteByIds(fileIdsArr);
|
|
|
+ if (integer != fileIdsArr.length){
|
|
|
+ return AjaxResult.error("删除系统附件信息失败");
|
|
|
+ }
|
|
|
+ //删除表zb_zip
|
|
|
+ if (!zbZipService.removeById(zbZip)){
|
|
|
+ return AjaxResult.error("删除压缩包信息失败");
|
|
|
+ }
|
|
|
+ //删除表zb_pic_to_pic
|
|
|
+ if (baseMapper.deleteById(id) < 1){
|
|
|
+ return AjaxResult.error("删除图来图往信息失败");
|
|
|
+ }
|
|
|
+ //获取附件表上传图片地址
|
|
|
+ for (ZbFile zbFile : zbFiles) {
|
|
|
+ String path = zbFile.getPath();
|
|
|
+ if (StringUtils.isNotEmpty(path)){
|
|
|
+ File file = new File(RuoYiConfig.getProfile() + File.separator + path);
|
|
|
+ log.info("删除原始文件: " + file);
|
|
|
+ try {
|
|
|
+ FileUtils.forceDelete(file);
|
|
|
+ String thumbnailPath = zbFile.getThumbnailPath();
|
|
|
+ if (StringUtils.isNotEmpty(thumbnailPath)){
|
|
|
+ File fileThumbnail = new File(RuoYiConfig.getProfile() + File.separator + thumbnailPath);
|
|
|
+ log.info("删除缩略图文件: " + fileThumbnail);
|
|
|
+ FileUtils.forceDelete(fileThumbnail);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String path = zbZip.getPath();
|
|
|
+ if (StringUtils.isNotEmpty(path)){
|
|
|
+ //删除压缩包表数据
|
|
|
+ File file = new File(RuoYiConfig.getProfile() + File.separator + path);
|
|
|
+ log.info("删除压缩包文件: " + file);
|
|
|
+ try {
|
|
|
+ FileUtils.forceDelete(file);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.error();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PicToPicDto getDetailById(Long picId) {
|
|
|
PicToPicDto detail = baseMapper.getDetailById(picId);
|