|
@@ -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;
|
|
|
}
|
|
|
}
|