sr 4 yıl önce
ebeveyn
işleme
4957472aa0
21 değiştirilmiş dosya ile 352 ekleme ve 72 silme
  1. 18 0
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/ZbFileController.java
  2. 2 1
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/gallery/ZbPicToPicController.java
  3. 5 4
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
  4. 4 2
      ruoyi-common/src/main/java/com/ruoyi/common/utils/FileHashUtil.java
  5. 1 1
      ruoyi-system/src/main/java/com/ruoyi/system/domain/grallery/ZbGalleryImg.java
  6. 1 0
      ruoyi-system/src/main/java/com/ruoyi/system/dto/UploadResult.java
  7. 4 0
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/ZbFileMapper.java
  8. 21 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/IZbFileService.java
  9. 2 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/IZbGalleryImgService.java
  10. 8 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/IZbPicToPicService.java
  11. 22 12
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FileServiceImpl.java
  12. 7 7
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
  13. 62 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbFileServiceImpl.java
  14. 1 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryCategoryServiceImpl.java
  15. 5 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryImgServiceImpl.java
  16. 66 35
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryServiceImpl.java
  17. 99 5
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbPicToPicServiceImpl.java
  18. 18 2
      ruoyi-system/src/main/resources/mapper/system/ZbFileMapper.xml
  19. 3 1
      ruoyi-system/src/main/resources/mapper/system/ZbGalleryMapper.xml
  20. 3 0
      ruoyi-ui/.env.development
  21. 0 1
      ruoyi-ui/src/settings.js

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/ZbFileController.java

@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.common;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -214,4 +215,21 @@ public class ZbFileController extends BaseController {
         }
         return toAjax(zbFileService.removeByIds(Arrays.asList(ids)));
     }
+
+
+    /**
+     * 到存放图片的文件夹下面删除图片
+     *
+     * @param zbFile
+     * @return
+     */
+    @ApiOperation("服务器文件删除")
+    @RepeatSubmit()
+    @PostMapping("/deletePicture")
+    public boolean deletePicture(ZbFile zbFile) {
+        if (zbFile.getId() == null) {
+            return false;
+        }
+        return zbFileService.deletePicture(zbFile);
+    }
 }

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gallery/ZbPicToPicController.java

@@ -73,6 +73,7 @@ public class ZbPicToPicController extends BaseController {
 
     /**
      * 删除图来图往
+     * id是zb_pic_to_pic表中的id
      */
     @DeleteMapping("/{id}")
     @PreAuthorize("@ss.hasPermi('system:pic:remove')")
@@ -80,6 +81,6 @@ public class ZbPicToPicController extends BaseController {
         if (id == null || id == 0) {
             return AjaxResult.error("参数不正确");
         }
-        return toAjax(zbPicToPicService.removeById(id));
+        return zbPicToPicService.removeZbPicToPic(id);
     }
 }

+ 5 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java

@@ -122,11 +122,12 @@ public class SysUserController extends BaseController {
     public AjaxResult add(@Validated @RequestBody SysUser user) {
         if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) {
             return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
-        } else if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+        }
+/*        else if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
             return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
         } else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
             return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
-        }
+        }*/
         user.setCreateBy(SecurityUtils.getUsername());
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
         return toAjax(userService.insertUser(user));
