Feat: [后台]:增删查完成

This commit is contained in:
fanxb 2019-07-15 18:13:13 +08:00
parent f0dedfc828
commit 122124d7bb
5 changed files with 40 additions and 30 deletions

View File

@ -24,16 +24,16 @@ public class BookmarkController {
private BookmarkService bookmarkService; private BookmarkService bookmarkService;
/** /**
* Description: 获取某个用户的节点树 * Description: 获取路径为path的书签数据
* *
* @param path 路径
* @return com.fanxb.bookmark.common.entity.Result * @return com.fanxb.bookmark.common.entity.Result
* @author fanxb * @author fanxb
* @date 2019/7/9 14:20 * @date 2019/7/15 13:36
*/ */
@GetMapping("/currentUser") @GetMapping("/currentUser/path")
public Result getCurrentUserBookmarkTree() { public Result getCurrentBookmarkList(String path) {
int userId = UserContextHolder.get().getUserId(); return Result.success(bookmarkService.getBookmarkListByPath(UserContextHolder.get().getUserId(), path));
return Result.success(bookmarkService.getOneBookmarkTree(userId));
} }
/** /**

View File

@ -59,12 +59,13 @@ public interface BookmarkDao {
*/ */
List<Bookmark> getListByUserId(int userId); List<Bookmark> getListByUserId(int userId);
List<Bookmark> getListByUserIdAndPath(@Param("userId") int userId,@Param("path") String path);
/** /**
* Description: 删除某用户某个书签文件下所有数据 * Description: 删除某用户某个书签文件下所有数据
* *
* @param userId 用户id * @param userId 用户id
* @param folderId 文件夹id * @param folderId 文件夹id
* @return void
* @author fanxb * @author fanxb
* @date 2019/7/12 14:13 * @date 2019/7/12 14:13
*/ */

View File

@ -2,20 +2,19 @@ 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.common.entity.Bookmark; import com.fanxb.bookmark.common.entity.Bookmark;
import com.fanxb.bookmark.common.exception.CustomException;
import com.fanxb.bookmark.common.util.UserContextHolder; import com.fanxb.bookmark.common.util.UserContextHolder;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 类功能简述 * 类功能简述
@ -66,31 +65,21 @@ public class BookmarkService {
} }
} }
/** /**
* Description: 获取某个用户的书签树 * Description: 根据userId和path获取书签列表
* *
* @param userId 用户id * @param userId userId
* @return void * @param path path
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
* @author fanxb * @author fanxb
* @date 2019/7/9 18:45 * @date 2019/7/15 13:40
*/ */
public Map<String, List<Bookmark>> getOneBookmarkTree(int userId) { public List<Bookmark> getBookmarkListByPath(int userId, String path) {
List<Bookmark> list = bookmarkDao.getListByUserId(userId); return bookmarkDao.getListByUserIdAndPath(userId, path);
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;
// }
} }
/** /**
* Description: 批量删除书签 * Description: 批量删除书签
* *
@ -124,7 +113,11 @@ public class BookmarkService {
bookmark.setUserId(userId); bookmark.setUserId(userId);
bookmark.setCreateTime(System.currentTimeMillis()); bookmark.setCreateTime(System.currentTimeMillis());
bookmark.setAddTime(bookmark.getCreateTime()); bookmark.setAddTime(bookmark.getCreateTime());
try {
bookmarkDao.insertOne(bookmark); bookmarkDao.insertOne(bookmark);
} catch (DuplicateKeyException e) {
throw new CustomException("同级目录下不能存在相同名称的数据");
}
return bookmark; return bookmark;
} }

View File

@ -42,6 +42,20 @@
order by path, sort order by path, sort
</select> </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 id="deleteUserFolder">
DELETE DELETE
FROM FROM

View File

@ -2,6 +2,7 @@ package com.fanxb.bookmark.common.entity;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -42,6 +43,7 @@ public class Bookmark {
this.setAddTime(addTime); this.setAddTime(addTime);
this.setSort(sort); this.setSort(sort);
this.setCreateTime(System.currentTimeMillis()); this.setCreateTime(System.currentTimeMillis());
this.setChildren(new ArrayList<>());
} }
public Bookmark(int userId, String path, String name, String url, String icon, long addTime, int sort) { public Bookmark(int userId, String path, String name, String url, String icon, long addTime, int sort) {