コード例 #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
 /**
  * 自定义保存资源. <br>
  * 说明:如果保存的资源类型为“功能” 则将所有子资源都设置为“功能”类型
  *
  * @param entity 资源对象
  * @throws DaoException
  * @throws SystemException
  * @throws ServiceException
  */
 public void saveResource(Resource entity) throws DaoException, SystemException, ServiceException {
   Assert.notNull(entity, "参数[entity]为空!");
   this.saveEntity(entity);
   if (entity.getType() != null && ResourceState.function.getValue().equals(entity.getType())) {
     List<Resource> subResources = entity.getSubResources();
     while (!Collections3.isEmpty(subResources)) {
       Iterator<Resource> iterator = subResources.iterator();
       while (iterator.hasNext()) {
         Resource subResource = iterator.next();
         subResource.setType(ResourceState.function.getValue());
         iterator.remove();
         subResources = ListUtils.union(subResources, subResource.getSubResources());
         super.update(subResource);
       }
     }
   }
 }
コード例 #3
0
 /** 设置组织机构页面. */
 @RequestMapping(value = {"organ"})
 public String organ(@ModelAttribute("model") User user, Model model) throws Exception {
   // 设置默认组织机构初始值
   List<Combobox> defaultOrganCombobox = Lists.newArrayList();
   if (user.getId() != null) {
     List<Organ> organs = user.getOrgans();
     Combobox combobox;
     if (!Collections3.isEmpty(organs)) {
       for (Organ organ : organs) {
         combobox = new Combobox(organ.getId().toString(), organ.getName());
         defaultOrganCombobox.add(combobox);
       }
     }
   }
   String defaultOrganComboboxData = JsonMapper.nonDefaultMapper().toJson(defaultOrganCombobox);
   logger.debug(defaultOrganComboboxData);
   model.addAttribute("defaultOrganComboboxData", defaultOrganComboboxData);
   return "modules/sys/user-organ";
 }
コード例 #4
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;
  }
コード例 #5
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;
  }