@@ -140,11 +141,11 @@ public class SysUserController extends BaseController {
     @PutMapping
     public AjaxResult edit(@Validated @RequestBody SysUser user) {
         userService.checkUserAllowed(user);
-        if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+/*        if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
             return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
         } else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
             return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
-        }
+        }*/
         user.setUpdateBy(SecurityUtils.getUsername());
         return toAjax(userService.updateUser(user));
     }

+ 4 - 2
ruoyi-common/src/main/java/com/ruoyi/common/utils/FileHashUtil.java

@@ -9,6 +9,7 @@ import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.security.MessageDigest;
+import java.util.Objects;
 
 /**
  * @author Admin
@@ -119,7 +120,7 @@ public class FileHashUtil {
         byte[] uploadBytes = new byte[0];
         MessageDigest md5 = null;
         try {
-            uploadBytes = file.getBytes();
+            uploadBytes = Objects.requireNonNull(file.getOriginalFilename()).getBytes();
             md5 = MessageDigest.getInstance("MD5");
         } catch (Exception e) {
             e.printStackTrace();
@@ -133,7 +134,8 @@ public class FileHashUtil {
         byte[] uploadBytes = new byte[0];
         MessageDigest md5 = null;
         try {
-            uploadBytes = FileUtil.readBytes(file);
+            uploadBytes = Objects.requireNonNull(file.getName()).getBytes();
+            //uploadBytes = FileUtil.readBytes(file);
             md5 = MessageDigest.getInstance("MD5");
         } catch (Exception e) {
             e.printStackTrace();

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/domain/grallery/ZbGalleryImg.java

@@ -32,7 +32,7 @@ public class ZbGalleryImg extends BaseEntity {
      * 图片id
      */
     @Excel(name = "图片id")
-    private Long thumbId;
+    private Integer thumbId;
 
     /**
      * 作者

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/dto/UploadResult.java

@@ -17,6 +17,7 @@ public class UploadResult implements Serializable {
     private static final long serialVersionUID = -4021803106776808659L;
 
     private String url;
+    private String path;
     private Integer fileId;
     private Long fileSize;
     private boolean img;

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/ZbFileMapper.java

@@ -23,4 +23,8 @@ public interface ZbFileMapper extends BaseMapper<ZbFile> {
      */
     List<ZbFile> selectZbFileList(@Param("obj") ZbFile zbFile, Page<ZbFile> page);
 
+    List<ZbFile> selectByIds(String[] fileIdsArr);
+
+    Integer deleteByIds(String[] fileIdsArr);
+
 }

+ 21 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IZbFileService.java

