diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteEsConsumer.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteEsConsumer.java deleted file mode 100644 index 0a3998c..0000000 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteEsConsumer.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fanxb.bookmark.business.bookmark.consumer; - -import cn.hutool.core.collection.CollectionUtil; -import com.alibaba.fastjson.JSONArray; -import com.fanxb.bookmark.common.annotation.MqConsumer; -import com.fanxb.bookmark.common.constant.EsConstant; -import com.fanxb.bookmark.common.constant.RedisConstant; -import com.fanxb.bookmark.common.entity.redis.RedisConsumer; -import com.fanxb.bookmark.common.util.EsUtil; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.List; - -/** - * Created with IntelliJ IDEA - * - * @author fanxb - * Date: 2020/3/29 - * Time: 13:08 - */ -@MqConsumer(RedisConstant.BOOKMARK_DELETE_ES) -public class BookmarkDeleteEsConsumer implements RedisConsumer { - @Autowired - private EsUtil esUtil; - - @Override - public void deal(String message) { - List strings = JSONArray.parseArray(message, String.class); - if (CollectionUtil.isEmpty(strings)) { - return; - } - esUtil.deleteBatch(EsConstant.BOOKMARK_INDEX, strings); - } -} diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteMessageConsumer.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteMessageConsumer.java new file mode 100644 index 0000000..b169631 --- /dev/null +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkDeleteMessageConsumer.java @@ -0,0 +1,45 @@ +package com.fanxb.bookmark.business.bookmark.consumer; + +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.fanxb.bookmark.business.bookmark.dao.PinBookmarkDao; +import com.fanxb.bookmark.business.bookmark.entity.redis.BookmarkDeleteMessage; +import com.fanxb.bookmark.common.annotation.MqConsumer; +import com.fanxb.bookmark.common.constant.EsConstant; +import com.fanxb.bookmark.common.constant.RedisConstant; +import com.fanxb.bookmark.common.entity.redis.RedisConsumer; +import com.fanxb.bookmark.common.util.EsUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +/** + * Created with IntelliJ IDEA + * + * @author fanxb + * Date: 2020/3/29 + * Time: 13:08 + */ +@MqConsumer(RedisConstant.BOOKMARK_DELETE_ES) +public class BookmarkDeleteMessageConsumer implements RedisConsumer { + private final PinBookmarkDao pinBookmarkDao; + private final EsUtil esUtil; + + @Autowired + public BookmarkDeleteMessageConsumer(PinBookmarkDao pinBookmarkDao, EsUtil esUtil) { + this.pinBookmarkDao = pinBookmarkDao; + this.esUtil = esUtil; + } + + @Override + public void deal(String message) { + BookmarkDeleteMessage obj = JSON.parseObject(message, BookmarkDeleteMessage.class); + //删除首页固定的数据 + pinBookmarkDao.deleteUnExistBookmark(obj.getUserId()); + //删除es数据 + if (CollectionUtil.isNotEmpty(obj.getBookmarkIds())) { + esUtil.deleteBatch(EsConstant.BOOKMARK_INDEX, obj.getBookmarkIds()); + } + } +} diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/PinBookmarkDao.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/PinBookmarkDao.java index be372d4..3775a9a 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/PinBookmarkDao.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/dao/PinBookmarkDao.java @@ -33,4 +33,12 @@ public interface PinBookmarkDao extends BaseMapper { */ @Select("select ifnull(max(sort),0) from pin_bookmark where userId=#{userId}") int getUserMaxSort(int userId); + + /** + * 删除书签后,需要清理此表,将不存在的书签删除 + * + * @param userId userId + * @author fanxb + */ + void deleteUnExistBookmark(int userId); } diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/BookmarkDeleteMessage.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/BookmarkDeleteMessage.java new file mode 100644 index 0000000..4a970f3 --- /dev/null +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/BookmarkDeleteMessage.java @@ -0,0 +1,26 @@ +package com.fanxb.bookmark.business.bookmark.entity.redis; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.Collection; +import java.util.List; + +/** + * @author fanxb + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BookmarkDeleteMessage { + /** + * 用户id + */ + private int userId; + /** + * 批量删除的书签id + */ + private Collection bookmarkIds; +} diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/BookmarkServiceImpl.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/BookmarkServiceImpl.java index 4e4e32d..d605078 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/BookmarkServiceImpl.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/BookmarkServiceImpl.java @@ -7,6 +7,7 @@ import com.fanxb.bookmark.business.api.UserApi; import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao; import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs; import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody; +import com.fanxb.bookmark.business.bookmark.entity.redis.BookmarkDeleteMessage; import com.fanxb.bookmark.business.bookmark.entity.redis.VisitNumPlus; import com.fanxb.bookmark.business.bookmark.service.BookmarkService; import com.fanxb.bookmark.business.bookmark.service.PinYinService; @@ -187,7 +188,7 @@ public class BookmarkServiceImpl implements BookmarkService { bookmarkDao.deleteUserBookmark(userId, bookmarkIdList); set.addAll(bookmarkIdList.stream().map(String::valueOf).collect(Collectors.toSet())); } - RedisUtil.addToMq(RedisConstant.BOOKMARK_DELETE_ES, set); + RedisUtil.addToMq(RedisConstant.BOOKMARK_DELETE_ES, new BookmarkDeleteMessage(userId, set)); userApi.versionPlus(userId); } diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/HomePinServiceImpl.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/HomePinServiceImpl.java index 4ff50ab..5152243 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/HomePinServiceImpl.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/service/impl/HomePinServiceImpl.java @@ -1,5 +1,7 @@ package com.fanxb.bookmark.business.bookmark.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao; import com.fanxb.bookmark.business.bookmark.dao.PinBookmarkDao; import com.fanxb.bookmark.business.bookmark.entity.po.PInBookmarkPo; @@ -7,6 +9,8 @@ import com.fanxb.bookmark.business.bookmark.entity.vo.HomePinItemVo; import com.fanxb.bookmark.business.bookmark.service.BookmarkService; import com.fanxb.bookmark.business.bookmark.service.HomePinService; import com.fanxb.bookmark.common.entity.UserContext; +import com.fanxb.bookmark.common.entity.po.Bookmark; +import com.fanxb.bookmark.common.exception.CustomException; import com.fanxb.bookmark.common.util.UserContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -43,8 +48,11 @@ public class HomePinServiceImpl implements HomePinService { List res = new ArrayList<>(MAX_PIN); if (UserContextHolder.get() != null) { res.addAll(pinBookmarkDao.selectUserPin(UserContextHolder.get().getUserId())); - if (res.size() < MAX_PIN) { - res.addAll(bookmarkDao.selectPopular(UserContextHolder.get().getUserId(), MAX_PIN - res.size()).stream() + if (res.size() < MAX_PIN - 1) { + //需要从取到的书签数据中排除已经固定到首页的数据 + Set existBookmark = res.stream().map(HomePinItemVo::getBookmarkId).collect(Collectors.toSet()); + List bookmarks = bookmarkDao.selectPopular(UserContextHolder.get().getUserId(), MAX_PIN - 1); + res.addAll(bookmarks.stream().filter(item -> !existBookmark.contains(item.getBookmarkId())).limit(MAX_PIN - res.size() - 1) .map(item -> new HomePinItemVo(null, item.getBookmarkId(), item.getName(), item.getUrl(), item.getIcon())).collect(Collectors.toList())); } } @@ -54,6 +62,10 @@ public class HomePinServiceImpl implements HomePinService { @Override public PInBookmarkPo addOne(PInBookmarkPo po) { int userId = UserContextHolder.get().getUserId(); + long count = pinBookmarkDao.selectCount(new QueryWrapper().eq("userId", userId)); + if (count > MAX_PIN) { + throw new CustomException("固定数量已超过最大限制:" + MAX_PIN); + } po.setUserId(userId); po.setCreateDate(System.currentTimeMillis()); po.setSort(pinBookmarkDao.getUserMaxSort(userId) + 1); diff --git a/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-pinBookmarkMapper.xml b/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-pinBookmarkMapper.xml new file mode 100644 index 0000000..c90f220 --- /dev/null +++ b/bookMarkService/business/bookmark/src/main/resources/mapper/bookmark-pinBookmarkMapper.xml @@ -0,0 +1,15 @@ + + + + + + delete + a + from pin_bookmark a + left join bookmark b on + a.bookmarkId = b.bookmarkId + where a.userId = #{userId} + and b.bookmarkId is null + + + \ No newline at end of file diff --git a/bookmark_front/src/components/main/things/AddBookmark.vue b/bookmark_front/src/components/main/things/AddBookmark.vue index 68c644f..f82dc74 100644 --- a/bookmark_front/src/components/main/things/AddBookmark.vue +++ b/bookmark_front/src/components/main/things/AddBookmark.vue @@ -44,7 +44,10 @@ export default { name: "addBookmark", props: { isAdd: Boolean, //是否新增 - addType: String, //新增的类别 + addType: { + type: String, + default: "bookmark", + }, //新增的类别 targetNode: Object, }, data() { @@ -69,13 +72,15 @@ export default { }, created() { console.log(this.isAdd, this.targetNode); - if (!this.isAdd) { + if (this.isAdd) { + this.form.type = this.addType; + } else { this.form.type = this.targetNode.type == 0 ? "bookmark" : "folder"; this.form.name = this.targetNode.name; this.form.url = this.form.type === "bookmark" ? this.targetNode.url : ""; } this.token = this.$store.state.globalConfig.token; - this.form.path = this.targetNode == null ? "" : this.targetNode.path + (this.isAdd ? "." + this.targetNode.bookmarkId : ""); + this.form.path = !this.targetNode ? "" : this.targetNode.path + (this.isAdd ? "." + this.targetNode.bookmarkId : ""); }, methods: { /** @@ -101,7 +106,7 @@ export default { await this.$store.dispatch("treeData/editNode", { node: this.targetNode, newName: this.form.name, newUrl: this.form.url, newIcon }); } this.$message.success("操作成功"); - this.$emit("close", this.form.type); + this.$emit("close", this.form.type, res); this.loading = false; }); }, diff --git a/bookmark_front/src/layout/home/Bottom.vue b/bookmark_front/src/layout/home/Bottom.vue index cfa1766..f62faae 100644 --- a/bookmark_front/src/layout/home/Bottom.vue +++ b/bookmark_front/src/layout/home/Bottom.vue @@ -1,5 +1,7 @@ diff --git a/bookmark_front/src/router/index.js b/bookmark_front/src/router/index.js index 7cfb98f..85d3876 100644 --- a/bookmark_front/src/router/index.js +++ b/bookmark_front/src/router/index.js @@ -25,6 +25,7 @@ const routes = [ { path: "register", component: () => import("@/views/public/register/index") }, { path: "resetPassword", component: () => import("@/views/public/passwordReset/index") }, { path: "oauth/github", component: () => import("@/views/public/oauth/github/index") }, + { path: "about", component: () => import("@/views/public/about/index") }, { path: "404", component: () => import("@/views/public/notFound/index") }, ] }, diff --git a/bookmark_front/src/store/modules/treeData.js b/bookmark_front/src/store/modules/treeData.js index 176e4e6..03a780a 100644 --- a/bookmark_front/src/store/modules/treeData.js +++ b/bookmark_front/src/store/modules/treeData.js @@ -16,6 +16,10 @@ export const HOME_PIN_LIST = "homePinList"; * 刷新首页固定标签 */ export const refreshHomePinList = "refreshHomePinList"; +/** + * 通过id获取书签数据 + */ +export const getById = "getById"; export const noLoginInit = "noLoginInit"; export const loginInit = "loginInit"; export const refresh = "refresh"; @@ -52,10 +56,7 @@ const state = { }; const getters = { - /** - * 通过id获取节点数据 - */ - getById: state => id => { + [getById]: state => id => { let arr = Object.values(state[TOTAL_TREE_DATA]); for (let i in arr) { for (let j in arr[i]) { diff --git a/bookmark_front/src/views/home/PinBookmark.vue b/bookmark_front/src/views/home/PinBookmark.vue index eb8c2e4..ffe1b28 100644 --- a/bookmark_front/src/views/home/PinBookmark.vue +++ b/bookmark_front/src/views/home/PinBookmark.vue @@ -3,9 +3,6 @@
-
- -
@@ -16,7 +13,7 @@ import { TREE_DATA, HOME_PIN_LIST } from "@/store/modules/treeData"; /** * 首页网页固定 */ -const LINE_NUM = 10; +const LINE_NUM = 20; export default { name: "PinBookmark", components: { PinBookmarkItem }, @@ -30,16 +27,6 @@ export default { return this.homePinList.slice(0, LINE_NUM); } }, - lineTwo() { - if (this.homePinList.length < LINE_NUM) { - return []; - } - if (this.homePinList.length - LINE_NUM < LINE_NUM) { - return [...this.homePinList.slice(LINE_NUM), null]; - } else { - return this.homePinList.slice(LINE_NUM, LINE_NUM * 2); - } - }, }, }; @@ -48,8 +35,11 @@ export default { .pinBookmark { .oneLine { display: flex; + flex-wrap: wrap; justify-content: center; align-items: center; + margin: 0 auto; + max-width: 62em; } } diff --git a/bookmark_front/src/views/home/PinBookmarkItem.vue b/bookmark_front/src/views/home/PinBookmarkItem.vue index cf2ba35..f2d01bf 100644 --- a/bookmark_front/src/views/home/PinBookmarkItem.vue +++ b/bookmark_front/src/views/home/PinBookmarkItem.vue @@ -3,27 +3,68 @@ {{ pinObj.name }} - ... + + ... + + {{ pinObj.id ? "取消固定" : "固定书签" }} + 修改书签 + 删除书签 + +
+ + + diff --git a/bookmark_front/src/views/home/index.vue b/bookmark_front/src/views/home/index.vue index fe3b70e..7083807 100644 --- a/bookmark_front/src/views/home/index.vue +++ b/bookmark_front/src/views/home/index.vue @@ -43,7 +43,7 @@ export default { background-attachment: fixed; .content { - height: calc(~"100vh" - 1.01rem); + height: calc(~"100vh" - 1.21rem); display: flex; flex-direction: column; justify-content: space-around; diff --git a/bookmark_front/src/views/manage/bookmarkTree/index.vue b/bookmark_front/src/views/manage/bookmarkTree/index.vue index 2281be7..892b890 100644 --- a/bookmark_front/src/views/manage/bookmarkTree/index.vue +++ b/bookmark_front/src/views/manage/bookmarkTree/index.vue @@ -288,7 +288,7 @@ export default { } this.loading = true; await HttpUtil.post("/bookmark/batchDelete", null, { pathList, bookmarkIdList }); - this.$store.dispatch(TREE_DATA + "/" + deleteData, { pathList, bookmarkIdList }); + await this.$store.dispatch(TREE_DATA + "/" + deleteData, { pathList, bookmarkIdList }); //删除已经被删除的数据 pathList.forEach((item) => { const id = parseInt(item.split(".").reverse()[0]); diff --git a/bookmark_front/src/views/public/about/index.vue b/bookmark_front/src/views/public/about/index.vue new file mode 100644 index 0000000..f73d773 --- /dev/null +++ b/bookmark_front/src/views/public/about/index.vue @@ -0,0 +1,45 @@ + + + + +