FileAndFolderController.java 7.7 KB

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