luobo 4 роки тому
батько
коміт
4b634c6f4a

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/family/TbFamilyPhotoController.java

@@ -34,6 +34,7 @@ import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
 import org.springframework.web.multipart.MultipartFile;
+import springfox.documentation.annotations.ApiIgnore;
 
 /**
  * 家族相簿照片
@@ -153,8 +154,8 @@ public class TbFamilyPhotoController extends BaseController {
     @ApiOperation("批量上传家族相簿照片")
     @PreAuthorize("@ss.hasPermi('system:familyPhoto:upload')" )
     @Log(title = "家族相簿照片" , businessType = BusinessType.DELETE)
-    @DeleteMapping("/batchUpload/{albumId}" )
-    public AjaxResult batchUpload(@PathVariable Long albumId, MultipartFile[] files, String modName) throws IOException {
+    @PostMapping("/batchUpload/{albumId}" )
+    public AjaxResult batchUpload(@PathVariable Long albumId, MultipartFile [] files, String modName) {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         Long userId = loginUser.getUser().getUserId();
         iTbFamilyPhotoService.batchUpload(userId,albumId,files,modName);

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/app/family/photo/service/ITbFamilyPhotoService.java

@@ -21,5 +21,5 @@ public interface ITbFamilyPhotoService extends IService<TbFamilyPhoto> {
      * @param modName
      * @return
      */
-    Boolean batchUpload(Long userId,Long albumId, MultipartFile[] files, String modName) throws IOException;
+    Boolean batchUpload(Long userId,Long albumId, MultipartFile[] files, String modName) ;
 }

+ 34 - 32
ruoyi-system/src/main/java/com/ruoyi/app/family/photo/service/impl/TbFamilyPhotoServiceImpl.java

@@ -6,6 +6,7 @@ import com.ruoyi.app.family.photo.domain.TbFamilyPhoto;
 import com.ruoyi.app.family.photo.mapper.TbFamilyPhotoMapper;
 import com.ruoyi.app.family.photo.service.ITbFamilyPhotoService;
 import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.exception.CustomException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
@@ -32,46 +33,47 @@ public class TbFamilyPhotoServiceImpl extends ServiceImpl<TbFamilyPhotoMapper, T
     private ITbFamilyAlbumService familyAlbumService;
 
     @Override
-    public Boolean batchUpload(Long userId,Long albumId, MultipartFile[] files, String modName) throws IOException {
+    public Boolean batchUpload(Long userId, Long albumId, MultipartFile[] files, String modName) {
         //查询相簿信息
         TbFamilyAlbum albumEntity = familyAlbumService.getEntityById(albumId);
         if (albumEntity == null) {
             throw new CustomException("请选择相簿!");
         }
-        // 上传文件路径
-        String filePath = RuoYiConfig.getUploadPath();
-        //@TODO 上传添加模块名称 luobo
-        if (StringUtils.isNotEmpty(modName) && !modName.equalsIgnoreCase("null") && !modName.equalsIgnoreCase("undefined")){
-            filePath += "/"+modName;
-        }
-        List<TbFamilyPhoto> list = new ArrayList<>();
-        for (MultipartFile item : files){
-            TbFamilyPhoto entity = new TbFamilyPhoto();
-            entity.setAlbumId(albumEntity.getId());
-            entity.setFamilyId(albumEntity.getFamilyId());
-            String title = item.getOriginalFilename();
-            title = title.substring(0,title.lastIndexOf("."));
-            entity.setTitle(title);
-            // 上传并返回新文件名称
-            String fileName = FileUploadUtils.upload(filePath, item);
-            entity.setUrl(fileName);
-            entity.setCreateBy(userId);
-            entity.setCreateTime(new Date());
-            entity.setStatus("0");
-            entity.setDelFlag("0");
-            list.add(entity);
-        }
-
-
-
+        try {
 
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            //@TODO 上传添加模块名称 luobo
+            if (StringUtils.isNotEmpty(modName) && !modName.equalsIgnoreCase("null") && !modName.equalsIgnoreCase("undefined")) {
+                filePath += "/" + modName;
+            }
+            List<TbFamilyPhoto> list = new ArrayList<>();
+            for (MultipartFile item : files) {
+                TbFamilyPhoto entity = new TbFamilyPhoto();
+                entity.setAlbumId(albumEntity.getId());
+                entity.setFamilyId(albumEntity.getFamilyId());
+                String title = item.getOriginalFilename();
+                title = title.substring(0, title.lastIndexOf("."));
+                entity.setTitle(title);
 
 
+                // 上传并返回新文件名称
+                String fileName = FileUploadUtils.upload(filePath, item);
+                entity.setUrl(fileName);
+                entity.setCreateBy(userId);
+                entity.setCreateTime(new Date());
+                entity.setStatus("0");
+                entity.setDelFlag("0");
+                list.add(entity);
+            }
+            // 上传并返回新文件名称
+            if (list.size() > 0) {
+                this.saveBatch(list);
+            }
+            return true;
+        } catch (Exception e) {
+            throw new CustomException(e.getMessage());
+        }
 
-
-
-        // 上传并返回新文件名称
-
-        return null;
     }
 }