Feat: [后台]:完成编辑接口

This commit is contained in:
fanxb 2019-07-17 17:30:40 +08:00
parent 7e491ab10e
commit 67d95c4a28
4 changed files with 478 additions and 426 deletions

View File

@ -1,82 +1,97 @@
package com.fanxb.bookmark.business.bookmark.controller;
import com.fanxb.bookmark.business.bookmark.entity.BatchDeleteBody;
import com.fanxb.bookmark.business.bookmark.service.BookmarkService;
import com.fanxb.bookmark.common.entity.Bookmark;
import com.fanxb.bookmark.common.entity.Result;
import com.fanxb.bookmark.common.util.UserContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 15:12
*/
@RestController
@RequestMapping("/bookmark")
public class BookmarkController {
@Autowired
private BookmarkService bookmarkService;
/**
* Description: 获取路径为path的书签数据
*
* @param path 路径
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/15 13:36
*/
@GetMapping("/currentUser/path")
public Result getCurrentBookmarkList(String path) {
return Result.success(bookmarkService.getBookmarkListByPath(UserContextHolder.get().getUserId(), path));
}
/**
* Description: 上传书签备份文件并解析
*
* @param file 文件
* @param path 存放节点路径(根节点为空字符串
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/8 15:17
*/
@PutMapping("/uploadBookmarkFile")
public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) throws Exception {
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file.getInputStream(), path);
return Result.success(null);
}
/**
* Description: 新增一条书签
*
* @param bookmark 书签信息
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/12 17:28
*/
@PutMapping("")
public Result addOne(@RequestBody Bookmark bookmark) {
bookmark = bookmarkService.addOne(bookmark);
return Result.success(bookmark);
}
/**
* Description: 批量删除
*
* @param body 批量删除表单
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/12 17:28
*/
@PostMapping("/batchDelete")
public Result batchDelete(@RequestBody BatchDeleteBody body) {
bookmarkService.batchDelete(UserContextHolder.get().getUserId(), body.getFolderIdList(), body.getBookmarkIdList());
return Result.success(null);
}
}
package com.fanxb.bookmark.business.bookmark.controller;
import com.fanxb.bookmark.business.bookmark.entity.BatchDeleteBody;
import com.fanxb.bookmark.business.bookmark.service.BookmarkService;
import com.fanxb.bookmark.common.entity.Bookmark;
import com.fanxb.bookmark.common.entity.Result;
import com.fanxb.bookmark.common.util.UserContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 15:12
*/
@RestController
@RequestMapping("/bookmark")
public class BookmarkController {
@Autowired
private BookmarkService bookmarkService;
/**
* Description: 获取路径为path的书签数据
*
* @param path 路径
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/15 13:36
*/
@GetMapping("/currentUser/path")
public Result getCurrentBookmarkList(String path) {
return Result.success(bookmarkService.getBookmarkListByPath(UserContextHolder.get().getUserId(), path));
}
/**
* Description: 上传书签备份文件并解析
*
* @param file 文件
* @param path 存放节点路径(根节点为空字符串
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/8 15:17
*/
@PutMapping("/uploadBookmarkFile")
public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) throws Exception {
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file.getInputStream(), path);
return Result.success(null);
}
/**
* Description: 新增一条书签
*
* @param bookmark 书签信息
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/12 17:28
*/
@PutMapping("")
public Result addOne(@RequestBody Bookmark bookmark) {
bookmark = bookmarkService.addOne(bookmark);
return Result.success(bookmark);
}
/**
* Description: 编辑当前用户的一个书签节点
*
* @param bookmark bookmark
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/17 14:40
*/
@PostMapping("/updateOne")
public Result editCurrentUserBookmark(@RequestBody Bookmark bookmark) {
bookmarkService.updateOne(UserContextHolder.get().getUserId(), bookmark);
return Result.success(null);
}
/**
* Description: 批量删除
*
* @param body 批量删除表单
* @return com.fanxb.bookmark.common.entity.Result
* @author fanxb
* @date 2019/7/12 17:28
*/
@PostMapping("/batchDelete")
public Result batchDelete(@RequestBody BatchDeleteBody body) {
bookmarkService.batchDelete(UserContextHolder.get().getUserId(), body.getFolderIdList(), body.getBookmarkIdList());
return Result.success(null);
}
}

View File

