@RequestMapping("msg-info-save")
public String save(@ModelAttribute MsgInfo msgInfo,
@RequestParam("username") String username,
RedirectAttributes redirectAttributes) {
MsgInfo dest = null;
Long id = msgInfo.getId();
if (id != null) {
dest = msgInfoManager.get(id);
beanMapper.copy(msgInfo, dest);
} else {
dest = msgInfo;
String userId = SpringSecurityUtils.getCurrentUserId();
dest.setSenderId(userId);
UserDTO userDto = userConnector.findByUsername(username, "1");
if (userDto == null) {
throw new IllegalStateException("user not exists : " + username);
}
dest.setReceiverId(userDto.getId());
dest.setCreateTime(new Date());
dest.setStatus(0);
}
msgInfoManager.save(dest);
messageHelper.addFlashMessage(redirectAttributes, "core.success.save",