123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- package com.wtkj.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
- import com.wtkj.dto.SelectFileDTO;
- import com.wtkj.dto.UploadFileDTO;
- import com.wtkj.entity.FileAndFolder;
- import com.wtkj.entity.FileAndFolderHistory;
- import com.wtkj.entity.FileRead;
- import com.wtkj.service.ICommonService;
- import com.wtkj.service.IFileAndFolderHistoryService;
- import com.wtkj.service.IFileAndFolderService;
- import com.wtkj.service.IFileReadService;
- import com.wtkj.vo.FileAndFolderVO;
- import com.wtkj.wrapper.FileAndFolderHistoryWrapper;
- import com.wtkj.wrapper.FileAndFolderWrapper;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springblade.core.log.exception.ServiceException;
- import org.springblade.core.mp.support.Condition;
- import org.springblade.core.mp.support.Query;
- import org.springblade.core.tool.api.R;
- import org.springblade.core.tool.utils.Func;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.Valid;
- import java.util.List;
- import java.util.Objects;
- import static com.wtkj.config.MagicValue.ONE;
- import static com.wtkj.config.MagicValue.TWO;
- /**
- * @author Blizzard
- * @create at 2023-09-14 15:06
- * @describe
- */
- @RestController
- @AllArgsConstructor
- @RequestMapping("/file-and-folder")
- @Api(value = "文件和文件夹模块", tags = "文件和文件夹模块")
- public class FileAndFolderController {
- private final IFileAndFolderService fileAndFolderService;
- private final ICommonService commonService;
- private final IFileReadService fileReadService;
- public final IFileAndFolderHistoryService historyService;
- /**
- * 新建文件夹
- */
- @PostMapping("/submit")
- @ApiOperation(value = "创建修改文件夹或者文件", notes = "")
- @ApiOperationSupport(order = 1)
- public R<Boolean> createFolder(@RequestBody FileAndFolder folder) {
- LambdaQueryWrapper<FileAndFolder> lqw = new LambdaQueryWrapper<>();
- lqw.eq(FileAndFolder::getStageId, folder.getStageId());
- lqw.eq(FileAndFolder::getTitle, folder.getTitle());
- lqw.eq(FileAndFolder::getParentId, folder.getParentId());
- if (Objects.equals(folder.getType(), ONE)) {
- lqw.eq(FileAndFolder::getType, ONE);
- long cnt = fileAndFolderService.count(lqw);
- if (cnt > 0L) {
- throw new ServiceException("此项目阶段下已经存在同名文件");
- }
- } else if (Objects.equals(folder.getType(), TWO)) {
- lqw.eq(FileAndFolder::getType, TWO);
- long cnt = fileAndFolderService.count(lqw);
- if (cnt > 0L) {
- throw new ServiceException("此项目阶段下已经存在同名文件夹");
- }
- }
- return R.status(fileAndFolderService.saveOrUpdate(folder));
- }
- /**
- * 上传文件
- */
- @PostMapping("/upload-file")
- @ApiOperationSupport(order = 2)
- @ApiOperation(value = "上传文件提示覆盖", notes = "")
- public R<Boolean> uploadFile(@Valid @RequestBody List<UploadFileDTO> files) {
- //判断是否存在重名文件
- boolean isExist = fileAndFolderService.isExistSameName(files);
- if (isExist) {
- //存同名文件 提示
- return R.fail("存在重名文件,是否覆盖");
- } else {
- //不存在同名文件 直接上传
- return R.status(commonService.uploadFile(files));
- }
- }
- /**
- * 文件覆盖
- */
- @PostMapping("/cover-file")
- @ApiOperationSupport(order = 3)
- @ApiOperation(value = "上传直接覆盖同名文件", notes = "")
- public R<Boolean> coverFile(@Valid @RequestBody List<UploadFileDTO> files) {
- return R.status(commonService.coverFile(files));
- }
- /**
- * 阶段下的文件夹和文件
- */
- @GetMapping("/page-by-stage")
- @ApiOperationSupport(order = 4)
- @ApiOperation(value = "阶段下的顶级文件和文件夹", notes = "")
- public R<IPage<FileAndFolderVO>> pageByStage(@RequestParam("stageId") Long stageId, Query query) {
- IPage<FileAndFolder> page = fileAndFolderService.pageByStageId(stageId, Condition.getPage(query));
- return R.data(FileAndFolderWrapper.build().pageVO(page));
- }
- /**
- * 文件夹下的文件和文件夹
- */
- @GetMapping("/page-by-parent")
- @ApiOperationSupport(order = 5)
- @ApiOperation(value = "文件夹下的文件和文件夹", notes = "")
- public R<IPage<FileAndFolderVO>> pageByParentId(@RequestParam("parentId") Long parentId, Query query) {
- IPage<FileAndFolder> page = fileAndFolderService.pageByParentId(parentId, Condition.getPage(query));
- return R.data(FileAndFolderWrapper.build().pageVO(page));
- }
- /**
- * 文件夹下的文件数量 页码数量
- */
- @GetMapping("/file-and-page-amount")
- @ApiOperationSupport(order = 6)
- @ApiOperation(value = "文夹下的文件数量", notes = "传入文件夹主键id")
- public R<JSONObject> getPageAmount(@RequestParam Long stageId, @RequestParam Long parentId) {
- return R.data(fileAndFolderService.getPageAndFileAmount(stageId, parentId));
- }
- /**
- * 删除文件/文件夹
- */
- @GetMapping("/remove")
- @ApiOperationSupport(order = 7)
- @ApiOperation(value = "删除文件夹或文件", notes = "")
- public R<Boolean> delete(@RequestParam String ids) {
- return R.status(commonService.remove(Func.toLongList(ids)));
- }
- /**
- * 文件或者文件夹移动
- */
- @GetMapping("/move")
- @ApiOperationSupport(order = 8)
- @ApiOperation(value = "移动文件或者文件夹", notes = "")
- public R<Boolean> move(String ids, Long stageId, Long parentId) {
- return R.status(commonService.move(ids, stageId, parentId));
- }
- /**
- * 文件详情
- */
- @GetMapping("/file-detail")
- @ApiOperationSupport(order = 10)
- @ApiOperation(value = "文件详情", notes = "")
- public R<FileAndFolderVO> detail(@RequestParam Long id) {
- FileAndFolder byId = fileAndFolderService.getById(id);
- return R.data(FileAndFolderWrapper.build().entityVO(byId));
- }
- /**
- * 阅读文件
- */
- @PostMapping("/read-file")
- @ApiOperationSupport(order = 10)
- @ApiOperation(value = "阅读文件", notes = "")
- public R<Boolean> readFile(@RequestBody FileRead read) {
- return R.status(fileReadService.readFile(read));
- }
- /**
- * 文件选择列表
- */
- @PostMapping("/select-file")
- @ApiOperationSupport(order = 11)
- @ApiOperation(value = "选择文件", notes = "")
- public R selectFile(@RequestBody @Valid SelectFileDTO dto) {
- Query query = new Query();
- query.setCurrent(dto.getCurrent());
- query.setSize(dto.getSize());
- IPage<FileAndFolder> page = fileAndFolderService.selectPage(dto.getProjectId(), dto.getStageId(), dto.getIsLatest(), Condition.getPage(query));
- return R.data(FileAndFolderWrapper.build().pageVO(page));
- }
- /**
- * 文件历史
- */
- @GetMapping("/v2/file-history")
- @ApiOperationSupport(order = 21)
- @ApiOperation(value = "文件历史", notes = "传入fileId字段,注意非主键id")
- public R fileHistory(@RequestParam Long fileId, Query query) {
- IPage<FileAndFolderHistory> page = historyService.getPage(fileId, Condition.getPage(query));
- return R.data(FileAndFolderHistoryWrapper.build().pageVO(page));
- }
- }
|