🎨 代码优化

pull/78/head
ruibaby 2019-01-05 17:16:56 +08:00
parent da923f3469
commit d63f7943b4
9 changed files with 125 additions and 56 deletions

2
docs/README-en-US.md → README-en_US.md Executable file → Normal file
View File

@ -11,7 +11,7 @@
</p>
------------------------------
🇨🇳[简体中文](../README.md) | 🇺🇸English
🇨🇳[简体中文](README.md) | 🇺🇸English
## Introduction

View File

@ -11,7 +11,7 @@
</p>
------------------------------
🇨🇳简体中文 | 🇺🇸[English](./docs/README-en-US.md)
🇨🇳简体中文 | 🇺🇸[English](README-en_US.md)
## 简介

View File

@ -60,7 +60,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
if (StrUtil.isNotEmpty(themeValue) && !StrUtil.equals(themeValue, null)) {
BaseController.THEME = themeValue;
} else {
//以防万一
//如果没有设置主题,则默认
BaseController.THEME = "anatole";
}
configuration.setSharedVariable("themeName", BaseController.THEME);

View File

@ -34,6 +34,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param postType post or page
*
* @return List
*/
List<Post> findPostsByPostType(String postType);
@ -43,6 +44,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param postType post or page
* @param pageable
*
* @return Page
*/
Page<Post> findPostsByPostType(String postType, Pageable pageable);
@ -52,6 +54,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param keyWord keyword
* @param pageable pageable
*
* @return List
*/
List<Post> findByPostTitleLike(String keyWord, Pageable pageable);
@ -62,6 +65,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param status 012
* @param postType post or page
* @param pageable
*
* @return Page
*/
Page<Post> findPostsByPostStatusAndPostType(Integer status, String postType, Pageable pageable);
@ -71,6 +75,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param status 0,1,2
* @param postType post or page
*
* @return List
*/
List<Post> findPostsByPostStatusAndPostType(Integer status, String postType);
@ -80,6 +85,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param postUrl
* @param postType post or page
*
* @return Post
*/
Post findPostByPostUrlAndPostType(String postUrl, String postType);
@ -89,30 +95,30 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param postId
* @param postType post or page
*
* @return Post
*/
Post findPostByPostIdAndPostType(Long postId, String postType);
/**
*
*
*
* @param postDate
* @param postStatus 012
* @param postType post or page
* @return List
* @param postDate
*
* @return Post
*/
List<Post> findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(Date postDate, Integer postStatus, String postType);
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date < :postDate ORDER BY post_date DESC LIMIT 1", nativeQuery = true)
Post queryPrePost(Date postDate);
/**
*
*
*
* @param postDate
* @param postStatus 012
* @param postType post or page
* @return List
* @param postDate
*
* @return Post
*/
List<Post> findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(Date postDate, Integer postStatus, String postType);
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date > :postDate ORDER BY post_date ASC LIMIT 1", nativeQuery = true)
Post queryNextPost(Date postDate);
/**
*
@ -132,32 +138,34 @@ public interface PostRepository extends JpaRepository<Post, Long> {
/**
* @return List
*
* @Author Aquan
* @Description
* @Date 2019.1.4 11:19
* @Param
* @return List
**/
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' ORDER BY post_date DESC", nativeQuery = true)
List<Post> findAllPost();
/**
* @return Integer
*
* @Author Aquan
* @Description
* @Date 2019.1.4 15:03
* @Param
* @return Integer
**/
@Query(value = "SELECT count(1) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post'", nativeQuery = true)
Integer totalAllPostCount();
/**
*
*
* @param year year
* @param month month
*
* @return List
*/
@Query(value = "SELECT *,YEAR(post_date) AS YEAR,MONTH(post_date) AS MONTH FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", nativeQuery = true)
@ -167,6 +175,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param year year
*
* @return List
*/
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' AND YEAR(post_date)=:year ORDER BY post_date DESC", nativeQuery = true)
@ -178,6 +187,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param year year
* @param month month
* @param pageable pageable
*
* @return Page
*/
@Query(value = "SELECT * FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", countQuery = "SELECT COUNT(*) FROM halo_post WHERE post_status=0 AND YEAR(post_date)=:year AND MONTH(post_date)=:month", nativeQuery = true)
@ -189,6 +199,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param category category
* @param status status
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable);
@ -199,6 +210,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param tag tag
* @param status status
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostsByTagsAndPostStatus(Tag tag, Integer status, Pageable pageable);
@ -207,6 +219,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param tag tag
*
* @return List
*/
List<Post> findPostsByTags(Tag tag);
@ -216,6 +229,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param keyword
* @param pageable
*
* @return Page
*/
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_title LIKE '%=:keyword%' OR post_content LIKE '%=:keyword%'", nativeQuery = true)
@ -225,6 +239,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param postStatus
*
* @return List<Post>
*/
List<Post> findPostsByPostTypeOrderByPostViewsDesc(String postStatus);
@ -242,6 +257,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
* @param status
* @param postType
*
* @return
*/
Integer countAllByPostStatusAndPostType(Integer status, String postType);
@ -250,8 +266,9 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param limit
*
* @return List
*/
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit",nativeQuery = true)
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true)
List<Post> getPostsByLimit(@Param(value = "limit") int limit);
}

