✨ Feat: [后台]:增删查完成
This commit is contained in:
parent
f0dedfc828
commit
122124d7bb
@ -24,16 +24,16 @@ public class BookmarkController {
|
||||
private BookmarkService bookmarkService;
|
||||
|
||||
/**
|
||||
* Description: 获取某个用户的节点树
|
||||
* Description: 获取路径为path的书签数据
|
||||
*
|
||||
* @param path 路径
|
||||
* @return com.fanxb.bookmark.common.entity.Result
|
||||
* @author fanxb
|
||||
* @date 2019/7/9 14:20
|
||||
* @date 2019/7/15 13:36
|
||||
*/
|
||||
@GetMapping("/currentUser")
|
||||
public Result getCurrentUserBookmarkTree() {
|
||||
int userId = UserContextHolder.get().getUserId();
|
||||
return Result.success(bookmarkService.getOneBookmarkTree(userId));
|
||||
@GetMapping("/currentUser/path")
|
||||
public Result getCurrentBookmarkList(String path) {
|
||||
return Result.success(bookmarkService.getBookmarkListByPath(UserContextHolder.get().getUserId(), path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,12 +59,13 @@ public interface BookmarkDao {
|
||||
*/
|
||||
List<Bookmark> getListByUserId(int userId);
|
||||
|
||||
List<Bookmark> getListByUserIdAndPath(@Param("userId") int userId,@Param("path") String path);
|
||||
|
||||
/**
|
||||
* Description: 删除某用户某个书签文件下所有数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param folderId 文件夹id
|
||||
* @return void
|
||||
* @author fanxb
|
||||
* @date 2019/7/12 14:13
|
||||
*/
|
||||
|
@ -2,20 +2,19 @@ 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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 类功能简述:
|
||||
@ -66,31 +65,21 @@ public class BookmarkService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description: 获取某个用户的书签树
|
||||
* Description: 根据userId和path获取书签列表
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return void
|
||||
* @param userId userId
|
||||
* @param path path
|
||||
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
|
||||
* @author fanxb
|
||||
* @date 2019/7/9 18:45
|
||||
* @date 2019/7/15 13:40
|
||||
*/
|
||||
public Map<String, List<Bookmark>> getOneBookmarkTree(int userId) {
|
||||
List<Bookmark> list = bookmarkDao.getListByUserId(userId);
|
||||
Map<String, List<Bookmark>> map = new HashMap<>(50);
|
||||
list.forEach(item -> {
|
||||
map.computeIfAbsent(item.getPath(), k -> new ArrayList<>());
|
||||
map.get(item.getPath()).add(item);
|
||||
});
|
||||
return map;
|
||||
// if (map.size() == 0) {
|
||||
// return new ArrayList<>();
|
||||
// } else {
|
||||
// List<Bookmark> res = map.get("");
|
||||
// res.forEach(item -> insertToBookmarkTree(item, map));
|
||||
// return res;
|
||||
// }
|
||||
public List<Bookmark> getBookmarkListByPath(int userId, String path) {
|
||||
return bookmarkDao.getListByUserIdAndPath(userId, path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description: 批量删除书签
|
||||
*
|
||||
@ -124,7 +113,11 @@ public class BookmarkService {
|
||||
bookmark.setUserId(userId);
|
||||
bookmark.setCreateTime(System.currentTimeMillis());
|
||||
bookmark.setAddTime(bookmark.getCreateTime());
|
||||
bookmarkDao.insertOne(bookmark);
|
||||
try {
|
||||
bookmarkDao.insertOne(bookmark);
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw new CustomException("同级目录下不能存在相同名称的数据");
|
||||
}
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,20 @@
|
||||
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
|
||||
|
@ -2,6 +2,7 @@ package com.fanxb.bookmark.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -42,6 +43,7 @@ public class Bookmark {
|
||||
this.setAddTime(addTime);
|
||||
this.setSort(sort);
|
||||
this.setCreateTime(System.currentTimeMillis());
|
||||
this.setChildren(new ArrayList<>());
|
||||
}
|
||||
|
||||
public Bookmark(int userId, String path, String name, String url, String icon, long addTime, int sort) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user