fix 恶意刷新查看量
全局搜索代替了原来长连接的方式,增加了很多隐藏的门路。
This commit is contained in:
@@ -26,4 +26,5 @@ public interface BlogService extends IService<Blog> {
|
||||
|
||||
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);
|
||||
|
||||
void addRecord(Blog blog, String sessionId);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public interface SourceService extends IService<Source> {
|
||||
* @throws IOException
|
||||
* @return
|
||||
*/
|
||||
Source view(String sid);
|
||||
Source view(String sid,String sessionId);
|
||||
|
||||
/**
|
||||
* 上传新资源
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.pojo.Blog;
|
||||
import com.quinn.mapper.BlogMapper;
|
||||
import com.quinn.pojo.BlogWithUser;
|
||||
import com.quinn.service.BlogService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.quinn.utils.RedisUtils;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -24,6 +27,8 @@ import java.util.List;
|
||||
@Service
|
||||
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
|
||||
|
||||
@Resource
|
||||
RedisUtils redisUtils;
|
||||
@Resource
|
||||
BlogMapper blogMapper;
|
||||
|
||||
@@ -59,4 +64,14 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
|
||||
return blogMapper.getMyBlogs(userId,myPageParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecord(Blog blog, String sessionId) {
|
||||
String value = redisUtils.get(sessionId);
|
||||
if (StringUtils.isEmpty(value)){
|
||||
redisUtils.set(sessionId, QuinnConstant.SESSION_LOCK,QuinnConstant.SESSION_TIME_OUT);
|
||||
blog.setViews(blog.getViews()+1);
|
||||
updateById(blog);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,9 +81,13 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source view(String sid) {
|
||||
public Source view(String sid,String sessionId) {
|
||||
Source source = getOne(new QueryWrapper<Source>().eq("sid", sid));
|
||||
addDownLoadRecord(source);
|
||||
String value = redisUtils.get(sessionId);
|
||||
if (StringUtils.isEmpty(value)){
|
||||
redisUtils.set(sessionId,QuinnConstant.SESSION_LOCK,QuinnConstant.SESSION_TIME_OUT);
|
||||
addDownLoadRecord(source);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -214,13 +218,16 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
* @param source
|
||||
*/
|
||||
private void addDownLoadRecord(Source source) {
|
||||
String downLoadTime = redisUtils.get(QuinnConstant.SOURCE_KEY + source.getSid());
|
||||
int downTimes = 0;
|
||||
if (StringUtils.isEmpty(downLoadTime)){
|
||||
downTimes = source.getDownRecord() + 1;
|
||||
}else {
|
||||
downTimes = Integer.parseInt(downLoadTime) + 1;
|
||||
}
|
||||
/** 使用redis记录访问量可以降低数据库压力,但是时效性就会降低,
|
||||
* 需要不断跑批处理,用户量小或者单实例不推荐这么做
|
||||
*/
|
||||
// int downTimes = 0;
|
||||
// if (StringUtils.isEmpty(downLoadTime)){
|
||||
// downTimes = source.getDownRecord() + 1;
|
||||
// }else {
|
||||
// downTimes = Integer.parseInt(downLoadTime) + 1;
|
||||
// }
|
||||
int downTimes = source.getDownRecord() + 1;
|
||||
redisUtils.set(QuinnConstant.SOURCE_KEY + source.getSid(),downTimes + "");
|
||||
source.setDownRecord(source.getDownRecord() + 1);
|
||||
updateById(source);
|
||||
|
||||
@@ -53,6 +53,7 @@ public class StarServiceImpl extends ServiceImpl<StarMapper, Star> implements St
|
||||
save(blogStar);
|
||||
starValue.setStar(true);
|
||||
}
|
||||
starValue.setTotal(getTotalStar(topicId,category));
|
||||
return starValue;
|
||||
}
|
||||
|
||||
@@ -68,9 +69,16 @@ public class StarServiceImpl extends ServiceImpl<StarMapper, Star> implements St
|
||||
starValue.setStar(true);
|
||||
}
|
||||
}
|
||||
starValue.setTotal(getTotalStar(topicId,category));
|
||||
return starValue;
|
||||
}
|
||||
|
||||
private int getTotalStar(String topicId,Category category){
|
||||
return count(new QueryWrapper<Star>()
|
||||
.eq("topic_category",category.name())
|
||||
.eq("topic_id",topicId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StarWithTopic> listStars(String userId, MyPageParam myPageParam) {
|
||||
int count = count(new QueryWrapper<Star>().eq("user_id",userId));
|
||||
|
||||
@@ -55,6 +55,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
user.setPassword(QuinnConstant.GUN);
|
||||
// 放入session
|
||||
session.setAttribute("loginUser",user);
|
||||
session.setMaxInactiveInterval(QuinnConstant.SESSION_TIME_OUT);
|
||||
//创建一个集合来存放权限
|
||||
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
|
||||
RoleType[] values = RoleType.values();
|
||||
|
||||
Reference in New Issue
Block a user