目录拖动,包含同步教材、专题资源、我的空间

This commit is contained in:
cjw 2024-07-12 15:06:25 +08:00
parent 64287e85eb
commit 6cfb02aafb
10 changed files with 184 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogPersonBo;
import org.dromara.system.domain.vo.SysCatalogPersonVo;
import org.dromara.system.service.ISysCatalogPersonService;
@ -103,4 +104,16 @@ public class SysCatalogPersonController extends BaseController {
}
return toAjax(personService.deleteById(catalogId));
}
/**
* 拖动目录-我的空间
*
* @param bo 拖动类
*/
@SaCheckPermission("catalog:person:edit")
@Log(title = "拖动目录-我的空间", businessType = BusinessType.UPDATE)
@PostMapping("/drag")
public R<Void> drag(@Validated @RequestBody CatalogDragBo bo) {
return toAjax(personService.dragCatalog(bo));
}
}

View File

@ -12,6 +12,7 @@ import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogResourceBo;
import org.dromara.system.domain.vo.SysCatalogResourceVo;
import org.dromara.system.service.ISysCatalogResourceService;
@ -119,4 +120,16 @@ public class SysCatalogResourceController extends BaseController {
}
return toAjax(resourceService.deleteById(catalogId));
}
/**
* 拖动目录-专题资源
*
* @param bo 拖动类
*/
@SaCheckPermission("catalog:resource:edit")
@Log(title = "拖动目录-专题资源", businessType = BusinessType.UPDATE)
@PostMapping("/drag")
public R<Void> drag(@Validated @RequestBody CatalogDragBo bo) {
return toAjax(resourceService.dragCatalog(bo));
}
}

View File

@ -1,6 +1,7 @@
package org.dromara.system.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.system.domain.SysCatalogPerson;
import org.dromara.system.domain.vo.SysCatalogPersonVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
@ -13,5 +14,7 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
*/
@Mapper
public interface SysCatalogPersonMapper extends BaseMapperPlus<SysCatalogPerson, SysCatalogPersonVo> {
int addOrderNum(@Param("mix") Long mix, @Param("max") Long max);
int subOrderNum(@Param("mix") Long mix, @Param("max") Long max);
}

View File

@ -21,4 +21,8 @@ public interface SysCatalogResourceMapper extends BaseMapperPlus<SysCatalogResou
Page<SysCatalogResourceVo> selectProtalPageList(@Param("page") Page<SysCatalogResource> page, @Param("tenantId") String tenantId);
long selectChildFileNumById(@Param("tenantId") String tenantId, @Param("catalogId") Long catalogId);
int addOrderNum(@Param("mix") Long mix, @Param("max") Long max);
int subOrderNum(@Param("mix") Long mix, @Param("max") Long max);
}

View File

@ -2,6 +2,7 @@ package org.dromara.system.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.dromara.system.domain.SysCatalogPerson;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogPersonBo;
import org.dromara.system.domain.vo.SysCatalogPersonVo;
@ -97,4 +98,11 @@ public interface ISysCatalogPersonService {
String selectCatalogNameById(Long catalogId);
List<SysCatalogPerson> selectList(Wrapper<SysCatalogPerson> queryWrapper);
/**
* 目录拖动
* @param bo
* @return
*/
boolean dragCatalog(CatalogDragBo bo);
}

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.SysCatalogResource;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogResourceBo;
import org.dromara.system.domain.vo.SysCatalogResourceVo;
@ -127,4 +128,6 @@ public interface ISysCatalogResourceService {
* @return 下拉树结构列表
*/
List<Tree<Long>> buildTreeSelect(SysCatalogResourceBo bo);
boolean dragCatalog(CatalogDragBo bo);
}

