/* * 输入用户id,用户名都可以 */ private UserRemarkEntity refactorUserRemarkEntity(UserRemarkEntity remark) { UserRemarkEntity result = new UserRemarkEntity(); Integer userId = 0; Integer friendId = 0; if (remark != null) { if (remark.getUserName() != null && (remark.getUserId() == null || remark.getUserId() == 0)) { User user = userService.findByLoginName(remark.getUserName()); if (user != null) { userId = user.getId(); } } else { userId = remark.getUserId(); } if (remark.getFriendUserName() != null && (remark.getFriendId() == null || remark.getFriendId() == 0)) { User fUser = userService.findByLoginName(remark.getFriendUserName()); if (fUser != null) { friendId = fUser.getId(); } } else { friendId = remark.getFriendId(); } } result.setUserId(userId); result.setFriendId(friendId); return result; }
@Override public UserRemarkResult saveOrUpdateRemark(UserRemarkEntity remark) { UserRemarkResult ur = new UserRemarkResult(); try { Integer userId = 0; Integer friendId = 0; UserRemarkEntity remarkEntity = refactorUserRemarkEntity(remark); userId = remarkEntity.getUserId(); friendId = remarkEntity.getFriendId(); if (userId > 0 && friendId > 0) { List<UserRemark> userRemarks = userRemarkService.find( " from UserRemark where userId=" + userId + " and friendId=" + friendId); UserRemark userRemark = null; Date time = new Date(); if (userRemarks != null && userRemarks.size() > 0) { userRemark = userRemarks.get(0); userRemark.setRemark(remark.getRemark()); userRemark.setUpdateDate(time); } else { userRemark = new UserRemark(); userRemark.setRemark(remark.getRemark()); userRemark.setUserId(userId); userRemark.setFriendId(friendId); userRemark.setCreateDate(time); userRemark.setUpdateDate(time); } userRemarkService.saveOrUpdate(userRemark); ur.setErrorCode(0); ur.setErrorMessage(""); UserRemarkEntity userRemarkEntity = ConvertHelper.toUserRemarkEntity(userRemark); ur.setRemark(userRemarkEntity); } else { ValidationError er = ValidationError.PARAM_MISSING; ur.setErrorCode(er.getErrorCode()); ur.setErrorMessage("Param Missing"); } } catch (Exception e) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(e.getMessage()); } return ur; }
@Override public UserRemarkResult removeRemark(UserRemarkEntity remark) { UserRemarkResult ur = new UserRemarkResult(); try { Integer userId = 0; Integer friendId = 0; UserRemarkEntity remarkEntity = refactorUserRemarkEntity(remark); userId = remarkEntity.getUserId(); friendId = remarkEntity.getFriendId(); if (userId > 0 && friendId > 0) { List<UserRemark> userRemarks = userRemarkService.find( " from UserRemark where userId=" + userId + " and friendId=" + friendId); if (userRemarks != null && userRemarks.size() > 0) { userRemarkService.delete(userRemarks.get(0)); } List<UserRemark> userRemarksReverse = userRemarkService.find( " from UserRemark where userId=" + friendId + " and friendId=" + userId); if (userRemarksReverse != null && userRemarksReverse.size() > 0) { userRemarkService.delete(userRemarksReverse.get(0)); } ur.setErrorCode(0); ur.setErrorMessage(""); } else { ValidationError er = ValidationError.PARAM_MISSING; ur.setErrorCode(er.getErrorCode()); ur.setErrorMessage("Param Missing"); } } catch (Exception e) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(e.getMessage()); } return ur; }