Fixbug 私密日志取消被推荐、私密日志取消被搜索
This commit is contained in:
@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -125,12 +126,12 @@ public class BlogController extends BaseModelController{
|
||||
// 阅读文章
|
||||
@GetMapping("/blog/read/{bid}")
|
||||
public String read(HttpServletRequest request, @PathVariable("bid") String bid, Model model){
|
||||
Blog blog = blogService.getOne(new QueryWrapper<Blog>().eq("bid", bid));
|
||||
String loginUserId = getLoginUserId(request);
|
||||
String sessionId = getSessionId(request);
|
||||
blogService.addRecord(blog,sessionId);
|
||||
model.addAttribute("blog",blog);
|
||||
BlogWithUser readBlog = blogService.getReadBlog(bid, sessionId, loginUserId);
|
||||
model.addAttribute("blog",readBlog);
|
||||
|
||||
StarValue starValue = starService.isStar(bid, getLoginUserId(request), Category.BLOG);
|
||||
StarValue starValue = starService.isStar(bid, loginUserId, Category.BLOG);
|
||||
model.addAttribute("starValue",starValue);
|
||||
|
||||
List<CommentWithUser> commentList = commentService.getCommentList(bid, Category.BLOG);
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface BlogMapper extends BaseMapper<Blog> {
|
||||
List<BlogWithUser> getBlogWithUserOrderBySort(String userId,MyPageParam myPageParam);
|
||||
|
||||
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);
|
||||
|
||||
BlogWithUser getReadBlog(String bid, String userId);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<select id="getTopBlog" resultType="com.quinn.pojo.Blog">
|
||||
select bid,title,(star + views) as views from
|
||||
(select bid,title,(select count(1) from qn_star where topic_id = bid and topic_category = 'BLOG') as star,views
|
||||
from qn_blog where sort = 0) t
|
||||
from qn_blog where sort = 0 and category_id = '2') t
|
||||
order by (views + star) desc limit 7
|
||||
</select>
|
||||
|
||||
@@ -34,4 +34,14 @@
|
||||
limit #{myPageParam.pageNum},#{myPageParam.size}
|
||||
</select>
|
||||
|
||||
<select id="getReadBlog" resultType="com.quinn.pojo.BlogWithUser">
|
||||
select a.id,a.bid,a.title,a.sort,a.views,a.content,a.author_id,a.category_id,a.category_name,a.gmt_create,a.gmt_update
|
||||
,b.username,b.avatar,
|
||||
(select count(1) from qn_star c where c.topic_id = a.bid and c.topic_category = 'BLOG') as star
|
||||
from qn_blog a,qn_user b
|
||||
where a.author_id = b.uid
|
||||
and (case when a.category_id = '1' then a.author_id = #{userId} else 1 end)
|
||||
and a.bid = #{bid}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
or a.content_json like CONCAT('%',#{findWhat},'%')
|
||||
union all
|
||||
select 1 from qn_blog b
|
||||
where b.title like CONCAT('%',#{findWhat},'%')
|
||||
or b.content_json like CONCAT('%',#{findWhat},'%')
|
||||
where (b.title like CONCAT('%',#{findWhat},'%')
|
||||
or b.content_json like CONCAT('%',#{findWhat},'%'))
|
||||
and b.category_id = '2'
|
||||
) t
|
||||
</select>
|
||||
|
||||
|
||||
@@ -24,5 +24,6 @@ public interface BlogService extends IService<Blog> {
|
||||
|
||||
List<BlogWithUser> getMyBlogs(String userId,MyPageParam myPageParam);
|
||||
|
||||
void addRecord(Blog blog, String sessionId);
|
||||
BlogWithUser getReadBlog(String bid,String sessionId,String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -56,14 +56,23 @@ 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 + blog.getBid());
|
||||
private void addRecord(BlogWithUser blogRead, String sessionId) {
|
||||
String value = redisUtils.get(sessionId + blogRead.getBid());
|
||||
Blog blog = new Blog();
|
||||
blog.setBid(blogRead.getBid());
|
||||
if (!QuinnConstant.SESSION_VIEW_KEY.equals(value)){
|
||||
blog.setViews(blog.getViews()+1);
|
||||
blog.setViews(blogRead.getViews()+1);
|
||||
redisUtils.set(sessionId + blog.getBid(),QuinnConstant.SESSION_VIEW_KEY,QuinnConstant.SESSION_TIME_OUT);
|
||||
updateById(blog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlogWithUser getReadBlog(String bid, String sessionId, String userId) {
|
||||
BlogWithUser blog = blogMapper.getReadBlog(bid,userId);
|
||||
if (blog!=null){
|
||||
addRecord(blog,sessionId);
|
||||
}
|
||||
return blog;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user