👽 添加小程序返回所有文章Api

pull/73/head
853029827@qq.com 2019-01-04 15:41:43 +08:00
parent 10b802b3a9
commit 2db77321e0
4 changed files with 75 additions and 0 deletions

View File

@ -130,6 +130,29 @@ public interface PostRepository extends JpaRepository<Post, Long> {
@Query(value = "SELECT YEAR(post_date) AS YEAR,COUNT(*) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post' GROUP BY YEAR(post_date) ORDER BY YEAR DESC", nativeQuery = true)
List<Object[]> findPostGroupByYear();
/**
* @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();
/**
* @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();
/**
*
*

View File

@ -161,6 +161,16 @@ public interface PostService {
*/
List<Archive> findPostGroupByYear();
/**
* @Author Aquan
* @Description
* @Date 2019.1.4 11:14
* @Param
* @return List
**/
List<Archive> findAllPost();
/**
*
*

View File

@ -286,6 +286,29 @@ public class PostServiceImpl implements PostService {
return archives;
}
/**
* @Author Aquan
* @Description
* @Date 2019.1.4 11:16
* @Param
* @return List
**/
@Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'")
public List<Archive> findAllPost() {
final List<Post> posts = postRepository.findAllPost();
final Integer count = postRepository.totalAllPostCount();
final List<Archive> archives = new ArrayList<>();
Archive archive = null;
archive = new Archive();
archive.setCount(String.valueOf(count));
archive.setPosts(posts);
archives.add(archive);
return archives;
}
/**
*
*

View File

@ -135,4 +135,23 @@ public class ApiArchivesController {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
}
}
/**
* @Author Aquan
* @Description
* @Date 2019.1.4 11:06
* @Param
* @return JsonResult
**/
@GetMapping(value = "/all")
public JsonResult archivesAllPost() {
final List<Archive> archive = postService.findAllPost();
if (null != archive && archive.size() > 0) {
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), archive);
} else {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
}
}
}