View File

@ -26,6 +26,7 @@ public interface PostService {
*
*
* @param post Post
*
* @return Post
*/
Post save(Post post);
@ -34,6 +35,7 @@ public interface PostService {
*
*
* @param postId postId
*
* @return Post
*/
Post remove(Long postId);
@ -43,6 +45,7 @@ public interface PostService {
*
* @param postId postId
* @param status status
*
* @return Post
*/
Post updatePostStatus(Long postId, Integer status);
@ -58,6 +61,7 @@ public interface PostService {
*
*
* @param postType post or page
*
* @return List
*/
List<Post> findAll(String postType);
@ -67,6 +71,7 @@ public interface PostService {
*
* @param keyWord keyword
* @param pageable pageable
*
* @return List
*/
List<Post> searchPosts(String keyWord, Pageable pageable);
@ -77,6 +82,7 @@ public interface PostService {
* @param status 012
* @param postType post or page
* @param pageable
*
* @return Page
*/
Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable);
@ -85,6 +91,7 @@ public interface PostService {
*
*
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostByStatus(Pageable pageable);
@ -94,6 +101,7 @@ public interface PostService {
*
* @param status 012
* @param postType post or page
*
* @return List
*/
List<Post> findPostByStatus(Integer status, String postType);
@ -102,6 +110,7 @@ public interface PostService {
*
*
* @param postId postId
*
* @return Post
*/
Optional<Post> findByPostId(Long postId);
@ -111,6 +120,7 @@ public interface PostService {
*
* @param postId postId
* @param postType postType
*
* @return Post
*/
Post findByPostId(Long postId, String postType);
@ -120,6 +130,7 @@ public interface PostService {
*
* @param postUrl
* @param postType post or page
*
* @return Post
*/
Post findByPostUrl(String postUrl, String postType);
@ -132,20 +143,22 @@ public interface PostService {
List<Post> findPostLatest();
/**
* Id
*
*
* @param postDate postDate
* @return List
*
* @return Post
*/
List<Post> findByPostDateAfter(Date postDate);
Post getNextPost(Date postDate);
/**
* Id
*
*
* @param postDate postDate
* @return List
*
* @return Post
*/
List<Post> findByPostDateBefore(Date postDate);
Post getPrePost(Date postDate);
/**
*
@ -162,11 +175,12 @@ public interface PostService {
List<Archive> findPostGroupByYear();
/**
* @return List
*
* @Author Aquan
* @Description
* @Date 2019.1.4 11:14
* @Param
* @return List
**/
List<Archive> findAllPost();
@ -176,6 +190,7 @@ public interface PostService {
*
* @param year year
* @param month month
*
* @return List
*/
List<Post> findPostByYearAndMonth(String year, String month);
@ -186,6 +201,7 @@ public interface PostService {
* @param year year
* @param month month
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostByYearAndMonth(String year, String month, Pageable pageable);
@ -194,6 +210,7 @@ public interface PostService {
*
*
* @param year year
*
* @return List
*/
List<Post> findPostByYear(String year);
@ -203,6 +220,7 @@ public interface PostService {
*
* @param category category
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostByCategories(Category category, Pageable pageable);
@ -212,6 +230,7 @@ public interface PostService {
*
* @param tag tag
* @param pageable pageable
*
* @return Page
*/
Page<Post> findPostsByTags(Tag tag, Pageable pageable);
@ -221,6 +240,7 @@ public interface PostService {
*
* @param keyword
* @param pageable
*
* @return Page
*/
Page<Post> searchByKeywords(String keyword, Pageable pageable);
@ -236,6 +256,7 @@ public interface PostService {
*
*
* @param post post
*
* @return List
*/
List<Post> relatedPosts(Post post);
@ -251,6 +272,7 @@ public interface PostService {
*
*
* @param status
*
* @return
*/
Integer getCountByStatus(Integer status);
@ -259,6 +281,7 @@ public interface PostService {
* rss
*
* @param posts posts
*
* @return String
*/
String buildRss(List<Post> posts);
@ -267,6 +290,7 @@ public interface PostService {
* sitemap
*
* @param posts posts
*
* @return String
*/
String buildSiteMap(List<Post> posts);
@ -284,6 +308,7 @@ public interface PostService {
* @param post post
* @param cateList cateList
* @param tagList tagList
*
* @return Post Post
*/
Post buildCategoriesAndTags(Post post, List<String> cateList, @RequestParam("tagList") String tagList);
@ -292,6 +317,7 @@ public interface PostService {
*
*
* @param limit
*
* @return List
*/
List<Post> getRecentPosts(int limit);

View File

@ -55,6 +55,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param post Post
*
* @return Post
*/
@Override
@ -67,6 +68,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param postId postId
*
* @return Post
*/
@Override
@ -82,6 +84,7 @@ public class PostServiceImpl implements PostService {
*
* @param postId postId
* @param status status
*
* @return Post
*/
@Override
@ -116,6 +119,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param postType post or page
*
* @return List
*/
@Override
@ -129,6 +133,7 @@ public class PostServiceImpl implements PostService {
*
* @param keyWord keyword
* @param pageable pageable
*
* @return List
*/
@Override
@ -142,6 +147,7 @@ public class PostServiceImpl implements PostService {
* @param status 012
* @param postType post or page
* @param pageable
*
* @return Page
*/
@Override
@ -153,6 +159,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param pageable pageable
*
* @return Page
*/
@Override
@ -166,6 +173,7 @@ public class PostServiceImpl implements PostService {
*
* @param status 012
* @param postType post or page
*
* @return List
*/
@Override
@ -178,6 +186,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param postId postId
*
* @return Optional
*/
@Override
@ -189,6 +198,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param postId postId
*
* @return Post
*/
@Override
@ -201,6 +211,7 @@ public class PostServiceImpl implements PostService {
*
* @param postUrl
* @param postType post or page
*
* @return Post
*/
@Override
@ -221,28 +232,29 @@ public class PostServiceImpl implements PostService {
}
/**
*
*
*
* @param postDate
* @return List
* @param postDate postDate
*
* @return Post
*/
@Override
public List<Post> findByPostDateAfter(Date postDate) {
return postRepository.findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(postDate, PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc());
public Post getNextPost(Date postDate) {
return postRepository.queryNextPost(postDate);
}
/**
* Id
*
*
* @param postDate
* @return List
* @param postDate postDate
*
* @return Post
*/
@Override
public List<Post> findByPostDateBefore(Date postDate) {
return postRepository.findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(postDate, PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc());
public Post getPrePost(Date postDate) {
return postRepository.queryPrePost(postDate);
}
/**
*
*
@ -287,11 +299,12 @@ public class PostServiceImpl implements PostService {
}
/**
* @return List
*
* @Author Aquan
* @Description
* @Date 2019.1.4 11:16
* @Param
* @return List
**/
@Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'")
@ -314,6 +327,7 @@ public class PostServiceImpl implements PostService {
*
* @param year year
* @param month month
*
* @return List
*/
@Override
@ -326,6 +340,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param year year
*
* @return List
*/
@Override
@ -340,6 +355,7 @@ public class PostServiceImpl implements PostService {
* @param year year year
* @param month month month
* @param pageable pageable pageable
*
* @return Page
*/
@Override
@ -353,6 +369,7 @@ public class PostServiceImpl implements PostService {
* @param category category
* @param status status
* @param pageable pageable
*
* @return Page
*/
@Override
@ -367,6 +384,7 @@ public class PostServiceImpl implements PostService {
* @param tag tag
* @param status status
* @param pageable pageable
*
* @return Page
*/
@Override
@ -380,6 +398,7 @@ public class PostServiceImpl implements PostService {
*
* @param keyword
* @param pageable
*
* @return Page
*/
@Override
@ -402,6 +421,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param post post
*
* @return List
*/
@Override
@ -439,6 +459,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param status
*
* @return
*/
@Override
@ -450,6 +471,7 @@ public class PostServiceImpl implements PostService {
* rss
*
* @param posts posts
*
* @return String
*/
@Override
@ -467,6 +489,7 @@ public class PostServiceImpl implements PostService {
* sitemap
*
* @param posts posts
*
* @return String
*/
@Override
@ -494,6 +517,7 @@ public class PostServiceImpl implements PostService {
* @param post post
* @param cateList cateList
* @param tagList tagList
*
* @return Post Post
*/
@Override
@ -511,6 +535,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param limit
*
* @return List
*/
@Override

View File

@ -125,16 +125,17 @@ public class FrontArchiveController extends BaseController {
}
//获得当前文章的发布日期
final Date postDate = post.getPostDate();
//查询当前文章日期之前的所有文章
final List<Post> beforePosts = postService.findByPostDateBefore(postDate);
//查询当前文章日期之后的所有文章
final List<Post> afterPosts = postService.findByPostDateAfter(postDate);
if (null != beforePosts && beforePosts.size() > 0) {
model.addAttribute("beforePost", beforePosts.get(beforePosts.size() - 1));
final Post prePost = postService.getPrePost(postDate);
final Post nextPost = postService.getNextPost(postDate);
if (null != prePost) {
//兼容老版本主题
model.addAttribute("beforePost", prePost);
model.addAttribute("prePost",prePost);
}
if (null != afterPosts && afterPosts.size() > 0) {
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
if (null != nextPost) {
//兼容老版本主题
model.addAttribute("afterPost", nextPost);
model.addAttribute("nextPost",nextPost);
}
List<Comment> comments = null;
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) {

View File

@ -79,14 +79,14 @@
</div>
<div class="pagination">
<ul class="clearfix">
<#if afterPost??>
<#if nextPost??>
<li class="pre pagbuttons">
<a class="btn" role="navigation" href="/archives/${afterPost.postUrl}" title="${afterPost.postTitle}">上一篇</a>
<a class="btn" role="navigation" href="/archives/${nextPost.postUrl}" title="${nextPost.postTitle}">上一篇</a>
</li>
</#if>
<#if beforePost??>
<#if prePost??>
<li class="next pagbuttons">
<a class="btn" role="navigation" href="/archives/${beforePost.postUrl}" title="${beforePost.postTitle}">下一篇</a>
<a class="btn" role="navigation" href="/archives/${prePost.postUrl}" title="${prePost.postTitle}">下一篇</a>
</li>
</#if>
</ul>

View File

@ -1,8 +1,8 @@
<nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
<!-- Prev Nav -->
<#if afterPost??>
<a href="/archives/${afterPost.postUrl!}" id="post_nav-newer" class="prev-content">
<#if nextPost??>
<a href="/archives/${nextPost.postUrl!}" id="post_nav-newer" class="prev-content">
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
<i class="material-icons">arrow_back</i>
</button>
@ -14,8 +14,8 @@
<div class="section-spacer"></div>
<!-- Next Nav -->
<#if beforePost??>
<a href="/archives/${beforePost.postUrl!}" id="post_nav-older" class="next-content">
<#if prePost??>
<a href="/archives/${prePost.postUrl!}" id="post_nav-older" class="next-content">
旧篇
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">