FileAndFolderController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package com.wtkj.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  6. import com.wtkj.dto.SelectFileDTO;
  7. import com.wtkj.dto.UploadFileDTO;
  8. import com.wtkj.entity.FileAndFolder;
  9. import com.wtkj.entity.FileAndFolderHistory;
  10. import com.wtkj.entity.FileRead;
  11. import com.wtkj.service.ICommonService;
  12. import com.wtkj.service.IFileAndFolderHistoryService;
  13. import com.wtkj.service.IFileAndFolderService;
  14. import com.wtkj.service.IFileReadService;
  15. import com.wtkj.vo.FileAndFolderVO;
  16. import com.wtkj.wrapper.FileAndFolderHistoryWrapper;
  17. import com.wtkj.wrapper.FileAndFolderWrapper;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import lombok.AllArgsConstructor;
  21. import org.springblade.core.log.exception.ServiceException;
  22. import org.springblade.core.mp.support.Condition;
  23. import org.springblade.core.mp.support.Query;
  24. import org.springblade.core.tool.api.R;
  25. import org.springblade.core.tool.utils.Func;
  26. import org.springframework.web.bind.annotation.*;
  27. import javax.validation.Valid;
  28. import java.util.List;
  29. import java.util.Objects;
  30. import static com.wtkj.config.MagicValue.ONE;
  31. import static com.wtkj.config.MagicValue.TWO;
  32. /**
  33. * @author Blizzard
  34. * @create at 2023-09-14 15:06
  35. * @describe
  36. */
  37. @RestController
  38. @AllArgsConstructor
  39. @RequestMapping("/file-and-folder")
  40. @Api(value = "文件和文件夹模块", tags = "文件和文件夹模块")
  41. public class FileAndFolderController {
  42. private final IFileAndFolderService fileAndFolderService;
  43. private final ICommonService commonService;
  44. private final IFileReadService fileReadService;
  45. public final IFileAndFolderHistoryService historyService;
  46. /**
  47. * 新建文件夹
  48. */
  49. @PostMapping("/submit")
  50. @ApiOperation(value = "创建修改文件夹或者文件", notes = "")
  51. @ApiOperationSupport(order = 1)
  52. public R<Boolean> createFolder(@RequestBody FileAndFolder folder) {
  53. LambdaQueryWrapper<FileAndFolder> lqw = new LambdaQueryWrapper<>();
  54. lqw.eq(FileAndFolder::getStageId, folder.getStageId());
  55. lqw.eq(FileAndFolder::getTitle, folder.getTitle());
  56. lqw.eq(FileAndFolder::getParentId, folder.getParentId());
  57. if (Objects.equals(folder.getType(), ONE)) {
  58. lqw.eq(FileAndFolder::getType, ONE);
  59. long cnt = fileAndFolderService.count(lqw);
  60. if (cnt > 0L) {
  61. throw new ServiceException("此项目阶段下已经存在同名文件");
  62. }
  63. } else if (Objects.equals(folder.getType(), TWO)) {
  64. lqw.eq(FileAndFolder::getType, TWO);
  65. long cnt = fileAndFolderService.count(lqw);
  66. if (cnt > 0L) {
  67. throw new ServiceException("此项目阶段下已经存在同名文件夹");
  68. }
  69. }
  70. return R.status(fileAndFolderService.saveOrUpdate(folder));
  71. }
  72. /**
  73. * 上传文件
  74. */
  75. @PostMapping("/upload-file")
  76. @ApiOperationSupport(order = 2)
  77. @ApiOperation(value = "上传文件提示覆盖", notes = "")
  78. public R<Boolean> uploadFile(@Valid @RequestBody List<UploadFileDTO> files) {
  79. //判断是否存在重名文件
  80. boolean isExist = fileAndFolderService.isExistSameName(files);
  81. if (isExist) {
  82. //存同名文件 提示
  83. return R.fail("存在重名文件,是否覆盖");
  84. } else {
  85. //不存在同名文件 直接上传
  86. return R.status(commonService.uploadFile(files));
  87. }
  88. }
  89. /**
  90. * 文件覆盖
  91. */
  92. @PostMapping("/cover-file")
  93. @ApiOperationSupport(order = 3)
  94. @ApiOperation(value = "上传直接覆盖同名文件", notes = "")
  95. public R<Boolean> coverFile(@Valid @RequestBody List<UploadFileDTO> files) {
  96. return R.status(commonService.coverFile(files));
  97. }
  98. /**
  99. * 阶段下的文件夹和文件
  100. */
  101. @GetMapping("/page-by-stage")
  102. @ApiOperationSupport(order = 4)
  103. @ApiOperation(value = "阶段下的顶级文件和文件夹", notes = "")
  104. public R<IPage<FileAndFolderVO>> pageByStage(@RequestParam("stageId") Long stageId, Query query) {
  105. IPage<FileAndFolder> page = fileAndFolderService.pageByStageId(stageId, Condition.getPage(query));
  106. return R.data(FileAndFolderWrapper.build().pageVO(page));
  107. }
  108. /**
  109. * 文件夹下的文件和文件夹
  110. */
  111. @GetMapping("/page-by-parent")
  112. @ApiOperationSupport(order = 5)
  113. @ApiOperation(value = "文件夹下的文件和文件夹", notes = "")
  114. public R<IPage<FileAndFolderVO>> pageByParentId(@RequestParam("parentId") Long parentId, Query query) {
  115. IPage<FileAndFolder> page = fileAndFolderService.pageByParentId(parentId, Condition.getPage(query));
  116. return R.data(FileAndFolderWrapper.build().pageVO(page));
  117. }
  118. /**
  119. * 文件夹下的文件数量 页码数量
  120. */
  121. @GetMapping("/file-and-page-amount")
  122. @ApiOperationSupport(order = 6)
  123. @ApiOperation(value = "文夹下的文件数量", notes = "传入文件夹主键id")
  124. public R<JSONObject> getPageAmount(@RequestParam Long stageId, @RequestParam Long parentId) {
  125. return R.data(fileAndFolderService.getPageAndFileAmount(stageId, parentId));
  126. }
  127. /**
  128. * 删除文件/文件夹
  129. */
  130. @GetMapping("/remove")
  131. @ApiOperationSupport(order = 7)
  132. @ApiOperation(value = "删除文件夹或文件", notes = "")
  133. public R<Boolean> delete(@RequestParam String ids) {
  134. return R.status(commonService.remove(Func.toLongList(ids)));
  135. }
  136. /**
  137. * 文件或者文件夹移动
  138. */
  139. @GetMapping("/move")
  140. @ApiOperationSupport(order = 8)
  141. @ApiOperation(value = "移动文件或者文件夹", notes = "")
  142. public R<Boolean> move(String ids, Long stageId, Long parentId) {
  143. return R.status(commonService.move(ids, stageId, parentId));
  144. }
  145. /**
  146. * 文件详情
  147. */
  148. @GetMapping("/file-detail")
  149. @ApiOperationSupport(order = 10)
  150. @ApiOperation(value = "文件详情", notes = "")
  151. public R<FileAndFolderVO> detail(@RequestParam Long id) {
  152. FileAndFolder byId = fileAndFolderService.getById(id);
  153. return R.data(FileAndFolderWrapper.build().entityVO(byId));
  154. }
  155. /**
  156. * 阅读文件
  157. */
  158. @PostMapping("/read-file")
  159. @ApiOperationSupport(order = 10)
  160. @ApiOperation(value = "阅读文件", notes = "")
  161. public R<Boolean> readFile(@RequestBody FileRead read) {
  162. return R.status(fileReadService.readFile(read));
  163. }
  164. /**
  165. * 文件选择列表
  166. */
  167. @PostMapping("/select-file")
  168. @ApiOperationSupport(order = 11)
  169. @ApiOperation(value = "选择文件", notes = "")
  170. public R selectFile(@RequestBody @Valid SelectFileDTO dto) {
  171. Query query = new Query();
  172. query.setCurrent(dto.getCurrent());
  173. query.setSize(dto.getSize());
  174. IPage<FileAndFolder> page = fileAndFolderService.selectPage(dto.getProjectId(), dto.getStageId(), dto.getIsLatest(), Condition.getPage(query));
  175. return R.data(FileAndFolderWrapper.build().pageVO(page));
  176. }
  177. /**
  178. * 文件历史
  179. */
  180. @GetMapping("/v2/file-history")
  181. @ApiOperationSupport(order = 21)
  182. @ApiOperation(value = "文件历史", notes = "传入fileId字段,注意非主键id")
  183. public R fileHistory(@RequestParam Long fileId, Query query) {
  184. IPage<FileAndFolderHistory> page = historyService.getPage(fileId, Condition.getPage(query));
  185. return R.data(FileAndFolderHistoryWrapper.build().pageVO(page));
  186. }
  187. }