/** * 根据条件删除用户基础信息 * * @param where 条件 * @param size 应删除条数, 0表示未知 * @param errorOnRowsNotMatch 删除行数不匹配时是否抛异常 * @param isId 是不是唯一主键 * @return 删除行数 * @throws ServiceException 删除失败 */ private int doDelete(UserCoreWhere where, int size, boolean errorOnRowsNotMatch) throws ServiceException { // 逻辑删除 if (where.getDataState() == null) { where.setDataState(DataState.NORMAL); } UserCoreUpdate model = new UserCoreUpdate(); model.setDataState(DataState.DELETED); model.setWhere(where); return doUpdate(model, size, errorOnRowsNotMatch); }
@Override public void resetPassword(String id, String newPassword, IAccount me) throws ServiceException { if (VerifyTools.isBlank(id)) { log.warn("参数不能为空: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (VerifyTools.isBlank(newPassword)) { log.warn("参数不能为空: newPassword"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 根据ID从User表查询, 并验证是否存在 userCoreExecutor.findByIdThrowOnNotExists(id); // 密码加密 String hashPassword = passwordService.create(id, newPassword); // 修改User表记录 UserCoreUpdate where = new UserCoreUpdate(); where.setId(id); where.setPassword(hashPassword); userCoreBasic.update(where, false); }
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); }
@Override public void enable(String id, IAccount me) throws ServiceException { if (VerifyTools.isBlank(id)) { log.warn("参数不能为空: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 根据ID从User表查询, 并验证是否存在 UserCoreBean old = userCoreExecutor.findByIdThrowOnNotExists(id); // 验证: 只有锁定状态的可以解锁 if (old.getUserState() != UserState.LOCKED) { throw new ServiceException(ResultCode.RECORD_STATE_ERROR); } // 修改User表的状态为正常 UserCoreUpdate where = new UserCoreUpdate(); where.setId(id); where.setUserState(UserState.NORMAL); userCoreBasic.update(where, false); }
@Override public void disable(String id, IAccount me) throws ServiceException { if (VerifyTools.isBlank(id)) { log.warn("参数不能为空: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 根据ID从User表查询, 并验证是否存在 UserCoreBean old = userCoreExecutor.findByIdThrowOnNotExists(id); // 验证: 不允许锁定自己 if (me.getId().equals(id)) { throw new ServiceException(UserErrorCode.USER_CAN_NOT_LOCK_SELF); } // 验证: 不允许锁定超级管理员 if (old.getSuperman()) { throw new ServiceException(UserErrorCode.USER_CAN_NOT_LOCK_SUPERMAN); } // 验证: 只有正常状态的可以锁定 if (old.getUserState() != UserState.NORMAL) { throw new ServiceException(ResultCode.RECORD_STATE_ERROR); } // 修改User表的状态为锁定 UserCoreUpdate where = new UserCoreUpdate(); where.setId(id); where.setUserState(UserState.LOCKED); userCoreBasic.update(where, false); }
UserCoreUpdate update = new UserCoreUpdate(); update.setWhere(where); update.setPhone(newPhone);
/** 当前登录用户修改自己的基本信息 **/ @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); } }
UserCoreUpdate newer = new UserCoreUpdate(); newer.setWhere(model.getWhere());