| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- package com.doc.biz.controller;
- import com.doc.biz.domain.*;
- import com.doc.biz.service.*;
- import com.doc.biz.vo.MatchVO;
- import com.doc.biz.vo.TreeVO;
- import com.doc.common.annotation.Log;
- import com.doc.common.constant.Constants;
- import com.doc.common.core.controller.BaseController;
- import com.doc.common.core.domain.AjaxResult;
- import com.doc.common.core.domain.entity.SysRole;
- import com.doc.common.enums.BusinessType;
- import com.doc.common.enums.EventLevel;
- import com.doc.common.utils.DateUtils;
- import com.doc.common.utils.SecurityUtils;
- import com.doc.common.utils.poi.ExcelUtil;
- import io.swagger.annotations.*;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 文档目录管理Controller
- *
- * @author wukai
- * @date 2023-08-15
- */
- @Api(tags = "文档目录管理")
- @RestController
- @RequestMapping("/biz/dir")
- public class DocDirController extends BaseController {
- @Resource
- private IDocDirService docDirService;
- @Resource
- private IDocInfoService docInfoService;
- @Resource
- private IDocSpaceService spaceService;
- @Resource
- private IDocDirUserService dirUserService;
- @Resource
- private IDocFavoriteService favoriteService;
- @Resource
- private IDocRecentService recentService;
- /**
- * 获取顶层目录
- */
- @ApiOperation("获取顶层目录")
- @GetMapping(value = "/top-dir/{type}")
- public DocDir topDir(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
- DocSpace space = spaceService.selectDocSpaceListByType(type);
- String dept = "2";
- if (space.getSpaceId() == null && dept.equals(type)) {
- spaceService.initDeptSpace(SecurityUtils.getLoginUser().getUser().getDept());
- space = spaceService.selectDocSpaceListByType(type);
- }
- DocDir dir = new DocDir();
- dir.setSpaceId(space.getSpaceId());
- dir.setParentId(0L);
- List<DocDir> dirList = docDirService.selectDocDirList(dir);
- if (dirList.size() > 0) {
- return dirList.get(0);
- } else {
- return null;
- }
- }
- /**
- * 获取目录树
- */
- @ApiOperation("目录树")
- @GetMapping(value = "/dir-tree/{type}")
- public TreeVO dirTree(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
- return tree(type, dirTree);
- }
- /**
- * 文件树
- */
- private final String fileTree = "1";
- /**
- * 目录树
- */
- private final String dirTree = "2";
- /**
- * 图片树
- */
- private final String picTree = "3";
- /**
- * 获取文件树
- */
- @ApiOperation("文件树")
- @GetMapping(value = "/file-tree/{type}")
- public TreeVO fileTree(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
- return tree(type, fileTree);
- }
- /**
- * 获取文件树
- */
- @ApiOperation("图片文件树")
- @GetMapping(value = "/pic-tree")
- public TreeVO picTree() {
- String type = "3";
- return tree(type, picTree);
- }
- /**
- * 获取树
- *
- * @param type 空间类型
- * @param st 1.文件树 2.目录树 3.图片树
- * @return
- */
- private TreeVO tree(String type, String st) {
- DocSpace space = spaceService.selectDocSpaceListByType(type);
- DocDir docDir = new DocDir();
- docDir.setSpaceId(space.getSpaceId());
- docDir.setParentId(0L);
- List<DocDir> list = docDirService.selectDocDirList(docDir);
- TreeVO vo = getChildren(list.get(0), st);
- return vo;
- }
- /**
- * 递归获取目录树
- *
- * @param dir 目录信息
- * @return
- */
- private TreeVO getChildren(DocDir dir, String st) {
- TreeVO vo = new TreeVO();
- vo.setId(dir.getDirId());
- vo.setLabel(dir.getDirName());
- List<TreeVO> children = new ArrayList<>();
- DocDir dir1 = new DocDir();
- dir1.setParentId(dir.getDirId());
- dir1.setSpaceId(dir.getSpaceId());
- docDirService.selectDocDirList(dir1).forEach(d -> {
- children.add(getChildren(d, st));
- });
- if (!dirTree.equals(st)) {
- //如果不是目录树
- vo.setDisabled(true);
- DocInfo info = new DocInfo();
- info.setDirId(dir.getDirId());
- docInfoService.selectDocInfoList(info).forEach(d -> {
- if (!picTree.equals(st) || Constants.IMAGE_EXTENSION.contains(d.getFileType())) {
- TreeVO childVO = new TreeVO();
- childVO.setId(d.getDocId());
- childVO.setLabel(d.getFileName());
- childVO.setRemark(d.getFileId());
- childVO.setDisabled(false);
- children.add(childVO);
- }
- });
- }
- vo.setChildren(children);
- return vo;
- }
- /**
- * 查询文档目录管理列表
- */
- @ApiOperation("查询目录列表")
- //@PreAuthorize("@ss.hasPermi('biz:dir:list')")
- @GetMapping("/list")
- public AjaxResult list(DocDir docDir) {
- List<DocDir> list = docDirService.selectDocDirList(docDir);
- DocDir dir = docDirService.selectDocDirByDirId(docDir.getParentId());
- if (dir.getParentId() != 0) {
- //如果不是顶层目录
- //插入最近访问记录
- DocRecent recent = new DocRecent();
- recent.setIsFolder("Y");
- recent.setOwner(SecurityUtils.getUserId());
- recent.setRelaId(dir.getDirId());
- recentService.insertDocRecent(recent);
- }
- return success(list);
- }
- /**
- * 查询文档目录管理列表
- */
- @ApiOperation("按空间类型查询目录列表")
- @GetMapping("/list/{type}")
- public AjaxResult listByType(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type, DocDir docDir) {
- String pub_t = "1";
- String dept_t = "2";
- String pub_k = "system";
- String dept_k = "dept";
- //如果不是个人空间,则需要按权限
- List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles();
- Set<String> roleKeys = roles.stream().map(SysRole::getRoleKey).collect(Collectors.toSet());
- if ((pub_t.equals(type) && !roleKeys.contains(pub_k)) || (dept_t.equals(type) && !roleKeys.contains(dept_k))) {
- //如果是公共空间,且不为系统管理员
- //如果是部门空间,且不为部门管理员
- //则需要判断组织目录是否有权限访问
- Map<String, Object> params = new HashMap<>(4);
- params.put("flag", 1);
- params.put("uid", SecurityUtils.getUserId());
- docDir.setParams(params);
- }
- return list(docDir);
- }
- /**
- * 导出文档目录管理列表
- */
- // @ApiOperation("导出文档目录管理列表")
- //@PreAuthorize("@ss.hasPermi('biz:dir:export')")
- @Log(title = "文档目录管理", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, DocDir docDir) {
- List<DocDir> list = docDirService.selectDocDirList(docDir);
- ExcelUtil<DocDir> util = new ExcelUtil<DocDir>(DocDir.class);
- util.exportExcel(response, list, "文档目录管理数据");
- }
- /**
- * 获取文档目录管理详细信息
- */
- @ApiOperation("获取文档目录管理详细信息")
- //@PreAuthorize("@ss.hasPermi('biz:dir:query')")
- @GetMapping(value = "/{dirId}")
- public AjaxResult getInfo(@PathVariable("dirId") Long dirId) {
- DocDir dir = docDirService.selectDocDirByDirId(dirId);
- DocDirUser dirUser = new DocDirUser();
- dirUser.setDirId(dirId);
- List<DocDirUser> users = dirUserService.selectDocDirUserList(dirUser);
- if (users.size() > 0) {
- dir.setUsers(users);
- }
- return success(dir);
- }
- /**
- * 新建目录
- */
- @ApiOperation("新建目录")
- //@PreAuthorize("@ss.hasPermi('biz:dir:add')")
- @Log(title = "文档目录管理", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody DocDir docDir) {
- checkDuplicateNames(docDir);
- int i = docDirService.insertDocDir(docDir);
- //如果是组织目录,则需要插入成员
- String dept = "2";
- if (dept.equals(docDir.getDirType())) {
- docDir.getUsers().forEach(u -> {
- u.setDirId(docDir.getDirId());
- dirUserService.insertDocDirUser(u);
- });
- }
- return toAjax(i);
- }
- /**
- * 检查重名
- *
- * @param docDir 目录信息
- */
- private void checkDuplicateNames(DocDir docDir) {
- DocDir query = new DocDir();
- query.setParentId(docDir.getParentId());
- query.setSearchValue(docDir.getDirName());
- List list = docDirService.selectDocDirList(query);
- if (list.size() > 0) {
- String dirName = docDir.getDirName();
- dirName = dirName + "-" + DateUtils.dateTimeNow();
- docDir.setDirName(dirName);
- }
- }
- /**
- * 新建目录
- */
- @ApiOperation("验证访问码")
- @Log(title = "文档目录管理", businessType = BusinessType.OTHER, eventLevel = EventLevel.HIGH)
- @PostMapping("/matches")
- public AjaxResult matches(@RequestBody MatchVO vo) {
- return success(docDirService.matchesCode(vo.getDirId(), vo.getCode()));
- }
- /**
- * 重命名
- */
- @ApiOperation("重命名")
- @Log(title = "文档目录管理", businessType = BusinessType.UPDATE)
- @GetMapping("/rename")
- @ApiImplicitParams({@ApiImplicitParam(name = "dirId", value = "目录ID", required = true), @ApiImplicitParam(name = "name", value = "新目录名", required = true)})
- public AjaxResult rename(Long dirId, String name) {
- DocDir docDir = docDirService.selectDocDirByDirId(dirId);
- docDir.setDirName(name);
- docDir.setUpdateBy(SecurityUtils.getUsername());
- checkDuplicateNames(docDir);
- return toAjax(docDirService.updateDocDir(docDir));
- }
- /**
- * 修改文档目录管理
- */
- @ApiOperation("修改目录信息")
- //@PreAuthorize("@ss.hasPermi('biz:dir:edit')")
- @Log(title = "文档目录管理", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody DocDir docDir) {
- //如果是部门目录,则需要插入成员
- String dept = "2";
- dirUserService.deleteDocDirUserByDirId(docDir.getDirId());
- if (dept.equals(docDir.getDirType()) && docDir.getUsers() != null) {
- docDir.getUsers().forEach(u -> {
- u.setDirId(docDir.getDirId());
- dirUserService.insertDocDirUser(u);
- });
- }
- return toAjax(docDirService.updateDocDir(docDir));
- }
- /**
- * 删除文档目录管理
- */
- @ApiOperation("删除目录")
- //@PreAuthorize("@ss.hasPermi('biz:dir:remove')")
- @Log(title = "文档目录管理", businessType = BusinessType.DELETE)
- @DeleteMapping("/{dirId}")
- public AjaxResult remove(@PathVariable Long dirId) {
- DocDir dir = new DocDir();
- dir.setParentId(dirId);
- List list = docDirService.selectDocDirList(dir);
- if (list.size() > 0) {
- return error("目录不为空,无法删除!");
- }
- DocInfo info = new DocInfo();
- info.setDirId(dirId);
- list = docInfoService.selectDocInfoList(info);
- if (list.size() > 0) {
- return error("目录不为空,无法删除!");
- }
- int i = docDirService.deleteDocDirByDirId(dirId);
- //删除收藏记录
- favoriteService.delete("Y", dirId);
- return toAjax(i);
- }
- }
|