@@ -39,4 +39,25 @@ public interface IZbFileService extends IService<ZbFile> {
     int updateZbFile(ZbFile zbFile);
 
     ZbFile findByHash(String hashString);
+
+    /**
+     * 删除图片接口
+     * @param zbFile
+     * @return
+     */
+    boolean deletePicture(ZbFile zbFile);
+
+    /**
+     * 根据ids查询数据
+     * @param fileIdsArr
+     * @return
+     */
+    List<ZbFile>selectByIds(String[] fileIdsArr);
+
+    /**
+     * 删除附件表信息
+     * @param fileIdsArr
+     * @return
+     */
+    Integer deleteByIds(String[] fileIdsArr);
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IZbGalleryImgService.java

@@ -43,6 +43,8 @@ public interface IZbGalleryImgService extends IService<ZbGalleryImg> {
 
     void removeByGalleryIds(List<Long> galleryId);
 
+    List<ZbGalleryImg> selectByGalleryIds(List<Long> galleryId);
+
     /**
      * 根据图库编号查询图片信息
      *

+ 8 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IZbPicToPicService.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.grallery.ZbPicToPic;
 import com.ruoyi.system.domain.grallery.ZbZip;
 import com.ruoyi.system.dto.PicToPicDto;
@@ -44,5 +45,12 @@ public interface IZbPicToPicService extends IService<ZbPicToPic> {
 
     ZbZip uploadToZip(MultipartFile[] files);
 
+    /**
+     * 后台删除图来图往
+     * @param id
+     * @return
+     */
+    AjaxResult removeZbPicToPic(Long id);
+
     PicToPicDto getDetailById(Long picId);
 }

+ 22 - 12
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FileServiceImpl.java

@@ -61,8 +61,11 @@ public class FileServiceImpl implements IFileService {
     @Override
     public List<UploadResult> upload(MultipartFile[] files, boolean parse) {
         List<UploadResult> urls = new ArrayList<>(files.length);
+        //获取的当前时间
         String timeFormat = FileUtils.getTimeFileDir();
+        //获取配置文件中图片文件预览路径
         String url = ruoYiConfig.getUrl();
+        //获取配置文件中图片文件存储路径
         String profile = RuoYiConfig.getProfile();
         for (MultipartFile file : files) {
             String fileHash = FileHashUtil.getFileHash(file);
@@ -79,12 +82,12 @@ public class FileServiceImpl implements IFileService {
                 }
                 urls.add(UploadResult.builder()
                         .url(url + hashFile.getUrl())
+                        .path(hashFile.getPath())
                         .fileId(hashFile.getId())
                         .img(hashFile.getImage() == 1)
                         .fileSize(hashFile.getSize())
                         .detail(imgDetailInfo)
                         .build());
-
                 continue;
             }
 
@@ -97,17 +100,16 @@ public class FileServiceImpl implements IFileService {
             try {
                 //组合File.separator = \
                 File saveFile = new File(profile + File.separator + pathname);
-                File saveFileThumbnail = new File(profile + File.separator + thumbnailPath);
                 //检查目录是否存在
                 FileUtils.checkOrCreateParentDir(saveFile);
                 file.transferTo(saveFile);
-
-                //生成缩略图返回缩略图地址
-                Thumbnails.of(saveFile)
-                        .size(120, 120)
-                        .toFile(saveFileThumbnail);
-                // 如果图片需要立即解析属性信息,就同步操作去执行
                 if (parse) {
+                    //生成缩略图返回缩略图地址
+                    File saveFileThumbnail = new File(profile + File.separator + thumbnailPath);
+                    Thumbnails.of(saveFile)
+                            .size(120, 120)
+                            .toFile(saveFileThumbnail);
+                    // 如果图片需要立即解析属性信息,就同步操作去执行
                     imgDetailInfo = printImageTags(saveFile);
                 }
             } catch (IOException e) {
@@ -125,8 +127,10 @@ public class FileServiceImpl implements IFileService {
             xmFile.setSize(file.getSize());
             xmFile.setUrl("?path=" + URLEncoder.createDefault().encode(pathname, Charset.defaultCharset()));
             xmFile.setDetail(JSON.toJSONString(imgDetailInfo));
-            xmFile.setThumbnailPath(thumbnailPath);
-            xmFile.setThumbnailUrl("?path=" + URLEncoder.createDefault().encode(thumbnailPath, Charset.defaultCharset()));
+            if(parse){
+                xmFile.setThumbnailPath(thumbnailPath);
+                xmFile.setThumbnailUrl("?path=" + URLEncoder.createDefault().encode(thumbnailPath, Charset.defaultCharset()));
+            }
             zbFileService.save(xmFile);
             // 如果图片需要立即解析属性信息
             if (!parse && isImg(name)) {
@@ -136,6 +140,7 @@ public class FileServiceImpl implements IFileService {
 
             urls.add(UploadResult.builder()
                     .url(url + xmFile.getUrl())
+                    .path(pathname)
                     .fileId(xmFile.getId())
                     .img(xmFile.getImage() == 1)
                     .fileSize(xmFile.getSize())
@@ -148,6 +153,8 @@ public class FileServiceImpl implements IFileService {
     @Override
     public UploadResult upload(File file) {
         String url = ruoYiConfig.getUrl();
+        //获取配置文件中图片文件存储路径
+        String profile = RuoYiConfig.getProfile();
         String fileHash = FileHashUtil.getFileHash(file);
         // 表示文件存在过了
         ZbFile hashFile = zbFileService.findByHash(fileHash);
@@ -164,8 +171,9 @@ public class FileServiceImpl implements IFileService {
         String name = file.getName();
         String pathname = timeFormat + File.separator + name;
         String newPath = RuoYiConfig.getProfile() + File.separator + timeFormat + name;
-        if (!newPath.equals(file.getAbsolutePath())) {
-            FileUtil.move(file, new File(newPath), false);
+        File fileNew = new File(newPath);
+        if (!fileNew.getAbsolutePath().equals(file.getAbsolutePath())) {
+            FileUtil.move(file, fileNew, false);
         }
         ZbFile xmFile = new ZbFile();
         xmFile.setCode(RandomUtil.randomString(20));
@@ -179,6 +187,7 @@ public class FileServiceImpl implements IFileService {
         zbFileService.save(xmFile);
         return UploadResult.builder()
                 .url(url + xmFile.getUrl())
+                .path(profile + File.separator + pathname)
                 .fileId(xmFile.getId())
                 .img(xmFile.getImage() == 1)
                 .fileSize(xmFile.getSize())
@@ -186,6 +195,7 @@ public class FileServiceImpl implements IFileService {
                 .build();
     }
 
+    //监听解析图片路径
     @Override
     public ImgDetailInfo parseImgInfo(ZbFile zbFile) {
         String path = RuoYiConfig.getProfile() + File.separator + zbFile.getPath();

+ 7 - 7
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -178,12 +178,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
      * @return 结果
      */
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public int insertUser(SysUser user) {
         // 新增用户信息
         int rows = baseMapper.insertUser(user);
         // 新增用户岗位关联
-        insertUserPost(user);
+        //insertUserPost(user);
         // 新增用户与角色管理
         insertUserRole(user);
         return rows;
@@ -196,7 +196,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
      * @return 结果
      */
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public int updateUser(SysUser user) {
         Long userId = user.getUserId();
         // 删除用户与角色关联
@@ -204,9 +204,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         // 新增用户与角色管理
         insertUserRole(user);
         // 删除用户与岗位关联
-        userPostService.deleteUserPostByUserId(userId);
+        //userPostService.deleteUserPostByUserId(userId);
         // 新增用户与岗位管理
-        insertUserPost(user);
+        //insertUserPost(user);
         return baseMapper.updateUser(user);
     }
 
@@ -322,7 +322,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         // 删除用户与角色关联
         userRoleService.deleteUserRoleByUserId(userId);
         // 删除用户与岗位表
-        userPostService.deleteUserPostByUserId(userId);
+        //userPostService.deleteUserPostByUserId(userId);
         return baseMapper.deleteUserById(userId);
     }
 
@@ -339,7 +339,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
             // 删除用户与角色关联
             userRoleService.deleteUserRoleByUserId(userId);
             // 删除用户与岗位表
-            userPostService.deleteUserPostByUserId(userId);
+            //userPostService.deleteUserPostByUserId(userId);
         }
         return baseMapper.deleteUserByIds(userIds);
     }

+ 62 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbFileServiceImpl.java

@@ -1,15 +1,22 @@
 package com.ruoyi.system.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.system.domain.ZbFile;
 import com.ruoyi.system.service.IZbFileService;
 import com.ruoyi.system.mapper.ZbFileMapper;
 import com.ruoyi.system.service.IZbGalleryCategoryService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -18,6 +25,7 @@ import java.util.List;
  * @author ruoyi
  * @date 2020-11-19
  */
+@Slf4j
 @Service
 @RequiredArgsConstructor
 public class ZbFileServiceImpl extends ServiceImpl<ZbFileMapper, ZbFile> implements IZbFileService {
@@ -62,4 +70,58 @@ public class ZbFileServiceImpl extends ServiceImpl<ZbFileMapper, ZbFile> impleme
         queryWrapper.eq(ZbFile::getFileHash, hashString).last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public boolean deletePicture(ZbFile zbFile) {
+        try {
+            Integer id = zbFile.getId();
+            if (id == null) {
+                return false;
+            }
+            //判断图片存放地址是否为空
+            if (StringUtils.isEmpty(zbFile.getPath())) {
+                zbFile = baseMapper.selectById(id);
+            }
+            if (ObjectUtil.isNotEmpty(zbFile)) {
+                File file = new File(RuoYiConfig.getProfile() + File.separator + zbFile.getPath());
+                log.info("删除原始文件: " + file);
+                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);
+                }
+                //删除数据库附件表信息
+                baseMapper.deleteById(id);
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            log.info("删除文件失败");
+            e.printStackTrace();
+        }
+        return true;
+    }
+
+    /**
+     * 根据ids查询数据
+     *
+     * @param fileIdsArr
+     * @return
+     */
+    @Override
+    public List<ZbFile> selectByIds(String[] fileIdsArr) {
+        return baseMapper.selectByIds(fileIdsArr);
+    }
+
+    /**
+     * 删除附件表信息
+     *
+     * @param fileIdsArr
+     * @return
+     */
+    @Override
+    public Integer deleteByIds(String[] fileIdsArr) {
+        return baseMapper.deleteByIds(fileIdsArr);
+    }
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryCategoryServiceImpl.java

@@ -160,7 +160,7 @@ public class ZbGalleryCategoryServiceImpl extends ServiceImpl<ZbGalleryCategoryM
 
     @Override
     public ZbGalleryCategory getByCode(String categoryCode) {
-        return getOne(new LambdaQueryWrapper<ZbGalleryCategory>().eq(ZbGalleryCategory::getCode, categoryCode).eq(ZbGalleryCategory::getTop, 1));
+        return getOne(new LambdaQueryWrapper<ZbGalleryCategory>().eq(ZbGalleryCategory::getCode, categoryCode).eq(ZbGalleryCategory::getTop, 1).last("limit 1"));
     }
 
     @Override

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryImgServiceImpl.java

@@ -66,6 +66,11 @@ public class ZbGalleryImgServiceImpl extends ServiceImpl<ZbGalleryImgMapper, ZbG
         remove(new LambdaQueryWrapper<ZbGalleryImg>().in(ZbGalleryImg::getGallertId, galleryId));
     }
 
+    @Override
+    public List<ZbGalleryImg> selectByGalleryIds(List<Long> galleryId) {
+        return baseMapper.selectList(new LambdaQueryWrapper<ZbGalleryImg>().in(ZbGalleryImg::getGallertId, galleryId));
+    }
+
     @Override
     public List<GalleryImgDto> getByGalleryId(Long galleryId) {
         return baseMapper.getByGalleryId(galleryId);

+ 66 - 35
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbGalleryServiceImpl.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.exception.BaseException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.system.domain.ZbFile;
 import com.ruoyi.system.domain.grallery.ZbGallery;
 import com.ruoyi.system.domain.grallery.ZbGalleryCategory;
 import com.ruoyi.system.domain.grallery.ZbGalleryImg;
@@ -41,10 +42,11 @@ import java.util.stream.Collectors;
 @Service
 @RequiredArgsConstructor
 public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery> implements IZbGalleryService {
-    private final IZbGalleryImgService      galleryImgService;
-    private final RuoYiConfig               ruoYiConfig;
-    private final IZbCommentService         commentService;
+    private final IZbGalleryImgService galleryImgService;
+    private final RuoYiConfig ruoYiConfig;
+    private final IZbCommentService commentService;
     private final IZbGalleryCategoryService galleryCategoryService;
+    private final ZbFileServiceImpl zbFileService;
 
     /**
      * 查询【请填写功能名称】列表
@@ -79,22 +81,27 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
             throw new BaseException("图库保存失败");
         }
 
-        List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().map(x -> {
-            ZbGalleryImg galleryImg = new ZbGalleryImg();
-            galleryImg.setAuthor(x.getAuthor());
-            galleryImg.setLocation(x.getLocation());
-            galleryImg.setGallertId(gallery.getId());
-            galleryImg.setQrCodeId(x.getQrCode());
-            galleryImg.setThumbId(x.getId().longValue());
-            galleryImg.setWatermarkType(x.getWatermarkType());
-            galleryImg.setWatermarkColor(x.getWatermarkColor());
-            galleryImg.setCreateBy(createBy);
-            galleryImg.setCreateTime(nowDate);
-            galleryImg.setAuthorConcat(x.getConcat());
-            galleryImg.setRemark(x.getRemark());
-            return galleryImg;
-        }).collect(Collectors.toList());
-        galleryImgService.saveBatch(imgList);
+        //判断是否新增图库时,新增了图片
+        if (zbGallery.getImgInfos().size() > 0) {
+            List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().filter(e -> e.getId() != null).map(x -> {
+                ZbGalleryImg galleryImg = new ZbGalleryImg();
+                galleryImg.setAuthor(x.getAuthor());
+                galleryImg.setLocation(x.getLocation());
+                galleryImg.setGallertId(gallery.getId());
+                galleryImg.setQrCodeId(x.getQrCode());
+                galleryImg.setThumbId(x.getId());
+                galleryImg.setWatermarkType(x.getWatermarkType());
+                galleryImg.setWatermarkColor(x.getWatermarkColor());
+                galleryImg.setCreateBy(createBy);
+                galleryImg.setCreateTime(nowDate);
+                galleryImg.setAuthorConcat(x.getConcat());
+                galleryImg.setRemark(x.getRemark());
+                return galleryImg;
+            }).collect(Collectors.toList());
+            if (imgList.size() > 0) {
+                galleryImgService.saveBatch(imgList);
+            }
+        }
         return true;
     }
 
@@ -121,24 +128,31 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
         }
 
         Long galleryId = gallery.getId();
+        //对应图片信息先删除
         galleryImgService.removeByGalleryId(galleryId);
 
-        List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().map(x -> {
-            ZbGalleryImg galleryImg = new ZbGalleryImg();
-            galleryImg.setAuthor(x.getAuthor());
-            galleryImg.setLocation(x.getLocation());
-            galleryImg.setGallertId(galleryId);
-            galleryImg.setQrCodeId(x.getQrCode());
-            galleryImg.setThumbId(x.getId().longValue());
-            galleryImg.setWatermarkColor(x.getWatermarkColor());
-            galleryImg.setWatermarkType(x.getWatermarkType());
-            galleryImg.setCreateBy(createBy);
-            galleryImg.setCreateTime(nowDate);
-            galleryImg.setAuthorConcat(x.getConcat());
-            galleryImg.setRemark(x.getRemark());
-            return galleryImg;
-        }).collect(Collectors.toList());
-        galleryImgService.saveBatch(imgList);
+        //在添加
+        //判断是否修改图库时,是否包含图片
+        if (zbGallery.getImgInfos().size() > 0) {
+            List<ZbGalleryImg> imgList = zbGallery.getImgInfos().stream().filter(e -> e.getId() != null).map(x -> {
+                ZbGalleryImg galleryImg = new ZbGalleryImg();
+                galleryImg.setAuthor(x.getAuthor());
+                galleryImg.setLocation(x.getLocation());
+                galleryImg.setGallertId(galleryId);
+                galleryImg.setQrCodeId(x.getQrCode());
+                galleryImg.setThumbId(x.getId());
+                galleryImg.setWatermarkColor(x.getWatermarkColor());
+                galleryImg.setWatermarkType(x.getWatermarkType());
+                galleryImg.setCreateBy(createBy);
+                galleryImg.setCreateTime(nowDate);
+                galleryImg.setAuthorConcat(x.getConcat());
+                galleryImg.setRemark(x.getRemark());
+                return galleryImg;
+            }).collect(Collectors.toList());
+            if (imgList.size() > 0) {
+                galleryImgService.saveBatch(imgList);
+            }
+        }
         return true;
     }
 
@@ -172,11 +186,26 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
         return galleryDto;
     }
 
+    /**
+     * 删除图库
+     * @param gallerys
+     * @return
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean delGallery(List<Long> gallerys) {
+        //删除图库表
         this.removeByIds(gallerys);
+        //先删除附件表信息和服务器存储数据
+        List<ZbGalleryImg> zbGalleryImgs = galleryImgService.selectByGalleryIds(gallerys);
+        for (ZbGalleryImg zbGalleryImg : zbGalleryImgs) {
+            ZbFile zbFile = new ZbFile();
+            zbFile.setId(zbGalleryImg.getThumbId());
+            zbFileService.deletePicture(zbFile);
+        }
+        //删除图库图片信息表
         galleryImgService.removeByGalleryIds(gallerys);
+        //删除评论信息
         commentService.removeByTypeAndFk(CommentType.GALLERY, gallerys);
         return true;
     }
@@ -191,6 +220,7 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
             }
         }
         if (categoryId != null) {
+
             categorys = StrUtil.split(galleryCategoryService.getChildrens(categoryId), ',')
                     .stream().map(Long::valueOf).collect(Collectors.toList());
         }
@@ -200,6 +230,7 @@ public class ZbGalleryServiceImpl extends ServiceImpl<ZbGalleryMapper, ZbGallery
                         x -> x.getImgInfos().forEach(i -> i.setUrl(profile + i.getUrl()))
                 ).collect(Collectors.toList());*/
 
+        //获取预览地址
         List<GalleryDto> galleryDtos = baseMapper.selectGalleryDtoThumbnail(categorys, pageInfo)
                 .stream().peek(
                         x -> x.getImgInfos().forEach(i -> i.setUrl(profile + i.getUrl()))

+ 99 - 5
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZbPicToPicServiceImpl.java

@@ -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 {
@@ -69,7 +76,7 @@ public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicTo
     @Override
     public int insertZbPicToPic(ZbPicToPic zbPicToPic) {
         zbPicToPic.setCreateTime(DateUtils.getNowDate());
-        Long qrCodeId = zbPicToPic.getQrCodeId();
+        //Long qrCodeId = zbPicToPic.getQrCodeId();
 
         return baseMapper.insert(zbPicToPic);
     }
@@ -86,6 +93,11 @@ public class ZbPicToPicServiceImpl extends ServiceImpl<ZbPicToPicMapper, ZbPicTo
         return baseMapper.updateById(zbPicToPic);
     }
 
+    /**
+     * 门户图来图往上传压缩包接口
+     * @param files
+     * @return
+     */
     @Override
     public ZbZip uploadToZip(MultipartFile[] files) {
         List<UploadResult> upload = fileService.upload(files, false);
@@ -94,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();
             }
@@ -108,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();
+                }
+            }
         }
-        UploadResult result = fileService.upload(file);
-
+        fileService.upload(file);
         ZbZip zbZip = new ZbZip();
         zbZip.setFileIds(CollectionUtil.join(upload.stream().map(UploadResult::getFileId).collect(Collectors.toList()), ","));
         zbZip.setFileNum(files.length);
@@ -123,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);

+ 18 - 2
ruoyi-system/src/main/resources/mapper/system/ZbFileMapper.xml

@@ -10,14 +10,14 @@
         <result property="name" column="name"/>
         <result property="url" column="url"/>
         <result property="path" column="path"/>
-        <result property="hash" column="hash"/>
+        <result property="fileHash" column="file_hash"/>
         <result property="size" column="size"/>
         <result property="image" column="image"/>
         <result property="uploadTime" column="upload_time"/>
     </resultMap>
 
     <sql id="selectZbFileVo">
-        select id, code, name, url, path, hash, size, image, upload_time from zb_file
+        select id, code, name, url, path, file_hash, size, image, upload_time from zb_file
     </sql>
 
     <select id="selectZbFileList" parameterType="com.ruoyi.system.domain.ZbFile" resultMap="ZbFileResult">
@@ -52,4 +52,20 @@
 
         </where>
     </select>
+
+
+    <select id="selectByIds" parameterType="java.lang.String" resultMap="ZbFileResult">
+        <include refid="selectZbFileVo"/>
+        where id in
+        <foreach collection="array" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+    </select>
+
+    <delete id="deleteByIds" parameterType="java.lang.String">
+        delete from zb_file where id in
+        <foreach collection="array" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
 </mapper>

+ 3 - 1
ruoyi-system/src/main/resources/mapper/system/ZbGalleryMapper.xml

@@ -68,6 +68,7 @@
                 </if>
             </if>
         </where>
+        order by zg.create_time DESC
     </select>
 
     <resultMap id="GalleryDtoMap" type="com.ruoyi.system.dto.GalleryDto">
@@ -105,7 +106,7 @@
         zgc.name categoryName
         FROM
         zb_gallery zg
-        JOIN zb_gallery_img zgi ON zg.id = zgi.gallert_id
+        LEFT JOIN zb_gallery_img zgi ON zg.id = zgi.gallert_id
         LEFT JOIN zb_file zf ON zf.id = zgi.thumb_id
         left join zb_gallery_category zgc on zgc.id = zg.category_id
         <if test="categoryIds != null and categoryIds.size() > 0">
@@ -135,6 +136,7 @@
                 #{item}
             </foreach>
         </if>
+        ORDER BY zg.name
     </select>
 
     <select id="checkCategoryHasValue" resultType="java.lang.Integer">

+ 3 - 0
ruoyi-ui/.env.development

@@ -6,3 +6,6 @@ VUE_APP_BASE_API = '/dev-api'
 
 # 路由懒加载
 VUE_CLI_BABEL_TRANSPILE_MODULES = true
+
+#端口
+Port = 8089

+ 0 - 1
ruoyi-ui/src/settings.js

@@ -29,6 +29,5 @@ module.exports = {
    */
   errorLog: 'production',
   // apiUrl: 'http://192.168.101.11:8080'
-
   apiUrl: 'http://36.7.89.102:8080'
 }