✨ Feat: [后台]:完成节点编辑,节点拖拽功能
This commit is contained in:
parent
d426f93080
commit
5009007966
@ -1,6 +1,7 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.controller;
|
package com.fanxb.bookmark.business.bookmark.controller;
|
||||||
|
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.BatchDeleteBody;
|
import com.fanxb.bookmark.business.bookmark.entity.BatchDeleteBody;
|
||||||
|
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
|
||||||
import com.fanxb.bookmark.business.bookmark.service.BookmarkService;
|
import com.fanxb.bookmark.business.bookmark.service.BookmarkService;
|
||||||
import com.fanxb.bookmark.common.entity.Bookmark;
|
import com.fanxb.bookmark.common.entity.Bookmark;
|
||||||
import com.fanxb.bookmark.common.entity.Result;
|
import com.fanxb.bookmark.common.entity.Result;
|
||||||
@ -94,4 +95,18 @@ public class BookmarkController {
|
|||||||
return Result.success(null);
|
return Result.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 移动一个节点
|
||||||
|
*
|
||||||
|
* @param body body
|
||||||
|
* @return com.fanxb.bookmark.common.entity.Result
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/18 10:54
|
||||||
|
*/
|
||||||
|
@PostMapping("/moveNode")
|
||||||
|
public Result moveNode(@RequestBody MoveNodeBody body) {
|
||||||
|
bookmarkService.moveNode(UserContextHolder.get().getUserId(), body);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,9 +93,45 @@ public interface BookmarkDao {
|
|||||||
/**
|
/**
|
||||||
* Description: 编辑书签
|
* Description: 编辑书签
|
||||||
*
|
*
|
||||||
|
* @param bookmark bookmark
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/17 14:49
|
* @date 2019/7/17 14:49
|
||||||
* @param bookmark bookmark
|
|
||||||
*/
|
*/
|
||||||
void editBookmark(Bookmark bookmark);
|
void editBookmark(Bookmark bookmark);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: path下sort>=某个值的sort自增1
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param path path
|
||||||
|
* @param sort sort
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/18 10:13
|
||||||
|
*/
|
||||||
|
void sortPlus(@Param("userId") int userId, @Param("path") String path, @Param("sort") int sort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 更新某个路径下所有子节点的路径信息
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param oldPath oldPath
|
||||||
|
* @param newPath newPath
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/18 10:35
|
||||||
|
*/
|
||||||
|
void updateChildrenPath(@Param("userId") int userId, @Param("oldPath") String oldPath, @Param("newPath") String newPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description: 更新某个书签的path,sort
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param bookmarkId bookmarkId
|
||||||
|
* @param path path
|
||||||
|
* @param sort sort
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/18 10:37
|
||||||
|
*/
|
||||||
|
void updatePathAndSort(@Param("userId") int userId, @Param("bookmarkId") int bookmarkId, @Param("path") String path, @Param("sort") int sort);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.fanxb.bookmark.business.bookmark.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类功能简述: 移动节点表单
|
||||||
|
* 类功能详述:
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/18 10:04
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MoveNodeBody {
|
||||||
|
int bookmarkId;
|
||||||
|
String sourcePath;
|
||||||
|
String targetPath;
|
||||||
|
/**
|
||||||
|
* sort -1,表示移动到某个文件夹下,放到最后
|
||||||
|
*/
|
||||||
|
int sort;
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.service;
|
package com.fanxb.bookmark.business.bookmark.service;
|
||||||
|
|
||||||
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
|
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
|
||||||
|
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
|
||||||
import com.fanxb.bookmark.common.entity.Bookmark;
|
import com.fanxb.bookmark.common.entity.Bookmark;
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
import com.fanxb.bookmark.common.util.UserContextHolder;
|
import com.fanxb.bookmark.common.util.UserContextHolder;
|
||||||
@ -95,8 +96,10 @@ public class BookmarkService {
|
|||||||
bookmarkDao.deleteUserFolder(userId, item);
|
bookmarkDao.deleteUserFolder(userId, item);
|
||||||
bookmarkIdList.add(item);
|
bookmarkIdList.add(item);
|
||||||
}
|
}
|
||||||
|
if (bookmarkIdList.size() > 0) {
|
||||||
bookmarkDao.deleteUserBookmark(userId, bookmarkIdList);
|
bookmarkDao.deleteUserBookmark(userId, bookmarkIdList);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: 详情
|
* Description: 详情
|
||||||
@ -124,10 +127,10 @@ public class BookmarkService {
|
|||||||
/**
|
/**
|
||||||
* Description: 编辑某个用户的某个书签
|
* Description: 编辑某个用户的某个书签
|
||||||
*
|
*
|
||||||
* @author fanxb
|
|
||||||
* @date 2019/7/17 14:42
|
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
* @param bookmark bookmark
|
* @param bookmark bookmark
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2019/7/17 14:42
|
||||||
*/
|
*/
|
||||||
public void updateOne(int userId, Bookmark bookmark) {
|
public void updateOne(int userId, Bookmark bookmark) {
|
||||||
bookmark.setUserId(userId);
|
bookmark.setUserId(userId);
|
||||||
@ -193,4 +196,22 @@ public class BookmarkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void moveNode(int userId, MoveNodeBody body) {
|
||||||
|
if (body.getSort() == -1) {
|
||||||
|
Integer max = bookmarkDao.selectMaxSort(userId, body.getTargetPath());
|
||||||
|
body.setSort(max == null ? 1 : max);
|
||||||
|
} else {
|
||||||
|
//更新目标节点的sort
|
||||||
|
bookmarkDao.sortPlus(userId, body.getTargetPath(), body.getSort());
|
||||||
|
}
|
||||||
|
//如果目标位置和当前位置不在一个层级中需要更新子节点的path
|
||||||
|
if (!body.getTargetPath().equals(body.getSourcePath())) {
|
||||||
|
bookmarkDao.updateChildrenPath(userId, body.getSourcePath() + "." + body.getBookmarkId()
|
||||||
|
, body.getTargetPath() + "." + body.getBookmarkId());
|
||||||
|
}
|
||||||
|
//更新被移动节点的path和sort
|
||||||
|
bookmarkDao.updatePathAndSort(userId, body.getBookmarkId(), body.getTargetPath(), body.getSort());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,5 +81,23 @@
|
|||||||
where bookmarkId = #{bookmarkId} and userId = #{userId}
|
where bookmarkId = #{bookmarkId} and userId = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="sortPlus">
|
||||||
|
update bookmark
|
||||||
|
set sort = sort + 1
|
||||||
|
where userId = #{userId} and path = #{path} and sort >= #{sort}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateChildrenPath">
|
||||||
|
update bookmark
|
||||||
|
set path = replace(path, #{oldPath}, #{newPath})
|
||||||
|
where userId = #{userId} and path like concat(#{oldPath}, "%")
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updatePathAndSort">
|
||||||
|
update bookmark
|
||||||
|
set path = #{path}, sort = #{sort}
|
||||||
|
where userId = #{userId} and bookmarkId = #{bookmarkId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user