/** {@inheritDoc} **/ @Override public UserCoreBean findById(String id) throws ServiceException { String msg = "Failed to query UserCore by id. "; if (VerifyTools.isBlank(id)) { log.error(msg + "params is null: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserCoreWhere where = new UserCoreWhere(); where.setId(id); return find(where); }
/** 根据ID查找用户,如果用户不存在则报错 **/ @Override public UserCoreBean findByIdThrowOnNotExists(String id) throws ServiceException { String msg = "Failed to FindUserById. "; if (VerifyTools.isBlank(id)) { log.error(msg + "params is null: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserCoreWhere where = new UserCoreWhere(); where.setId(id); UserCoreBean user = userCoreBasic.find(where); if (user != null) { return user; } else { log.error(msg + "user info not found, id={}", id); throw new ServiceException(UserErrorCode.USER_NOT_EXIST); } }
@Override public UserCoreBean login(String id, String password) throws ServiceException { String msg = "Failed to login. "; if (VerifyTools.isBlank(id)) { log.error(msg + "params is null: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (VerifyTools.isBlank(password)) { log.error(msg + "params is null: password"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 查找用户 UserCoreWhere where = new UserCoreWhere(); where.setId(id); UserCoreBean user = findUser(where, password, msg); // 判断用户状态 checkUserState(user); user.setPassword(null); // 清空密码 return user; }
private void doUpdatePassword(String factory, IAccountType userType, String userId, String newPassword) throws ServiceException { // 密码加密 String hashPassword = passwordService.create(userId, newPassword); UserCoreUpdate ud = new UserCoreUpdate(); ud.setPassword(hashPassword); UserCoreWhere where = ud.getWhere(true); where.setTenantCode(factory); where.setUserType(userType); where.setId(userId); userCoreBasic.update(ud, true); }
/** {@inheritDoc} **/ @Override public int update(UserCoreUpdate model, boolean errorOnUnaffected) throws ServiceException { String msg = "Failed to update UserCore. "; if (model == null) { log.error(msg + "params is null: model"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserCoreWhere where = model.getWhere(true); if (VerifyTools.isBlank(where.getId()) && VerifyTools.isNotBlank(model.getId())) { where.setId(model.getId()); } model.setDataState(null); // 数据状态只允许通过删除操作来修改 if (where.getDataState() == null) { where.setDataState(DataState.NORMAL); } return doUpdate(model, 0, errorOnUnaffected); }
where.setId(user.getId()); UserCoreUpdate update = new UserCoreUpdate(); update.setWhere(where);
/** 当前登录用户修改自己的基本信息 **/ @ResponseBody @RequestMapping("base-info/update") @OperateRecord(value = "用户基本信息:修改", type = OperateType.UPDATE) public ResponseMessage updateBaseInfo(UserCoreUpdate model) { // 只允许修改这些内容 UserCoreUpdate ud = new UserCoreUpdate(); copyUserBaseInfo(model, ud); try { IAccount me = SessionTools.getLoginUser(); ud.getWhere(true).setId(me.getId()); userCoreExecutor.update(ud, me); // 查询修改后的内容 UserCoreBean newer = userCoreQueryer.find(me.getId()); // 修改Session中的内容 UserCoreBean older = ((UserCoreBean.Wrap) me).original(); copyUserBaseInfo(newer, older); // 刷新分布式Session缓存中的数据 SessionTools.sessionChanged(); return new ResponseMessage(encrypt(me)); } catch (ServiceException e) { return new ResponseMessage(e); } }
where.setTenantCode(cu.getFactory()); where.setUserType(userType); where.setId(cu.getId()); user = userCoreQueryer.find(where); if (user == null) {