public @ResponseBody
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);
Spot spot = spotService.getSpot(ownerId);
if (spot == null) {
result.put("success", Boolean.FALSE);
result.put("errmsg", "不存在制定spot");
return result;
}
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, ownerId, 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, ownerId);
} catch (Exception e) {
LOGGER.warn("获取相册失败", e);
result.put("success", Boolean.FALSE);
result.put("errmsg", "没有找到对应相册,压缩图片失败!");
return result;
}
List<Photo> photos = null;
if (!filesInfo.isEmpty()) {
/**
* 构造一个spot User
*/
User tempUser = new User();
tempUser.setId(ownerId);
tempUser.setNickname(spot.getName());
tempUser.setPortrait(spot.getPortrait());
photos = albumService.createPhotos(tempUser, album, filesInfo);
}
Map<Long, List<Photo>> filesMap = (Map<Long, List<Photo>>) WebHelper.getSessionAttribute(
null, Constant.SESSION_UPLOAD_OK_FILES);