@ -1,83 +1,101 @@
package com.fanxb.bookmark.business.bookmark.dao;
import com.fanxb.bookmark.common.entity.Bookmark;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 16:39
*/
@Component
public interface BookmarkDao {
/**
* Description: 插入一条书签记录
*
* @param node node
* @return void
* @author fanxb
* @date 2019/7/8 16:49
*/
void insertOne(Bookmark node);
/**
* Description: 根据用户名和name获取节点id
*
* @param userId 用户名
* @param name 姓名
* @param path 当前节点路径
* @return Integer
* @author fanxb
* @date 2019/7/8 17:18
*/
Integer selectIdByUserIdAndNameAndPath(@Param("userId") int userId, @Param("name") String name, @Param("path") String path);
/**
* Description:
*
* @param userId 用户id
* @param path 父节点路径
* @return java.lang.Integer
* @author fanxb
* @date 2019/7/8 17:35
*/
Integer selectMaxSort(@Param("userId") int userId, @Param("path") String path);
/**
* Description: 根据用户id获取其所有数据
*
* @param userId userid
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2019/7/9 18:55
*/
List<Bookmark> getListByUserId(int userId);
List<Bookmark> getListByUserIdAndPath(@Param("userId") int userId,@Param("path") String path);
/**
* Description: 删除某用户某个书签文件下所有数据
*
* @param userId 用户id
* @param folderId 文件夹id
* @author fanxb
* @date 2019/7/12 14:13
*/
void deleteUserFolder(@Param("userId") int userId, @Param("folderId") int folderId);
/**
* Description: 删除用户书签
*
* @param userId 用户id
* @param bookmarkIds 书签id
* @author fanxb
* @date 2019/7/12 17:24
*/
void deleteUserBookmark(@Param("userId") int userId, @Param("bookmarkIds") List<Integer> bookmarkIds);
}
package com.fanxb.bookmark.business.bookmark.dao;
import com.fanxb.bookmark.common.entity.Bookmark;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 16:39
*/
@Component
public interface BookmarkDao {
/**
* Description: 插入一条书签记录
*
* @param node node
* @return void
* @author fanxb
* @date 2019/7/8 16:49
*/
void insertOne(Bookmark node);
/**
* Description: 根据用户名和name获取节点id
*
* @param userId 用户名
* @param name 姓名
* @param path 当前节点路径
* @return Integer
* @author fanxb
* @date 2019/7/8 17:18
*/
Integer selectIdByUserIdAndNameAndPath(@Param("userId") int userId, @Param("name") String name, @Param("path") String path);
/**
* Description:
*
* @param userId 用户id
* @param path 父节点路径
* @return java.lang.Integer
* @author fanxb
* @date 2019/7/8 17:35
*/
Integer selectMaxSort(@Param("userId") int userId, @Param("path") String path);
/**
* Description: 根据用户id获取其所有数据
*
* @param userId userid
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2019/7/9 18:55
*/
List<Bookmark> getListByUserId(int userId);
/**
* Description: 根据userId和path查询path下的子节点
*
* @param userId userId
* @param path path
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2019/7/17 14:48
*/
List<Bookmark> getListByUserIdAndPath(@Param("userId") int userId, @Param("path") String path);
/**
* Description: 删除某用户某个书签文件下所有数据
*
* @param userId 用户id
* @param folderId 文件夹id
* @author fanxb
* @date 2019/7/12 14:13
*/
void deleteUserFolder(@Param("userId") int userId, @Param("folderId") int folderId);
/**
* Description: 删除用户书签
*
* @param userId 用户id
* @param bookmarkIds 书签id
* @author fanxb
* @date 2019/7/12 17:24
*/
void deleteUserBookmark(@Param("userId") int userId, @Param("bookmarkIds") List<Integer> bookmarkIds);
/**
* Description: 编辑书签
*
* @author fanxb
* @date 2019/7/17 14:49
* @param bookmark bookmark
*/
void editBookmark(Bookmark bookmark);
}

View File

