parent
21c370c4c9
commit
a1b89a6b44
|
@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -96,6 +97,14 @@ public class ArticleController {
|
|||
return articleService.detail(code, ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签code获取文章
|
||||
*
|
||||
* @param tagName
|
||||
* @param page
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/article/list/{tagName}")
|
||||
public ReType getArticleByTag(@PathVariable("tagName") String tagName, Integer page, Integer limit) {
|
||||
limit = limit > 100 ? 100 : limit;
|
||||
|
@ -104,4 +113,19 @@ public class ArticleController {
|
|||
List<BlogArticle> articles = articleService.selectArticleByTag(tagName);
|
||||
return new ReType(startPage.getTotal(), startPage.getPageNum(), articles);
|
||||
}
|
||||
|
||||
@GetMapping("/article/list/order/read")
|
||||
public ReType getArticleByReadNumber() {
|
||||
Condition condition = new Condition(BlogArticle.class);
|
||||
PageHelper.startPage(1, 5);
|
||||
condition.createCriteria();
|
||||
condition.orderBy("readNumber").desc();
|
||||
List<BlogArticle> articles = articleService.selectByExample(condition);
|
||||
articles.forEach(s -> {
|
||||
s.setContent(null);
|
||||
});
|
||||
ReType reType = new ReType();
|
||||
reType.setData(articles);
|
||||
return reType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,10 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
}
|
||||
BlogArticle blogArticle = detail.getArticle();
|
||||
//点击次数
|
||||
addArticleReadNum(ip, blogArticle.getId());
|
||||
int clickNum = addArticleReadNum(ip, blogArticle.getId());
|
||||
if (clickNum > 0) {
|
||||
blogArticle.setReadNumber(clickNum);
|
||||
}
|
||||
|
||||
//上一篇
|
||||
PageHelper.startPage(1, 1);
|
||||
|
@ -157,7 +160,7 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
* @param ip 访问者ip
|
||||
* @param articleId 文章id
|
||||
*/
|
||||
private void addArticleReadNum(String ip, String articleId) {
|
||||
private int addArticleReadNum(String ip, String articleId) {
|
||||
String str = ip + "_" + articleId;
|
||||
if (!StringUtils.isBlank(str)) {
|
||||
if (StringUtils.isEmpty(redisService.get(str))) {
|
||||
|
@ -165,7 +168,9 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
BlogArticle article = selectByPrimaryKey(articleId);
|
||||
article.setReadNumber(article.getReadNumber() + 1);
|
||||
updateByPrimaryKey(article);
|
||||
return article.getReadNumber();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
bat.tag_id=bt.id
|
||||
where
|
||||
bt.tag_code=#{tagCode}
|
||||
order by ba.top_num desc,ba.create_date desc
|
||||
</select>
|
||||
|
||||
<select id="selectPrevious" resultMap="BaseResultMap">
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.len.util;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -13,6 +15,7 @@ import java.util.Map;
|
|||
* @email 154040976@qq.com
|
||||
* 查询返回json格式依照ui默认属性名称
|
||||
*/
|
||||
@Data
|
||||
public class ReType implements Serializable{
|
||||
/**状态*/
|
||||
public int code=0;
|
||||
|
|
Loading…
Reference in New Issue