예제 #1
0
  /** 设置用户组织机构. */
  @RequestMapping(value = {"updateUserOrgan"})
  @ResponseBody
  public Result updateUserOrgan(
      @ModelAttribute("model") User user,
      @RequestParam(value = "organIds", required = false) List<Long> organIds,
      String defaultOrganId)
      throws Exception {
    Result result = null;
    // 绑定组织机构
    user.setOrgans(null);
    List<Organ> organs = Lists.newArrayList();
    if (Collections3.isNotEmpty(organIds)) {
      for (Long organId : organIds) {
        Organ organ = organManager.loadById(organId);
        organs.add(organ);
      }
    }

    user.setOrgans(organs);

    // 绑定默认组织机构
    user.setDefaultOrgan(null);
    Organ defaultOrgan = null;
    if (defaultOrganId != null) {
      defaultOrgan = organManager.loadById(user.getDefaultOrganId());
    }
    user.setDefaultOrgan(defaultOrgan);

    userManager.saveEntity(user);
    result = Result.successResult();
    return result;
  }
예제 #2
0
  /**
   * combogrid
   *
   * @return
   * @throws Exception
   */
  @RequestMapping(value = {"combogrid"})
  @ResponseBody
  public Datagrid<User> combogrid(
      @RequestParam(value = "ids", required = false) List<Long> ids,
      String loginNameOrName,
      Integer rows)
      throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
      // in条件
      Criterion inCriterion = Restrictions.in("id", ids);

      if (StringUtils.isNotBlank(loginNameOrName)) {
        Criterion loginNameCriterion =
            Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
        Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
        Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
        criterion = Restrictions.or(inCriterion, criterion1);
      } else {
        criterion = inCriterion;
      }
      // 合并查询条件
      criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
    } else {
      if (StringUtils.isNotBlank(loginNameOrName)) {
        Criterion loginNameCriterion =
            Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE);
        Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
        criterion = Restrictions.or(loginNameCriterion, nameCriterion);
        // 合并查询条件
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
      }
    }

    // 分页查询
    Page<User> p = new Page<User>(rows); // 分页对象
    p = userManager.findByCriteria(p, criterions);
    Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult());
    return dg;
  }
예제 #3
0
  /** 修改用户资源. */
  @RequestMapping(value = {"updateUserResource"})
  @ResponseBody
  public Result updateUserResource(
      @ModelAttribute("model") User user,
      @RequestParam(value = "resourceIds", required = false) List<Long> resourceIds)
      throws Exception {
    Result result = null;
    List<Resource> rs = Lists.newArrayList();
    if (Collections3.isNotEmpty(resourceIds)) {
      for (Long id : resourceIds) {
        Resource resource = resourceManager.loadById(id);
        rs.add(resource);
      }
    }

    user.setResources(rs);
    userManager.saveEntity(user);
    result = Result.successResult();
    return result;
  }