@ -1,183 +1,196 @@
package com.fanxb.bookmark.business.bookmark.service;
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
import com.fanxb.bookmark.common.entity.Bookmark;
import com.fanxb.bookmark.common.exception.CustomException;
import com.fanxb.bookmark.common.util.UserContextHolder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.util.List;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 15:00
*/
@Service
public class BookmarkService {
/**
* chrome导出书签tag
*/
private static final String DT = "dt";
private static final String A = "a";
@Autowired
private BookmarkDao bookmarkDao;
/**
* Description: 解析书签文件
*
* @param stream 输入流
* @param path 存放路径
* @author fanxb
* @date 2019/7/9 18:44
*/
@Transactional(rollbackFor = Exception.class)
public void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception {
Document doc = Jsoup.parse(stream, "utf-8", "");
Elements elements = doc.select("html>body>dl>dt");
//获取当前层sort最大值
Integer sortBase = bookmarkDao.selectMaxSort(1, path);
if (sortBase == null) {
sortBase = 0;
}
int count = 0;
for (int i = 0, length = elements.size(); i < length; i++) {
if (i == 0) {
Elements firstChildren = elements.get(0).child(1).children();
count = firstChildren.size();
for (int j = 0; j < count; j++) {
dealBookmark(userId, firstChildren.get(j), path, sortBase + j);
}
} else {
dealBookmark(userId, elements.get(i), path, sortBase + count + i - 1);
}
}
}
/**
* Description: 根据userId和path获取书签列表
*
* @param userId userId
* @param path path
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2019/7/15 13:40
*/
public List<Bookmark> getBookmarkListByPath(int userId, String path) {
return bookmarkDao.getListByUserIdAndPath(userId, path);
}
/**
* Description: 批量删除书签
*
* @param userId 用户id
* @param folderIdList 书签文件夹id list
* @param bookmarkIdList 书签id list
* @author fanxb
* @date 2019/7/12 14:09
*/
@Transactional(rollbackFor = Exception.class)
public void batchDelete(int userId, List<Integer> folderIdList, List<Integer> bookmarkIdList) {
for (Integer item : folderIdList) {
bookmarkDao.deleteUserFolder(userId, item);
bookmarkIdList.add(item);
}
bookmarkDao.deleteUserBookmark(userId, bookmarkIdList);
}
/**
* Description: 详情
*
* @param bookmark 插入一条记录
* @return com.fanxb.bookmark.common.entity.Bookmark
* @author fanxb
* @date 2019/7/12 17:18
*/
public Bookmark addOne(Bookmark bookmark) {
int userId = UserContextHolder.get().getUserId();
Integer sort = bookmarkDao.selectMaxSort(userId, bookmark.getPath());
bookmark.setSort(sort == null ? 1 : sort + 1);
bookmark.setUserId(userId);
bookmark.setCreateTime(System.currentTimeMillis());
bookmark.setAddTime(bookmark.getCreateTime());
try {
bookmarkDao.insertOne(bookmark);
} catch (DuplicateKeyException e) {
throw new CustomException("同级目录下不能存在相同名称的数据");
}
return bookmark;
}
/**
* Description: 处理html节点解析出文件夹和书签
*
* @param ele 待处理节点
* @param path 节点路径不包含自身
* @param sort 当前层级中的排序序号
* @author fanxb
* @date 2019/7/8 14:49
*/
private void dealBookmark(int userId, Element ele, String path, int sort) {
if (!DT.equalsIgnoreCase(ele.tagName())) {
return;
}
Element first = ele.child(0);
if (A.equalsIgnoreCase(first.tagName())) {
//说明为链接
Bookmark node = new Bookmark(userId, path, first.ownText(), first.attr("href"), first.attr("icon")
, Long.valueOf(first.attr("add_date")) * 1000, sort);
//存入数据库
insertOne(node);
} else {
//说明为文件夹
Bookmark node = new Bookmark(userId, path, first.ownText(), Long.valueOf(first.attr("add_date")) * 1000, sort);
Integer sortBase = 0;
if (insertOne(node)) {
sortBase = bookmarkDao.selectMaxSort(node.getUserId(), path);
if (sortBase == null) {
sortBase = 0;
}
}
String childPath = path + "." + node.getBookmarkId();
Elements children = ele.child(1).children();
for (int i = 0, size = children.size(); i < size; i++) {
dealBookmark(userId, children.get(i), childPath, sortBase + i + 1);
}
}
}
/**
* Description: 插入一条书签如果已经存在同名书签将跳过
*
* @param node node
* @return boolean 如果已经存在返回true否则false
* @author fanxb
* @date 2019/7/8 17:25
*/
private boolean insertOne(Bookmark node) {
//先根据name,userId,parentId获取此节点id
Integer id = bookmarkDao.selectIdByUserIdAndNameAndPath(node.getUserId(), node.getName(), node.getPath());
if (id == null) {
bookmarkDao.insertOne(node);
return false;
} else {
node.setBookmarkId(id);
return true;
}
}
}
package com.fanxb.bookmark.business.bookmark.service;
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
import com.fanxb.bookmark.common.entity.Bookmark;
import com.fanxb.bookmark.common.exception.CustomException;
import com.fanxb.bookmark.common.util.UserContextHolder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.util.List;
/**
* 类功能简述
* 类功能详述
*
* @author fanxb
* @date 2019/7/8 15:00
*/
@Service
public class BookmarkService {
/**
* chrome导出书签tag
*/
private static final String DT = "dt";
private static final String A = "a";
@Autowired
private BookmarkDao bookmarkDao;
/**
* Description: 解析书签文件
*
* @param stream 输入流
* @param path 存放路径
* @author fanxb
* @date 2019/7/9 18:44
*/
@Transactional(rollbackFor = Exception.class)
public void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception {
Document doc = Jsoup.parse(stream, "utf-8", "");
Elements elements = doc.select("html>body>dl>dt");
//获取当前层sort最大值
Integer sortBase = bookmarkDao.selectMaxSort(1, path);
if (sortBase == null) {
sortBase = 0;
}
int count = 0;
for (int i = 0, length = elements.size(); i < length; i++) {
if (i == 0) {
Elements firstChildren = elements.get(0).child(1).children();
count = firstChildren.size();
for (int j = 0; j < count; j++) {
dealBookmark(userId, firstChildren.get(j), path, sortBase + j);
}
} else {
dealBookmark(userId, elements.get(i), path, sortBase + count + i - 1);
}
}
}
/**
* Description: 根据userId和path获取书签列表
*
* @param userId userId
* @param path path
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb
* @date 2019/7/15 13:40
*/
public List<Bookmark> getBookmarkListByPath(int userId, String path) {
return bookmarkDao.getListByUserIdAndPath(userId, path);
}
/**
* Description: 批量删除书签
*
* @param userId 用户id
* @param folderIdList 书签文件夹id list
* @param bookmarkIdList 书签id list
* @author fanxb
* @date 2019/7/12 14:09
*/
@Transactional(rollbackFor = Exception.class)
public void batchDelete(int userId, List<Integer> folderIdList, List<Integer> bookmarkIdList) {
for (Integer item : folderIdList) {
bookmarkDao.deleteUserFolder(userId, item);
bookmarkIdList.add(item);
}
bookmarkDao.deleteUserBookmark(userId, bookmarkIdList);
}
/**
* Description: 详情
*
* @param bookmark 插入一条记录
* @return com.fanxb.bookmark.common.entity.Bookmark
* @author fanxb
* @date 2019/7/12 17:18
*/
public Bookmark addOne(Bookmark bookmark) {
int userId = UserContextHolder.get().getUserId();
Integer sort = bookmarkDao.selectMaxSort(userId, bookmark.getPath());
bookmark.setSort(sort == null ? 1 : sort + 1);
bookmark.setUserId(userId);
bookmark.setCreateTime(System.currentTimeMillis());
bookmark.setAddTime(bookmark.getCreateTime());
try {
bookmarkDao.insertOne(bookmark);
} catch (DuplicateKeyException e) {
throw new CustomException("同级目录下不能存在相同名称的数据");
}
return bookmark;
}
/**
* Description: 编辑某个用户的某个书签
*
* @author fanxb
* @date 2019/7/17 14:42
* @param userId userId
* @param bookmark bookmark
*/
public void updateOne(int userId,Bookmark bookmark){
bookmark.setUserId(userId);
bookmarkDao.editBookmark(bookmark);
}
/**
* Description: 处理html节点解析出文件夹和书签
*
* @param ele 待处理节点
* @param path 节点路径不包含自身
* @param sort 当前层级中的排序序号
* @author fanxb
* @date 2019/7/8 14:49
*/
private void dealBookmark(int userId, Element ele, String path, int sort) {
if (!DT.equalsIgnoreCase(ele.tagName())) {
return;
}
Element first = ele.child(0);
if (A.equalsIgnoreCase(first.tagName())) {
//说明为链接
Bookmark node = new Bookmark(userId, path, first.ownText(), first.attr("href"), first.attr("icon")
, Long.valueOf(first.attr("add_date")) * 1000, sort);
//存入数据库
insertOne(node);
} else {
//说明为文件夹
Bookmark node = new Bookmark(userId, path, first.ownText(), Long.valueOf(first.attr("add_date")) * 1000, sort);
Integer sortBase = 0;
if (insertOne(node)) {
sortBase = bookmarkDao.selectMaxSort(node.getUserId(), path);
if (sortBase == null) {
sortBase = 0;
}
}
String childPath = path + "." + node.getBookmarkId();
Elements children = ele.child(1).children();
for (int i = 0, size = children.size(); i < size; i++) {
dealBookmark(userId, children.get(i), childPath, sortBase + i + 1);
}
}
}
/**
* Description: 插入一条书签如果已经存在同名书签将跳过
*
* @param node node
* @return boolean 如果已经存在返回true否则false
* @author fanxb
* @date 2019/7/8 17:25
*/
private boolean insertOne(Bookmark node) {
//先根据name,userId,parentId获取此节点id
Integer id = bookmarkDao.selectIdByUserIdAndNameAndPath(node.getUserId(), node.getName(), node.getPath());
if (id == null) {
bookmarkDao.insertOne(node);
return false;
} else {
node.setBookmarkId(id);
return true;
}
}
}

