mirror of https://github.com/halo-dev/halo
commit
366936e268
|
@ -44,7 +44,7 @@ Let's start: http://localhost:8090
|
|||
|
||||
## Demo 演示
|
||||
|
||||
[测试地址](http://39.105.26.52),[测试后台(admin,123456)](http://39.105.26.52/admin)
|
||||
[测试地址](http://149.28.63.223),[测试后台(admin,123456)](http://149.28.63.223/admin)
|
||||
|
||||
[Ryan0up'S Blog](https://ryanc.cc)
|
||||
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -92,6 +92,11 @@
|
|||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- freemarker依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
|
||||
/**
|
||||
* @author RYAN0UP
|
||||
|
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.config;
|
||||
|
||||
import cc.ryanc.halo.web.interceptor.ApiInterceptor;
|
||||
import cc.ryanc.halo.web.interceptor.InstallInterceptor;
|
||||
import cc.ryanc.halo.web.interceptor.LoginInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -30,6 +31,9 @@ public class MvcConfig implements WebMvcConfigurer {
|
|||
@Autowired
|
||||
private InstallInterceptor installInterceptor;
|
||||
|
||||
@Autowired
|
||||
private ApiInterceptor apiInterceptor;
|
||||
|
||||
/**
|
||||
* 注册拦截器
|
||||
*
|
||||
|
@ -48,6 +52,8 @@ public class MvcConfig implements WebMvcConfigurer {
|
|||
.excludePathPatterns("/install")
|
||||
.excludePathPatterns("/install/do")
|
||||
.excludePathPatterns("/static/**");
|
||||
registry.addInterceptor(apiInterceptor)
|
||||
.addPathPatterns("/api/**");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.model.dto;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +15,9 @@ import java.util.List;
|
|||
* @date : 2018/1/20
|
||||
*/
|
||||
@Data
|
||||
public class Archive {
|
||||
public class Archive implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 年份
|
||||
|
|
|
@ -36,14 +36,4 @@ public class HaloConst {
|
|||
* 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";
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import java.io.Serializable;
|
|||
@Data
|
||||
public class Theme implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主题名称
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
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 freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
|
@ -33,7 +33,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
|
|||
String method = map.get(METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
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;
|
||||
case "archives":
|
||||
environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth()));
|
||||
|
|
|
@ -42,6 +42,13 @@ public interface PostService {
|
|||
*/
|
||||
Post updatePostStatus(Long postId, Integer status);
|
||||
|
||||
/**
|
||||
* 修改文章阅读量
|
||||
*
|
||||
* @param post post
|
||||
*/
|
||||
void updatePostView(Post post);
|
||||
|
||||
/**
|
||||
* 批量修改摘要
|
||||
*
|
||||
|
@ -76,7 +83,7 @@ public interface PostService {
|
|||
List<Post> searchPosts(String keyWord, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页
|
||||
* 根据文章状态查询 分页,用于后台管理
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
|
@ -85,6 +92,13 @@ public interface PostService {
|
|||
*/
|
||||
Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,首页分页
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByStatus(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章状态查询
|
||||
*
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Attachment;
|
|||
import cc.ryanc.halo.repository.AttachmentRepository;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -21,6 +23,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
@Autowired
|
||||
private AttachmentRepository attachmentRepository;
|
||||
|
||||
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
|
||||
|
||||
/**
|
||||
* 新增附件信息
|
||||
*
|
||||
|
@ -28,6 +32,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
* @return Attachment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Attachment saveByAttachment(Attachment attachment) {
|
||||
return attachmentRepository.save(attachment);
|
||||
}
|
||||
|
@ -38,6 +43,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = ATTACHMENTS_CACHE_NAME, key = "'attachment'")
|
||||
public List<Attachment> findAllAttachments() {
|
||||
return attachmentRepository.findAll();
|
||||
}
|
||||
|
@ -71,6 +77,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
* @return Attachment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Attachment removeByAttachId(Long attachId) {
|
||||
Optional<Attachment> attachment = this.findByAttachId(attachId);
|
||||
attachmentRepository.delete(attachment.get());
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Category;
|
|||
import cc.ryanc.halo.repository.CategoryRepository;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -20,6 +22,8 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
@Autowired
|
||||
private CategoryRepository categoryRepository;
|
||||
|
||||
private static final String CATEGORIES_CACHE_NAME = "categories";
|
||||
|
||||
/**
|
||||
* 保存/修改分类目录
|
||||
*
|
||||
|
@ -27,6 +31,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Category saveByCategory(Category category) {
|
||||
return categoryRepository.save(category);
|
||||
}
|
||||
|
@ -38,6 +43,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CATEGORIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Category removeByCateId(Long cateId) {
|
||||
Optional<Category> category = this.findByCateId(cateId);
|
||||
categoryRepository.delete(category.get());
|
||||
|
@ -50,6 +56,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = CATEGORIES_CACHE_NAME, key = "'category'")
|
||||
public List<Category> findAllCategories() {
|
||||
return categoryRepository.findAll();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ import cc.ryanc.halo.model.domain.Post;
|
|||
import cc.ryanc.halo.repository.CommentRepository;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -22,12 +25,15 @@ public class CommentServiceImpl implements CommentService {
|
|||
@Autowired
|
||||
private CommentRepository commentRepository;
|
||||
|
||||
private static final String COMMENTS_CACHE_NAME = "comments";
|
||||
|
||||
/**
|
||||
* 新增评论
|
||||
*
|
||||
* @param comment comment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public void saveByComment(Comment comment) {
|
||||
commentRepository.save(comment);
|
||||
}
|
||||
|
@ -39,6 +45,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
* @return Optional
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Optional<Comment> removeByCommentId(Long commentId) {
|
||||
Optional<Comment> comment = this.findCommentById(commentId);
|
||||
commentRepository.delete(comment.get());
|
||||
|
@ -63,6 +70,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = COMMENTS_CACHE_NAME, key = "'comments_status_'+#status")
|
||||
public List<Comment> findAllComments(Integer status) {
|
||||
return commentRepository.findCommentsByCommentStatus(status);
|
||||
}
|
||||
|
@ -73,6 +81,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
* @return List<Comment></>
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = COMMENTS_CACHE_NAME, key = "'comment'")
|
||||
public List<Comment> findAllComments() {
|
||||
return commentRepository.findAll();
|
||||
}
|
||||
|
@ -85,6 +94,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
* @return Comment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Comment updateCommentStatus(Long commentId, Integer status) {
|
||||
Optional<Comment> comment = findCommentById(commentId);
|
||||
comment.get().setCommentStatus(status);
|
||||
|
@ -133,6 +143,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = COMMENTS_CACHE_NAME, key = "'comments_latest'")
|
||||
public List<Comment> findCommentsLatest() {
|
||||
return commentRepository.findTopFive();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Gallery;
|
|||
import cc.ryanc.halo.repository.GalleryRepository;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -21,6 +23,8 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
@Autowired
|
||||
private GalleryRepository galleryRepository;
|
||||
|
||||
private static final String GALLERIES_CACHE_NAME = "galleries";
|
||||
|
||||
/**
|
||||
* 保存图片
|
||||
*
|
||||
|
@ -28,6 +32,7 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
* @return Gallery
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery saveByGallery(Gallery gallery) {
|
||||
return galleryRepository.save(gallery);
|
||||
}
|
||||
|
@ -39,6 +44,7 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
* @return Gallery
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery removeByGalleryId(Long galleryId) {
|
||||
Optional<Gallery> gallery = this.findByGalleryId(galleryId);
|
||||
galleryRepository.delete(gallery.get());
|
||||
|
@ -52,6 +58,7 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
* @return Gallery
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery updateByGallery(Gallery gallery) {
|
||||
return galleryRepository.save(gallery);
|
||||
}
|
||||
|
@ -73,6 +80,7 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = GALLERIES_CACHE_NAME, key = "'gallery'")
|
||||
public List<Gallery> findAllGalleries() {
|
||||
return galleryRepository.findAll();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Link;
|
|||
import cc.ryanc.halo.repository.LinkRepository;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -19,6 +21,10 @@ public class LinkServiceImpl implements LinkService {
|
|||
@Autowired
|
||||
private LinkRepository linkRepository;
|
||||
|
||||
private static final String LINKS_CACHE_KEY = "'link'";
|
||||
|
||||
private static final String LINKS_CACHE_NAME = "links";
|
||||
|
||||
/**
|
||||
* 新增/修改友情链接
|
||||
*
|
||||
|
@ -26,6 +32,7 @@ public class LinkServiceImpl implements LinkService {
|
|||
* @return Link
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = LINKS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Link saveByLink(Link link) {
|
||||
return linkRepository.save(link);
|
||||
}
|
||||
|
@ -37,6 +44,7 @@ public class LinkServiceImpl implements LinkService {
|
|||
* @return Link
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = LINKS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Link removeByLinkId(Long linkId) {
|
||||
Optional<Link> link = this.findByLinkId(linkId);
|
||||
linkRepository.delete(link.get());
|
||||
|
@ -49,6 +57,7 @@ public class LinkServiceImpl implements LinkService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = LINKS_CACHE_NAME, key = LINKS_CACHE_KEY)
|
||||
public List<Link> findAllLinks() {
|
||||
return linkRepository.findAll();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Menu;
|
|||
import cc.ryanc.halo.repository.MenuRepository;
|
||||
import cc.ryanc.halo.service.MenuService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -19,12 +21,17 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Autowired
|
||||
private MenuRepository menuRepository;
|
||||
|
||||
private static final String MENUS_CACHE_KEY = "'menu'";
|
||||
|
||||
private static final String MENUS_CACHE_NAME = "menus";
|
||||
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = MENUS_CACHE_NAME, key = MENUS_CACHE_KEY)
|
||||
public List<Menu> findAllMenus() {
|
||||
return menuRepository.findAll();
|
||||
}
|
||||
|
@ -36,6 +43,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
* @return Menu
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = MENUS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Menu saveByMenu(Menu menu) {
|
||||
return menuRepository.save(menu);
|
||||
}
|
||||
|
@ -47,6 +55,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
* @return Menu
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = MENUS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Menu removeByMenuId(Long menuId) {
|
||||
Optional<Menu> menu = this.findByMenuId(menuId);
|
||||
menuRepository.delete(menu.get());
|
||||
|
|
|
@ -4,12 +4,16 @@ import cc.ryanc.halo.model.domain.Category;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
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.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -29,6 +33,8 @@ public class PostServiceImpl implements PostService {
|
|||
@Autowired
|
||||
private PostRepository postRepository;
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
/**
|
||||
* 保存文章
|
||||
*
|
||||
|
@ -36,6 +42,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Post saveByPost(Post post) {
|
||||
return postRepository.save(post);
|
||||
}
|
||||
|
@ -47,6 +54,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Post removeByPostId(Long postId) {
|
||||
Optional<Post> post = this.findByPostId(postId);
|
||||
postRepository.delete(post.get());
|
||||
|
@ -61,20 +69,33 @@ public class PostServiceImpl implements PostService {
|
|||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Post updatePostStatus(Long postId, Integer status) {
|
||||
Optional<Post> post = this.findByPostId(postId);
|
||||
post.get().setPostStatus(status);
|
||||
return postRepository.save(post.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章阅读量
|
||||
*
|
||||
* @param post post
|
||||
*/
|
||||
@Override
|
||||
public void updatePostView(Post post) {
|
||||
post.setPostViews(post.getPostViews()+1);
|
||||
postRepository.save(post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新文章摘要
|
||||
*
|
||||
* @param postSummary postSummary
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
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) {
|
||||
String text = HtmlUtil.cleanHtmlTag(post.getPostContent());
|
||||
if (text.length() > postSummary) {
|
||||
|
@ -105,6 +126,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_type_'+#postType")
|
||||
public List<Post> findAllPosts(String postType) {
|
||||
return postRepository.findPostsByPostType(postType);
|
||||
}
|
||||
|
@ -122,7 +144,7 @@ public class PostServiceImpl implements PostService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页
|
||||
* 根据文章状态查询 分页,用于后台管理
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
|
@ -134,6 +156,18 @@ public class PostServiceImpl implements PostService {
|
|||
return postRepository.findPostsByPostStatusAndPostType(status, postType, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,首页分页
|
||||
*
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_page_'+#pageable.pageNumber")
|
||||
public Page<Post> findPostByStatus(Pageable pageable) {
|
||||
return postRepository.findPostsByPostStatusAndPostType(PostStatus.PUBLISHED.getCode(),PostType.POST_TYPE_POST.getDesc(),pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询
|
||||
*
|
||||
|
@ -165,6 +199,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME,key = "'posts_posturl_'+#postUrl+'_'+#postType")
|
||||
public Post findByPostUrl(String postUrl, String postType) {
|
||||
return postRepository.findPostByPostUrlAndPostType(postUrl, postType);
|
||||
}
|
||||
|
@ -175,6 +210,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_latest'")
|
||||
public List<Post> findPostLatest() {
|
||||
return postRepository.findTopFive();
|
||||
}
|
||||
|
@ -187,7 +223,7 @@ public class PostServiceImpl implements PostService {
|
|||
*/
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +234,7 @@ public class PostServiceImpl implements PostService {
|
|||
*/
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -208,6 +244,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year_month'")
|
||||
public List<Archive> findPostGroupByYearAndMonth() {
|
||||
List<Object[]> objects = postRepository.findPostGroupByYearAndMonth();
|
||||
List<Archive> archives = new ArrayList<>();
|
||||
|
@ -229,6 +266,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year'")
|
||||
public List<Archive> findPostGroupByYear() {
|
||||
List<Object[]> objects = postRepository.findPostGroupByYear();
|
||||
List<Archive> archives = new ArrayList<>();
|
||||
|
@ -251,6 +289,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_year_month_'+#year+'_'+#month")
|
||||
public List<Post> findPostByYearAndMonth(String year, String month) {
|
||||
return postRepository.findPostByYearAndMonth(year, month);
|
||||
}
|
||||
|
@ -262,6 +301,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_year_'+#year")
|
||||
public List<Post> findPostByYear(String year) {
|
||||
return postRepository.findPostByYear(year);
|
||||
}
|
||||
|
@ -299,6 +339,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_tag_'+#tag.tagId+'_'+#pageable.pageNumber")
|
||||
public Page<Post> findPostsByTags(Tag tag, Pageable pageable) {
|
||||
return postRepository.findPostsByTags(tag, pageable);
|
||||
}
|
||||
|
@ -321,8 +362,9 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_hot'")
|
||||
public List<Post> hotPosts() {
|
||||
return postRepository.findPostsByPostTypeOrderByPostViewsDesc(HaloConst.POST_TYPE_POST);
|
||||
return postRepository.findPostsByPostTypeOrderByPostViewsDesc(PostType.POST_TYPE_POST.getDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -332,6 +374,7 @@ public class PostServiceImpl implements PostService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_related_'+#post.getPostId()")
|
||||
public List<Post> relatedPosts(Post post) {
|
||||
//获取当前文章的所有标签
|
||||
List<Tag> tags = post.getTags();
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Tag;
|
|||
import cc.ryanc.halo.repository.TagRepository;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -20,6 +22,8 @@ public class TagServiceImpl implements TagService {
|
|||
@Autowired
|
||||
private TagRepository tagRepository;
|
||||
|
||||
private static final String TAGS_CACHE_NAME = "tags";
|
||||
|
||||
/**
|
||||
* 新增/修改标签
|
||||
*
|
||||
|
@ -27,6 +31,7 @@ public class TagServiceImpl implements TagService {
|
|||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = TAGS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Tag saveByTag(Tag tag) {
|
||||
return tagRepository.save(tag);
|
||||
}
|
||||
|
@ -38,6 +43,7 @@ public class TagServiceImpl implements TagService {
|
|||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = TAGS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Tag removeByTagId(Long tagId) {
|
||||
Optional<Tag> tag = findByTagId(tagId);
|
||||
tagRepository.delete(tag.get());
|
||||
|
@ -50,6 +56,7 @@ public class TagServiceImpl implements TagService {
|
|||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = TAGS_CACHE_NAME, key = "'tag'")
|
||||
public List<Tag> findAllTags() {
|
||||
return tagRepository.findAll();
|
||||
}
|
||||
|
|
|
@ -16,10 +16,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
|
@ -36,7 +32,6 @@ import java.time.Instant;
|
|||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
@ -57,34 +52,6 @@ public class HaloUtils {
|
|||
|
||||
private static ArrayList<String> FILE_LIST = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 截取图片
|
||||
*
|
||||
* @param src 输入路径
|
||||
* @param dest 输出路径
|
||||
* @param w 宽度
|
||||
* @param h 长度
|
||||
* @param suffix 后缀
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void cutCenterImage(String src, String dest, int w, int h, String suffix) {
|
||||
try {
|
||||
Iterator iterator = ImageIO.getImageReadersByFormatName(suffix);
|
||||
ImageReader reader = (ImageReader) iterator.next();
|
||||
InputStream in = new FileInputStream(src);
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(in);
|
||||
reader.setInput(iis, true);
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
int imageIndex = 0;
|
||||
Rectangle rect = new Rectangle((reader.getWidth(imageIndex) - w) / 2, (reader.getHeight(imageIndex) - h) / 2, w, h);
|
||||
param.setSourceRegion(rect);
|
||||
BufferedImage bi = reader.read(0, param);
|
||||
ImageIO.write(bi, suffix, new File(dest));
|
||||
} catch (Exception e) {
|
||||
log.error("剪裁失败,图片本身尺寸小于需要修剪的尺寸:{0}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有附件
|
||||
*
|
||||
|
@ -325,7 +292,7 @@ public class HaloUtils {
|
|||
*
|
||||
* @param hostIp ip
|
||||
* @param userName 用户名
|
||||
* @param password 密码
|
||||
* @param password password
|
||||
* @param savePath 保存路径
|
||||
* @param fileName 文件名
|
||||
* @param databaseName 数据库名
|
||||
|
@ -470,7 +437,7 @@ public class HaloUtils {
|
|||
*
|
||||
* @param smtpHost smtpHost
|
||||
* @param userName 邮件地址
|
||||
* @param password 密码
|
||||
* @param password password
|
||||
*/
|
||||
public static void configMail(String smtpHost, String userName, String password) {
|
||||
Properties properties = OhMyEmail.defaultConfig(false);
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.ryanc.halo.model.domain.User;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
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.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -69,7 +70,7 @@ public class AdminController extends BaseController {
|
|||
@GetMapping(value = {"", "/index"})
|
||||
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);
|
||||
|
||||
//查询评论的条数
|
||||
|
|
|
@ -24,12 +24,9 @@ import org.springframework.util.ResourceUtils;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.websocket.server.PathParam;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.ryanc.halo.model.domain.User;
|
|||
import cc.ryanc.halo.model.dto.BackupDto;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
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.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
|
@ -139,8 +140,8 @@ public class BackupController {
|
|||
* @return JsonResult
|
||||
*/
|
||||
public JsonResult backupPosts() {
|
||||
List<Post> posts = postService.findAllPosts(HaloConst.POST_TYPE_POST);
|
||||
posts.addAll(postService.findAllPosts(HaloConst.POST_TYPE_PAGE));
|
||||
List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
|
||||
posts.addAll(postService.findAllPosts(PostType.POST_TYPE_PAGE.getDesc()));
|
||||
try {
|
||||
if(HaloUtils.getBackUps("posts").size()>10){
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
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.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -118,7 +119,7 @@ public class CommentController extends BaseController {
|
|||
try {
|
||||
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
|
||||
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());
|
||||
} else {
|
||||
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("commentAuthor", lastComment.getCommentAuthor());
|
||||
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());
|
||||
} else {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.*;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
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.LinkService;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
|
@ -59,7 +60,7 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping
|
||||
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);
|
||||
return "admin/admin_page";
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ public class PageController {
|
|||
Link backLink = linkService.saveByLink(link);
|
||||
log.info("保存成功,数据为:" + backLink);
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/page/links";
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ public class PageController {
|
|||
Link link = linkService.removeByLinkId(linkId);
|
||||
log.info("删除的友情链接:" + link);
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/page/links";
|
||||
}
|
||||
|
@ -218,7 +219,7 @@ public class PageController {
|
|||
//发表用户
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
post.setUser(user);
|
||||
post.setPostType(HaloConst.POST_TYPE_PAGE);
|
||||
post.setPostType(PostType.POST_TYPE_PAGE.getDesc());
|
||||
if(null!=post.getPostId()){
|
||||
post.setPostViews(postService.findByPostId(post.getPostId()).get().getPostViews());
|
||||
post.setPostDate(postService.findByPostId(post.getPostId()).get().getPostDate());
|
||||
|
@ -260,7 +261,7 @@ public class PageController {
|
|||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
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 还没写完
|
||||
if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) {
|
||||
return true;
|
||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.*;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
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.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -86,11 +88,11 @@ public class PostController extends BaseController {
|
|||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
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("publishCount", postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getTotalElements());
|
||||
model.addAttribute("draftCount", postService.findPostByStatus(1, HaloConst.POST_TYPE_POST, pageable).getTotalElements());
|
||||
model.addAttribute("trashCount", postService.findPostByStatus(2, 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(PostStatus.DRAFT.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
|
||||
model.addAttribute("trashCount", postService.findPostByStatus(PostStatus.RECYCLE.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
|
||||
model.addAttribute("status", status);
|
||||
return "admin/admin_post";
|
||||
}
|
||||
|
@ -115,7 +117,7 @@ public class PostController extends BaseController {
|
|||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
model.addAttribute("posts", postService.searchPosts(keyword, pageable));
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return "admin/admin_post";
|
||||
}
|
||||
|
@ -259,10 +261,10 @@ public class PostController extends BaseController {
|
|||
@GetMapping("/throw")
|
||||
public String moveToTrash(@RequestParam("postId") Long postId, @RequestParam("status") Integer status) {
|
||||
try {
|
||||
postService.updatePostStatus(postId, 2);
|
||||
postService.updatePostStatus(postId, PostStatus.RECYCLE.getCode());
|
||||
log.info("编号为" + postId + "的文章已被移到回收站");
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/posts?status=" + status;
|
||||
}
|
||||
|
@ -277,10 +279,10 @@ public class PostController extends BaseController {
|
|||
public String moveToPublish(@RequestParam("postId") Long postId,
|
||||
@RequestParam("status") Integer status) {
|
||||
try {
|
||||
postService.updatePostStatus(postId, 0);
|
||||
postService.updatePostStatus(postId, PostStatus.PUBLISHED.getCode());
|
||||
log.info("编号为" + postId + "的文章已改变为发布状态");
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/posts?status=" + status;
|
||||
}
|
||||
|
@ -298,9 +300,9 @@ public class PostController extends BaseController {
|
|||
postService.removeByPostId(postId);
|
||||
logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
|
||||
} 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/page";
|
||||
|
@ -348,7 +350,7 @@ public class PostController extends BaseController {
|
|||
@ResponseBody
|
||||
public boolean checkUrlExists(@PathParam("postUrl") String 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;
|
||||
}
|
||||
|
||||
|
@ -365,7 +367,7 @@ public class PostController extends BaseController {
|
|||
return false;
|
||||
}
|
||||
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();
|
||||
for (Post post : posts) {
|
||||
urls.append(blogUrl);
|
||||
|
|
|
@ -15,6 +15,7 @@ import cn.hutool.extra.servlet.ServletUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
@ -67,6 +68,7 @@ public class ThemeController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "/set")
|
||||
@ResponseBody
|
||||
@CacheEvict(value = "posts", allEntries = true, beforeInvocation = true)
|
||||
public JsonResult activeTheme(@PathParam("siteTheme") String siteTheme,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.dto.Archive;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -30,9 +31,9 @@ public class ApiArchivesController {
|
|||
public JsonResult archivesYear(){
|
||||
List<Archive> archives = postService.findPostGroupByYear();
|
||||
if(null!=archives || archives.size()>0){
|
||||
return new JsonResult(200,"success",archives);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
|
||||
}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(){
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
if(null!=archives || archives.size()>0){
|
||||
return new JsonResult(200,"success",archives);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
|
||||
}else {
|
||||
return new JsonResult(200,"empty");
|
||||
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -31,9 +32,9 @@ public class ApiCategoryController {
|
|||
public JsonResult categories(){
|
||||
List<Category> categories = categoryService.findAllCategories();
|
||||
if(null!=categories && categories.size()>0){
|
||||
return new JsonResult(200,"success",categories);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),categories);
|
||||
}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){
|
||||
Category category = categoryService.findByCateUrl(cateUrl);
|
||||
if(null!=category){
|
||||
return new JsonResult(200,"success",category);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),category);
|
||||
}else{
|
||||
return new JsonResult(404,"not found");
|
||||
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -32,9 +33,9 @@ public class ApiGalleryController {
|
|||
public JsonResult galleries(){
|
||||
List<Gallery> galleries = galleryService.findAllGalleries();
|
||||
if(null!=galleries && galleries.size()>0){
|
||||
return new JsonResult(200,"success",galleries);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),galleries);
|
||||
}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){
|
||||
Optional<Gallery> gallery = galleryService.findByGalleryId(id);
|
||||
if(gallery.isPresent()){
|
||||
return new JsonResult(200,"success",gallery.get());
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),gallery.get());
|
||||
}else{
|
||||
return new JsonResult(404,"not found");
|
||||
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -30,9 +31,9 @@ public class ApiLinkController {
|
|||
public JsonResult links(){
|
||||
List<Link> links = linkService.findAllLinks();
|
||||
if(null!=links && links.size()>0){
|
||||
return new JsonResult(200,"success",links);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),links);
|
||||
}else{
|
||||
return new JsonResult(200,"empty");
|
||||
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.MenuService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -30,9 +31,9 @@ public class ApiMenuController {
|
|||
public JsonResult menus(){
|
||||
List<Menu> menus = menuService.findAllMenus();
|
||||
if(null!=menus && menus.size()>0){
|
||||
return new JsonResult(200,"success",menus);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),menus);
|
||||
}else{
|
||||
return new JsonResult(200,"empty");
|
||||
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
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.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -28,11 +29,11 @@ public class ApiPageController {
|
|||
*/
|
||||
@GetMapping(value = "/{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){
|
||||
return new JsonResult(200,"success",post);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
|
||||
}else{
|
||||
return new JsonResult(404,"not found");
|
||||
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package cc.ryanc.halo.web.controller.api;
|
|||
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.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -42,20 +45,20 @@ public class ApiPostController {
|
|||
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
|
||||
}
|
||||
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) {
|
||||
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")
|
||||
public JsonResult hotPosts() {
|
||||
List<Post> posts = postService.hotPosts();
|
||||
if (null != posts && posts.size() > 0) {
|
||||
return new JsonResult(200, "success", posts);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(), posts);
|
||||
} 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}")
|
||||
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){
|
||||
return new JsonResult(200,"success",post);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
|
||||
}else {
|
||||
return new JsonResult(404,"not found");
|
||||
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -31,9 +32,9 @@ public class ApiTagController {
|
|||
public JsonResult tags(){
|
||||
List<Tag> tags = tagService.findAllTags();
|
||||
if(null!=tags && tags.size()>0){
|
||||
return new JsonResult(200,"success",tags);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tags);
|
||||
}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){
|
||||
Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
if(null!=tag){
|
||||
return new JsonResult(200,"success",tag);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tag);
|
||||
}else{
|
||||
return new JsonResult(404,"not found");
|
||||
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.api;
|
|||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -27,6 +28,6 @@ public class ApiUserController {
|
|||
@GetMapping
|
||||
public JsonResult user(){
|
||||
User user = userService.findUser();
|
||||
return new JsonResult(200,"success",user);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
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.PostService;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
|
@ -61,7 +61,7 @@ public class FrontArchiveController extends BaseController {
|
|||
//所有文章数据,分页,material主题适用
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
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){
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ public class FrontArchiveController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "{postUrl}")
|
||||
public String getPost(@PathVariable String postUrl, Model model) {
|
||||
Post post = postService.findByPostUrl(postUrl, HaloConst.POST_TYPE_POST);
|
||||
if(null==post){
|
||||
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
|
||||
if(null==post || post.getPostStatus()!=0){
|
||||
return this.renderNotFound();
|
||||
}
|
||||
//获得当前文章的发布日期
|
||||
|
@ -120,8 +120,7 @@ public class FrontArchiveController extends BaseController {
|
|||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0);
|
||||
model.addAttribute("post", post);
|
||||
model.addAttribute("comments",comments);
|
||||
post.setPostViews(post.getPostViews()+1);
|
||||
postService.saveByPost(post);
|
||||
postService.updatePostView(post);
|
||||
return this.render("post");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
|||
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.enums.PostType;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -149,7 +150,7 @@ public class FrontCommentController {
|
|||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("author", userService.findUser().getUserDisplayName());
|
||||
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());
|
||||
} else {
|
||||
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("commentAuthor",lastComment.getCommentAuthor());
|
||||
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());
|
||||
} else {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get("blog_url") + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
|
|
|
@ -66,7 +66,7 @@ public class FrontIndexController extends BaseController {
|
|||
}
|
||||
//所有文章数据,分页
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable);
|
||||
Page<Post> posts = postService.findPostByStatus(pageable);
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class FrontIndexController extends BaseController {
|
|||
|
||||
//文章数据,只获取文章,没有分页
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
List<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getContent();
|
||||
List<Post> posts = postService.findPostByStatus(pageable).getContent();
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
|
||||
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.PostService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -40,7 +41,7 @@ public class FrontOthersController {
|
|||
//获取文章列表并根据时间排序
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
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();
|
||||
return postService.buildRss(posts);
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ public class FrontOthersController {
|
|||
//获取文章列表并根据时间排序
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
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();
|
||||
return postService.buildSiteMap(posts);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
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.GalleryService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -67,7 +67,7 @@ public class FrontPageController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "/p/{postUrl}")
|
||||
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");
|
||||
Pageable pageable = PageRequest.of(0,999,sort);
|
||||
|
@ -77,8 +77,7 @@ public class FrontPageController extends BaseController {
|
|||
}
|
||||
model.addAttribute("comments",comments);
|
||||
model.addAttribute("post", post);
|
||||
post.setPostViews(post.getPostViews()+1);
|
||||
postService.saveByPost(post);
|
||||
postService.updatePostView(post);
|
||||
return this.render("page");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package cc.ryanc.halo.web.interceptor;
|
||||
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/28
|
||||
*/
|
||||
@Component
|
||||
public class ApiInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if (StringUtils.equals("true", HaloConst.OPTIONS.get("api_status"))) {
|
||||
return true;
|
||||
}
|
||||
response.sendRedirect("/404");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ server:
|
|||
port: 8090
|
||||
use-forward-headers: true
|
||||
undertow:
|
||||
io-threads : 2
|
||||
io-threads: 2
|
||||
worker-threads: 36
|
||||
buffer-size: 1024
|
||||
directBuffers: true
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
|
||||
updateCheck="false">
|
||||
|
||||
<defaultCache
|
||||
eternal="false"
|
||||
maxElementsInMemory="1000"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="600"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="links"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="menus"
|
||||
eternal="false"
|
||||
maxElementsInMemory="20"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="posts"
|
||||
eternal="false"
|
||||
maxElementsInMemory="1000"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="comments"
|
||||
eternal="false"
|
||||
maxElementsInMemory="1000"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="attachments"
|
||||
eternal="false"
|
||||
maxElementsInMemory="1000"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="galleries"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="tags"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache
|
||||
name="categories"
|
||||
eternal="false"
|
||||
maxElementsInMemory="100"
|
||||
overflowToDisk="false"
|
||||
diskPersistent="false"
|
||||
timeToIdleSeconds="0"
|
||||
timeToLiveSeconds="300"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
</ehcache>
|
|
@ -17,7 +17,7 @@
|
|||
</style>
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
设置
|
||||
博客设置
|
||||
<small></small>
|
||||
</h1>
|
||||
<ol class="breadcrumb">
|
||||
|
@ -26,7 +26,7 @@
|
|||
<i class="fa fa-dashboard"></i> 首页</a>
|
||||
</li>
|
||||
<li><a data-pjax="true" href="#">设置</a></li>
|
||||
<li class="active">网站设置</li>
|
||||
<li class="active">博客设置</li>
|
||||
</ol>
|
||||
</section>
|
||||
<!-- tab选项卡 -->
|
||||
|
@ -395,12 +395,66 @@
|
|||
<!-- 附件设置 -->
|
||||
<div class="tab-pane" id="attach">
|
||||
<form method="post" class="form-horizontal" id="attachOptions">
|
||||
<div class="box-body">
|
||||
<p>
|
||||
开发中...<br/>
|
||||
可选图片存储在本地或者七牛云等云...
|
||||
</p>
|
||||
</div>
|
||||
<#--<div class="box-body">-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label class="col-sm-2 control-label">存储位置:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<label class="radio-inline">-->
|
||||
<#--<input type="radio" name="attach_loc" value="server" ${((options.attach_loc?default('server'))=='server')?string('checked','')}> 本地服务器-->
|
||||
<#--</label>-->
|
||||
<#--<label class="radio-inline">-->
|
||||
<#--<input type="radio" name="attach_loc" value="upyun" ${((options.attach_loc?if_exists)=='upyun')?string('checked','')}> 又拍云-->
|
||||
<#--</label>-->
|
||||
<#--<label class="radio-inline">-->
|
||||
<#--<input type="radio" name="attach_loc" value="qiniu" ${((options.attach_loc?if_exists)=='qiniu')?string('checked','')}> 七牛云-->
|
||||
<#--</label>-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
|
||||
<#--<!-- 原生设置 –>-->
|
||||
<#--<div class="server-options" style="display: none">-->
|
||||
|
||||
<#--</div>-->
|
||||
|
||||
<#--<!-- 又拍云选项 –>-->
|
||||
<#--<div class="upyun-options" style="display: none">-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label for="upyunOssDomain" class="col-sm-2 control-label">域名绑定:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<input type="text" class="form-control" id="upyunOssDomain" name="upyun_oss_domain" value="${options.upyun_oss_domain?if_exists}">-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label for="upyunOssBucket" class="col-sm-2 control-label">空间名称:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<input type="text" class="form-control" id="upyunOssBucket" name="upyun_oss_bucket" value="${options.upyun_oss_bucket?if_exists}">-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label for="upyunOssOperator" class="col-sm-2 control-label">操作员名称:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<input type="text" class="form-control" id="upyunOssOperator" name="upyun_oss_operator" value="${options.upyun_oss_operator?if_exists}">-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label for="upyunOssPwd" class="col-sm-2 control-label">操作员密码:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<input type="text" class="form-control" id="upyunOssPwd" name="upyun_oss_pwd" value="${options.upyun_oss_pwd?if_exists}">-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<#--<div class="form-group">-->
|
||||
<#--<label for="upyunOssSrc" class="col-sm-2 control-label">文件目录:</label>-->
|
||||
<#--<div class="col-sm-4">-->
|
||||
<#--<input type="text" class="form-control" id="upyunOssSrc" name="upyun_oss_src" value="${options.upyun_oss_src?if_exists}">-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
|
||||
<#--<!-- 七牛云 –>-->
|
||||
<#--<div class="qiniu-options" style="display: none">-->
|
||||
|
||||
<#--</div>-->
|
||||
<#--</div>-->
|
||||
<div class="box-footer">
|
||||
<button type="button" class="btn btn-primary btn-sm " onclick="saveOptions('attachOptions')">保存</button>
|
||||
</div>
|
||||
|
@ -529,6 +583,17 @@
|
|||
<div class="tab-pane" id="other">
|
||||
<form method="post" class="form-horizontal" id="otherOptions">
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">API服务:</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="api_status" value="true" ${((options.api_status?if_exists)=='true')?string('checked','')}> 启用
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="api_status" value="false" ${((options.api_status?default('false'))=='false')?string('checked','')}> 禁用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="statisticsCode" class="col-sm-2 control-label">统计代码:
|
||||
<span data-toggle="tooltip" data-placement="top" title="可以使用cnzz,百度,google等" style="cursor: pointer">
|
||||
|
@ -651,6 +716,27 @@
|
|||
}
|
||||
}
|
||||
|
||||
function checkAttachOption() {
|
||||
var server = $('input:radio[value=server]:checked').val();
|
||||
var upyun = $('input:radio[value=upyun]:checked').val();
|
||||
var qiniu = $('input:radio[value=qiniu]:checked').val();
|
||||
if(server!=null){
|
||||
$('.server-options').show();
|
||||
}else{
|
||||
$('.server-options').hide();
|
||||
}
|
||||
if(upyun!=null){
|
||||
$('.upyun-options').show();
|
||||
}else{
|
||||
$('.upyun-options').hide();
|
||||
}
|
||||
if(qiniu!=null){
|
||||
$('.qiniu-options').show();
|
||||
}else{
|
||||
$('.qiniu-options').hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台布局切换
|
||||
*/
|
||||
|
@ -677,6 +763,9 @@
|
|||
$('input[name=comment_system]').click(function () {
|
||||
checkCommentOption();
|
||||
});
|
||||
$('input[name=attach_loc]').click(function () {
|
||||
checkAttachOption();
|
||||
});
|
||||
$('input[name=admin_layout]').click(function () {
|
||||
viewLayout();
|
||||
});
|
||||
|
|
|
@ -55,7 +55,24 @@
|
|||
<!-- 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="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">
|
||||
<link rel="stylesheet" href="/material/source/css/fontawesome.min.css">
|
||||
</#if>
|
||||
|
|
|
@ -17,18 +17,11 @@
|
|||
</script>
|
||||
|
||||
<!-- 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.vendors.materialcdn) { %>
|
||||
<%- jsLsload({path:(theme.vendors.materialcdn + '/js/hanabi-browser-bundle.js'),key:'hanabi'}) %>
|
||||
|
|
Loading…
Reference in New Issue