Esempio n. 1
0
  @RequestMapping(value = "{source}/move", method = RequestMethod.GET)
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  public String showMoveForm(
      HttpServletRequest request,
      @RequestParam(value = "async", required = false, defaultValue = "false") boolean async,
      @PathVariable("source") M source,
      Searchable searchable,
      Model model) {

    if (this.permissionList != null) {
      this.permissionList.assertHasEditPermission();
    }

    List<M> models = null;

    // 排除自己及子子孙孙
    searchable.addSearchFilter("id", SearchOperator.ne, source.getId());
    searchable.addSearchFilter(
        "parentIds", SearchOperator.notLike, source.makeSelfAsNewParentIds() + "%");

    if (!async) {
      models = baseService.findAllWithSort(searchable);
    } else {
      models = baseService.findRootAndChild(searchable);
    }

    model.addAttribute("trees", convertToZtreeList(request.getContextPath(), models, async, true));

    model.addAttribute(Constants.OP_NAME, "移动节点");

    return viewName("moveForm");
  }
Esempio n. 2
0
  @RequestMapping(value = "ajax/load")
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  @ResponseBody
  public Object load(
      HttpServletRequest request,
      @RequestParam(value = "async", defaultValue = "true") boolean async,
      @RequestParam(value = "asyncLoadAll", defaultValue = "false") boolean asyncLoadAll,
      @RequestParam(value = "searchName", required = false) String searchName,
      @RequestParam(value = "id", required = false) ID parentId,
      @RequestParam(value = "excludeId", required = false) ID excludeId,
      @RequestParam(value = "onlyCheckLeaf", required = false, defaultValue = "false")
          boolean onlyCheckLeaf,
      Searchable searchable) {

    M excludeM = baseService.findOne(excludeId);

    List<M> models = null;

    if (!StringUtils.isEmpty(searchName)) { // 按name模糊查
      searchable.addSearchParam("name_like", searchName);
      models = baseService.findAllByName(searchable, excludeM);
      if (!async || asyncLoadAll) { // 非异步模式 查自己及子子孙孙 但排除
        searchable.removeSearchFilter("name_like");
        List<M> children = baseService.findChildren(models, searchable);
        models.removeAll(children);
        models.addAll(children);
      } else { // 异步模式 只查匹配的一级

      }
    } else { // 根据有没有parentId加载

      if (parentId != null) { // 只查某个节点下的 异步
        searchable.addSearchFilter("parentId", SearchOperator.eq, parentId);
      }

      if (async && !asyncLoadAll) { // 异步模式下 且非异步加载所有
        // 排除自己 及 子子孙孙
        baseService.addExcludeSearchFilter(searchable, excludeM);
      }

      if (parentId == null && !asyncLoadAll) {
        models = baseService.findRootAndChild(searchable);
      } else {
        models = baseService.findAllWithSort(searchable);
      }
    }

    return convertToZtreeList(
        request.getContextPath(),
        models,
        async && !asyncLoadAll && parentId != null,
        onlyCheckLeaf);
  }
Esempio n. 3
0
  @RequestMapping(value = "batch/delete")
  public String deleteInBatch(
      @RequestParam(value = "ids", required = false) ID[] ids,
      @RequestParam(value = Constants.BACK_URL, required = false) String backURL,
      RedirectAttributes redirectAttributes) {

    if (permissionList != null) {
      permissionList.assertHasDeletePermission();
    }

    // 如果要求不严格 此处可以删除判断 前台已经判断过了
    Searchable searchable =
        Searchable.newSearchable().addSearchFilter("id", SearchOperator.in, ids);
    List<M> mList = baseService.findAllWithNoPageNoSort(searchable);
    for (M m : mList) {
      if (m.isRoot()) {
        redirectAttributes.addFlashAttribute(Constants.ERROR, "您删除的数据中包含根节点,根节点不能删除");
        return redirectToUrl(backURL);
      }
    }

    baseService.deleteSelfAndChild(mList);
    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "删除成功");
    return redirectToUrl(backURL);
  }
Esempio n. 4
0
  @RequestMapping
  @PageableDefaults(value = 20, sort = "id=desc")
  public String list(@CurrentUser User user, Pageable pageable, Model model) {

    Searchable searchable = Searchable.newSearchable();
    searchable.addSearchFilter("userId", SearchOperator.eq, user.getId());

    Page<NotificationData> page = notificationDataService.findAll(pageable);

    model.addAttribute("page", page);
    if (pageable.getPageNumber() == 0) {
      notificationDataService.markReadAll(user.getId());
    }

    return viewName("list");
  }
