/** * @author 删除目录 * @throws FolderNotFoundException */ @ResponseBody @RequestMapping(value = "/delete.json", method = RequestMethod.POST) public JsonVo<String> delete(@RequestParam(value = "folderId") long folderId) throws FolderNotFoundException { JsonVo<String> json = new JsonVo<String>(); List<FolderVo> folderList = folderService.getFolderListByFatherId(folderId, null); FolderVo folder = folderService.getFolderById(folderId); if (folder.getOwner().equals(FolderConstant.Owner.system)) { json.setResult(false); json.setMsg("此目录是系统目录,无法删除!"); } else { if (folderList.size() == 0) { int count = articleService.getArticleCountByFoderId( folder.getFirstFolderId(), folder.getSecondFolderId(), folder.getThirdFolderId(), folder.getFourthFolderId()); if (count != 0) { json.setResult(false); json.setMsg("此目录下还有文件,不能被删除。"); } else { json.setResult(true); folderService.deleteFolderById(folderId); } } else { json.setResult(false); json.setMsg("此目录下有子目录,不能删除。"); } } return json; }
/** @author 添加新的目录 */ @ResponseBody @RequestMapping(value = "/add.json", method = RequestMethod.POST) public JsonVo<String> add( @RequestParam(value = "fatherId", defaultValue = "0") long fatherId, @RequestParam(value = "folderName") String folderName, @RequestParam(value = "folderEname") String folderEname, @RequestParam(value = "status") FolderConstant.Status status, ModelMap modelMap) { JsonVo<String> json = new JsonVo<String>(); // FIXME 检查目录的ename不能用循环遍历检查 List<FolderVo> list = folderService.getAllFolderList(0, null); try { if (StringUtils.isBlank(folderName)) { json.getErrors().put("folderName", "目录名称不能为空"); } if (StringUtils.isBlank(folderEname)) { json.getErrors().put("folderEname", "英文名称不能为空"); } else if (!RegexUtils.isAlphaUnderline(folderEname)) { json.getErrors().put("folderEname", "只能是英文字母,数字和下划线"); } else { for (Folder folder : list) { if (folderEname.equals(folder.getEname())) { json.getErrors().put("folderEname", "英文名称不能重复"); } } } // 检测校验结果 validate(json); folderService.addFolder( fatherId, folderName, status, folderEname.toLowerCase(), FolderConstant.Rank.everyone, FolderConstant.Type.folder); json.setResult(true); } catch (Exception e) { logger.error(e.getMessage(), e); json.setResult(false); json.setMsg(e.getMessage()); } return json; }
/** @author 修改目录资料 */ @ResponseBody @RequestMapping(value = "/update.json", method = RequestMethod.POST) public JsonVo<String> updateFolder( @RequestParam(value = "folderId") long folderId, @RequestParam(value = "name") String name, @RequestParam(value = "ename") String ename, @RequestParam(value = "content", required = false) String content) { JsonVo<String> json = new JsonVo<String>(); // FIXME 检查目录的ename不能用循环遍历检查 List<FolderVo> list = folderService.getAllFolderList(0, null); try { if (name.equals("")) { json.getErrors().put("name", "目录名称不能为空"); } if (ename.equals("")) { json.getErrors().put("ename", "英文名称不能为空"); } else { for (Folder folder : list) { if (folderId != folder.getFolderId()) { if (ename.equals(folder.getEname())) { json.getErrors().put("folderEname", "英文名称不能重复"); } } } } // 检测校验结果 validate(json); String newEname = ename.toLowerCase(); folderService.updateFolderById(folderId, newEname, name, content); json.setResult(true); } catch (Exception e) { json.setResult(false); json.setMsg(e.getMessage()); } return json; }