/** {@inheritDoc} **/ @Override public PageList<UserRoleRefBean> listByIds(List<String> ids) throws ServiceException { String msg = "Failed to query UserRoleRef by id list. "; if (VerifyTools.isBlank(ids)) { log.error(msg + "params is null: ids"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserRoleRefWhere where = new UserRoleRefWhere(); where.setIds(ids); return list(where, OrderPaging.NONE); }
/** {@inheritDoc} **/ @Override public UserRoleRefBean findById(String id) throws ServiceException { String msg = "Failed to query UserRoleRef by id. "; if (VerifyTools.isBlank(id)) { log.error(msg + "params is null: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserRoleRefWhere where = new UserRoleRefWhere(); where.setId(id); return find(where); }
@Override public List<RoleCoreBean> listByUserId(String userId) throws ServiceException { UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserId(userId); PageList<UserRoleRefBean> refList = userRoleRefBasic.list(where, OrderPaging.NONE); if (refList.isEmpty()) { return new ArrayList<>(); } // 查询角色列表 return listByRefList(refList); }
/** {@inheritDoc} **/ @Override public int update(UserRoleRefUpdate model, boolean errorOnUnaffected) throws ServiceException { String msg = "Failed to update UserRoleRef. "; if (model == null) { log.error(msg + "params is null: model"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserRoleRefWhere 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); }
/** {@inheritDoc} **/ @Override public PageList<UserRoleRefBean> list(UserRoleRefWhere where, OrderPaging paging) throws ServiceException { String msg = "Failed to query UserRoleRef. "; if (paging == null) { log.error(msg + "params is null: paging"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (where == null) { where = new UserRoleRefWhere(); where.setDataState(DataState.NORMAL); } else if (where.getDataState() == null) { where.setDataState(DataState.NORMAL); } doHandleDate(where); try { OrderWhere<UserRoleRefWhere> ow = OrderWhere.of(where, paging.getOrderings()); return PageList.of(userRoleRefBasicDao.list(ow, paging)); } catch (Exception e) { ServiceException.throwWhenServiceException(e); log.error(msg + "\n\t" + JsonTools.toJsonString(where), e); throw new ServiceException(ResultCode.DB_SELECT_ERROR, e); } }
UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserId(userId); userRoleRefBasic.delete(where, false); return; UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserId(userId); old = userRoleRefBasic.list(where, OrderPaging.NONE); UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserId(userId); where.setRoleIds(new ArrayList<>(needDelList)); userRoleRefBasic.delete(where, false);
@Override public Map<String, List<RoleCoreBean>> listByUserIds(List<String> userIds) throws ServiceException { UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserIds(userIds); PageList<UserRoleRefBean> refList = userRoleRefBasic.list(where, OrderPaging.NONE); if (refList.isEmpty()) { return new HashMap<>(); } // 查询角色列表 List<RoleCoreBean> roles = listByRefList(refList); Map<String, List<RoleCoreBean>> map = new HashMap<>(); for (RoleCoreBean role : roles) { // 保证顺序 for (UserRoleRefBean ref : refList) { if (ref.getRoleId().equals(role.getId())) { if (!map.containsKey(ref.getUserId())) { map.put(ref.getUserId(), new ArrayList<RoleCoreBean>()); } map.get(ref.getUserId()).add(role); } } } return map; }
/** * 根据条件删除用户角色关系 * * @param where 条件 * @param size 应删除条数, 0表示未知 * @param errorOnRowsNotMatch 删除行数不匹配时是否抛异常 * @param isId 是不是唯一主键 * @return 删除行数 * @throws ServiceException 删除失败 */ private int doDelete(UserRoleRefWhere where, int size, boolean errorOnRowsNotMatch) throws ServiceException { // 逻辑删除 if (where.getDataState() == null) { where.setDataState(DataState.NORMAL); } UserRoleRefUpdate model = new UserRoleRefUpdate(); model.setDataState(DataState.DELETED); model.setWhere(where); return doUpdate(model, size, errorOnRowsNotMatch); }
/** {@inheritDoc} **/ @Override public PageList<UserRoleRefBean> list(OrderPaging paging) throws ServiceException { String msg = "Failed to query UserRoleRef. "; if (paging == null) { log.error(msg + "params is null: paging"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } return list(new UserRoleRefWhere(), paging); }
@Override public void delete(List<String> ids, IAccount me) throws ServiceException { String msg = "Failed to delete UserCore. "; if (VerifyTools.isBlank(me)) { log.error(msg + "params is null: me"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (VerifyTools.isBlank(ids)) { log.error(msg + "params is null: ids"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 删除用户角色关联 UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserIds(ids); userRoleRefBasic.delete(where, false); // 删除sys_user_core_info表的记录 userCoreBasic.deleteByIds(ids, false); }
/** {@inheritDoc} **/ @Override public UserRoleRefBean find(UserRoleRefWhere where) throws ServiceException { String msg = "Failed to query UserRoleRef. "; if (where == null) { log.error(msg + "params is null: where"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (where.getDataState() == null) { where.setDataState(DataState.NORMAL); } doHandleDate(where); UserRoleRefBean bean; try { bean = userRoleRefBasicDao.find(Where.of(where)); } catch (Exception e) { ServiceException.throwWhenServiceException(e); log.error(msg + "\n\t" + JsonTools.toJsonString(where), e); throw new ServiceException(ResultCode.DB_SELECT_ERROR, e); } if (bean == null) { log.trace("UserRoleRef not found. {}", JsonTools.toJsonString(where)); } return bean; }
@Override public void delete(UserCoreWhere where, IAccount me) throws ServiceException { String msg = "Failed to delete UserCore. "; if (VerifyTools.isBlank(me)) { log.error(msg + "params is null: me"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (VerifyTools.isBlank(where)) { log.error(msg + "params is null: where"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } Set<String> temp = new HashSet<>(); { // 根据条件查询UserId PageList<UserCoreBean> PageList = userCoreBasic.list(where, OrderPaging.NONE); if (VerifyTools.isBlank(PageList)) { return; } for (UserCoreBean user : PageList) { temp.add(user.getId()); } } List<String> ids = new ArrayList<>(temp); // 删除用户角色关联 UserRoleRefWhere rw = new UserRoleRefWhere(); rw.setUserIds(ids); userRoleRefBasic.delete(rw, false); // 删除sys_user_core_info表的记录 userCoreBasic.deleteByIds(ids, false); }
/** {@inheritDoc} **/ @Override public int deleteByIds(List<String> ids, boolean errorOnRowsNotMatch) throws ServiceException { String msg = "Failed to delete UserRoleRef. "; if (VerifyTools.isBlank(ids)) { log.error(msg + "params is null: ids"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } UserRoleRefWhere where = new UserRoleRefWhere(); where.setIds(ids); return doDelete(where, ids.size(), errorOnRowsNotMatch); }
@Override public void delete(String id, IAccount me) throws ServiceException { String msg = "Failed to delete UserCore. "; if (VerifyTools.isBlank(me)) { log.error(msg + "params is null: me"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } if (VerifyTools.isBlank(id)) { log.error(msg + "params is null: id"); throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED); } // 从sys_user_core_info表查询原记录 UserCoreBean older = userCoreBasic.findById(id); if (older == null) { log.error(msg + "record is not found.\n\tid is " + id); throw new ServiceException(ResultCode.RECORD_NOT_EXIST); } // 删除用户角色关联 UserRoleRefWhere where = new UserRoleRefWhere(); where.setUserId(id); userRoleRefBasic.delete(where, false); // 删除sys_user_core_info表的记录 userCoreBasic.deleteByIds(ConvertTools.toList(id), false); }