예제 #1
0
  /**
   * 处理其他方法
   *
   * @throws Exception
   * @throws
   * @throws InstantiationException
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected boolean handleOther(
      HttpServletRequest request,
      Set<SearchFilter> filterSet,
      Method method,
      DataControl dataControl,
      Module module)
      throws Exception {

    String[] ids = null;
    if (method.getName().endsWith(MANY_METHOD_SUFFIX)) { // 多对象操作方法
      ids = request.getParameterValues(MANY_KEY);
      if (ids != null) {
        filterSet.add(new SearchFilter("id", Operator.IN, ids));
      }
    } else {
      String id = request.getParameter("id");
      if (id != null) {
        filterSet.add(new SearchFilter("id", Operator.EQ, id));
      } else {
        // 截取类似/update/{id}的id
        String uri = request.getRequestURI();
        String tmp = StringUtils.substringAfterLast(uri, "/");
        Long longId = NumberUtils.toLong(tmp);
        if (longId != 0L) {
          filterSet.add(new SearchFilter("id", Operator.EQ, longId));
        }
      }
    }

    Object clazz = Class.forName(module.getClassName()).newInstance();
    // Object clazz = null;
    Specification spec = DynamicSpecifications.bySearchFilter(request, clazz.getClass(), filterSet);

    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery criteriaQuery = builder.createQuery(clazz.getClass());
    Root root = criteriaQuery.from(clazz.getClass());

    Predicate predicate = spec.toPredicate(root, criteriaQuery, builder);
    criteriaQuery.where(predicate);

    List<Object> objects = em.createQuery(criteriaQuery).getResultList();
    if (ids != null) {
      if (objects.size() == ids.length) {
        return true;
      }
    } else {
      if (objects.size() > 0) {
        return true;
      }
    }

    return false;
  }
예제 #2
0
  @RequiresPermissions("ClassifyInfo:view")
  @RequestMapping(
      value = "/list",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String list(ServletRequest request, Page page, Map<String, Object> map) {
    Specification<ClassifyInfo> specification =
        DynamicSpecifications.bySearchFilter(request, ClassifyInfo.class);
    List<ClassifyInfo> classifyInfos = classifyInfoService.findByExample(specification, page);

    map.put("page", page);
    map.put("classifyInfos", classifyInfos);
    mapPutCostsCategoriess(map);
    return LIST;
  }
예제 #3
0
  @RequiresPermissions("Organization:view")
  @RequestMapping(
      value = "/list/{parentOrganizationId}",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String list(
      ServletRequest request,
      Page page,
      @PathVariable Long parentOrganizationId,
      Map<String, Object> map) {
    Specification<Organization> specification =
        DynamicSpecifications.bySearchFilter(
            request,
            Organization.class,
            new SearchFilter("parent.id", Operator.EQ, parentOrganizationId));
    List<Organization> organizations = organizationService.findByExample(specification, page);

    map.put("page", page);
    map.put("organizations", organizations);
    map.put("parentOrganizationId", parentOrganizationId);

    return LIST;
  }