👽 代码优化

pull/18/head
ruibaby 2018-07-01 11:35:50 +08:00
parent 1b1ec582ed
commit 2dd9b2918b
29 changed files with 254 additions and 104 deletions

View File

@ -3,6 +3,7 @@ package cc.ryanc.halo.model.dto;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
@ -14,7 +15,9 @@ import java.util.List;
* @date : 2018/1/20 * @date : 2018/1/20
*/ */
@Data @Data
public class Archive { public class Archive implements Serializable {
private static final long serialVersionUID = 1L;
/** /**
* *

View File

@ -36,14 +36,4 @@ public class HaloConst {
* user_session * user_session
*/ */
public static String USER_SESSION_KEY = "user_session"; public static String USER_SESSION_KEY = "user_session";
/**
* Post
*/
public static String POST_TYPE_POST = "post";
/**
* Post
*/
public static String POST_TYPE_PAGE = "page";
} }

View File

@ -0,0 +1,39 @@
package cc.ryanc.halo.model.enums;
/**
* @author : RYAN0UP
* @date : 2018/7/1
*/
public enum PostStatus {
/**
*
*/
PUBLISHED(0,"已发布"),
/**
* 稿
*/
DRAFT(1,"草稿"),
/**
*
*/
RECYCLE(2,"回收站");
private Integer code;
private String desc;
PostStatus(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public Integer getCode() {
return code;
}
public String getDesc() {
return desc;
}
}

View File

@ -0,0 +1,28 @@
package cc.ryanc.halo.model.enums;
/**
* @author : RYAN0UP
* @date : 2018/7/1
*/
public enum PostType {
/**
*
*/
POST_TYPE_POST("post"),
/**
*
*/
POST_TYPE_PAGE("page");
private String desc;
PostType(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}

View File

@ -0,0 +1,44 @@
package cc.ryanc.halo.model.enums;
/**
* @author : RYAN0UP
* @date : 2018/7/1
*/
public enum ResponseStatus {
/**
*
*/
SUCCESS(200,"OK"),
/**
*
*/
EMPTY(204,"No Content"),
/**
*
*/
ERROR(500,"Internal Server Error"),
/**
*
*/
NOTFOUND(404,"Not Found");
private Integer code;
private String msg;
ResponseStatus(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
}

View File

@ -1,6 +1,6 @@
package cc.ryanc.halo.model.tag; package cc.ryanc.halo.model.tag;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import freemarker.core.Environment; import freemarker.core.Environment;
import freemarker.template.*; import freemarker.template.*;
@ -33,7 +33,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
String method = map.get(METHOD_KEY).toString(); String method = map.get(METHOD_KEY).toString();
switch (method) { switch (method) {
case "postsCount": case "postsCount":
environment.setVariable("postsCount", builder.build().wrap(postService.findAllPosts(HaloConst.POST_TYPE_POST).size())); environment.setVariable("postsCount", builder.build().wrap(postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()).size()));
break; break;
case "archives": case "archives":
environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth())); environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth()));
@ -50,4 +50,4 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
} }
templateDirectiveBody.render(environment.getOut()); templateDirectiveBody.render(environment.getOut());
} }
} }

View File

