From 7d04719990b8cb0c45ee85b577f3d43ae70589b9 Mon Sep 17 00:00:00 2001 From: fanxb Date: Sat, 14 Dec 2019 00:19:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B9=A6=E7=AD=BEmap=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BookmarkController.java | 13 +++++++++ .../bookmark/service/BookmarkService.java | 27 ++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) 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 2f19688..83354b4 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 @@ -6,6 +6,7 @@ import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody; 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.entity.UserContext; import com.fanxb.bookmark.common.util.UserContextHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -40,6 +41,18 @@ public class BookmarkController { return Result.success(bookmarkService.getBookmarkListByPath(UserContextHolder.get().getUserId(), path)); } + /** + * 功能描述: 获取当前登陆用户的书签树 + * + * @return com.fanxb.bookmark.common.entity.Result + * @author fanxb + * @date 2019/12/14 0:09 + */ + @GetMapping("/currentUser") + public Result getBookmarkMap(){ + return Result.success(bookmarkService.getOneBookmarkTree(UserContextHolder.get().getUserId())); + } + /** * Description: 上传书签备份文件,并解析 * 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 6e8f133..d6a9c22 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 @@ -24,10 +24,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * 类功能简述: @@ -102,13 +99,13 @@ public class BookmarkService { 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); + , Long.parseLong(first.attr("add_date")) * 1000, sort); //存入数据库 insertOne(node); insertList.add(new EsEntity<>(node.getBookmarkId().toString(), new BookmarkEs(node))); } else { //说明为文件夹 - Bookmark node = new Bookmark(userId, path, first.ownText(), Long.valueOf(first.attr("add_date")) * 1000, sort); + Bookmark node = new Bookmark(userId, path, first.ownText(), Long.parseLong(first.attr("add_date")) * 1000, sort); Integer sortBase = 0; if (insertOne(node)) { sortBase = bookmarkDao.selectMaxSort(node.getUserId(), path); @@ -145,6 +142,24 @@ public class BookmarkService { } + /** + * 功能描述: 获取某个用户的书签map + * + * @param userId userId + * @return java.util.Map> + * @author fanxb + * @date 2019/12/14 0:02 + */ + 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; + } + /** * Description: 根据userId和path获取书签列表 *