Esempio n. 1
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. 2
0
  @RequestMapping(
      value = {"", "main"},
      method = RequestMethod.GET)
  public String main() {

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

    return viewName("main");
  }
Esempio n. 3
0
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public String view(@PathVariable("id") M m, Model model) {
    if (permissionList != null) {
      permissionList.assertHasViewPermission();
    }

    setCommonData(model);
    model.addAttribute("m", m);
    model.addAttribute(Constants.OP_NAME, "查看");
    return viewName("editForm");
  }
Esempio n. 4
0
  @RequestMapping(
      value = "ajax/{parent}/appendChild",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public Object ajaxAppendChild(HttpServletRequest request, @PathVariable("parent") M parent) {

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

    M child = newModel();
    child.setName("新节点");
    baseService.appendChild(parent, child);
    return convertToZtree(child, true, true);
  }
Esempio n. 5
0
  @RequestMapping(value = "{parent}/appendChild", method = RequestMethod.GET)
  public String appendChildForm(@PathVariable("parent") M parent, Model model) {

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

    setCommonData(model);
    if (!model.containsAttribute("child")) {
      model.addAttribute("child", newModel());
    }

    model.addAttribute(Constants.OP_NAME, "添加子节点");

    return viewName("appendChildForm");
  }
Esempio n. 6
0
  @RequestMapping(
      value = "ajax/{id}/rename",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public Object ajaxRename(
      HttpServletRequest request,
      @PathVariable("id") M tree,
      @RequestParam("newName") String newName) {

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

    tree.setName(newName);
    baseService.update(tree);
    return convertToZtree(tree, true, true);
  }
Esempio n. 7
0
  @RequestMapping(value = "{id}/update", method = RequestMethod.GET)
  public String updateForm(
      @PathVariable("id") M m, Model model, RedirectAttributes redirectAttributes) {

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

    if (m == null) {
      redirectAttributes.addFlashAttribute(Constants.ERROR, "您修改的数据不存在!");
      return redirectToUrl(viewName("success"));
    }

    setCommonData(model);
    model.addAttribute("m", m);
    model.addAttribute(Constants.OP_NAME, "修改");
    return viewName("editForm");
  }
Esempio n. 8
0
  @RequestMapping(value = "{id}/update", method = RequestMethod.POST)
  public String update(
      Model model,
      @ModelAttribute("m") M m,
      BindingResult result,
      RedirectAttributes redirectAttributes) {

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

    if (result.hasErrors()) {
      return updateForm(m, model, redirectAttributes);
    }

    baseService.update(m);
    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "修改成功");
    return redirectToUrl(viewName("success"));
  }
Esempio n. 9
0
  @RequestMapping(value = "{id}/delete", method = RequestMethod.POST)
  public String deleteSelfAndChildren(
      Model model,
      @ModelAttribute("m") M m,
      BindingResult result,
      RedirectAttributes redirectAttributes) {

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

    if (m.isRoot()) {
      result.reject("您删除的数据中包含根节点,根节点不能删除");
      return deleteForm(m, model);
    }

    baseService.deleteSelfAndChild(m);
    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "删除成功");
    return redirectToUrl(viewName("success"));
  }
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
  @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");
  }
Esempio n. 12
0
  @RequestMapping(value = "{parent}/appendChild", method = RequestMethod.POST)
  public String appendChild(
      Model model,
      @PathVariable("parent") M parent,
      @ModelAttribute("child") M child,
      BindingResult result,
      RedirectAttributes redirectAttributes) {

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

    setCommonData(model);

    if (result.hasErrors()) {
      return appendChildForm(parent, model);
    }

    baseService.appendChild(parent, child);

    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "添加子节点成功");
    return redirectToUrl(viewName("success"));
  }
Esempio n. 13
0
 /** 权限前缀:如sys:user 则生成的新增权限为 sys:user:create */
 public void setResourceIdentity(String resourceIdentity) {
   if (!StringUtils.isEmpty(resourceIdentity)) {
     permissionList = PermissionList.newPermissionList(resourceIdentity);
   }
 }