很多优化

This commit is contained in:
cjw 2024-07-18 16:36:03 +08:00
parent 0d337286b1
commit fb1870328e
10 changed files with 122 additions and 73 deletions

View File

@ -36,7 +36,8 @@ public class SysCatalogPersonController extends BaseController {
/**
* 查询目录-我的空间列表
*/
@SaCheckPermission("catalog:person:list")
//@SaCheckPermission("catalog:person:list")
@SaCheckPermission("sys:person:oss")
@GetMapping("/list")
public R<List<SysCatalogPersonVo>> list(SysCatalogPersonBo bo) {
List<SysCatalogPersonVo> list = personService.queryList(bo);
@ -48,7 +49,8 @@ public class SysCatalogPersonController extends BaseController {
*
* @param catalogId 主键
*/
@SaCheckPermission("catalog:person:query")
//@SaCheckPermission("catalog:person:query")
@SaCheckPermission("sys:person:oss")
@GetMapping("/{catalogId}")
public R<SysCatalogPersonVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long catalogId) {
@ -58,7 +60,8 @@ public class SysCatalogPersonController extends BaseController {
/**
* 新增目录-我的空间
*/
@SaCheckPermission("catalog:person:add")
//@SaCheckPermission("catalog:person:add")
@SaCheckPermission("sys:person:oss")
@Log(title = "目录-我的空间", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
@ -72,17 +75,19 @@ public class SysCatalogPersonController extends BaseController {
/**
* 修改目录-我的空间
*/
@SaCheckPermission("catalog:person:edit")
//@SaCheckPermission("catalog:person:edit")
@SaCheckPermission("sys:person:oss")
@Log(title = "目录-我的空间", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCatalogPersonBo bo) {
Long catalogId = bo.getCatalogId();
// Long catalogId = bo.getCatalogId();
if (!personService.checkNameUnique(bo)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,名称已存在");
} else if (bo.getParentId().equals(catalogId)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
}
// } else if (bo.getParentId().equals(catalogId)) {
// return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
// }
return toAjax(personService.updateByBo(bo));
}
@ -91,7 +96,8 @@ public class SysCatalogPersonController extends BaseController {
*
* @param catalogId 主键串
*/
@SaCheckPermission("catalog:person:remove")
//@SaCheckPermission("catalog:person:remove")
@SaCheckPermission("sys:person:oss")
@Log(title = "目录-我的空间", businessType = BusinessType.DELETE)
@DeleteMapping("/{catalogId}")
public R<Void> remove(@NotNull(message = "主键不能为空")
@ -110,7 +116,8 @@ public class SysCatalogPersonController extends BaseController {
*
* @param bo 拖动类
*/
@SaCheckPermission("catalog:person:edit")
//@SaCheckPermission("catalog:person:edit")
@SaCheckPermission("sys:person:oss")
@Log(title = "拖动目录-我的空间", businessType = BusinessType.UPDATE)
@PostMapping("/drag")
public R<Void> drag(@Validated @RequestBody CatalogDragBo bo) {

View File

@ -89,12 +89,13 @@ public class SysCatalogResourceController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCatalogResourceBo bo) {
Long catalogId = bo.getCatalogId();
// Long catalogId = bo.getCatalogId();
if (!resourceService.checkNameUnique(bo)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,名称已存在");
} else if (bo.getParentId().equals(catalogId)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
}
// } else if (bo.getParentId().equals(catalogId)) {
// return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
// }
return toAjax(resourceService.updateByBo(bo));
}

View File

@ -62,7 +62,7 @@ public class SysCatalogTextbookController extends BaseController {
@SaCheckPermission("catalog:textbook:query")
@GetMapping("/{catalogId}")
public R<SysCatalogTextbookVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long catalogId) {
@PathVariable Long catalogId) {
return R.ok(textbookService.queryById(catalogId));
}
@ -88,12 +88,13 @@ public class SysCatalogTextbookController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCatalogTextbookBo bo) {
Long catalogId = bo.getCatalogId();
// Long catalogId = bo.getCatalogId();
if (!textbookService.checkNameUnique(bo)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,名称已存在");
} else if (bo.getParentId().equals(catalogId)) {
return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
}
// } else if (bo.getParentId().equals(catalogId)) {
// return R.fail("修改'" + bo.getCatalogName() + "'失败,上级不能是自己");
// }
return toAjax(textbookService.updateByBo(bo));
}

View File

@ -38,7 +38,8 @@ public class SysOssPersonController extends BaseController {
/**
* 查询资源-我的空间列表
*/
@SaCheckPermission("file:person:pageList")
//@SaCheckPermission("file:person:pageList")
@SaCheckPermission("sys:person:oss")
@GetMapping("/pageList")
public TableDataInfo<SysOssPersonVo> list(SysOssPersonBo bo, PageQuery pageQuery) {
return sysOssPersonService.queryPageList(bo, pageQuery);
@ -49,7 +50,8 @@ public class SysOssPersonController extends BaseController {
*
* @param id 主键
*/
@SaCheckPermission("file:person:query")
//@SaCheckPermission("file:person:query")
@SaCheckPermission("sys:person:oss")
@GetMapping("/{id}")
public R<SysOssPersonVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
@ -59,7 +61,8 @@ public class SysOssPersonController extends BaseController {
/**
* 新增资源-我的空间
*/
@SaCheckPermission("file:person:add")
//@SaCheckPermission("file:person:add")
@SaCheckPermission("sys:person:oss")
@Log(title = "资源-我的空间", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
@ -73,7 +76,8 @@ public class SysOssPersonController extends BaseController {
*
* @param ids 主键串
*/
@SaCheckPermission("file:person:remove")
//@SaCheckPermission("file:person:remove")
@SaCheckPermission("sys:person:oss")
@Log(title = "资源-我的空间", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@ -86,7 +90,8 @@ public class SysOssPersonController extends BaseController {
*
* @param bo 主键串
*/
@SaCheckPermission("file:person:copy")
//@SaCheckPermission("file:person:copy")
@SaCheckPermission("sys:person:oss")
@Log(title = "【复制我的空间】", businessType = BusinessType.UPDATE)
@PutMapping("/copy")
public R<Void> copy(@RequestBody SysOssPersonBo bo) {
@ -98,7 +103,8 @@ public class SysOssPersonController extends BaseController {
*
* @param bo 主键串
*/
@SaCheckPermission("file:person:move")
//@SaCheckPermission("file:person:move")
@SaCheckPermission("sys:person:oss")
@Log(title = "【移动我的空间】", businessType = BusinessType.UPDATE)
@PutMapping("/move")
public R<Void> move(@RequestBody SysOssPersonBo bo) {
@ -110,7 +116,8 @@ public class SysOssPersonController extends BaseController {
*
* @param bo 主键串
*/
@SaCheckPermission("file:person:share")
//@SaCheckPermission("file:person:share")
@SaCheckPermission("sys:person:oss")
@Log(title = "【分享我的空间】", businessType = BusinessType.UPDATE)
@PutMapping("/share")
public R<Void> share(@RequestBody SysOssPersonBo bo) {
@ -122,7 +129,8 @@ public class SysOssPersonController extends BaseController {
*
* @param id 主键
*/
@SaCheckPermission("file:person:download")
//@SaCheckPermission("file:person:download")
@SaCheckPermission("sys:person:oss")
@PostMapping("/download/{id}")
public void download(@NotNull(message = "主键不能为空") @PathVariable Long id, HttpServletResponse response) throws Exception {
sysOssPersonService.download(id, response);
@ -133,7 +141,8 @@ public class SysOssPersonController extends BaseController {
*
* @param id 主键
*/
@SaCheckPermission("file:person:preview")
//@SaCheckPermission("file:person:preview")
@SaCheckPermission("sys:person:oss")
@PostMapping("/preview/{id}")
public R<String> preview(@NotNull(message = "主键不能为空") @PathVariable Long id) throws Exception {
return R.ok("操作成功", sysOssPersonService.preview(id));

View File

@ -3,6 +3,7 @@ package org.dromara.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -25,6 +26,7 @@ import org.dromara.system.mapper.SysOssPersonMapper;
import org.dromara.system.service.ISysCatalogPersonService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@ -87,7 +89,9 @@ public class SysCatalogPersonServiceImpl implements ISysCatalogPersonService {
* @param bo 目录-我的空间
* @return 是否新增成功
*/
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(SysCatalogPersonBo bo) {
Long parentId = bo.getParentId();
SysCatalogPerson info = baseMapper.selectById(parentId);
@ -106,17 +110,20 @@ public class SysCatalogPersonServiceImpl implements ISysCatalogPersonService {
*/
@Override
public Boolean updateByBo(SysCatalogPersonBo bo) {
SysCatalogPerson update = MapstructUtils.convert(bo, SysCatalogPerson.class);
SysCatalogPerson old = baseMapper.selectById(update.getCatalogId());
if (!old.getParentId().equals(update.getParentId())) {
SysCatalogPerson newParentDept = baseMapper.selectById(update.getParentId());
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
String oldAncestors = old.getAncestors();
update.setAncestors(newAncestors);
updateDeptChildren(update.getCatalogId(), newAncestors, oldAncestors);
}
}
// SysCatalogPerson update = MapstructUtils.convert(bo, SysCatalogPerson.class);
// SysCatalogPerson old = baseMapper.selectById(update.getCatalogId());
// if (!old.getParentId().equals(update.getParentId())) {
// SysCatalogPerson newParentDept = baseMapper.selectById(update.getParentId());
// if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
// String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
// String oldAncestors = old.getAncestors();
// update.setAncestors(newAncestors);
// updateDeptChildren(update.getCatalogId(), newAncestors, oldAncestors);
// }
// }
SysCatalogPerson update = new SysCatalogPerson();
update.setCatalogId(bo.getCatalogId());
update.setCatalogName(bo.getCatalogName());
return baseMapper.updateById(update) > 0;
}
@ -189,7 +196,9 @@ public class SysCatalogPersonServiceImpl implements ISysCatalogPersonService {
return baseMapper.selectList(queryWrapper);
}
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public boolean dragCatalog(CatalogDragBo bo) {
Long oldCatalogId = bo.getOldCatalog();
Long newCatalogId = bo.getNewCatalog();

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -29,6 +30,7 @@ import org.dromara.system.mapper.SysOssResourceMapper;
import org.dromara.system.service.ISysCatalogResourceService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@ -134,7 +136,9 @@ public class SysCatalogResourceServiceImpl implements ISysCatalogResourceService
* @param bo 目录-专题资源
* @return 是否新增成功
*/
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(SysCatalogResourceBo bo) {
Long parentId = bo.getParentId();
SysCatalogResource info = baseMapper.selectById(parentId);
@ -159,17 +163,20 @@ public class SysCatalogResourceServiceImpl implements ISysCatalogResourceService
*/
@Override
public Boolean updateByBo(SysCatalogResourceBo bo) {
SysCatalogResource update = MapstructUtils.convert(bo, SysCatalogResource.class);
SysCatalogResourceVo old = SpringUtils.getAopProxy(this).selectCatalogById(update.getCatalogId());
if (!old.getParentId().equals(update.getParentId())) {
SysCatalogResourceVo newParentDept = SpringUtils.getAopProxy(this).selectCatalogById(update.getParentId());
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
String oldAncestors = old.getAncestors();
update.setAncestors(newAncestors);
updateDeptChildren(update.getCatalogId(), newAncestors, oldAncestors);
}
}
// SysCatalogResource update = MapstructUtils.convert(bo, SysCatalogResource.class);
// SysCatalogResourceVo old = SpringUtils.getAopProxy(this).selectCatalogById(update.getCatalogId());
// if (!old.getParentId().equals(update.getParentId())) {
// SysCatalogResourceVo newParentDept = SpringUtils.getAopProxy(this).selectCatalogById(update.getParentId());
// if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
// String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
// String oldAncestors = old.getAncestors();
// update.setAncestors(newAncestors);
// updateDeptChildren(update.getCatalogId(), newAncestors, oldAncestors);
// }
// }
SysCatalogResource update = new SysCatalogResource();
update.setCatalogId(bo.getCatalogId());
update.setCatalogName(bo.getCatalogName());
return baseMapper.updateById(update) > 0;
}
@ -249,7 +256,9 @@ public class SysCatalogResourceServiceImpl implements ISysCatalogResourceService
return buildCatalogTreeSelect(voList);
}
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public boolean dragCatalog(CatalogDragBo bo) {
Long oldCatalogId = bo.getOldCatalog();
Long newCatalogId = bo.getNewCatalog();

View File

@ -27,6 +27,7 @@ import org.dromara.system.mapper.SysOssTextbookMapper;
import org.dromara.system.service.ISysCatalogTextbookService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@ -100,6 +101,7 @@ public class SysCatalogTextbookServiceImpl implements ISysCatalogTextbookService
*/
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(SysCatalogTextbookBo bo) {
Long parentId = bo.getParentId();
SysCatalogTextbook info = baseMapper.selectById(parentId);
@ -124,17 +126,21 @@ public class SysCatalogTextbookServiceImpl implements ISysCatalogTextbookService
*/
@Override
public Boolean updateByBo(SysCatalogTextbookBo bo) {
SysCatalogTextbook update = MapstructUtils.convert(bo, SysCatalogTextbook.class);
SysCatalogTextbookVo old = SpringUtils.getAopProxy(this).selectCatalogById(update.getCatalogId());
if (!old.getParentId().equals(update.getParentId())) {
SysCatalogTextbookVo newParentDept = SpringUtils.getAopProxy(this).selectCatalogById(update.getParentId());
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
String oldAncestors = old.getAncestors();
update.setAncestors(newAncestors);
updateCatalogChildren(update.getCatalogId(), newAncestors, oldAncestors);
}
}
// SysCatalogTextbook update = MapstructUtils.convert(bo, SysCatalogTextbook.class);
// SysCatalogTextbookVo old = SpringUtils.getAopProxy(this).selectCatalogById(update.getCatalogId());
// if (!old.getParentId().equals(update.getParentId())) {
// SysCatalogTextbookVo newParentDept = SpringUtils.getAopProxy(this).selectCatalogById(update.getParentId());
// if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(old)) {
// String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getCatalogId();
// String oldAncestors = old.getAncestors();
// update.setAncestors(newAncestors);
// updateCatalogChildren(update.getCatalogId(), newAncestors, oldAncestors);
// }
// }
// update.setOrderNum(null);
SysCatalogTextbook update = new SysCatalogTextbook();
update.setCatalogId(bo.getCatalogId());
update.setCatalogName(bo.getCatalogName());
return baseMapper.updateById(update) > 0;
}
@ -220,7 +226,9 @@ public class SysCatalogTextbookServiceImpl implements ISysCatalogTextbookService
return buildCatalogTreeSelect(voList);
}
@Lock4j
@Override
@Transactional(rollbackFor = Exception.class)
public boolean dragCatalog(CatalogDragBo bo) {
Long oldCatalogId = bo.getOldCatalog();
Long newCatalogId = bo.getNewCatalog();

View File

@ -16,20 +16,15 @@ import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.helper.DataBaseHelper;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.constant.StatusConstants;
import org.dromara.system.domain.SysCatalogPerson;
import org.dromara.system.domain.SysOssPerson;
import org.dromara.system.domain.SysOssTextbook;
import org.dromara.system.domain.bo.SysOssPersonBo;
import org.dromara.system.domain.bo.SysOssTextbookBo;
import org.dromara.system.domain.vo.SysCatalogPersonVo;
import org.dromara.system.domain.vo.SysOssPersonVo;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.mapper.SysOssPersonMapper;
import org.dromara.system.mapper.SysOssTextbookMapper;
import org.dromara.system.service.ISysCatalogPersonService;
import org.dromara.system.service.ISysCatalogTextbookService;
import org.dromara.system.service.ISysOssPersonService;
import org.dromara.system.service.ISysOssService;
import org.dromara.system.service.*;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -51,9 +46,8 @@ public class SysOssPersonServiceImpl implements ISysOssPersonService {
private final ISysOssService ossService;
private final SysOssTextbookMapper textbookMapper;
private final ISysOssTextbookService textbookService;
private final ISysCatalogTextbookService catalogTextbookService;
/**
* 查询资源-我的空间
@ -231,20 +225,19 @@ public class SysOssPersonServiceImpl implements ISysOssPersonService {
@Override
public boolean share(SysOssPersonBo bo) {
SysOssPerson ossPerson = baseMapper.selectById(bo.getId());
SysOssTextbook date = new SysOssTextbook();
SysOssTextbookBo date = new SysOssTextbookBo();
date.setOssId(ossPerson.getOssId());
String path = catalogTextbookService.selectCatalogNameById(bo.getCatalogId());
date.setCatalogId(bo.getCatalogId());
date.setFileName(ossPerson.getFileName());
date.setFileSuffix(ossPerson.getFileSuffix());
date.setFilePath(path);
date.setType(ossPerson.getType());
date.setOssType(1);
date.setStatus(StatusConstants.IN_USE);
date.setFinalizeStatus(StatusConstants.DISABLED);
date.setCreateDept(ossPerson.getCreateDept());
date.setCreateBy(ossPerson.getCreateBy());
date.setUpdateBy(ossPerson.getCreateBy());
return textbookMapper.insert(date) > 0;
if (!textbookService.checkNameUnique(date)) {
throw new ServiceException("分享'" + date.getFileName() + "'失败,名称已存在");
}
return textbookService.insertByBo(date);
}
}

View File

@ -253,6 +253,10 @@ public class SysOssResourceServiceImpl implements ISysOssResourceService {
if (ossResource.getCatalogId().equals(bo.getCatalogId())) {
throw new ServiceException("同目录下不能复制或移动");
}
bo.setFileName(ossResource.getFileName());
if(this.checkNameUnique(bo)){
throw new ServiceException("复制或移动'" + bo.getFileName() + "'失败,名称已存在");
}
SysOssResource date = new SysOssResource();
date.setOssId(ossResource.getOssId());
String path = catalogService.selectCatalogNameById(bo.getCatalogId());

View File

@ -272,6 +272,11 @@ public class SysOssTextbookServiceImpl implements ISysOssTextbookService {
if (ossTextbook.getCatalogId().equals(bo.getCatalogId())) {
throw new ServiceException("同目录下不能复制或移动");
}
bo.setFileName(ossTextbook.getFileName());
bo.setOssType(ossTextbook.getOssType());
if (this.checkNameUnique(bo)) {
throw new ServiceException("复制或移动'" + bo.getFileName() + "'失败,名称已存在");
}
SysOssTextbook date = new SysOssTextbook();
date.setOssId(ossTextbook.getOssId());
String path = catalogService.selectCatalogNameById(bo.getCatalogId());
@ -360,6 +365,9 @@ public class SysOssTextbookServiceImpl implements ISysOssTextbookService {
public Boolean finalize(SysOssTextbookBo bo) {
Long id = bo.getId();
SysOssTextbook ossTextbook = baseMapper.selectById(id);
if (ossTextbook.getFinalizeStatus() == 1) {
throw new ServiceException("请勿重复定稿");
}
SysOssTextbook date = new SysOssTextbook();
date.setOssId(ossTextbook.getOssId());
date.setCatalogId(ossTextbook.getCatalogId());