diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkInsertEsConsumer.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkInsertEsConsumer.java index 16d6cac..6d40f0f 100644 --- a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkInsertEsConsumer.java +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkInsertEsConsumer.java @@ -21,6 +21,7 @@ import java.util.stream.Collectors; * Created By Fxb * Date: 2020/3/29 * Time: 11:34 + * @author fanxb */ @MqConsumer(RedisConstant.BOOKMARK_INSERT_ES) public class BookmarkInsertEsConsumer implements RedisConsumer { diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkVisitNumPlusConsumer.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkVisitNumPlusConsumer.java new file mode 100644 index 0000000..ef5cf6d --- /dev/null +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/consumer/BookmarkVisitNumPlusConsumer.java @@ -0,0 +1,41 @@ +package com.fanxb.bookmark.business.bookmark.consumer; + +import com.alibaba.fastjson.JSON; +import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao; +import com.fanxb.bookmark.business.bookmark.entity.redis.VisitNumPlus; +import com.fanxb.bookmark.common.annotation.MqConsumer; +import com.fanxb.bookmark.common.constant.RedisConstant; +import com.fanxb.bookmark.common.entity.redis.RedisConsumer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 更新书签时间 + * Created with IntelliJ IDEA + * Created By Fxb + * Date: 2020/5/12 + * Time: 10:33 + * + * @author fanxb + */ +@MqConsumer(RedisConstant.BOOKMARK_VISIT_NUM_PLUS) +@Slf4j +public class BookmarkVisitNumPlusConsumer implements RedisConsumer { + + private final BookmarkDao bookmarkDao; + + @Autowired + public BookmarkVisitNumPlusConsumer(BookmarkDao bookmarkDao) { + this.bookmarkDao = bookmarkDao; + } + + @Override + public void deal(String message) { + VisitNumPlus item = JSON.parseObject(message, VisitNumPlus.class); + try { + bookmarkDao.updateVisitNum(item); + } catch (Exception e) { + log.error("书签访问次数增加失败:{}", e.getMessage()); + } + } +} 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 1d5eed4..b48aa8e 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 @@ -161,4 +161,18 @@ public class BookmarkController { return Result.success(null); } + /** + * 功能描述: 书签增加1 + * + * @param id id + * @return com.fanxb.bookmark.common.entity.Result + * @author fanxb + * @date 2020/5/12 10:44 + */ + @PostMapping("/visitNum") + public Result visitNum(int id) { + bookmarkService.visitNumPlus(id); + return Result.success(null); + } + } 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 9e3ccec..bab2ba6 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 @@ -2,6 +2,7 @@ package com.fanxb.bookmark.business.bookmark.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs; +import com.fanxb.bookmark.business.bookmark.entity.redis.VisitNumPlus; import com.fanxb.bookmark.common.entity.Bookmark; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -24,7 +25,6 @@ public interface BookmarkDao extends BaseMapper { * Description: 插入一条书签记录 * * @param node node - * @return void * @author fanxb * @date 2019/7/8 16:49 */ @@ -177,7 +177,7 @@ public interface BookmarkDao extends BaseMapper { * 功能描述: 更新一个bookmark的key * * @param bookmarkId id - * @param searchKey searchKey + * @param searchKey searchKey * @author fanxb * @date 2020/3/22 22:08 */ @@ -189,9 +189,20 @@ public interface BookmarkDao extends BaseMapper { * * @param size 大小 * @param startIndex 开始下标 - * @return + * @return bookmark List + * @author fanxb */ @Select("select * from bookmark order by bookmarkId limit ${startIndex},${size}") List getBookmarkListPage(@Param("size") int size, @Param("startIndex") int startIndex); + /** + * 功能描述: 书签访问次数+1 + * + * @param item 信息 + * @author fanxb + * @date 2020/5/12 10:40 + */ + @Update("update bookmark set visitNum=visitNum+1 where userId=#{userId} and bookmarkId=#{bookmarkId}") + void updateVisitNum(VisitNumPlus item); + } diff --git a/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/VisitNumPlus.java b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/VisitNumPlus.java new file mode 100644 index 0000000..c3d27d0 --- /dev/null +++ b/bookMarkService/business/bookmark/src/main/java/com/fanxb/bookmark/business/bookmark/entity/redis/VisitNumPlus.java @@ -0,0 +1,23 @@ +package com.fanxb.bookmark.business.bookmark.entity.redis; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * Created with IntelliJ IDEA + * + * @author fanxb + * Date: 2020/5/12 11:47 + */ +@Data +@AllArgsConstructor +public class VisitNumPlus { + /** + * 用户id + */ + private int userId; + /** + * 书签id + */ + private int bookmarkId; +} 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 02908b8..93aa385 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 @@ -98,8 +98,18 @@ public interface BookmarkService { * * @param userId userId * @param context context + * @return es搜索结果 * @author fanxb * @date 2019/7/25 10:45 */ List searchUserBookmark(int userId, String context); + + /** + * 功能描述: 当前用户书签访问次数+1 + * + * @param id 书签id + * @author fanxb + * @date 2020/5/12 10:21 + */ + void visitNumPlus(int id); } 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 ca99c96..b685b8a 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 @@ -1,8 +1,10 @@ package com.fanxb.bookmark.business.bookmark.service.impl; +import com.alibaba.fastjson.JSON; 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.VisitNumPlus; import com.fanxb.bookmark.business.bookmark.service.BookmarkService; import com.fanxb.bookmark.business.bookmark.service.PinYinService; import com.fanxb.bookmark.common.constant.EsConstant; @@ -239,6 +241,12 @@ public class BookmarkServiceImpl implements BookmarkService { return esUtil.search(EsConstant.BOOKMARK_INDEX, builder, BookmarkEs.class); } + @Override + public void visitNumPlus(int id) { + VisitNumPlus item = new VisitNumPlus(UserContextHolder.get().getUserId(), id); + RedisUtil.addToMq(RedisConstant.BOOKMARK_VISIT_NUM_PLUS, JSON.toJSONString(item)); + } + /** * 功能描述: 向mq发送消息通知,数据更新 * diff --git a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/configuration/MqConfiguration.java b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/configuration/MqConfiguration.java index ddfb3d1..01cecf6 100644 --- a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/configuration/MqConfiguration.java +++ b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/configuration/MqConfiguration.java @@ -75,9 +75,9 @@ public class MqConfiguration implements ApplicationRunner { } }); if (count.get() == topicMap.keySet().size()) { - //当所有的队列都为空时休眠1s + //当所有的队列都为空时休眠3s try { - TimeUnit.SECONDS.sleep(1); + TimeUnit.SECONDS.sleep(3); } catch (Exception e) { log.error("休眠出错", e); } diff --git a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/constant/RedisConstant.java b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/constant/RedisConstant.java index 8dea283..488dbf5 100644 --- a/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/constant/RedisConstant.java +++ b/bookMarkService/common/src/main/java/com/fanxb/bookmark/common/constant/RedisConstant.java @@ -27,4 +27,8 @@ public class RedisConstant { * 从es中删除数据 */ public static final String BOOKMARK_DELETE_ES = "bookmark_DELETE_es"; + /** + * 书签访问次数+1 + */ + public static final String BOOKMARK_VISIT_NUM_PLUS = "bookmark_visit_num_plus"; } 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 7358501..73645af 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 @@ -40,6 +40,10 @@ public class Bookmark { private String searchKey = ""; private Long addTime; private Long createTime; + /** + * 访问次数 + */ + private int visitNum; private List children; public Bookmark() { diff --git a/bookMarkService/web/src/main/resources/db/migration/V11__bookmark表增加字段记录访问次数.sql b/bookMarkService/web/src/main/resources/db/migration/V11__bookmark表增加字段记录访问次数.sql new file mode 100644 index 0000000..f114b2c --- /dev/null +++ b/bookMarkService/web/src/main/resources/db/migration/V11__bookmark表增加字段记录访问次数.sql @@ -0,0 +1 @@ +ALTER TABLE `bookmark`.`bookmark` ADD COLUMN `visitNum` int(0) UNSIGNED NOT NULL DEFAULT 0 COMMENT '访问次数' AFTER `createTime`; \ No newline at end of file diff --git a/bookMarkService/web/src/main/resources/db/migration/V12__bookmark增加userId,bookmarkId索引.sql b/bookMarkService/web/src/main/resources/db/migration/V12__bookmark增加userId,bookmarkId索引.sql new file mode 100644 index 0000000..ec31d8a --- /dev/null +++ b/bookMarkService/web/src/main/resources/db/migration/V12__bookmark增加userId,bookmarkId索引.sql @@ -0,0 +1,2 @@ +ALTER TABLE `bookmark`.`bookmark` +ADD INDEX `userId_bookmarkId_index`(`userId`, `bookmarkId`) USING BTREE; \ No newline at end of file diff --git a/front/src/components/Search/index.jsx b/front/src/components/Search/index.jsx index 2338b5a..0eada7c 100644 --- a/front/src/components/Search/index.jsx +++ b/front/src/components/Search/index.jsx @@ -1,17 +1,18 @@ -import React from "react"; -import { Input, Select, Empty } from "antd"; -import styles from "./index.module.less"; -import { keySearch } from "../../util/cacheUtil"; +import React from 'react'; +import { Input, Select, Empty } from 'antd'; +import styles from './index.module.less'; +import { keySearch } from '../../util/cacheUtil'; +import httpUtil from '../../util/httpUtil'; class Search extends React.Component { constructor(props) { super(props); this.state = { - content: "", + content: '', currentIndex: 0, isFocus: false, resultList: [], - options: ["书签", "百度", "谷歌"], + options: ['书签', '百度', '谷歌'], currentOptionIndex: 0 }; } @@ -63,28 +64,25 @@ class Search extends React.Component { this.setState({ resultList, currentIndex: 0 }); } + goTo(item) { + window.open(item.url.startsWith('http') ? item.url : 'http://' + item.url); + httpUtil.post('/bookmark/visitNum?id=' + item.bookmarkId); + } + /** * 处理跳转到搜索引擎或者对应的书签 */ enter() { - const { - currentIndex, - currentOptionIndex, - resultList, - content - } = this.state; + const { currentIndex, currentOptionIndex, resultList, content } = this.state; if (currentOptionIndex === 0 && resultList.length > 0) { let url = resultList[currentIndex].url; - window.open(url.startsWith("http") ? url : "http://" + url); + window.open(url.startsWith('http') ? url : 'http://' + url); + httpUtil.post('/bookmark/visitNum?id=' + resultList[currentIndex].bookmarkId); } if (currentOptionIndex === 1) { - window.open( - "https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(content) - ); + window.open('https://www.baidu.com/s?ie=UTF-8&wd=' + encodeURIComponent(content)); } else if (currentOptionIndex === 2) { - window.open( - "https://www.google.com/search?q=" + encodeURIComponent(content) - ); + window.open('https://www.google.com/search?q=' + encodeURIComponent(content)); } } @@ -130,12 +128,7 @@ class Search extends React.Component { * 渲染结果列表 */ renderResults() { - const { - resultList, - currentIndex, - currentOptionIndex, - isFocus - } = this.state; + const { resultList, currentIndex, currentOptionIndex, isFocus } = this.state; if (currentOptionIndex !== 0 || !isFocus) { return; } @@ -143,38 +136,22 @@ class Search extends React.Component { return (
{resultList.map((item, index) => ( -
window.open(item.url)} - > +
this.goTo(item)}> {item.name}  - - {item.url} - + {item.url}
))}
); } else { - return ( - - ); + return ; } } render() { const { content, options, currentOptionIndex } = this.state; const prefix = ( - {options.map((item, index) => ( {item} @@ -188,15 +165,13 @@ class Search extends React.Component { addonBefore={prefix} ref="searchInput" value={content} - placeholder={currentOptionIndex === 0 ? "检索我的书签" : "搜索"} + placeholder={currentOptionIndex === 0 ? '检索我的书签' : '搜索'} enterButton onSearch={this.enter.bind(this)} onChange={this.contentChange.bind(this)} onKeyDown={this.keyUp.bind(this)} onFocus={() => this.setState({ isFocus: true })} - onBlur={() => - setTimeout(() => this.setState({ isFocus: false }), 600) - } + onBlur={() => setTimeout(() => this.setState({ isFocus: false }), 600)} /> {this.renderResults()}
diff --git a/front/src/pages/manage/OverView/index.jsx b/front/src/pages/manage/OverView/index.jsx index d2e09b1..7047fcf 100644 --- a/front/src/pages/manage/OverView/index.jsx +++ b/front/src/pages/manage/OverView/index.jsx @@ -105,6 +105,7 @@ class OverView extends React.Component { const item = e.node.props.dataRef; if (item.type === 0) { window.open(item.url.startsWith('http') ? item.url : 'http://' + item.url); + httpUtil.post('/bookmark/visitNum?id=' + item.bookmarkId); } else { const id = item.bookmarkId.toString(); const index = expandedKeys.indexOf(id);