@ -42,6 +42,13 @@ public interface PostService {
*/ */
Post updatePostStatus(Long postId, Integer status); Post updatePostStatus(Long postId, Integer status);
/**
*
*
* @param post post
*/
void updatePostView(Post post);
/** /**
* *
* *

View File

@ -4,7 +4,8 @@ import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.repository.PostRepository; import cc.ryanc.halo.repository.PostRepository;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
@ -75,6 +76,17 @@ public class PostServiceImpl implements PostService {
return postRepository.save(post.get()); return postRepository.save(post.get());
} }
/**
*
*
* @param post post
*/
@Override
public void updatePostView(Post post) {
post.setPostViews(post.getPostViews()+1);
postRepository.save(post);
}
/** /**
* *
* *
@ -83,7 +95,7 @@ public class PostServiceImpl implements PostService {
@Override @Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true) @CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public void updateAllSummary(Integer postSummary) { public void updateAllSummary(Integer postSummary) {
List<Post> posts = this.findAllPosts(HaloConst.POST_TYPE_POST); List<Post> posts = this.findAllPosts(PostType.POST_TYPE_POST.getDesc());
for (Post post : posts) { for (Post post : posts) {
String text = HtmlUtil.cleanHtmlTag(post.getPostContent()); String text = HtmlUtil.cleanHtmlTag(post.getPostContent());
if (text.length() > postSummary) { if (text.length() > postSummary) {
@ -153,7 +165,7 @@ public class PostServiceImpl implements PostService {
@Override @Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_page_'+#pageable.pageNumber") @Cacheable(value = POSTS_CACHE_NAME, key = "'posts_page_'+#pageable.pageNumber")
public Page<Post> findPostByStatus(Pageable pageable) { public Page<Post> findPostByStatus(Pageable pageable) {
return postRepository.findPostsByPostStatusAndPostType(0,HaloConst.POST_TYPE_POST,pageable); return postRepository.findPostsByPostStatusAndPostType(PostStatus.PUBLISHED.getCode(),PostType.POST_TYPE_POST.getDesc(),pageable);
} }
/** /**
@ -187,6 +199,7 @@ public class PostServiceImpl implements PostService {
* @return Post * @return Post
*/ */
@Override @Override
@Cacheable(value = POSTS_CACHE_NAME,key = "'posts_posturl_'+#postUrl+'_'+#postType")
public Post findByPostUrl(String postUrl, String postType) { public Post findByPostUrl(String postUrl, String postType) {
return postRepository.findPostByPostUrlAndPostType(postUrl, postType); return postRepository.findPostByPostUrlAndPostType(postUrl, postType);
} }
@ -210,7 +223,7 @@ public class PostServiceImpl implements PostService {
*/ */
@Override @Override
public List<Post> findByPostDateAfter(Date postDate) { public List<Post> findByPostDateAfter(Date postDate) {
return postRepository.findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(postDate, 0, HaloConst.POST_TYPE_POST); return postRepository.findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(postDate, PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc());
} }
/** /**
@ -221,7 +234,7 @@ public class PostServiceImpl implements PostService {
*/ */
@Override @Override
public List<Post> findByPostDateBefore(Date postDate) { public List<Post> findByPostDateBefore(Date postDate) {
return postRepository.findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(postDate, 0, HaloConst.POST_TYPE_POST); return postRepository.findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(postDate, PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc());
} }
@ -351,7 +364,7 @@ public class PostServiceImpl implements PostService {
@Override @Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_hot'") @Cacheable(value = POSTS_CACHE_NAME, key = "'posts_hot'")
public List<Post> hotPosts() { public List<Post> hotPosts() {
return postRepository.findPostsByPostTypeOrderByPostViewsDesc(HaloConst.POST_TYPE_POST); return postRepository.findPostsByPostTypeOrderByPostViewsDesc(PostType.POST_TYPE_POST.getDesc());
} }
/** /**

View File

@ -7,6 +7,7 @@ import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.LogsService; import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -69,7 +70,7 @@ public class AdminController extends BaseController {
@GetMapping(value = {"", "/index"}) @GetMapping(value = {"", "/index"})
public String index(Model model, HttpSession session) { public String index(Model model, HttpSession session) {
//查询文章条数 //查询文章条数
Integer postCount = postService.findAllPosts(HaloConst.POST_TYPE_POST).size(); Integer postCount = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()).size();
model.addAttribute("postCount", postCount); model.addAttribute("postCount", postCount);
//查询评论的条数 //查询评论的条数

View File

@ -5,6 +5,7 @@ import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.BackupDto; import cc.ryanc.halo.model.dto.BackupDto;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
@ -139,8 +140,8 @@ public class BackupController {
* @return JsonResult * @return JsonResult
*/ */
public JsonResult backupPosts() { public JsonResult backupPosts() {
List<Post> posts = postService.findAllPosts(HaloConst.POST_TYPE_POST); List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
posts.addAll(postService.findAllPosts(HaloConst.POST_TYPE_PAGE)); posts.addAll(postService.findAllPosts(PostType.POST_TYPE_PAGE.getDesc()));
try { try {
if(HaloUtils.getBackUps("posts").size()>10){ if(HaloUtils.getBackUps("posts").size()>10){
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/"); FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.User; import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -118,7 +119,7 @@ public class CommentController extends BaseController {
try { try {
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) { if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (StringUtils.equals(post.getPostType(), HaloConst.POST_TYPE_POST)) { if (StringUtils.equals(post.getPostType(), PostType.POST_TYPE_POST.getDesc())) {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
} else { } else {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
@ -210,7 +211,7 @@ public class CommentController extends BaseController {
map.put("blogTitle", HaloConst.OPTIONS.get("blog_title")); map.put("blogTitle", HaloConst.OPTIONS.get("blog_title"));
map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("commentAuthor", lastComment.getCommentAuthor());
map.put("pageName", lastComment.getPost().getPostTitle()); map.put("pageName", lastComment.getPost().getPostTitle());
if (StringUtils.equals(post.getPostType(), HaloConst.POST_TYPE_POST)) { if (StringUtils.equals(post.getPostType(), PostType.POST_TYPE_POST.getDesc())) {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
} else { } else {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.*;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.GalleryService;
import cc.ryanc.halo.service.LinkService; import cc.ryanc.halo.service.LinkService;
import cc.ryanc.halo.service.LogsService; import cc.ryanc.halo.service.LogsService;
@ -59,7 +60,7 @@ public class PageController {
*/ */
@GetMapping @GetMapping
public String pages(Model model) { public String pages(Model model) {
List<Post> posts = postService.findAllPosts(HaloConst.POST_TYPE_PAGE); List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_PAGE.getDesc());
model.addAttribute("pages", posts); model.addAttribute("pages", posts);
return "admin/admin_page"; return "admin/admin_page";
} }
@ -100,7 +101,7 @@ public class PageController {
Link backLink = linkService.saveByLink(link); Link backLink = linkService.saveByLink(link);
log.info("保存成功,数据为:" + backLink); log.info("保存成功,数据为:" + backLink);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
return "redirect:/admin/page/links"; return "redirect:/admin/page/links";
} }
@ -117,7 +118,7 @@ public class PageController {
Link link = linkService.removeByLinkId(linkId); Link link = linkService.removeByLinkId(linkId);
log.info("删除的友情链接:" + link); log.info("删除的友情链接:" + link);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
return "redirect:/admin/page/links"; return "redirect:/admin/page/links";
} }
@ -218,7 +219,7 @@ public class PageController {
//发表用户 //发表用户
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY); User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
post.setUser(user); post.setUser(user);
post.setPostType(HaloConst.POST_TYPE_PAGE); post.setPostType(PostType.POST_TYPE_PAGE.getDesc());
if(null!=post.getPostId()){ if(null!=post.getPostId()){
post.setPostViews(postService.findByPostId(post.getPostId()).get().getPostViews()); post.setPostViews(postService.findByPostId(post.getPostId()).get().getPostViews());
post.setPostDate(postService.findByPostId(post.getPostId()).get().getPostDate()); post.setPostDate(postService.findByPostId(post.getPostId()).get().getPostDate());
@ -260,7 +261,7 @@ public class PageController {
@GetMapping(value = "/checkUrl") @GetMapping(value = "/checkUrl")
@ResponseBody @ResponseBody
public boolean checkUrlExists(@PathParam("postUrl") String postUrl) { public boolean checkUrlExists(@PathParam("postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_PAGE); Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
// TODO 还没写完 // TODO 还没写完
if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) { if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) {
return true; return true;

View File

@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.*;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.LogsService; import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -86,11 +88,11 @@ public class PostController extends BaseController {
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(value = "size", defaultValue = "10") Integer size) {
Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(page, size, sort); Pageable pageable = PageRequest.of(page, size, sort);
Page<Post> posts = postService.findPostByStatus(status, HaloConst.POST_TYPE_POST, pageable); Page<Post> posts = postService.findPostByStatus(status, PostType.POST_TYPE_POST.getDesc(), pageable);
model.addAttribute("posts", posts); model.addAttribute("posts", posts);
model.addAttribute("publishCount", postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getTotalElements()); model.addAttribute("publishCount", postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
model.addAttribute("draftCount", postService.findPostByStatus(1, HaloConst.POST_TYPE_POST, pageable).getTotalElements()); model.addAttribute("draftCount", postService.findPostByStatus(PostStatus.DRAFT.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
model.addAttribute("trashCount", postService.findPostByStatus(2, HaloConst.POST_TYPE_POST, pageable).getTotalElements()); model.addAttribute("trashCount", postService.findPostByStatus(PostStatus.RECYCLE.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
model.addAttribute("status", status); model.addAttribute("status", status);
return "admin/admin_post"; return "admin/admin_post";
} }
@ -115,7 +117,7 @@ public class PostController extends BaseController {
Pageable pageable = PageRequest.of(page, size, sort); Pageable pageable = PageRequest.of(page, size, sort);
model.addAttribute("posts", postService.searchPosts(keyword, pageable)); model.addAttribute("posts", postService.searchPosts(keyword, pageable));
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
return "admin/admin_post"; return "admin/admin_post";
} }
@ -259,10 +261,10 @@ public class PostController extends BaseController {
@GetMapping("/throw") @GetMapping("/throw")
public String moveToTrash(@RequestParam("postId") Long postId, @RequestParam("status") Integer status) { public String moveToTrash(@RequestParam("postId") Long postId, @RequestParam("status") Integer status) {
try { try {
postService.updatePostStatus(postId, 2); postService.updatePostStatus(postId, PostStatus.RECYCLE.getCode());
log.info("编号为" + postId + "的文章已被移到回收站"); log.info("编号为" + postId + "的文章已被移到回收站");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
return "redirect:/admin/posts?status=" + status; return "redirect:/admin/posts?status=" + status;
} }
@ -277,10 +279,10 @@ public class PostController extends BaseController {
public String moveToPublish(@RequestParam("postId") Long postId, public String moveToPublish(@RequestParam("postId") Long postId,
@RequestParam("status") Integer status) { @RequestParam("status") Integer status) {
try { try {
postService.updatePostStatus(postId, 0); postService.updatePostStatus(postId, PostStatus.PUBLISHED.getCode());
log.info("编号为" + postId + "的文章已改变为发布状态"); log.info("编号为" + postId + "的文章已改变为发布状态");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
return "redirect:/admin/posts?status=" + status; return "redirect:/admin/posts?status=" + status;
} }
@ -298,9 +300,9 @@ public class PostController extends BaseController {
postService.removeByPostId(postId); postService.removeByPostId(postId);
logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date())); logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:", e.getMessage());
} }
if (StringUtils.equals(HaloConst.POST_TYPE_POST, postType)) { if (StringUtils.equals(PostType.POST_TYPE_POST.getDesc(), postType)) {
return "redirect:/admin/posts?status=2"; return "redirect:/admin/posts?status=2";
} }
return "redirect:/admin/page"; return "redirect:/admin/page";
@ -348,7 +350,7 @@ public class PostController extends BaseController {
@ResponseBody @ResponseBody
public boolean checkUrlExists(@PathParam("postUrl") String postUrl) { public boolean checkUrlExists(@PathParam("postUrl") String postUrl) {
postUrl = urlFilter(postUrl); postUrl = urlFilter(postUrl);
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_POST); Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
return null != post; return null != post;
} }
@ -365,7 +367,7 @@ public class PostController extends BaseController {
return false; return false;
} }
String blogUrl = HaloConst.OPTIONS.get("blog_url"); String blogUrl = HaloConst.OPTIONS.get("blog_url");
List<Post> posts = postService.findAllPosts(HaloConst.POST_TYPE_POST); List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
StringBuilder urls = new StringBuilder(); StringBuilder urls = new StringBuilder();
for (Post post : posts) { for (Post post : posts) {
urls.append(blogUrl); urls.append(blogUrl);

View File

@ -14,7 +14,6 @@ import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.ehcache.CacheManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -30,9 +31,9 @@ public class ApiArchivesController {
public JsonResult archivesYear(){ public JsonResult archivesYear(){
List<Archive> archives = postService.findPostGroupByYear(); List<Archive> archives = postService.findPostGroupByYear();
if(null!=archives || archives.size()>0){ if(null!=archives || archives.size()>0){
return new JsonResult(200,"success",archives); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
}else { }else {
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
@ -45,9 +46,9 @@ public class ApiArchivesController {
public JsonResult archivesYearAndMonth(){ public JsonResult archivesYearAndMonth(){
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
if(null!=archives || archives.size()>0){ if(null!=archives || archives.size()>0){
return new JsonResult(200,"success",archives); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
}else { }else {
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Category; import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -31,9 +32,9 @@ public class ApiCategoryController {
public JsonResult categories(){ public JsonResult categories(){
List<Category> categories = categoryService.findAllCategories(); List<Category> categories = categoryService.findAllCategories();
if(null!=categories && categories.size()>0){ if(null!=categories && categories.size()>0){
return new JsonResult(200,"success",categories); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),categories);
}else{ }else{
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
@ -47,9 +48,9 @@ public class ApiCategoryController {
public JsonResult categories(@PathVariable("cateUrl") String cateUrl){ public JsonResult categories(@PathVariable("cateUrl") String cateUrl){
Category category = categoryService.findByCateUrl(cateUrl); Category category = categoryService.findByCateUrl(cateUrl);
if(null!=category){ if(null!=category){
return new JsonResult(200,"success",category); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),category);
}else{ }else{
return new JsonResult(404,"not found"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Gallery; import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.GalleryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -32,9 +33,9 @@ public class ApiGalleryController {
public JsonResult galleries(){ public JsonResult galleries(){
List<Gallery> galleries = galleryService.findAllGalleries(); List<Gallery> galleries = galleryService.findAllGalleries();
if(null!=galleries && galleries.size()>0){ if(null!=galleries && galleries.size()>0){
return new JsonResult(200,"success",galleries); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),galleries);
}else { }else {
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
@ -48,9 +49,9 @@ public class ApiGalleryController {
public JsonResult galleries(@PathVariable("id") Long id){ public JsonResult galleries(@PathVariable("id") Long id){
Optional<Gallery> gallery = galleryService.findByGalleryId(id); Optional<Gallery> gallery = galleryService.findByGalleryId(id);
if(gallery.isPresent()){ if(gallery.isPresent()){
return new JsonResult(200,"success",gallery.get()); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),gallery.get());
}else{ }else{
return new JsonResult(404,"not found"); return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Link; import cc.ryanc.halo.model.domain.Link;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.LinkService; import cc.ryanc.halo.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -30,9 +31,9 @@ public class ApiLinkController {
public JsonResult links(){ public JsonResult links(){
List<Link> links = linkService.findAllLinks(); List<Link> links = linkService.findAllLinks();
if(null!=links && links.size()>0){ if(null!=links && links.size()>0){
return new JsonResult(200,"success",links); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),links);
}else{ }else{
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Menu; import cc.ryanc.halo.model.domain.Menu;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.MenuService; import cc.ryanc.halo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -30,9 +31,9 @@ public class ApiMenuController {
public JsonResult menus(){ public JsonResult menus(){
List<Menu> menus = menuService.findAllMenus(); List<Menu> menus = menuService.findAllMenus();
if(null!=menus && menus.size()>0){ if(null!=menus && menus.size()>0){
return new JsonResult(200,"success",menus); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),menus);
}else{ }else{
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
} }

View File

@ -1,8 +1,9 @@
package cc.ryanc.halo.web.controller.api; package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -28,11 +29,11 @@ public class ApiPageController {
*/ */
@GetMapping(value = "/{postUrl}") @GetMapping(value = "/{postUrl}")
public JsonResult pages(@PathVariable(value = "postUrl") String postUrl){ public JsonResult pages(@PathVariable(value = "postUrl") String postUrl){
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_PAGE); Post post = postService.findByPostUrl(postUrl,PostType.POST_TYPE_PAGE.getDesc());
if(null!=post){ if(null!=post){
return new JsonResult(200,"success",post); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
}else{ }else{
return new JsonResult(404,"not found"); return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
} }
} }
} }

View File

@ -3,6 +3,9 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -42,20 +45,20 @@ public class ApiPostController {
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts")); size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
} }
Pageable pageable = PageRequest.of(page - 1, size, sort); Pageable pageable = PageRequest.of(page - 1, size, sort);
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable); Page<Post> posts = postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable);
if (null == posts) { if (null == posts) {
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
return new JsonResult(200,"success",posts); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),posts);
} }
@GetMapping(value = "/hot") @GetMapping(value = "/hot")
public JsonResult hotPosts() { public JsonResult hotPosts() {
List<Post> posts = postService.hotPosts(); List<Post> posts = postService.hotPosts();
if (null != posts && posts.size() > 0) { if (null != posts && posts.size() > 0) {
return new JsonResult(200, "success", posts); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(), posts);
} else { } else {
return new JsonResult(200, "empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
@ -67,11 +70,11 @@ public class ApiPostController {
*/ */
@GetMapping(value = "/{postUrl}") @GetMapping(value = "/{postUrl}")
public JsonResult posts(@PathVariable(value = "postUrl") String postUrl){ public JsonResult posts(@PathVariable(value = "postUrl") String postUrl){
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST); Post post = postService.findByPostUrl(postUrl,PostType.POST_TYPE_POST.getDesc());
if(null!=post){ if(null!=post){
return new JsonResult(200,"success",post); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
}else { }else {
return new JsonResult(404,"not found"); return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.TagService; import cc.ryanc.halo.service.TagService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -31,9 +32,9 @@ public class ApiTagController {
public JsonResult tags(){ public JsonResult tags(){
List<Tag> tags = tagService.findAllTags(); List<Tag> tags = tagService.findAllTags();
if(null!=tags && tags.size()>0){ if(null!=tags && tags.size()>0){
return new JsonResult(200,"success",tags); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tags);
}else{ }else{
return new JsonResult(200,"empty"); return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
} }
} }
@ -47,9 +48,9 @@ public class ApiTagController {
public JsonResult tags(@PathVariable("tagUrl") String tagUrl){ public JsonResult tags(@PathVariable("tagUrl") String tagUrl){
Tag tag = tagService.findByTagUrl(tagUrl); Tag tag = tagService.findByTagUrl(tagUrl);
if(null!=tag){ if(null!=tag){
return new JsonResult(200,"success",tag); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tag);
}else{ }else{
return new JsonResult(404,"not found"); return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
} }
} }
} }

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.model.domain.User; import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatus;
import cc.ryanc.halo.service.UserService; import cc.ryanc.halo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -27,6 +28,6 @@ public class ApiUserController {
@GetMapping @GetMapping
public JsonResult user(){ public JsonResult user(){
User user = userService.findUser(); User user = userService.findUser();
return new JsonResult(200,"success",user); return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),user);
} }
} }

View File

@ -2,7 +2,7 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
@ -61,7 +61,7 @@ public class FrontArchiveController extends BaseController {
//所有文章数据分页material主题适用 //所有文章数据分页material主题适用
Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(page - 1, 5, sort); Pageable pageable = PageRequest.of(page - 1, 5, sort);
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable); Page<Post> posts = postService.findPostByStatus(0, PostType.POST_TYPE_POST.getDesc(), pageable);
if(null==posts){ if(null==posts){
return this.renderNotFound(); return this.renderNotFound();
} }
@ -98,7 +98,7 @@ public class FrontArchiveController extends BaseController {
*/ */
@GetMapping(value = "{postUrl}") @GetMapping(value = "{postUrl}")
public String getPost(@PathVariable String postUrl, Model model) { public String getPost(@PathVariable String postUrl, Model model) {
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_POST); Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
if(null==post || post.getPostStatus()!=0){ if(null==post || post.getPostStatus()!=0){
return this.renderNotFound(); return this.renderNotFound();
} }
@ -120,8 +120,7 @@ public class FrontArchiveController extends BaseController {
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0); Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0);
model.addAttribute("post", post); model.addAttribute("post", post);
model.addAttribute("comments",comments); model.addAttribute("comments",comments);
post.setPostViews(post.getPostViews()+1); postService.updatePostView(post);
postService.saveByPost(post);
return this.render("post"); return this.render("post");
} }
} }

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -149,7 +150,7 @@ public class FrontCommentController {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("author", userService.findUser().getUserDisplayName()); map.put("author", userService.findUser().getUserDisplayName());
map.put("pageName", post.getPostTitle()); map.put("pageName", post.getPostTitle());
if (StringUtils.equals(post.getPostType(), HaloConst.POST_TYPE_POST)) { if (StringUtils.equals(post.getPostType(), PostType.POST_TYPE_POST.getDesc())) {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
} else { } else {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
@ -189,7 +190,7 @@ public class FrontCommentController {
map.put("blogTitle",HaloConst.OPTIONS.get("blog_title")); map.put("blogTitle",HaloConst.OPTIONS.get("blog_title"));
map.put("commentAuthor",lastComment.getCommentAuthor()); map.put("commentAuthor",lastComment.getCommentAuthor());
map.put("pageName",lastComment.getPost().getPostTitle()); map.put("pageName",lastComment.getPost().getPostTitle());
if (StringUtils.equals(post.getPostType(), HaloConst.POST_TYPE_POST)) { if (StringUtils.equals(post.getPostType(), PostType.POST_TYPE_POST.getDesc())) {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
} else { } else {
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());

View File

@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -40,7 +41,7 @@ public class FrontOthersController {
//获取文章列表并根据时间排序 //获取文章列表并根据时间排序
Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort); Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable); Page<Post> postsPage = postService.findPostByStatus(0, PostType.POST_TYPE_POST.getDesc(), pageable);
List<Post> posts = postsPage.getContent(); List<Post> posts = postsPage.getContent();
return postService.buildRss(posts); return postService.buildRss(posts);
} }
@ -56,7 +57,7 @@ public class FrontOthersController {
//获取文章列表并根据时间排序 //获取文章列表并根据时间排序
Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(0, 999, sort); Pageable pageable = PageRequest.of(0, 999, sort);
Page<Post> postsPage = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable); Page<Post> postsPage = postService.findPostByStatus(0, PostType.POST_TYPE_POST.getDesc(), pageable);
List<Post> posts = postsPage.getContent(); List<Post> posts = postsPage.getContent();
return postService.buildSiteMap(posts); return postService.buildSiteMap(posts);
} }

View File

@ -3,7 +3,7 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Gallery; import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.GalleryService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -67,7 +67,7 @@ public class FrontPageController extends BaseController {
*/ */
@GetMapping(value = "/p/{postUrl}") @GetMapping(value = "/p/{postUrl}")
public String getPage(@PathVariable(value = "postUrl") String postUrl, Model model) { public String getPage(@PathVariable(value = "postUrl") String postUrl, Model model) {
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_PAGE); Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
Sort sort = new Sort(Sort.Direction.DESC,"commentDate"); Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
Pageable pageable = PageRequest.of(0,999,sort); Pageable pageable = PageRequest.of(0,999,sort);
@ -77,8 +77,7 @@ public class FrontPageController extends BaseController {
} }
model.addAttribute("comments",comments); model.addAttribute("comments",comments);
model.addAttribute("post", post); model.addAttribute("post", post);
post.setPostViews(post.getPostViews()+1); postService.updatePostView(post);
postService.saveByPost(post);
return this.render("page"); return this.render("page");
} }
} }

View File

@ -55,7 +55,24 @@
<!-- Import CSS --> <!-- Import CSS -->
<style id="material_css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("material_css","/material/source/css/material.min.css?Z7a72R1E4SxzBKR/WGctOA==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";}, false)</script> <style id="material_css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("material_css","/material/source/css/material.min.css?Z7a72R1E4SxzBKR/WGctOA==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";}, false)</script>
<style id="style_css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("style_css","/material/source/css/style.min.css?MKetZV3cUTfDxvMffaOezg==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";}, false)</script> <style id="style_css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("style_css","/material/source/css/style.min.css?MKetZV3cUTfDxvMffaOezg==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";}, false)</script>
<style id="prettify_css"></style>
<script>
void 0 === window.lsLoadCSSMaxNums && (window.lsLoadCSSMaxNums = 0), window.lsLoadCSSMaxNums++, lsloader.load(
"prettify_css", "/material/source/css/prettify.min.css?zp8STOU9v89XWFEnN+6YmQ==",
function () {
void 0 === window.lsLoadCSSNums && (window.lsLoadCSSNums = 0), ++window.lsLoadCSSNums == window.lsLoadCSSMaxNums &&
(document.documentElement.style.display = "")
}, !1)
</script>
<style id="prettify_theme"></style>
<script>
void 0 === window.lsLoadCSSMaxNums && (window.lsLoadCSSMaxNums = 0), window.lsLoadCSSMaxNums++, lsloader.load(
"prettify_theme", "/material/source/css/prettify/github-v2.min.css?AfzKxt++K+/lhZBlSjnxwg==",
function () {
void 0 === window.lsLoadCSSNums && (window.lsLoadCSSNums = 0), ++window.lsLoadCSSNums == window.lsLoadCSSMaxNums &&
(document.documentElement.style.display = "")
}, !1)
</script>
<#if options.theme_material_scheme?default('Paradox') == "Isolation"> <#if options.theme_material_scheme?default('Paradox') == "Isolation">
<link rel="stylesheet" href="/material/source/css/fontawesome.min.css"> <link rel="stylesheet" href="/material/source/css/fontawesome.min.css">
</#if> </#if>
@ -129,4 +146,4 @@
<% } %> <% } %>
--> -->
</head> </head>
</#macro> </#macro>

View File

@ -17,18 +17,11 @@
</script> </script>
<!-- Import prettify js --> <!-- Import prettify js -->
<script>
lsloader.load("prettify_js", "/material/source/js/prettify.min.js?WN07fivHQSMKWy7BmHBB6w==", !0)
</script>
<!-- <!--
<% if (theme.prettify.enable){ %>
<% if ( (is_post()) ) { %>
<% if(theme.vendors.prettify) { %>
<%- jsLsload({path:(theme.vendors.prettify),key:'prettify_js'}) %>
<% } else if(theme.vendors.materialcdn) { %>
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/prettify.min.js'),key:'prettify_js'}) %>
<% } else { %>
<%- jsLsload({path:('js/prettify.min.js'),key:'prettify_js'}) %>
<% } %>
<% } %>
<% } %>
<% if (theme.hanabi.enable) { %> <% if (theme.hanabi.enable) { %>
<% if(theme.vendors.materialcdn) { %> <% if(theme.vendors.materialcdn) { %>
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/hanabi-browser-bundle.js'),key:'hanabi'}) %> <%- jsLsload({path:(theme.vendors.materialcdn + '/js/hanabi-browser-bundle.js'),key:'hanabi'}) %>
@ -96,4 +89,4 @@
} }
})() })()
console.log('\n %c © Material Theme | Version: 1.5.2 | https://github.com/viosey/hexo-theme-material %c \n', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-left-radius:5px;border-bottom-left-radius:5px;', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-right-radius:5px;border-bottom-right-radius:5px;'); console.log('\n %c © Material Theme | Version: 1.5.2 | https://github.com/viosey/hexo-theme-material %c \n', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-left-radius:5px;border-bottom-left-radius:5px;', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-right-radius:5px;border-bottom-right-radius:5px;');
</script> </script>