DocDirController.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. package com.doc.biz.controller;
  2. import com.doc.biz.domain.*;
  3. import com.doc.biz.service.*;
  4. import com.doc.biz.vo.TreeVO;
  5. import com.doc.common.annotation.Log;
  6. import com.doc.common.constant.Constants;
  7. import com.doc.common.core.controller.BaseController;
  8. import com.doc.common.core.domain.AjaxResult;
  9. import com.doc.common.enums.BusinessType;
  10. import com.doc.common.utils.SecurityUtils;
  11. import com.doc.common.utils.poi.ExcelUtil;
  12. import io.swagger.annotations.*;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.annotation.Resource;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. /**
  19. * 文档目录管理Controller
  20. *
  21. * @author wukai
  22. * @date 2023-08-15
  23. */
  24. @Api(tags = "文档目录管理")
  25. @RestController
  26. @RequestMapping("/biz/dir")
  27. public class DocDirController extends BaseController {
  28. @Resource
  29. private IDocDirService docDirService;
  30. @Resource
  31. private IDocInfoService docInfoService;
  32. @Resource
  33. private IDocSpaceService spaceService;
  34. @Resource
  35. private IDocDirUserService dirUserService;
  36. @Resource
  37. private IDocFavoriteService favoriteService;
  38. @Resource
  39. private IDocRecentService recentService;
  40. /**
  41. * 获取顶层目录
  42. */
  43. @ApiOperation("获取顶层目录")
  44. @GetMapping(value = "/top-dir/{type}")
  45. public DocDir topDir(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
  46. DocSpace space = spaceService.selectDocSpaceListByType(type);
  47. DocDir dir = new DocDir();
  48. dir.setSpaceId(space.getSpaceId());
  49. dir.setParentId(0L);
  50. List<DocDir> dirList = docDirService.selectDocDirList(dir);
  51. if (dirList.size() > 0) {
  52. return dirList.get(0);
  53. } else {
  54. return null;
  55. }
  56. }
  57. /**
  58. * 获取目录树
  59. */
  60. @ApiOperation("目录树")
  61. @GetMapping(value = "/dir-tree/{type}")
  62. public TreeVO dirTree(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
  63. return tree(type, dirTree);
  64. }
  65. /**
  66. * 文件树
  67. */
  68. private final String fileTree = "1";
  69. /**
  70. * 目录树
  71. */
  72. private final String dirTree = "2";
  73. /**
  74. * 图片树
  75. */
  76. private final String picTree = "3";
  77. /**
  78. * 获取文件树
  79. */
  80. @ApiOperation("文件树")
  81. @GetMapping(value = "/file-tree/{type}")
  82. public TreeVO fileTree(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
  83. return tree(type, fileTree);
  84. }
  85. /**
  86. * 获取文件树
  87. */
  88. @ApiOperation("图片文件树")
  89. @GetMapping(value = "/pic-tree")
  90. public TreeVO picTree() {
  91. String type = "3";
  92. return tree(type, picTree);
  93. }
  94. /**
  95. * 获取树
  96. *
  97. * @param type 空间类型
  98. * @param st 1.文件树 2.目录树 3.图片树
  99. * @return
  100. */
  101. private TreeVO tree(String type, String st) {
  102. DocSpace space = spaceService.selectDocSpaceListByType(type);
  103. DocDir docDir = new DocDir();
  104. docDir.setSpaceId(space.getSpaceId());
  105. docDir.setParentId(0L);
  106. List<DocDir> list = docDirService.selectDocDirList(docDir);
  107. TreeVO vo = getChildren(list.get(0), st);
  108. return vo;
  109. }
  110. /**
  111. * 递归获取目录树
  112. *
  113. * @param dir 目录信息
  114. * @return
  115. */
  116. private TreeVO getChildren(DocDir dir, String st) {
  117. TreeVO vo = new TreeVO();
  118. vo.setId(dir.getDirId());
  119. vo.setLabel(dir.getDirName());
  120. List<TreeVO> children = new ArrayList<>();
  121. DocDir dir1 = new DocDir();
  122. dir1.setParentId(dir.getDirId());
  123. dir1.setSpaceId(dir.getSpaceId());
  124. docDirService.selectDocDirList(dir1).forEach(d -> {
  125. children.add(getChildren(d, st));
  126. });
  127. if (!dirTree.equals(st)) {
  128. //如果不是目录树
  129. vo.setDisabled(true);
  130. DocInfo info = new DocInfo();
  131. info.setDirId(dir.getDirId());
  132. docInfoService.selectDocInfoList(info).forEach(d -> {
  133. if (!picTree.equals(st) || Constants.IMAGE_EXTENSION.contains(d.getFileType())) {
  134. TreeVO childVO = new TreeVO();
  135. childVO.setId(d.getDocId());
  136. childVO.setLabel(d.getFileName());
  137. childVO.setRemark(d.getFileId());
  138. childVO.setDisabled(false);
  139. children.add(childVO);
  140. }
  141. });
  142. }
  143. vo.setChildren(children);
  144. return vo;
  145. }
  146. /**
  147. * 查询文档目录管理列表
  148. */
  149. @ApiOperation("查询目录列表")
  150. //@PreAuthorize("@ss.hasPermi('biz:dir:list')")
  151. @GetMapping("/list")
  152. public AjaxResult list(DocDir docDir) {
  153. List<DocDir> list = docDirService.selectDocDirList(docDir);
  154. DocDir dir = docDirService.selectDocDirByDirId(docDir.getParentId());
  155. if (dir.getParentId() != 0) {
  156. //如果不是顶层目录
  157. //插入最近访问记录
  158. DocRecent recent = new DocRecent();
  159. recent.setIsFolder("Y");
  160. recent.setOwner(SecurityUtils.getUserId());
  161. recent.setRelaId(dir.getDirId());
  162. recentService.insertDocRecent(recent);
  163. }
  164. return success(list);
  165. }
  166. /**
  167. * 导出文档目录管理列表
  168. */
  169. // @ApiOperation("导出文档目录管理列表")
  170. //@PreAuthorize("@ss.hasPermi('biz:dir:export')")
  171. @Log(title = "文档目录管理", businessType = BusinessType.EXPORT)
  172. @PostMapping("/export")
  173. public void export(HttpServletResponse response, DocDir docDir) {
  174. List<DocDir> list = docDirService.selectDocDirList(docDir);
  175. ExcelUtil<DocDir> util = new ExcelUtil<DocDir>(DocDir.class);
  176. util.exportExcel(response, list, "文档目录管理数据");
  177. }
  178. /**
  179. * 获取文档目录管理详细信息
  180. */
  181. // @ApiOperation("获取文档目录管理详细信息")
  182. //@PreAuthorize("@ss.hasPermi('biz:dir:query')")
  183. @GetMapping(value = "/{dirId}")
  184. public AjaxResult getInfo(@PathVariable("dirId") Long dirId) {
  185. DocDir dir = docDirService.selectDocDirByDirId(dirId);
  186. DocDirUser dirUser = new DocDirUser();
  187. dirUser.setDirId(dirId);
  188. dir.setUsers(dirUserService.selectDocDirUserList(dirUser));
  189. return success(dir);
  190. }
  191. /**
  192. * 新建目录
  193. */
  194. @ApiOperation("新建目录")
  195. //@PreAuthorize("@ss.hasPermi('biz:dir:add')")
  196. @Log(title = "文档目录管理", businessType = BusinessType.INSERT)
  197. @PostMapping
  198. public AjaxResult add(@RequestBody DocDir docDir) {
  199. int i = docDirService.insertDocDir(docDir);
  200. //如果是部门目录,则需要插入成员
  201. String dept = "2";
  202. if (dept.equals(docDir.getDirType())) {
  203. docDir.getUsers().forEach(u -> {
  204. u.setDirId(docDir.getDirId());
  205. dirUserService.insertDocDirUser(u);
  206. });
  207. }
  208. return toAjax(i);
  209. }
  210. /**
  211. * 重命名
  212. */
  213. @ApiOperation("重命名")
  214. @Log(title = "文档目录管理", businessType = BusinessType.UPDATE)
  215. @GetMapping("/rename")
  216. @ApiImplicitParams({@ApiImplicitParam(name = "dirId", value = "目录ID", required = true), @ApiImplicitParam(name = "name", value = "新目录名", required = true)})
  217. public AjaxResult rename(Long dirId, String name) {
  218. DocDir docDir = new DocDir();
  219. docDir.setDirId(dirId);
  220. docDir.setDirName(name);
  221. docDir.setUpdateBy(SecurityUtils.getUsername());
  222. return toAjax(docDirService.updateDocDir(docDir));
  223. }
  224. /**
  225. * 修改文档目录管理
  226. */
  227. @ApiOperation("修改目录信息")
  228. //@PreAuthorize("@ss.hasPermi('biz:dir:edit')")
  229. @Log(title = "文档目录管理", businessType = BusinessType.UPDATE)
  230. @PutMapping
  231. public AjaxResult edit(@RequestBody DocDir docDir) {
  232. //如果是部门目录,则需要插入成员
  233. String dept = "2";
  234. dirUserService.deleteDocDirUserByDirId(docDir.getDirId());
  235. if (dept.equals(docDir.getDirType())) {
  236. docDir.getUsers().forEach(u -> {
  237. u.setDirId(docDir.getDirId());
  238. dirUserService.insertDocDirUser(u);
  239. });
  240. }
  241. return toAjax(docDirService.updateDocDir(docDir));
  242. }
  243. /**
  244. * 删除文档目录管理
  245. */
  246. @ApiOperation("删除目录")
  247. //@PreAuthorize("@ss.hasPermi('biz:dir:remove')")
  248. @Log(title = "文档目录管理", businessType = BusinessType.DELETE)
  249. @DeleteMapping("/{dirId}")
  250. public AjaxResult remove(@PathVariable Long dirId) {
  251. DocDir dir = new DocDir();
  252. dir.setParentId(dirId);
  253. List list = docDirService.selectDocDirList(dir);
  254. if (list.size() > 0) {
  255. return error("目录不为空,无法删除!");
  256. }
  257. DocInfo info = new DocInfo();
  258. info.setDirId(dirId);
  259. list = docInfoService.selectDocInfoList(info);
  260. if (list.size() > 0) {
  261. return error("目录不为空,无法删除!");
  262. }
  263. int i = docDirService.deleteDocDirByDirId(dirId);
  264. //删除收藏记录
  265. favoriteService.delete("Y", dirId);
  266. return toAjax(i);
  267. }
  268. }