return view;
}
@RequestMapping(value = "/photoupload", method = RequestMethod.POST)
public ModelAndView photoUploadOk(Integer x, Integer y, Integer size, String submitToken) {
User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
if (user == null) {
throw new NotLoginException("上传头像必须登录");
}
String errMsg = this.validateForm("portraitUploadForm", submitToken);
if (errMsg != null) {
return processValidationErrors("errMsg", errMsg, photoUploadRequest());
}
long ownerId = user.getId();
Photo portrait = albumService.getUserCurrentPortraitPhoto(ownerId);
if (portrait == null) {
throw new OperateFailedException("不存在当前图片,无法剪切");
}
long albumId = portrait.getAlbumId();
String smallFile = portrait.getSmallFile();
String ext = portrait.getExt();
String remoteFileKey = smallFile + '.' + ext;
SkylineImageCropTask cropTask = new SkylineImageCropTask(remoteFileKey, portraitSize);
cropTask.setAlbumId(albumId);
cropTask.setUserId(ownerId);
cropTask.setOffsetX(x);
cropTask.setOffsetY(y);
cropTask.setCropSize(size);
ImageCropResult cropResult;
try {
cropResult = crop.processImage(basePath, cropTask);
} catch (IOException e) {
throw new OperateFailedException("无法剪切图片");
}
if (cropResult == null || cropResult.getResultState() != ResultState.SUCCESS) {
throw new OperateFailedException("无法剪切图片,原因:"
+ (cropResult == null ? null : cropResult.getResultState()));
}
String portraitFile = cropResult.getFileKey();
personalInfoService.changeUserPortrait(ownerId, portraitFile);
user.setPortrait(portraitFile);
WebHelper.setSessionAttribute(null, Constant.SESSION_USER, user);
String url = buildRecirectPath("/wo/myWo");
ModelAndView view = new ModelAndView(new RedirectView(url));
return view;