1、增加访问数量

2、主页的样式修改
3、头像自定义实现
4、注册修改为自动跳转到登录页面,登录失败友好提示,不进行跳转页面处理
5、博客增加私密的功能
This commit is contained in:
limqhz
2022-05-15 18:40:41 +08:00
parent 12ff775d36
commit e51efb81f4
64 changed files with 358 additions and 317 deletions

View File

@@ -20,9 +20,7 @@ public interface BlogService extends IService<Blog> {
List<Blog> getTopBlog();
List<BlogWithUser> getBlogWithUserOrderBySort(MyPageParam myPageParam);
List<BlogWithUser> getBlogWithUser(MyPageParam myPageParam);
List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam);
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);

View File

@@ -31,9 +31,9 @@ public interface SourceService extends IService<Source> {
* @param source
* @throws IOException
*/
void downloadSource(HttpServletResponse response, Source source) throws IOException;
void downloadSource(HttpServletResponse response, Source source,String sessionId) throws IOException;
void downloadForBaidu(HttpServletResponse response, Source source) throws IOException;
void downloadForBaidu(HttpServletResponse response, Source source,String sessionId) throws IOException;
/**
* 点击对应的资源

View File

@@ -28,6 +28,8 @@ import java.util.List;
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
@Resource
BlogMapper blogMapper;
@Resource
RedisUtils redisUtils;
@Override
public List<Blog> getTopBlog(){
@@ -41,17 +43,10 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
}
@Override
public List<BlogWithUser> getBlogWithUserOrderBySort(MyPageParam myPageParam) {
int count = count(null);
public List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam) {
int count = blogMapper.getBlogWithUserOrderBySortCount(userId);
myPageParam.setTotal(count);
return blogMapper.getBlogWithUserOrderBySort(myPageParam);
}
@Override
public List<BlogWithUser> getBlogWithUser(MyPageParam myPageParam) {
int count = count(null);
myPageParam.setTotal(count);
return blogMapper.getBlogWithUser(myPageParam);
return blogMapper.getBlogWithUserOrderBySort(userId,myPageParam);
}
@Override
@@ -63,8 +58,12 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements Bl
@Override
public void addRecord(Blog blog, String sessionId) {
blog.setViews(blog.getViews()+1);
updateById(blog);
String value = redisUtils.get(sessionId + blog.getBid());
if (!QuinnConstant.SESSION_VIEW_KEY.equals(value)){
blog.setViews(blog.getViews()+1);
redisUtils.set(sessionId + blog.getBid(),QuinnConstant.SESSION_VIEW_KEY,QuinnConstant.SESSION_TIME_OUT);
updateById(blog);
}
}
}

View File

@@ -10,10 +10,7 @@ import com.quinn.pojo.SourceCategory;
import com.quinn.pojo.SourceWithStar;
import com.quinn.service.SourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quinn.utils.ContentUtil;
import com.quinn.utils.OSSClientUtil;
import com.quinn.utils.QuinnUtils;
import com.quinn.utils.RedisUtils;
import com.quinn.utils.*;
import com.quinn.vo.MyPageParam;
import com.quinn.vo.QuerySource;
import com.quinn.vo.SourceUpdateForm;
@@ -52,9 +49,9 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
SourceMapper sourceMapper;
@Override
public void downloadSource(HttpServletResponse response, Source source) throws IOException {
public void downloadSource(HttpServletResponse response, Source source,String sessionId) throws IOException {
String sourceLink = source.getSourceLink();
addDownLoadRecord(source);
addDownLoadRecord(source,sessionId);
// 读取文件内容。
BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink));
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
@@ -73,8 +70,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
}
@Override
public void downloadForBaidu(HttpServletResponse response, Source source) throws IOException {
addDownLoadRecord(source);
public void downloadForBaidu(HttpServletResponse response, Source source,String sessionId) throws IOException {
addDownLoadRecord(source,sessionId);
PrintWriter writer = response.getWriter();
writer.write(source.getSourceLink());
writer.flush();
@@ -84,7 +81,7 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
@Override
public Source view(String sid,String sessionId) {
Source source = getOne(new QueryWrapper<Source>().eq("sid", sid));
addDownLoadRecord(source);
addDownLoadRecord(source,sessionId);
return source;
}
@@ -105,9 +102,9 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
source.setEnName(sourceWriteForm.getEnName());
source.setFileType(fileType);
source.setSourceName(sourceWriteForm.getTitle());
source.setDetail(sourceWriteForm.getSubContent());
source.setDetail(CovertEmojStr.coverStr(sourceWriteForm.getSubContent()));
source.setSourceContent(sourceWriteForm.getContent());
String s = ContentUtil.toTextContentFromWangEdit(sourceWriteForm.getContentJson());
String s = ContentUtil.toTextContentFromWangEdit(CovertEmojStr.coverStr(sourceWriteForm.getContentJson()));
sourceWriteForm.setContentJson(s);
source.setSourceType(sourceWriteForm.getSourceType());
source.setSourceLink(fileLink);
@@ -143,8 +140,8 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
before.setFileType(fileType);
before.setSourceName(sourceUpdateForm.getSourceName());
before.setDetail(sourceUpdateForm.getDetail());
before.setSourceContent(sourceUpdateForm.getSourceContent());
String s = ContentUtil.toTextContentFromWangEdit(sourceUpdateForm.getContentJson());
before.setSourceContent(CovertEmojStr.coverStr(sourceUpdateForm.getSourceContent()));
String s = ContentUtil.toTextContentFromWangEdit(CovertEmojStr.coverStr(sourceUpdateForm.getContentJson()));
before.setContentJson(s);
before.setSourceType(sourceUpdateForm.getSourceType());
before.setSourceLink(fileLink);
@@ -189,23 +186,20 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
}
/**
* 更新页码
* 更新热度
* @param source
*/
private void addDownLoadRecord(Source source) {
private void addDownLoadRecord(Source source,String sessionId) {
/** 使用redis记录访问量可以降低数据库压力,但是时效性就会降低,
* 需要不断跑批处理,用户量小或者单实例不推荐这么做
* 我们此处是为了实现session级别不能恶意刷热度
*/
// 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);
String value = redisUtils.get(sessionId + source.getSid());
if (!QuinnConstant.SESSION_VIEW_KEY.equals(value)){
source.setDownRecord(source.getDownRecord() + 1);
redisUtils.set(sessionId + source.getSid(),QuinnConstant.SESSION_VIEW_KEY,QuinnConstant.SESSION_TIME_OUT);
updateById(source);
}
}
}