feat:增加bookmark访问次数统计

This commit is contained in:
fanxb 2020-05-12 11:44:28 +08:00
parent ee84f8d68e
commit 4e7861b5b1
10 changed files with 90 additions and 3 deletions

View File

@ -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 {

View File

@ -0,0 +1,38 @@
package com.fanxb.bookmark.business.bookmark.consumer;
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
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) {
try {
bookmarkDao.updateVisitNum(Integer.parseInt(message));
} catch (Exception e) {
log.error("书签访问次数增加失败:{}", e.getMessage());
}
}
}

View File

@ -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);
}
}

View File

@ -177,7 +177,7 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
* 功能描述: 更新一个bookmark的key
*
* @param bookmarkId id
* @param searchKey searchKey
* @param searchKey searchKey
* @author fanxb
* @date 2020/3/22 22:08
*/
@ -194,4 +194,14 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
@Select("select * from bookmark order by bookmarkId limit ${startIndex},${size}")
List<Bookmark> getBookmarkListPage(@Param("size") int size, @Param("startIndex") int startIndex);
/**
* 功能描述: 书签访问次数+1
*
* @param id 书签id
* @author fanxb
* @date 2020/5/12 10:40
*/
@Update("update bookmark set visitNum=visitNum+1 where bookmarkId=#{id}")
void updateVisitNum(int id);
}

View File

@ -98,8 +98,18 @@ public interface BookmarkService {
*
* @param userId userId
* @param context context
* @return es搜索结果
* @author fanxb
* @date 2019/7/25 10:45
*/
List<BookmarkEs> searchUserBookmark(int userId, String context);
/**
* 功能描述: 当前用户书签访问次数+1
*
* @param id 书签id
* @author fanxb
* @date 2020/5/12 10:21
*/
void visitNumPlus(int id);
}

View File

@ -239,6 +239,11 @@ public class BookmarkServiceImpl implements BookmarkService {
return esUtil.search(EsConstant.BOOKMARK_INDEX, builder, BookmarkEs.class);
}
@Override
public void visitNumPlus(int id) {
RedisUtil.addToMq(RedisConstant.BOOKMARK_VISIT_NUM_PLUS, id);
}
/**
* 功能描述: 向mq发送消息通知数据更新
*

View File

@ -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);
}

View File

@ -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";
}

View File

@ -40,6 +40,10 @@ public class Bookmark {
private String searchKey = "";
private Long addTime;
private Long createTime;
/**
* 访问次数
*/
private int visitNum;
private List<Bookmark> children;
public Bookmark() {

View File

@ -0,0 +1 @@
ALTER TABLE `bookmark`.`bookmark` ADD COLUMN `visitNum` int(0) UNSIGNED NOT NULL DEFAULT 0 COMMENT '访问次数' AFTER `createTime`;