View File

@ -1,79 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fanxb.bookmark.business.bookmark.dao.BookmarkDao">
<insert id="insertOne" useGeneratedKeys="true" keyColumn="bookmarkId" keyProperty="bookmarkId">
insert into bookmark(userId,path,type,name,url,icon,sort,addTime,createTime)
value
( #{userId},#{path},#{type},#{name},
<if test="url == null">
"","",
</if>
<if test="url != null">
#{url},#{icon},
</if>
#{sort},#{addTime},#{createTime})
</insert>
<select id="selectIdByUserIdAndNameAndPath" resultType="java.lang.Integer">
select bookmarkId
from bookmark
where userId = #{userId} and path = #{path} and name = #{name};
</select>
<select id="selectMaxSort" resultType="java.lang.Integer">
select max(sort)
from bookmark
where userId = #{userId} and path = #{path}
</select>
<select id="getListByUserId" resultType="com.fanxb.bookmark.common.entity.Bookmark">
select
bookmarkId,
path,
type,
name,
url,
icon,
sort
from bookmark
where userId = #{userId}
order by path, sort
</select>
<select id="getListByUserIdAndPath" resultType="com.fanxb.bookmark.common.entity.Bookmark">
select
bookmarkId,
path,
type,
name,
url,
icon,
sort
from bookmark
where userId = #{userId} and path = #{path}
order by sort
</select>
<delete id="deleteUserFolder">
DELETE
FROM
bookmark
WHERE
userId = #{userId}
and path LIKE (SELECT a.path
FROM (SELECT CONCAT(path, '.', '${folderId}', '%') AS path
FROM bookmark
WHERE bookmarkId = #{folderId}) a);
</delete>
<delete id="deleteUserBookmark">
delete from bookmark where userId = #{userId} and bookmarkId in
<foreach collection="bookmarkIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</delete>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fanxb.bookmark.business.bookmark.dao.BookmarkDao">
<insert id="insertOne" useGeneratedKeys="true" keyColumn="bookmarkId" keyProperty="bookmarkId">
insert into bookmark(userId,path,type,name,url,icon,sort,addTime,createTime)
value
( #{userId},#{path},#{type},#{name},
<if test="url == null">
"","",
</if>
<if test="url != null">
#{url},#{icon},
</if>
#{sort},#{addTime},#{createTime})
</insert>
<select id="selectIdByUserIdAndNameAndPath" resultType="java.lang.Integer">
select bookmarkId
from bookmark
where userId = #{userId} and path = #{path} and name = #{name};
</select>
<select id="selectMaxSort" resultType="java.lang.Integer">
select max(sort)
from bookmark
where userId = #{userId} and path = #{path}
</select>
<select id="getListByUserId" resultType="com.fanxb.bookmark.common.entity.Bookmark">
select
bookmarkId,
path,
type,
name,
url,
icon,
sort
from bookmark
where userId = #{userId}
order by path, sort
</select>
<select id="getListByUserIdAndPath" resultType="com.fanxb.bookmark.common.entity.Bookmark">
select
bookmarkId,
path,
type,
name,
url,
icon,
sort
from bookmark
where userId = #{userId} and path = #{path}
order by sort
</select>
<delete id="deleteUserFolder">
DELETE
FROM
bookmark
WHERE
userId = #{userId}
and path LIKE (SELECT a.path
FROM (SELECT CONCAT(path, '.', '${folderId}', '%') AS path
FROM bookmark
WHERE bookmarkId = #{folderId}) a);
</delete>
<delete id="deleteUserBookmark">
delete from bookmark where userId = #{userId} and bookmarkId in
<foreach collection="bookmarkIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</delete>
<update id="editBookmark" parameterType="com.fanxb.bookmark.common.entity.Bookmark">
update bookmark
set name = #{name}, url = #{url}
where bookmarkId = #{bookmarkId} and userId = #{userId}
</update>
</mapper>