Esempio n. 5
0
  @SearchableDefaults(value = "type_eq=user")
  @Override
  public String list(Searchable searchable, Model model) {

    String typeName = String.valueOf(searchable.getValue("type_eq"));
    model.addAttribute("type", AuthType.valueOf(typeName));

    return super.list(searchable, model);
  }
Esempio n. 6
0
  @Override
  protected void setCommonData(Model model) {
    super.setCommonData(model);
    model.addAttribute("types", AuthType.values());

    Searchable searchable = Searchable.newSearchable();
    //        searchable.addSearchFilter("show", SearchOperator.eq, true);
    model.addAttribute("roles", roleService.findAllWithNoPageNoSort(searchable));
  }
 @Override
 public void delete(Long[] ids) {
   Map<String, Object> searchParams = Maps.newHashMap();
   searchParams.put("id_in", ids);
   Searchable searchable = Searchable.newSearchable(searchParams);
   Page<M> page = getCoreRepository().findAll(searchable);
   for (M m : page.getContent()) {
     attachmentImageService.delete(m.getWork().getId());
   }
   super.delete(ids);
 }
Esempio n. 8
0
  @RequestMapping(value = "tree", method = RequestMethod.GET)
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  public String tree(
      HttpServletRequest request,
      @RequestParam(value = "searchName", required = false) String searchName,
      @RequestParam(value = "async", required = false, defaultValue = "false") boolean async,
      Searchable searchable,
      Model model) {

    if (permissionList != null) {
      permissionList.assertHasViewPermission();
    }

    List<M> models = null;

    if (!StringUtils.isEmpty(searchName)) {
      searchable.addSearchParam("name_like", searchName);
      models = baseService.findAllByName(searchable, null);
      if (!async) { // 非异步 查自己和子子孙孙
        searchable.removeSearchFilter("name_like");
        List<M> children = baseService.findChildren(models, searchable);
        models.removeAll(children);
        models.addAll(children);
      } else { // 异步模式只查自己

      }
    } else {
      if (!async) { // 非异步 查自己和子子孙孙
        models = baseService.findAllWithSort(searchable);
      } else { // 异步模式只查根 和 根一级节点
        models = baseService.findRootAndChild(searchable);
      }
    }

    model.addAttribute("trees", convertToZtreeList(request.getContextPath(), models, async, true));

    return viewName("tree");
  }
  @RequestMapping("/load")
  @ResponseBody
  public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser User loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<Calendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<Calendar, Map>transform(
        calendarList,
        new Function<Calendar, Map>() {
          @Override
          public Map apply(Calendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
              startDate.setHours(c.getStartTime().getHours());
              startDate.setMinutes(c.getStartTime().getMinutes());
              startDate.setSeconds(c.getStartTime().getSeconds());
              endDate.setHours(c.getEndTime().getHours());
              endDate.setMinutes(c.getEndTime().getMinutes());
              endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
              m.put("backgroundColor", c.getBackgroundColor());
              m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
              m.put("textColor", c.getTextColor());
            }
            return m;
          }
        });
  }
Esempio n. 10
0
  @RequestMapping(value = "{parent}/children", method = RequestMethod.GET)
  @PageableDefaults(sort = {"parentIds=asc", "weight=asc"})
  public String list(
      HttpServletRequest request,
      @PathVariable("parent") M parent,
      Searchable searchable,
      Model model)
      throws UnsupportedEncodingException {

    if (permissionList != null) {
      permissionList.assertHasViewPermission();
    }

    if (parent != null) {
      searchable.addSearchFilter("parentId", SearchOperator.eq, parent.getId());
    }

    model.addAttribute("page", baseService.findAll(searchable));

    return viewName("listChildren");
  }
Esempio n. 11
0
 @Override
 public Page<M> findAll(final Searchable searchable) {
   List<M> list = repositoryHelper.findAll(findAllQL, searchable, searchCallback);
   long total = searchable.hasPageable() ? count(searchable) : list.size();
   return new PageImpl<M>(list, searchable.getPage(), total);
 }
Esempio n. 12
0
 /**
  * 按条件分页并排序统计实体数量
  *
  * @param searchable 条件
  * @return
  */
 public Long count(Searchable searchable) {
   return baseRepository.count(searchable.getSpecifications(entityClass));
 }
Esempio n. 13
0
 /**
  * 按条件分页并排序查询实体
  *
  * @param searchable 条件
  * @return
  */
 public Page<M> findAll(Searchable searchable) {
   return baseRepository.findAll(searchable.getSpecifications(entityClass), searchable.getPage());
 }
Esempio n. 14
0
 /**
  * 按条件排序查询实体
  *
  * @param searchable 条件
  * @return
  */
 public List<M> findAllBySort(Searchable searchable) {
   return baseRepository.findAll(searchable.getSpecifications(entityClass), searchable.getSort());
 }