View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
@ -16,6 +17,7 @@ import org.dromara.common.redis.utils.CacheUtils;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.SysCatalogPerson;
import org.dromara.system.domain.SysOssPerson;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogPersonBo;
import org.dromara.system.domain.vo.SysCatalogPersonVo;
import org.dromara.system.mapper.SysCatalogPersonMapper;
@ -178,6 +180,48 @@ public class SysCatalogPersonServiceImpl implements ISysCatalogPersonService {
return baseMapper.selectList(queryWrapper);
}
@Override
public boolean dragCatalog(CatalogDragBo bo) {
Long oldCatalogId = bo.getOldCatalog();
Long newCatalogId = bo.getNewCatalog();
SysCatalogPerson oldCatalog = baseMapper.selectById(oldCatalogId);
SysCatalogPerson newCatalog = baseMapper.selectById(newCatalogId);
if (!oldCatalog.getParentId().equals(newCatalog.getParentId())) {
throw new ServiceException("只支持同级目录的拖动");
}
if (oldCatalogId.equals(newCatalogId)) {
throw new ServiceException("不支持单个目录的拖动");
}
Long oldOrder = oldCatalog.getOrderNum();
Long newOrder = newCatalog.getOrderNum();
boolean upFlag = oldOrder > newOrder;
String position = bo.getPosition();
//移动到new的前面
if ("before".equals(position)) {
if (upFlag) {
//上移
int i = baseMapper.addOrderNum(newOrder - 1, oldOrder);
} else {
//下移
baseMapper.subOrderNum(oldOrder, newOrder);
}
} else if ("after".equals(position)) {
if (upFlag) {
//上移
int i = baseMapper.addOrderNum(newOrder, oldOrder);
} else {
//下移
baseMapper.subOrderNum(oldOrder, newOrder + 1);
}
} else {
throw new ServiceException("不支持的拖动方式");
}
SysCatalogPerson update = new SysCatalogPerson();
update.setCatalogId(oldCatalogId);
update.setOrderNum(newOrder);
return baseMapper.updateById(update) > 0;
}
/**
* 修改子元素关系
*

View File

@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
@ -21,6 +22,7 @@ import org.dromara.common.mybatis.helper.DataBaseHelper;
import org.dromara.common.redis.utils.CacheUtils;
import org.dromara.system.domain.SysCatalogResource;
import org.dromara.system.domain.SysOssResource;
import org.dromara.system.domain.bo.CatalogDragBo;
import org.dromara.system.domain.bo.SysCatalogResourceBo;
import org.dromara.system.domain.vo.SysCatalogResourceVo;
import org.dromara.system.mapper.SysCatalogResourceMapper;
@ -226,6 +228,48 @@ public class SysCatalogResourceServiceImpl implements ISysCatalogResourceService
return buildCatalogTreeSelect(voList);
}
@Override
public boolean dragCatalog(CatalogDragBo bo) {
Long oldCatalogId = bo.getOldCatalog();
Long newCatalogId = bo.getNewCatalog();
SysCatalogResource oldCatalog = baseMapper.selectById(oldCatalogId);
SysCatalogResource newCatalog = baseMapper.selectById(newCatalogId);
if (!oldCatalog.getParentId().equals(newCatalog.getParentId())) {
throw new ServiceException("只支持同级目录的拖动");
}
if (oldCatalogId.equals(newCatalogId)) {
throw new ServiceException("不支持单个目录的拖动");
}
Long oldOrder = oldCatalog.getOrderNum();
Long newOrder = newCatalog.getOrderNum();
boolean upFlag = oldOrder > newOrder;
String position = bo.getPosition();
//移动到new的前面
if ("before".equals(position)) {
if (upFlag) {
//上移
int i = baseMapper.addOrderNum(newOrder - 1, oldOrder);
} else {
//下移
baseMapper.subOrderNum(oldOrder, newOrder);
}
} else if ("after".equals(position)) {
if (upFlag) {
//上移
int i = baseMapper.addOrderNum(newOrder, oldOrder);
} else {
//下移
baseMapper.subOrderNum(oldOrder, newOrder + 1);
}
} else {
throw new ServiceException("不支持的拖动方式");
}
SysCatalogResource update = new SysCatalogResource();
update.setCatalogId(oldCatalogId);
update.setOrderNum(newOrder);
return baseMapper.updateById(update) > 0;
}
//@Override
private List<Tree<Long>> buildCatalogTreeSelect(List<SysCatalogResourceVo> catalogs) {
if (CollUtil.isEmpty(catalogs)) {

View File

@ -4,4 +4,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysCatalogPersonMapper">
<update id="addOrderNum">
update sys_catalog_person
set order_num = order_num + 1
<where>
<if test="mix != null">
order_num &gt; #{mix}
</if>
<if test="max != null">
and order_num &lt; #{max}
</if>
</where>
</update>
<update id="subOrderNum">
update sys_catalog_person
set order_num = order_num - 1
<where>
<if test="mix != null">
order_num &gt; #{mix}
</if>
<if test="max != null">
and order_num &lt; #{max}
</if>
</where>
</update>
</mapper>

View File

@ -35,4 +35,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and r.status = 1
and FIND_IN_SET(#{catalogId}, cr.ancestors)
</select>
<update id="addOrderNum">
update sys_catalog_resource
set order_num = order_num + 1
<where>
<if test="mix != null">
order_num &gt; #{mix}
</if>
<if test="max != null">
and order_num &lt; #{max}
</if>
</where>
</update>
<update id="subOrderNum">
update sys_catalog_resource
set order_num = order_num - 1
<where>
<if test="mix != null">
order_num &gt; #{mix}
</if>
<if test="max != null">
and order_num &lt; #{max}
</if>
</where>
</update>
</mapper>