Map<String, Object> batchUploadSpotOk(
@PathVariable("ownerId") Long ownerId,
@PathVariable("albumId") Long albumId,
@RequestParam("files") String files) {
Map<String, Object> result = new HashMap<String, Object>();
User user = (User) WebHelper.getSessionAttribute(null,
Constant.SESSION_USER);
if (user == null) {
result.put("success", Boolean.FALSE);
result.put("errmsg", "压缩图片必须");
result.put("logined", Boolean.FALSE);
return result;
} else {
result.put("logined", Boolean.TRUE);
}
String[] filesPath = files.split("\\|");
List<File> localFiles = new ArrayList<File>();
for (String filePath : filesPath) {
if (!StringUtils.hasLength(filePath)) {
continue;
}
File localFile = new File(filePath);
localFiles.add(localFile);
}
if (localFiles.isEmpty()) {
result.put("success", Boolean.FALSE);
result.put("errmsg", "没有找到需要压缩的文件!");
return result;
}
StringBuilder message = new StringBuilder();
List<SkylineImageResizeTask> tasks = prepareResizeTask(localFiles,
user.getId(), albumId, message);
if (tasks == null || tasks.isEmpty()) {
result.put("success", Boolean.FALSE);
result.put("errmsg", "没有找到需要压缩的文件!");
return result;
}
List<ImageResizeResult> results = imagine.processImage(localStorePath,
tasks);
List<ImageResizeResult> filesInfo = processResizeResult(results,
message);
Album album = null;
try {
album = albumService.getAlbumForChange(albumId, user.getId());
} catch (Exception e) {
LOGGER.warn("获取相册失败", e);
result.put("success", Boolean.FALSE);
result.put("errmsg", "没有找到对应相册,压缩图片失败!");
return result;
}
List<Photo> photos = null;
if (!filesInfo.isEmpty()) {
photos = albumService.createPhotos(user, album, filesInfo);
}
albumService.changeAlbumCover(user.getId(), album.getId(), photos
.get(0).getSmallFile(), photos.get(0).getExt());
Map<Long, List<Photo>> filesMap = (Map<Long, List<Photo>>) WebHelper
.getSessionAttribute(null, Constant.SESSION_UPLOAD_OK_FILES);
if (filesMap == null) {