diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/controller/BookmarkController.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/controller/BookmarkController.java index d7a40ac..ba21010 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/controller/BookmarkController.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/controller/BookmarkController.java @@ -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)); } /** diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/BookmarkDao.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/BookmarkDao.java index f314ae9..350d52c 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/BookmarkDao.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/BookmarkDao.java @@ -59,12 +59,13 @@ public interface BookmarkDao { */ List getListByUserId(int userId); + List 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 */ diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/BookmarkService.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/BookmarkService.java index 7c3d30e..c4d240e 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/BookmarkService.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/BookmarkService.java @@ -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 * @author fanxb - * @date 2019/7/9 18:45 + * @date 2019/7/15 13:40 */ - public Map> getOneBookmarkTree(int userId) { - List list = bookmarkDao.getListByUserId(userId); - Map> 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 res = map.get(""); -// res.forEach(item -> insertToBookmarkTree(item, map)); -// return res; -// } + public List 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; } diff --git a/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-bookmarkMapper.xml b/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-bookmarkMapper.xml index 4610435..38be6b9 100644 --- a/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-bookmarkMapper.xml +++ b/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-bookmarkMapper.xml @@ -42,6 +42,20 @@ order by path, sort + + DELETE FROM diff --git a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Bookmark.java b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Bookmark.java index 18c9d81..e76cea9 100644 --- a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Bookmark.java +++ b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/entity/Bookmark.java @@ -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) {