parent
37bf0d609b
commit
abc6521f80
|
@ -2,8 +2,8 @@ package com.len.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.len.entity.ArticleList;
|
||||
import com.len.entity.BlogArticle;
|
||||
import com.len.model.Article;
|
||||
import com.len.service.ArticleCategoryService;
|
||||
import com.len.service.BlogArticleService;
|
||||
import com.len.service.BlogCategoryService;
|
||||
|
@ -73,16 +73,9 @@ public class ArticleController {
|
|||
limit = limit > 100 ? 100 : limit;
|
||||
Page<Object> startPage = PageHelper.startPage(page, limit);
|
||||
|
||||
List<BlogArticle> articles = articleService.selectArticle(code);
|
||||
List<Article> articles = articleService.selectArticle(code);
|
||||
|
||||
List<ArticleList> articleLists = new ArrayList<>();
|
||||
articles.forEach(s -> articleLists.add(
|
||||
new ArticleList(s.getId(), s.getCode(), s.getTitle(),
|
||||
s.getTopNum(), s.getCreateBy(),
|
||||
format.format(s.getCreateDate()), s.getContent())
|
||||
)
|
||||
);
|
||||
return new ReType(startPage.getTotal(), startPage.getPageNum(), articleLists);
|
||||
return new ReType(startPage.getTotal(), startPage.getPageNum(), articles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +103,7 @@ public class ArticleController {
|
|||
limit = limit > 100 ? 100 : limit;
|
||||
Page<Object> startPage = PageHelper.startPage(page, limit);
|
||||
|
||||
List<BlogArticle> articles = articleService.selectArticleByTag(tagName);
|
||||
List<Article> articles = articleService.selectArticleByTag(tagName);
|
||||
return new ReType(startPage.getTotal(), startPage.getPageNum(), articles);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ package com.len.controller;
|
|||
|
||||
import com.len.core.LenUser;
|
||||
import com.len.entity.*;
|
||||
import com.len.model.Article;
|
||||
import com.len.service.*;
|
||||
import com.len.util.BeanUtil;
|
||||
import com.len.util.JsonUtil;
|
||||
import com.len.util.Principal;
|
||||
import com.len.util.ReType;
|
||||
import com.len.util.UploadUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -97,7 +98,7 @@ public class BlogAdminController {
|
|||
public JsonUtil addArticle(@RequestBody ArticleDetail detail) {
|
||||
JsonUtil json = new JsonUtil();
|
||||
json.setStatus(400);
|
||||
BlogArticle article = detail.getArticle();
|
||||
Article article = detail.getArticle();
|
||||
if (article == null) {
|
||||
json.setMsg("数据获取失败");
|
||||
return json;
|
||||
|
@ -124,7 +125,12 @@ public class BlogAdminController {
|
|||
article.setId(articleId);
|
||||
article.setCreateDate(new Date());
|
||||
article.setCreateBy(LenUser.getPrincipal().getUserId());
|
||||
articleService.insert(article);
|
||||
article.setReadNumber(0);
|
||||
|
||||
BlogArticle blogArticle = new BlogArticle();
|
||||
BeanUtil.copyNotNullBean(article, blogArticle);
|
||||
|
||||
articleService.insert(blogArticle);
|
||||
|
||||
List<ArticleCategory> categories = new ArrayList<>();
|
||||
for (String cateId : detail.getCategory()) {
|
||||
|
@ -175,7 +181,7 @@ public class BlogAdminController {
|
|||
@Transactional
|
||||
public JsonUtil updateArticle(@RequestBody ArticleDetail detail) {
|
||||
JsonUtil json = new JsonUtil();
|
||||
BlogArticle article = detail.getArticle();
|
||||
Article article = detail.getArticle();
|
||||
json.setFlag(false);
|
||||
json.setStatus(400);
|
||||
if (StringUtils.isBlank(article.getId())) {
|
||||
|
@ -202,7 +208,10 @@ public class BlogAdminController {
|
|||
}
|
||||
article.setUpdateBy(LenUser.getPrincipal().getUserId());
|
||||
article.setUpdateDate(new Date());
|
||||
articleService.updateByPrimaryKey(article);
|
||||
|
||||
BlogArticle blogArticle = new BlogArticle();
|
||||
BeanUtil.copyNotNullBean(article,blogArticle);
|
||||
articleService.updateByPrimaryKey(blogArticle);
|
||||
|
||||
ArticleTag articleTag = new ArticleTag();
|
||||
articleTag.setArticleId(article.getId());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.len.entity;
|
||||
|
||||
import com.len.model.Article;
|
||||
import com.len.model.SimpleArticle;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class ArticleDetail {
|
|||
/**
|
||||
* 文章对象
|
||||
*/
|
||||
BlogArticle article;
|
||||
Article article;
|
||||
/**
|
||||
* 文章标签
|
||||
*/
|
||||
|
|
|
@ -52,5 +52,8 @@ public class BlogArticle {
|
|||
*/
|
||||
private String content;
|
||||
|
||||
@Column(name = "del_flag")
|
||||
private Byte delFlag;
|
||||
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.len.mapper;
|
|||
|
||||
import com.len.base.BaseMapper;
|
||||
import com.len.entity.BlogArticle;
|
||||
import com.len.model.Article;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -9,9 +10,9 @@ import java.util.List;
|
|||
|
||||
public interface BlogArticleMapper extends BaseMapper<BlogArticle, String> {
|
||||
|
||||
List<BlogArticle> selectArticle(@Param("code") String code);
|
||||
List<Article> selectArticle(@Param("code") String code);
|
||||
|
||||
List<BlogArticle> selectArticleByTag(@Param("tagCode") String tagCode);
|
||||
List<Article> selectArticleByTag(@Param("tagCode") String tagCode);
|
||||
|
||||
BlogArticle selectPrevious(@Param("createDate")Date date);
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.len.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Article {
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* code
|
||||
*/
|
||||
private String code;
|
||||
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 阅读次数
|
||||
*/
|
||||
private Integer readNumber;
|
||||
|
||||
/**
|
||||
* 次序(置顶功能)
|
||||
*/
|
||||
private Integer topNum;
|
||||
|
||||
private String createBy;
|
||||
|
||||
private String createName;
|
||||
|
||||
private String updateBy;
|
||||
|
||||
private Date createDate;
|
||||
|
||||
private Date updateDate;
|
||||
|
||||
/**
|
||||
* 文章内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
private Byte delFlag;
|
||||
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package com.len.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BlogArticle {
|
||||
private String id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String description;
|
||||
|
||||
private String contentMd;
|
||||
|
||||
private String contentHtml;
|
||||
|
||||
private Integer readQuantity;
|
||||
|
||||
private Date gmtCreated;
|
||||
|
||||
private Date gmtModified;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id == null ? null : id.trim();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title == null ? null : title.trim();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description == null ? null : description.trim();
|
||||
}
|
||||
|
||||
public String getContentMd() {
|
||||
return contentMd;
|
||||
}
|
||||
|
||||
public void setContentMd(String contentMd) {
|
||||
this.contentMd = contentMd == null ? null : contentMd.trim();
|
||||
}
|
||||
|
||||
public String getContentHtml() {
|
||||
return contentHtml;
|
||||
}
|
||||
|
||||
public void setContentHtml(String contentHtml) {
|
||||
this.contentHtml = contentHtml == null ? null : contentHtml.trim();
|
||||
}
|
||||
|
||||
public Integer getReadQuantity() {
|
||||
return readQuantity;
|
||||
}
|
||||
|
||||
public void setReadQuantity(Integer readQuantity) {
|
||||
this.readQuantity = readQuantity;
|
||||
}
|
||||
|
||||
public Date getGmtCreated() {
|
||||
return gmtCreated;
|
||||
}
|
||||
|
||||
public void setGmtCreated(Date gmtCreated) {
|
||||
this.gmtCreated = gmtCreated;
|
||||
}
|
||||
|
||||
public Date getGmtModified() {
|
||||
return gmtModified;
|
||||
}
|
||||
|
||||
public void setGmtModified(Date gmtModified) {
|
||||
this.gmtModified = gmtModified;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.len.service;
|
|||
|
||||
import com.len.base.BaseService;
|
||||
import com.len.entity.BlogArticle;
|
||||
import com.len.model.Article;
|
||||
import com.len.util.JsonUtil;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -18,9 +19,9 @@ public interface BlogArticleService extends BaseService<BlogArticle, String> {
|
|||
|
||||
public JsonUtil detail(String code,String ip);
|
||||
|
||||
List<BlogArticle> selectArticle(String code);
|
||||
List<Article> selectArticle(String code);
|
||||
|
||||
List<BlogArticle> selectArticleByTag(String tagCode);
|
||||
List<Article> selectArticleByTag(String tagCode);
|
||||
|
||||
BlogArticle selectPrevious(Date date);
|
||||
|
||||
|
|
|
@ -5,12 +5,10 @@ import com.len.base.BaseMapper;
|
|||
import com.len.base.impl.BaseServiceImpl;
|
||||
import com.len.entity.*;
|
||||
import com.len.mapper.BlogArticleMapper;
|
||||
import com.len.model.Article;
|
||||
import com.len.model.SimpleArticle;
|
||||
import com.len.redis.RedisService;
|
||||
import com.len.service.ArticleCategoryService;
|
||||
import com.len.service.ArticleTagService;
|
||||
import com.len.service.BlogArticleService;
|
||||
import com.len.service.BlogTagService;
|
||||
import com.len.service.*;
|
||||
import com.len.util.BeanUtil;
|
||||
import com.len.util.JsonUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -45,6 +43,10 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
|
||||
@Override
|
||||
public BaseMapper<BlogArticle, String> getMappser() {
|
||||
return blogArticleMapper;
|
||||
|
@ -52,14 +54,29 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
|
||||
private ArticleDetail getArticleByCode(String code) {
|
||||
Condition condition = new Condition(BlogArticle.class);
|
||||
condition.createCriteria().andEqualTo("code", code);
|
||||
condition.createCriteria().andEqualTo("code", code)
|
||||
.andEqualTo("delFlag", 0);
|
||||
List<BlogArticle> articles = selectByExample(condition);
|
||||
if (articles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
ArticleDetail detail = new ArticleDetail();
|
||||
BlogArticle blogArticle = articles.get(0);
|
||||
detail.setArticle(blogArticle);
|
||||
|
||||
|
||||
Article article = new Article();
|
||||
BeanUtil.copyNotNullBean(blogArticle, article);
|
||||
detail.setArticle(article);
|
||||
|
||||
String createBy = blogArticle.getCreateBy();
|
||||
if (!StringUtils.isEmpty(createBy)) {
|
||||
SysUser sysUser = sysUserService.selectByPrimaryKey(createBy);
|
||||
if (sysUser != null) {
|
||||
article.setCreateName(sysUser.getUsername());
|
||||
}
|
||||
}else{
|
||||
article.setCreateName("admin");
|
||||
}
|
||||
|
||||
ArticleTag articleTag = new ArticleTag();
|
||||
articleTag.setArticleId(blogArticle.getId());
|
||||
|
@ -106,16 +123,16 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
json.setFlag(false);
|
||||
return json;
|
||||
}
|
||||
BlogArticle blogArticle = detail.getArticle();
|
||||
Article article = detail.getArticle();
|
||||
//点击次数
|
||||
int clickNum = addArticleReadNum(ip, blogArticle.getId());
|
||||
int clickNum = addArticleReadNum(ip, article.getId());
|
||||
if (clickNum > 0) {
|
||||
blogArticle.setReadNumber(clickNum);
|
||||
article.setReadNumber(clickNum);
|
||||
}
|
||||
|
||||
//上一篇
|
||||
PageHelper.startPage(1, 1);
|
||||
BlogArticle previous = selectPrevious(blogArticle.getCreateDate());
|
||||
BlogArticle previous = selectPrevious(article.getCreateDate());
|
||||
if (previous != null) {
|
||||
SimpleArticle simpleArticle = new SimpleArticle();
|
||||
BeanUtil.copyNotNullBean(previous, simpleArticle);
|
||||
|
@ -123,7 +140,7 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
}
|
||||
//下一篇
|
||||
PageHelper.startPage(1, 1);
|
||||
BlogArticle next = selectNext(blogArticle.getCreateDate());
|
||||
BlogArticle next = selectNext(article.getCreateDate());
|
||||
if (next != null) {
|
||||
SimpleArticle simpleArticle = new SimpleArticle();
|
||||
BeanUtil.copyNotNullBean(next, simpleArticle);
|
||||
|
@ -135,12 +152,12 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<BlogArticle> selectArticle(String code) {
|
||||
public List<Article> selectArticle(String code) {
|
||||
return blogArticleMapper.selectArticle(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlogArticle> selectArticleByTag(String tagCode) {
|
||||
public List<Article> selectArticleByTag(String tagCode) {
|
||||
return blogArticleMapper.selectArticleByTag(tagCode);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,58 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.len.mapper.BlogArticleMapper">
|
||||
<resultMap id="BaseResultMap" type="com.len.entity.BlogArticle">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="code" jdbcType="VARCHAR" property="code" />
|
||||
<result column="title" jdbcType="VARCHAR" property="title" />
|
||||
<result column="read_number" jdbcType="INTEGER" property="readNumber" />
|
||||
<result column="top_num" jdbcType="INTEGER" property="topNum" />
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
|
||||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
|
||||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
|
||||
<result column="content" jdbcType="LONGVARCHAR" property="content" />
|
||||
</resultMap>
|
||||
<resultMap id="BaseResultMap" type="com.len.entity.BlogArticle">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="code" jdbcType="VARCHAR" property="code"/>
|
||||
<result column="title" jdbcType="VARCHAR" property="title"/>
|
||||
<result column="read_number" jdbcType="INTEGER" property="readNumber"/>
|
||||
<result column="top_num" jdbcType="INTEGER" property="topNum"/>
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
|
||||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
|
||||
<result column="content" jdbcType="LONGVARCHAR" property="content"/>
|
||||
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectListByPage" parameterType="com.len.entity.BlogArticle" resultMap="BaseResultMap">
|
||||
SELECT id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content
|
||||
from blog_article
|
||||
<where>
|
||||
<if test="title!=null and title!=''"> and title like concat(concat('%',#{title}),'%')</if>
|
||||
<if test="content!=null and content!=''"> and content like concat(concat('%',#{content}),'%')</if>
|
||||
</where>
|
||||
order by read_number asc,create_date desc
|
||||
</select>
|
||||
<select id="selectListByPage" parameterType="com.len.entity.BlogArticle" resultMap="BaseResultMap">
|
||||
SELECT id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content,del_flag
|
||||
from blog_article
|
||||
<where>
|
||||
<if test="title!=null and title!=''">and title like concat(concat('%',#{title}),'%')</if>
|
||||
<if test="content!=null and content!=''">and content like concat(concat('%',#{content}),'%')</if>
|
||||
</where>
|
||||
order by read_number asc,create_date desc
|
||||
</select>
|
||||
|
||||
<select id="selectArticle" resultMap="BaseResultMap">
|
||||
select ba.id,ba.code,ba.title,ba.read_number,ba.top_num,ba.create_by,ba.create_date,
|
||||
left(ba.content,50) content
|
||||
from
|
||||
<select id="selectArticle" resultType="com.len.model.Article">
|
||||
select ba.id,ba.code,ba.title,ba.read_number readNumber,
|
||||
ba.top_num topNum,ba.create_by createBy,ba.create_date createDate,
|
||||
left(ba.content,50) content,su.username createName
|
||||
from
|
||||
blog_article ba
|
||||
left JOIN
|
||||
left JOIN
|
||||
blog_article_category bac
|
||||
on
|
||||
on
|
||||
ba.id=bac.article_id
|
||||
LEFT JOIN
|
||||
LEFT JOIN
|
||||
blog_category bc
|
||||
on
|
||||
on
|
||||
bac.category_id=bc.id
|
||||
<where>
|
||||
<if test="code!=null and code!=''">
|
||||
bc.code=#{code}
|
||||
</if>
|
||||
</where>
|
||||
order by ba.top_num desc,ba.create_date desc
|
||||
</select>
|
||||
LEFT JOIN
|
||||
sys_user su on ba.create_by=su.id
|
||||
where
|
||||
ba.del_flag=0
|
||||
<if test="code!=null and code!=''">
|
||||
and bc.code=#{code}
|
||||
</if>
|
||||
order by ba.top_num desc,ba.create_date desc
|
||||
</select>
|
||||
|
||||
<select id="selectArticleByTag" resultMap="BaseResultMap">
|
||||
select ba.id,ba.code,ba.title,ba.read_number,ba.top_num,ba.create_by,ba.create_date,
|
||||
left(ba.content,50) content
|
||||
<select id="selectArticleByTag" resultType="com.len.model.Article">
|
||||
selectba.id,ba.code,ba.title,ba.read_number readNumber,
|
||||
ba.top_num topNum,ba.create_by createBy,ba.create_date createDate,
|
||||
left(ba.content,50) content,su.username createName
|
||||
from
|
||||
blog_article ba
|
||||
LEFT JOIN
|
||||
|
@ -63,34 +68,39 @@
|
|||
blog_tag bt
|
||||
on
|
||||
bat.tag_id=bt.id
|
||||
LEFT JOIN
|
||||
sys_user su on ba.create_by=su.id
|
||||
where
|
||||
bt.tag_code=#{tagCode}
|
||||
and ba.del_flag=0
|
||||
order by ba.top_num desc,ba.create_date desc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectPrevious" resultMap="BaseResultMap">
|
||||
select
|
||||
id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content
|
||||
id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content
|
||||
from
|
||||
blog_article
|
||||
blog_article
|
||||
where
|
||||
<if test="createDate!=null">
|
||||
unix_timestamp(create_date) <![CDATA[ > ]]> unix_timestamp(#{createDate})
|
||||
</if>
|
||||
del_flag=0
|
||||
<if test="createDate!=null">
|
||||
and unix_timestamp(create_date) <![CDATA[ > ]]> unix_timestamp(#{createDate})
|
||||
</if>
|
||||
order by create_date asc
|
||||
</select>
|
||||
|
||||
<select id="selectNext" resultMap="BaseResultMap">
|
||||
select
|
||||
id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content
|
||||
id,code,title,read_number,top_num,create_by,create_date,
|
||||
left(content,50) content
|
||||
from
|
||||
blog_article
|
||||
blog_article
|
||||
where
|
||||
<if test="createDate!=null">
|
||||
unix_timestamp(create_date) <![CDATA[ < ]]> unix_timestamp(#{createDate})
|
||||
</if>
|
||||
del_flag=0
|
||||
<if test="createDate!=null">
|
||||
and unix_timestamp(create_date) <![CDATA[ < ]]> unix_timestamp(#{createDate})
|
||||
</if>
|
||||
order by create_date desc
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue