From abc6521f802d849ede5c4e5c916831511fc66572 Mon Sep 17 00:00:00 2001 From: meng <154040976@qq.com> Date: Sun, 25 Nov 2018 15:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E5=B1=95=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=88=9B=E5=BB=BA=E4=BA=BA=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20=20=20=20=20=20=20=20=20=20=20--=E5=90=AC?= =?UTF-8?q?=E4=B8=80=E9=A6=96=E6=AD=8C=EF=BC=8C=E5=9B=9E=E5=BF=86=E4=B8=80?= =?UTF-8?q?=E6=AE=B5=E5=BE=80=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/len/controller/ArticleController.java | 15 +-- .../len/controller/BlogAdminController.java | 19 ++- .../java/com/len/entity/ArticleDetail.java | 3 +- .../main/java/com/len/entity/BlogArticle.java | 3 + .../com/len/mapper/BlogArticleMapper.java | 5 +- .../src/main/java/com/len/model/Article.java | 51 ++++++++ .../main/java/com/len/model/BlogArticle.java | 85 ------------ .../com/len/service/BlogArticleService.java | 5 +- .../service/impl/BlogArticleServiceImpl.java | 43 ++++-- .../resources/mapper/BlogArticleMapper.xml | 122 ++++++++++-------- 10 files changed, 176 insertions(+), 175 deletions(-) create mode 100644 len-blog/src/main/java/com/len/model/Article.java delete mode 100644 len-blog/src/main/java/com/len/model/BlogArticle.java diff --git a/len-blog/src/main/java/com/len/controller/ArticleController.java b/len-blog/src/main/java/com/len/controller/ArticleController.java index 3be6821..fb74d74 100644 --- a/len-blog/src/main/java/com/len/controller/ArticleController.java +++ b/len-blog/src/main/java/com/len/controller/ArticleController.java @@ -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 startPage = PageHelper.startPage(page, limit); - List articles = articleService.selectArticle(code); + List
articles = articleService.selectArticle(code); - List 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 startPage = PageHelper.startPage(page, limit); - List articles = articleService.selectArticleByTag(tagName); + List
articles = articleService.selectArticleByTag(tagName); return new ReType(startPage.getTotal(), startPage.getPageNum(), articles); } diff --git a/len-blog/src/main/java/com/len/controller/BlogAdminController.java b/len-blog/src/main/java/com/len/controller/BlogAdminController.java index 81c03f8..89a7489 100644 --- a/len-blog/src/main/java/com/len/controller/BlogAdminController.java +++ b/len-blog/src/main/java/com/len/controller/BlogAdminController.java @@ -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 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()); diff --git a/len-blog/src/main/java/com/len/entity/ArticleDetail.java b/len-blog/src/main/java/com/len/entity/ArticleDetail.java index c64dce5..623e69f 100644 --- a/len-blog/src/main/java/com/len/entity/ArticleDetail.java +++ b/len-blog/src/main/java/com/len/entity/ArticleDetail.java @@ -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; /** * 文章标签 */ diff --git a/len-blog/src/main/java/com/len/entity/BlogArticle.java b/len-blog/src/main/java/com/len/entity/BlogArticle.java index 1b34562..5229c45 100644 --- a/len-blog/src/main/java/com/len/entity/BlogArticle.java +++ b/len-blog/src/main/java/com/len/entity/BlogArticle.java @@ -52,5 +52,8 @@ public class BlogArticle { */ private String content; + @Column(name = "del_flag") + private Byte delFlag; + } \ No newline at end of file diff --git a/len-blog/src/main/java/com/len/mapper/BlogArticleMapper.java b/len-blog/src/main/java/com/len/mapper/BlogArticleMapper.java index 2009702..0bdb2aa 100644 --- a/len-blog/src/main/java/com/len/mapper/BlogArticleMapper.java +++ b/len-blog/src/main/java/com/len/mapper/BlogArticleMapper.java @@ -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 { - List selectArticle(@Param("code") String code); + List
selectArticle(@Param("code") String code); - List selectArticleByTag(@Param("tagCode") String tagCode); + List
selectArticleByTag(@Param("tagCode") String tagCode); BlogArticle selectPrevious(@Param("createDate")Date date); diff --git a/len-blog/src/main/java/com/len/model/Article.java b/len-blog/src/main/java/com/len/model/Article.java new file mode 100644 index 0000000..42084ce --- /dev/null +++ b/len-blog/src/main/java/com/len/model/Article.java @@ -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; + + +} \ No newline at end of file diff --git a/len-blog/src/main/java/com/len/model/BlogArticle.java b/len-blog/src/main/java/com/len/model/BlogArticle.java deleted file mode 100644 index 3bbcede..0000000 --- a/len-blog/src/main/java/com/len/model/BlogArticle.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/len-blog/src/main/java/com/len/service/BlogArticleService.java b/len-blog/src/main/java/com/len/service/BlogArticleService.java index ebf8e2f..d2d7a74 100644 --- a/len-blog/src/main/java/com/len/service/BlogArticleService.java +++ b/len-blog/src/main/java/com/len/service/BlogArticleService.java @@ -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 { public JsonUtil detail(String code,String ip); - List selectArticle(String code); + List
selectArticle(String code); - List selectArticleByTag(String tagCode); + List
selectArticleByTag(String tagCode); BlogArticle selectPrevious(Date date); diff --git a/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java b/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java index 4215077..03276d3 100644 --- a/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java +++ b/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java @@ -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 @Autowired private RedisService redisService; + @Autowired + private SysUserService sysUserService; + + @Override public BaseMapper getMappser() { return blogArticleMapper; @@ -52,14 +54,29 @@ public class BlogArticleServiceImpl extends BaseServiceImpl 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 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 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 } //下一篇 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 } @Override - public List selectArticle(String code) { + public List
selectArticle(String code) { return blogArticleMapper.selectArticle(code); } @Override - public List selectArticleByTag(String tagCode) { + public List
selectArticleByTag(String tagCode) { return blogArticleMapper.selectArticleByTag(tagCode); } diff --git a/len-blog/src/main/resources/mapper/BlogArticleMapper.xml b/len-blog/src/main/resources/mapper/BlogArticleMapper.xml index dfbc54b..ddf0a1c 100644 --- a/len-blog/src/main/resources/mapper/BlogArticleMapper.xml +++ b/len-blog/src/main/resources/mapper/BlogArticleMapper.xml @@ -1,58 +1,63 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + - + - + 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 - - - bc.code=#{code} - - - order by ba.top_num desc,ba.create_date desc - + LEFT JOIN + sys_user su on ba.create_by=su.id + where + ba.del_flag=0 + + and bc.code=#{code} + + order by ba.top_num desc,ba.create_date desc + - + 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 - + \ No newline at end of file