feat:用户只能增加自己的书签访问次数
This commit is contained in:
parent
4e7861b5b1
commit
cf960d4210
@ -1,6 +1,8 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.consumer;
|
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.dao.BookmarkDao;
|
||||||
|
import com.fanxb.bookmark.business.bookmark.entity.redis.VisitNumPlus;
|
||||||
import com.fanxb.bookmark.common.annotation.MqConsumer;
|
import com.fanxb.bookmark.common.annotation.MqConsumer;
|
||||||
import com.fanxb.bookmark.common.constant.RedisConstant;
|
import com.fanxb.bookmark.common.constant.RedisConstant;
|
||||||
import com.fanxb.bookmark.common.entity.redis.RedisConsumer;
|
import com.fanxb.bookmark.common.entity.redis.RedisConsumer;
|
||||||
@ -29,8 +31,9 @@ public class BookmarkVisitNumPlusConsumer implements RedisConsumer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deal(String message) {
|
public void deal(String message) {
|
||||||
|
VisitNumPlus item = JSON.parseObject(message, VisitNumPlus.class);
|
||||||
try {
|
try {
|
||||||
bookmarkDao.updateVisitNum(Integer.parseInt(message));
|
bookmarkDao.updateVisitNum(item);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("书签访问次数增加失败:{}", e.getMessage());
|
log.error("书签访问次数增加失败:{}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.fanxb.bookmark.business.bookmark.dao;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
|
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 com.fanxb.bookmark.common.entity.Bookmark;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
@ -201,7 +202,7 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
|
|||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2020/5/12 10:40
|
* @date 2020/5/12 10:40
|
||||||
*/
|
*/
|
||||||
@Update("update bookmark set visitNum=visitNum+1 where bookmarkId=#{id}")
|
@Update("update bookmark set visitNum=visitNum+1 where userId=#{userId} and bookmarkId=#{bookmarkId}")
|
||||||
void updateVisitNum(int id);
|
void updateVisitNum(VisitNumPlus item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.service.impl;
|
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.dao.BookmarkDao;
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
|
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
|
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.BookmarkService;
|
||||||
import com.fanxb.bookmark.business.bookmark.service.PinYinService;
|
import com.fanxb.bookmark.business.bookmark.service.PinYinService;
|
||||||
import com.fanxb.bookmark.common.constant.EsConstant;
|
import com.fanxb.bookmark.common.constant.EsConstant;
|
||||||
@ -241,7 +243,8 @@ public class BookmarkServiceImpl implements BookmarkService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNumPlus(int id) {
|
public void visitNumPlus(int id) {
|
||||||
RedisUtil.addToMq(RedisConstant.BOOKMARK_VISIT_NUM_PLUS, id);
|
VisitNumPlus item = new VisitNumPlus(UserContextHolder.get().getUserId(), id);
|
||||||
|
RedisUtil.addToMq(RedisConstant.BOOKMARK_VISIT_NUM_PLUS, JSON.toJSONString(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `bookmark`.`bookmark`
|
||||||
|
ADD INDEX `userId_bookmarkId_index`(`userId`, `bookmarkId`) USING BTREE;
|
@ -1,17 +1,18 @@
|
|||||||
import React from "react";
|
import React from 'react';
|
||||||
import { Input, Select, Empty } from "antd";
|
import { Input, Select, Empty } from 'antd';
|
||||||
import styles from "./index.module.less";
|
import styles from './index.module.less';
|
||||||
import { keySearch } from "../../util/cacheUtil";
|
import { keySearch } from '../../util/cacheUtil';
|
||||||
|
import httpUtil from '../../util/httpUtil';
|
||||||
|
|
||||||
class Search extends React.Component {
|
class Search extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
content: "",
|
content: '',
|
||||||
currentIndex: 0,
|
currentIndex: 0,
|
||||||
isFocus: false,
|
isFocus: false,
|
||||||
resultList: [],
|
resultList: [],
|
||||||
options: ["书签", "百度", "谷歌"],
|
options: ['书签', '百度', '谷歌'],
|
||||||
currentOptionIndex: 0
|
currentOptionIndex: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -63,28 +64,25 @@ class Search extends React.Component {
|
|||||||
this.setState({ resultList, currentIndex: 0 });
|
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() {
|
enter() {
|
||||||
const {
|
const { currentIndex, currentOptionIndex, resultList, content } = this.state;
|
||||||
currentIndex,
|
|
||||||
currentOptionIndex,
|
|
||||||
resultList,
|
|
||||||
content
|
|
||||||
} = this.state;
|
|
||||||
if (currentOptionIndex === 0 && resultList.length > 0) {
|
if (currentOptionIndex === 0 && resultList.length > 0) {
|
||||||
let url = resultList[currentIndex].url;
|
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) {
|
if (currentOptionIndex === 1) {
|
||||||
window.open(
|
window.open('https://www.baidu.com/s?ie=UTF-8&wd=' + encodeURIComponent(content));
|
||||||
"https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(content)
|
|
||||||
);
|
|
||||||
} else if (currentOptionIndex === 2) {
|
} else if (currentOptionIndex === 2) {
|
||||||
window.open(
|
window.open('https://www.google.com/search?q=' + encodeURIComponent(content));
|
||||||
"https://www.google.com/search?q=" + encodeURIComponent(content)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +128,7 @@ class Search extends React.Component {
|
|||||||
* 渲染结果列表
|
* 渲染结果列表
|
||||||
*/
|
*/
|
||||||
renderResults() {
|
renderResults() {
|
||||||
const {
|
const { resultList, currentIndex, currentOptionIndex, isFocus } = this.state;
|
||||||
resultList,
|
|
||||||
currentIndex,
|
|
||||||
currentOptionIndex,
|
|
||||||
isFocus
|
|
||||||
} = this.state;
|
|
||||||
if (currentOptionIndex !== 0 || !isFocus) {
|
if (currentOptionIndex !== 0 || !isFocus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,38 +136,22 @@ class Search extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.resultList}>
|
<div className={styles.resultList}>
|
||||||
{resultList.map((item, index) => (
|
{resultList.map((item, index) => (
|
||||||
<div
|
<div className={`${styles.item} ${index === currentIndex ? styles.checked : ''}`} key={item.bookmarkId} onClick={() => this.goTo(item)}>
|
||||||
className={`${styles.item} ${
|
|
||||||
index === currentIndex ? styles.checked : ""
|
|
||||||
}`}
|
|
||||||
key={item.bookmarkId}
|
|
||||||
onClick={() => window.open(item.url)}
|
|
||||||
>
|
|
||||||
<span style={{ fontWeight: 600 }}>{item.name} </span>
|
<span style={{ fontWeight: 600 }}>{item.name} </span>
|
||||||
<span style={{ fontSize: "0.8em", fontWeight: 400 }}>
|
<span style={{ fontSize: '0.8em', fontWeight: 400 }}>{item.url}</span>
|
||||||
{item.url}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return <Empty className={styles.resultList} image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
||||||
<Empty
|
|
||||||
className={styles.resultList}
|
|
||||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { content, options, currentOptionIndex } = this.state;
|
const { content, options, currentOptionIndex } = this.state;
|
||||||
const prefix = (
|
const prefix = (
|
||||||
<Select
|
<Select value={options[currentOptionIndex]} onChange={this.valueIndexChange.bind(this)}>
|
||||||
value={options[currentOptionIndex]}
|
|
||||||
onChange={this.valueIndexChange.bind(this)}
|
|
||||||
>
|
|
||||||
{options.map((item, index) => (
|
{options.map((item, index) => (
|
||||||
<Select.Option key={index} value={index}>
|
<Select.Option key={index} value={index}>
|
||||||
{item}
|
{item}
|
||||||
@ -188,15 +165,13 @@ class Search extends React.Component {
|
|||||||
addonBefore={prefix}
|
addonBefore={prefix}
|
||||||
ref="searchInput"
|
ref="searchInput"
|
||||||
value={content}
|
value={content}
|
||||||
placeholder={currentOptionIndex === 0 ? "检索我的书签" : "搜索"}
|
placeholder={currentOptionIndex === 0 ? '检索我的书签' : '搜索'}
|
||||||
enterButton
|
enterButton
|
||||||
onSearch={this.enter.bind(this)}
|
onSearch={this.enter.bind(this)}
|
||||||
onChange={this.contentChange.bind(this)}
|
onChange={this.contentChange.bind(this)}
|
||||||
onKeyDown={this.keyUp.bind(this)}
|
onKeyDown={this.keyUp.bind(this)}
|
||||||
onFocus={() => this.setState({ isFocus: true })}
|
onFocus={() => this.setState({ isFocus: true })}
|
||||||
onBlur={() =>
|
onBlur={() => setTimeout(() => this.setState({ isFocus: false }), 600)}
|
||||||
setTimeout(() => this.setState({ isFocus: false }), 600)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
{this.renderResults()}
|
{this.renderResults()}
|
||||||
</div>
|
</div>
|
||||||
|
@ -105,6 +105,7 @@ class OverView extends React.Component {
|
|||||||
const item = e.node.props.dataRef;
|
const item = e.node.props.dataRef;
|
||||||
if (item.type === 0) {
|
if (item.type === 0) {
|
||||||
window.open(item.url.startsWith('http') ? item.url : 'http://' + item.url);
|
window.open(item.url.startsWith('http') ? item.url : 'http://' + item.url);
|
||||||
|
httpUtil.post('/bookmark/visitNum?id=' + item.bookmarkId);
|
||||||
} else {
|
} else {
|
||||||
const id = item.bookmarkId.toString();
|
const id = item.bookmarkId.toString();
|
||||||
const index = expandedKeys.indexOf(id);
|
const index = expandedKeys.indexOf(id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user