👽 代码优化

pull/21/head
ruibaby 2018-07-15 11:51:38 +08:00
parent 99e204fb18
commit b7d7e9fa1c
40 changed files with 215 additions and 185 deletions

View File

@ -9,17 +9,17 @@ public enum CommentStatus {
/**
*
*/
PUBLISHED(0,"已发布"),
PUBLISHED(0, "已发布"),
/**
*
*/
CHECKING(1,"待审核"),
CHECKING(1, "待审核"),
/**
*
*/
RECYCLE(2,"回收站");
RECYCLE(2, "回收站");
private Integer code;
private String desc;

View File

@ -9,17 +9,17 @@ public enum PostStatus {
/**
*
*/
PUBLISHED(0,"已发布"),
PUBLISHED(0, "已发布"),
/**
* 稿
*/
DRAFT(1,"草稿"),
DRAFT(1, "草稿"),
/**
*
*/
RECYCLE(2,"回收站");
RECYCLE(2, "回收站");
private Integer code;
private String desc;

View File

@ -9,22 +9,22 @@ public enum ResponseStatus {
/**
*
*/
SUCCESS(200,"OK"),
SUCCESS(200, "OK"),
/**
*
*/
EMPTY(204,"No Content"),
EMPTY(204, "No Content"),
/**
*
*/
ERROR(500,"Internal Server Error"),
ERROR(500, "Internal Server Error"),
/**
*
*/
NOTFOUND(404,"Not Found");
NOTFOUND(404, "Not Found");
private Integer code;
private String msg;

View File

@ -155,7 +155,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
*
*
* @param category category
* @param status status
* @param status status
* @param pageable pageable
* @return Page
*/
@ -164,8 +164,8 @@ public interface PostRepository extends JpaRepository<Post, Long> {
/**
*
*
* @param tag tag
* @param status status
* @param tag tag
* @param status status
* @param pageable pageable
* @return Page
*/
@ -182,8 +182,8 @@ public interface PostRepository extends JpaRepository<Post, Long> {
/**
*
*
* @param keyword
* @param pageable
* @param keyword
* @param pageable
* @return Page
*/
@Query(value = "select * from halo_post where post_status = 0 and post_type='post' and post_title like '%=:keyword%' or post_content like '%=:keyword%'", nativeQuery = true)

View File

@ -94,6 +94,7 @@ public interface PostService {
/**
*
*
* @param pageable pageable
* @return Page
*/
@ -196,7 +197,7 @@ public interface PostService {
* @param pageable pageable
* @return Page
*/
Page<Post> findPostByCategories(Category category,Pageable pageable);
Page<Post> findPostByCategories(Category category, Pageable pageable);
/**
*
@ -210,11 +211,11 @@ public interface PostService {
/**
*
*
* @param keyword
* @param keyword
* @param pageable
* @return Page
*/
Page<Post> searchByKeywords(String keyword,Pageable pageable);
Page<Post> searchByKeywords(String keyword, Pageable pageable);
/**
*

View File

@ -20,11 +20,11 @@ import java.util.Optional;
@Service
public class AttachmentServiceImpl implements AttachmentService {
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
@Autowired
private AttachmentRepository attachmentRepository;
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
/**
*
*

View File

@ -22,11 +22,11 @@ import java.util.Optional;
@Service
public class CommentServiceImpl implements CommentService {
private static final String COMMENTS_CACHE_NAME = "comments";
@Autowired
private CommentRepository commentRepository;
private static final String COMMENTS_CACHE_NAME = "comments";
/**
*
*

View File

@ -20,11 +20,11 @@ import java.util.Optional;
@Service
public class GalleryServiceImpl implements GalleryService {
private static final String GALLERIES_CACHE_NAME = "galleries";
@Autowired
private GalleryRepository galleryRepository;
private static final String GALLERIES_CACHE_NAME = "galleries";
/**
*
*

View File

@ -18,13 +18,13 @@ import java.util.Optional;
@Service
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";
@Autowired
private LinkRepository linkRepository;
/**
* /
*

View File

@ -96,16 +96,16 @@ public class MailServiceImpl implements MailService {
HaloConst.OPTIONS.get(BlogProperties.MAIL_SMTP_PASSWORD.getProp()));
File file = new File(attachSrc);
String text = "";
try{
try {
Template template = freeMarker.getConfiguration().getTemplate(templateName);
text = FreeMarkerTemplateUtils.processTemplateIntoString(template,content);
text = FreeMarkerTemplateUtils.processTemplateIntoString(template, content);
OhMyEmail.subject(subject)
.from(HaloConst.OPTIONS.get(BlogProperties.MAIL_FROM_NAME.getProp()))
.to(to)
.html(text)
.attach(file,file.getName())
.attach(file, file.getName())
.send();
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -18,13 +18,13 @@ import java.util.Optional;
@Service
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";
@Autowired
private MenuRepository menuRepository;
/**
*
*

View File

@ -30,11 +30,11 @@ import java.util.Optional;
@Service
public class PostServiceImpl implements PostService {
private static final String POSTS_CACHE_NAME = "posts";
@Autowired
private PostRepository postRepository;
private static final String POSTS_CACHE_NAME = "posts";
/**
*
*
@ -83,7 +83,7 @@ public class PostServiceImpl implements PostService {
*/
@Override
public void updatePostView(Post post) {
post.setPostViews(post.getPostViews()+1);
post.setPostViews(post.getPostViews() + 1);
postRepository.save(post);
}
@ -99,7 +99,7 @@ public class PostServiceImpl implements PostService {
for (Post post : posts) {
String text = HtmlUtil.cleanHtmlTag(post.getPostContent());
if (text.length() > postSummary) {
post.setPostSummary(text.substring(0,postSummary));
post.setPostSummary(text.substring(0, postSummary));
} else {
post.setPostSummary(text);
}
@ -165,7 +165,7 @@ public class PostServiceImpl implements PostService {
@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);
return postRepository.findPostsByPostStatusAndPostType(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable);
}
/**
@ -200,7 +200,7 @@ public class PostServiceImpl implements PostService {
* @return Post
*/
@Override
@Cacheable(value = POSTS_CACHE_NAME,key = "'posts_posturl_'+#postUrl+'_'+#postType")
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_posturl_'+#postUrl+'_'+#postType")
public Post findByPostUrl(String postUrl, String postType) {
return postRepository.findPostByPostUrlAndPostType(postUrl, postType);
}
@ -324,7 +324,7 @@ public class PostServiceImpl implements PostService {
*
*
* @param category category
* @param status status
* @param status status
* @param pageable pageable
* @return Page
*/
@ -337,8 +337,8 @@ public class PostServiceImpl implements PostService {
/**
*
*
* @param tag tag
* @param status status
* @param tag tag
* @param status status
* @param pageable pageable
* @return Page
*/
@ -351,13 +351,13 @@ public class PostServiceImpl implements PostService {
/**
*
*
* @param keyword
* @param keyword
* @param pageable
* @return Page
*/
@Override
public Page<Post> searchByKeywords(String keyword,Pageable pageable) {
return postRepository.findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(keyword,pageable);
public Page<Post> searchByKeywords(String keyword, Pageable pageable) {
return postRepository.findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(keyword, pageable);
}
/**

View File

@ -215,7 +215,7 @@ public class AdminController extends BaseController {
try {
logsService.removeAllLogs();
} catch (Exception e) {
log.error("未知错误:" + e.getMessage());
log.error("清除日志失败:{}" + e.getMessage());
}
return "redirect:/admin";
}

View File

@ -177,7 +177,7 @@ public class AttachmentController {
result.put("message", "上传成功!");
result.put("url", attachment.getAttachPath());
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("上传文件失败:{}", e.getMessage());
e.printStackTrace();
result.put("success", 0);
result.put("message", "上传失败!");

View File

@ -107,7 +107,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了数据库备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("备份数据库失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
}
}
@ -130,7 +130,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了资源文件备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) {
e.printStackTrace();
log.error("备份资源文件失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
}
}
@ -159,7 +159,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了文章备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) {
e.printStackTrace();
log.error("备份文章失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
}
}
@ -227,7 +227,7 @@ public class BackupController {
content.put("size", HaloUtils.parseSize(file.length()));
mailService.sendAttachMail(user.getUserEmail(), "有新的备份!", content, "common/mail/mail_attach.ftl", srcPath);
} catch (Exception e) {
log.error("邮件服务器未配置:", e.getMessage());
log.error("邮件服务器未配置:{}", e.getMessage());
}
}
}

View File

@ -44,7 +44,7 @@ public class CategoryController {
try {
categoryService.saveByCategory(category);
} catch (Exception e) {
log.error("未知错误{0}", e.getMessage());
log.error("修改分类失败{0}", e.getMessage());
}
return "redirect:/admin/category";
}
@ -74,7 +74,7 @@ public class CategoryController {
Category category = categoryService.removeByCateId(cateId);
log.info("删除的分类目录:" + category);
} catch (Exception e) {
log.error("未知错误{}", e.getMessage());
log.error("删除分类失败{}", e.getMessage());
}
return "redirect:/admin/category";
}

View File

@ -17,6 +17,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HtmlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -92,13 +93,14 @@ public class CommentController extends BaseController {
*/
@GetMapping(value = "/throw")
public String moveToTrash(@PathParam("commentId") Long commentId,
@PathParam("status") String status) {
@PathParam("status") String status,
@RequestParam(value = "page",defaultValue = "0") Integer page) {
try {
commentService.updateCommentStatus(commentId, CommentStatus.RECYCLE.getCode());
} catch (Exception e) {
log.error("未知错误{}", e.getMessage());
log.error("删除评论失败{}", e.getMessage());
}
return "redirect:/admin/comments?status=" + status;
return "redirect:/admin/comments?status=" + status+"&page="+page;
}
/**
@ -153,13 +155,14 @@ public class CommentController extends BaseController {
*/
@GetMapping("/remove")
public String moveToAway(@PathParam("commentId") Long commentId,
@PathParam("status") Integer status) {
@PathParam("status") Integer status,
@RequestParam(value = "page",defaultValue = "0") Integer page) {
try {
commentService.removeByCommentId(commentId);
} catch (Exception e) {
log.error("删除评论失败:{}", e.getMessage());
}
return "redirect:/admin/comments?status=" + status;
return "redirect:/admin/comments?status=" + status+"&page="+page;
}
@ -200,7 +203,7 @@ public class CommentController extends BaseController {
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
comment.setCommentDate(DateUtil.date());
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
comment.setCommentContent(lastContent + OwoUtil.markToImg(commentContent));
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.encode(commentContent)));
comment.setCommentAgent(userAgent);
comment.setCommentParent(commentId);
comment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
@ -228,7 +231,7 @@ public class CommentController extends BaseController {
}
}
} catch (Exception e) {
log.error("回复评论失败{}", e.getMessage());
log.error("回复评论失败{}", e.getMessage());
}
return "redirect:/admin/comments";
}

View File

@ -44,7 +44,7 @@ public class MenuController {
try {
menuService.saveByMenu(menu);
} catch (Exception e) {
log.error("保存菜单失败:" + e.getMessage());
log.error("保存菜单失败:{}" + e.getMessage());
}
return "redirect:/admin/menus";
}
@ -74,7 +74,7 @@ public class MenuController {
try {
menuService.removeByMenuId(menuId);
} catch (Exception e) {
log.error("删除菜单失败:{0}", e.getMessage());
log.error("删除菜单失败:{}", e.getMessage());
}
return "redirect:/admin/menus";
}

View File

@ -55,7 +55,7 @@ public class OptionController {
log.info("所保存的设置选项列表:" + options);
return new JsonResult(ResultCode.SUCCESS.getCode(),"保存成功!");
} catch (Exception e) {
log.error("未知错误:{0}", e.getMessage());
log.error("保存设置选项失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"保存失败!");
}
}

View File

@ -99,10 +99,9 @@ public class PageController {
@PostMapping(value = "/links/save")
public String saveLink(@ModelAttribute Link link) {
try {
Link backLink = linkService.saveByLink(link);
log.info("保存成功,数据为:" + backLink);
linkService.saveByLink(link);
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("保存/修改友情链接失败:{}", e.getMessage());
}
return "redirect:/admin/page/links";
}
@ -116,10 +115,9 @@ public class PageController {
@GetMapping(value = "/links/remove")
public String removeLink(@PathParam("linkId") Long linkId) {
try {
Link link = linkService.removeByLinkId(linkId);
log.info("删除的友情链接:" + link);
linkService.removeByLinkId(linkId);
} catch (Exception e) {
log.error("未知错误", e.getMessage());
log.error("删除友情链接失败", e.getMessage());
}
return "redirect:/admin/page/links";
}
@ -180,18 +178,18 @@ public class PageController {
*
*
* @param galleryId
* @return truefalse
* @return JsonResult
*/
@GetMapping(value = "/gallery/remove")
@ResponseBody
public boolean removeGallery(@RequestParam("galleryId") Long galleryId) {
public JsonResult removeGallery(@RequestParam("galleryId") Long galleryId) {
try {
galleryService.removeByGalleryId(galleryId);
} catch (Exception e) {
log.error("删除图片失败:{0}", e.getMessage());
return false;
log.error("删除图片失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "删除失败!");
}
return true;
return new JsonResult(ResultCode.SUCCESS.getCode(), "删除成功!");
}
@ -234,7 +232,7 @@ public class PageController {
logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCode.SUCCESS.getCode(),msg);
} catch (Exception e) {
log.error("未知错误{}", e.getMessage());
log.error("保存页面失败{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"保存失败");
}
}
@ -257,16 +255,16 @@ public class PageController {
*
*
* @param postUrl postUrl
* @return true or false
* @return JsonResult
*/
@GetMapping(value = "/checkUrl")
@ResponseBody
public boolean checkUrlExists(@PathParam("postUrl") String postUrl) {
public JsonResult checkUrlExists(@PathParam("postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
// TODO 还没写完
if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) {
return true;
return new JsonResult(ResultCode.FAIL.getCode(), "该路径已经存在!");
}
return false;
return new JsonResult(ResultCode.SUCCESS.getCode(), "");
}
}

View File

@ -119,7 +119,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("未知错误:", e.getMessage());
log.error("未知错误:{}", e.getMessage());
}
return "admin/admin_post";
}
@ -165,7 +165,7 @@ public class PostController extends BaseController {
//提取摘要
int postSummary = 50;
if (StringUtils.isNotEmpty(BlogProperties.POST_SUMMARY.getProp())) {
postSummary = Integer.parseInt(BlogProperties.POST_SUMMARY.getProp());
postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogProperties.POST_SUMMARY.getProp()));
}
//文章摘要
String summaryText = HtmlUtil.cleanHtmlTag(post.getPostContent());
@ -198,7 +198,7 @@ public class PostController extends BaseController {
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCode.SUCCESS.getCode(), msg);
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("保存文章失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "保存失败");
}
}
@ -207,9 +207,13 @@ public class PostController extends BaseController {
/**
* 稿
*
* @param post post
* @param postId
* @param postTitle
* @param postUrl
* @param postContentMd
* @param postType
* @param session session
* @return
* @return JsonResult
*/
@PostMapping(value = "/new/autoPush")
@ResponseBody
@ -266,7 +270,7 @@ public class PostController extends BaseController {
postService.updatePostStatus(postId, PostStatus.RECYCLE.getCode());
log.info("编号为" + postId + "的文章已被移到回收站");
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("未知错误:{}", e.getMessage());
}
return "redirect:/admin/posts?status=" + status;
}
@ -284,7 +288,7 @@ public class PostController extends BaseController {
postService.updatePostStatus(postId, PostStatus.PUBLISHED.getCode());
log.info("编号为" + postId + "的文章已改变为发布状态");
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
log.error("未知错误:{}", e.getMessage());
}
return "redirect:/admin/posts?status=" + status;
}
@ -302,7 +306,7 @@ 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("未知错误:", e.getMessage());
log.error("未知错误:{}", e.getMessage());
}
if (StringUtils.equals(PostType.POST_TYPE_POST.getDesc(), postType)) {
return "redirect:/admin/posts?status=2";
@ -328,18 +332,19 @@ public class PostController extends BaseController {
*
*
* @param postSummary
* @return truefalse
* @return JsonResult
*/
@GetMapping(value = "/updateSummary")
@ResponseBody
public boolean updateSummary(@PathParam("postSummary") Integer postSummary) {
public JsonResult updateSummary(@PathParam("postSummary") Integer postSummary) {
try {
postService.updateAllSummary(postSummary);
return true;
} catch (Exception e) {
log.error("未知错误:", e.getMessage());
return false;
log.error("更新摘要失败:{}", e.getMessage());
e.printStackTrace();
return new JsonResult(ResultCode.FAIL.getCode(), "更新失败!");
}
return new JsonResult(ResultCode.SUCCESS.getCode(), "所有文章摘要更新成功!");
}
/**
@ -360,13 +365,13 @@ public class PostController extends BaseController {
*
*
* @param baiduToken baiduToken
* @return true or false
* @return JsonResult
*/
@GetMapping(value = "/pushAllToBaidu")
@ResponseBody
public boolean pushAllToBaidu(@PathParam("baiduToken") String baiduToken) {
public JsonResult pushAllToBaidu(@PathParam("baiduToken") String baiduToken) {
if (StringUtils.isEmpty(baiduToken)) {
return false;
return new JsonResult(ResultCode.FAIL.getCode(), "百度推送Token为空");
}
String blogUrl = HaloConst.OPTIONS.get(BlogProperties.BLOG_URL.getProp());
List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
@ -379,8 +384,8 @@ public class PostController extends BaseController {
}
String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString());
if (StringUtils.isEmpty(result)) {
return false;
return new JsonResult(ResultCode.FAIL.getCode(), "推送所有文章成功!");
}
return true;
return new JsonResult(ResultCode.SUCCESS.getCode(), "推送成功!");
}
}

View File

@ -43,7 +43,7 @@ public class TagController {
try {
tagService.saveByTag(tag);
} catch (Exception e) {
log.error("未知错误:{0}", e.getMessage());
log.error("新增/修改标签失败:{}", e.getMessage());
}
return "redirect:/admin/tag";
}
@ -73,7 +73,7 @@ public class TagController {
Tag tag = tagService.removeByTagId(tagId);
log.info("删除的标签:" + tag);
} catch (Exception e) {
log.error("未知错误:{0}", e.getMessage());
log.error("删除标签失败:{}", e.getMessage());
}
return "redirect:/admin/tag";
}

View File

@ -119,7 +119,7 @@ public class ThemeController extends BaseController {
return new JsonResult(ResultCode.FAIL.getCode(),"请选择上传的主题!");
}
} catch (Exception e) {
log.error("上传主题失败:", e.getMessage());
log.error("上传主题失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"主题上传失败!");
}
return new JsonResult(ResultCode.SUCCESS.getCode(),"主题上传成功!");

View File

@ -57,7 +57,7 @@ public class UserController {
return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!");
}
} catch (Exception e) {
log.error("未知错误:{0}", e.getMessage());
log.error("修改用户资料失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!");
}
return new JsonResult(ResultCode.SUCCESS.getCode(),"修改成功!");
@ -88,7 +88,7 @@ public class UserController {
return new JsonResult(ResultCode.FAIL.getCode(),"原密码错误!");
}
} catch (Exception e) {
log.error("修改密码未知错误,{0}", e.getMessage());
log.error("修改密码失败{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"密码修改失败!");
}
return new JsonResult(ResultCode.SUCCESS.getCode(),"修改密码成功!");

View File

@ -28,12 +28,12 @@ public class ApiArchivesController {
* @return JsonResult
*/
@GetMapping(value = "/year")
public JsonResult archivesYear(){
public JsonResult archivesYear() {
List<Archive> archives = postService.findPostGroupByYear();
if(null!=archives || archives.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
}else {
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != archives || archives.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), archives);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
@ -43,12 +43,12 @@ public class ApiArchivesController {
* @return JsonResult
*/
@GetMapping(value = "/year/month")
public JsonResult archivesYearAndMonth(){
public JsonResult archivesYearAndMonth() {
List<Archive> archives = postService.findPostGroupByYearAndMonth();
if(null!=archives || archives.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),archives);
}else {
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != archives || archives.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), archives);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
}

View File

@ -29,12 +29,12 @@ public class ApiCategoryController {
* @return JsonResult
*/
@GetMapping
public JsonResult categories(){
public JsonResult categories() {
List<Category> categories = categoryService.findAllCategories();
if(null!=categories && categories.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),categories);
}else{
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != categories && categories.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), categories);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
@ -45,12 +45,12 @@ public class ApiCategoryController {
* @return JsonResult
*/
@GetMapping(value = "/{cateUrl}")
public JsonResult categories(@PathVariable("cateUrl") String cateUrl){
public JsonResult categories(@PathVariable("cateUrl") String cateUrl) {
Category category = categoryService.findByCateUrl(cateUrl);
if(null!=category){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),category);
}else{
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != category) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), category);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
}

View File

@ -30,12 +30,12 @@ public class ApiGalleryController {
* @return JsonResult
*/
@GetMapping
public JsonResult galleries(){
public JsonResult galleries() {
List<Gallery> galleries = galleryService.findAllGalleries();
if(null!=galleries && galleries.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),galleries);
}else {
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != galleries && galleries.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), galleries);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
@ -46,12 +46,12 @@ public class ApiGalleryController {
* @return JsonResult
*/
@GetMapping(value = "/{id}")
public JsonResult galleries(@PathVariable("id") Long id){
public JsonResult galleries(@PathVariable("id") Long id) {
Optional<Gallery> gallery = galleryService.findByGalleryId(id);
if(gallery.isPresent()){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),gallery.get());
}else{
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
if (gallery.isPresent()) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), gallery.get());
} else {
return new JsonResult(ResponseStatus.NOTFOUND.getCode(), ResponseStatus.NOTFOUND.getMsg());
}
}
}

View File

@ -28,12 +28,12 @@ public class ApiLinkController {
* @return JsonResult
*/
@GetMapping
public JsonResult links(){
public JsonResult links() {
List<Link> links = linkService.findAllLinks();
if(null!=links && links.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),links);
}else{
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != links && links.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), links);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
}

View File

@ -28,12 +28,12 @@ public class ApiMenuController {
* @return JsonResult
*/
@GetMapping
public JsonResult menus(){
public JsonResult menus() {
List<Menu> menus = menuService.findAllMenus();
if(null!=menus && menus.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),menus);
}else{
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != menus && menus.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), menus);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
}

View File

@ -28,12 +28,12 @@ public class ApiPageController {
* @return JsonResult
*/
@GetMapping(value = "/{postUrl}")
public JsonResult pages(@PathVariable(value = "postUrl") String postUrl){
Post post = postService.findByPostUrl(postUrl,PostType.POST_TYPE_PAGE.getDesc());
if(null!=post){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
}else{
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
public JsonResult pages(@PathVariable(value = "postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
if (null != post) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), post);
} else {
return new JsonResult(ResponseStatus.NOTFOUND.getCode(), ResponseStatus.NOTFOUND.getMsg());
}
}
}

View File

@ -39,7 +39,7 @@ public class ApiPostController {
* @return JsonResult
*/
@GetMapping(value = "/page/{page}")
public JsonResult posts(@PathVariable(value = "page") Integer page){
public JsonResult posts(@PathVariable(value = "page") Integer page) {
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Integer size = 10;
if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogProperties.INDEX_POSTS.getProp()))) {
@ -48,18 +48,18 @@ public class ApiPostController {
Pageable pageable = PageRequest.of(page - 1, size, sort);
Page<Post> posts = postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable);
if (null == posts) {
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),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(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(), posts);
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), posts);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
@ -70,12 +70,12 @@ public class ApiPostController {
* @return JsonResult
*/
@GetMapping(value = "/{postUrl}")
public JsonResult posts(@PathVariable(value = "postUrl") String postUrl){
Post post = postService.findByPostUrl(postUrl,PostType.POST_TYPE_POST.getDesc());
if(null!=post){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),post);
}else {
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
public JsonResult posts(@PathVariable(value = "postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
if (null != post) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), post);
} else {
return new JsonResult(ResponseStatus.NOTFOUND.getCode(), ResponseStatus.NOTFOUND.getMsg());
}
}
}

View File

@ -29,12 +29,12 @@ public class ApiTagController {
* @return JsonResult
*/
@GetMapping
public JsonResult tags(){
public JsonResult tags() {
List<Tag> tags = tagService.findAllTags();
if(null!=tags && tags.size()>0){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tags);
}else{
return new JsonResult(ResponseStatus.EMPTY.getCode(),ResponseStatus.EMPTY.getMsg());
if (null != tags && tags.size() > 0) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), tags);
} else {
return new JsonResult(ResponseStatus.EMPTY.getCode(), ResponseStatus.EMPTY.getMsg());
}
}
@ -45,12 +45,12 @@ public class ApiTagController {
* @return JsonResult
*/
@GetMapping(value = "/{tagUrl}")
public JsonResult tags(@PathVariable("tagUrl") String tagUrl){
public JsonResult tags(@PathVariable("tagUrl") String tagUrl) {
Tag tag = tagService.findByTagUrl(tagUrl);
if(null!=tag){
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),tag);
}else{
return new JsonResult(ResponseStatus.NOTFOUND.getCode(),ResponseStatus.NOTFOUND.getMsg());
if (null != tag) {
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), tag);
} else {
return new JsonResult(ResponseStatus.NOTFOUND.getCode(), ResponseStatus.NOTFOUND.getMsg());
}
}
}

View File

@ -26,8 +26,8 @@ public class ApiUserController {
* @return JsonResult
*/
@GetMapping
public JsonResult user(){
public JsonResult user() {
User user = userService.findUser();
return new JsonResult(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),user);
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), user);
}
}

View File

@ -26,9 +26,10 @@ public abstract class BaseController {
/**
* 404
*
* @return redirect:/404
*/
public String renderNotFound(){
public String renderNotFound() {
return "redirect:/404";
}
}

View File

@ -104,6 +104,12 @@ public class FrontCommentController {
public JsonResult newComment(@ModelAttribute("comment") Comment comment,
@ModelAttribute("post") Post post,
HttpServletRequest request) {
if (StringUtils.equals(StringUtils.trim(comment.getCommentAuthor()), "")) {
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入昵称!");
}
if (StringUtils.equals(StringUtils.trim(comment.getCommentContent()), "")) {
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入评论内容!");
}
try{
Comment lastComment = null;
post = postService.findByPostId(post.getPostId()).get();
@ -163,7 +169,7 @@ public class FrontCommentController {
map.put("commentContent", comment.getCommentContent());
mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail/mail_admin.ftl");
} catch (Exception e) {
log.error("邮件服务器未配置:", e.getMessage());
log.error("邮件服务器未配置:{}", e.getMessage());
}
}
}

View File

@ -63,16 +63,16 @@
<#switch comment.commentStatus>
<#case 0>
<button class="btn btn-primary btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')" <#if comment.isAdmin==1>disabled</#if>>回复</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0','确定移动到回收站?')">丢弃</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0&page=${comments.number}','确定移动到回收站?')">丢弃</button>
<#break >
<#case 1>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=1">通过</a>
<button class="btn btn-info btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')">通过并回复</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1','确定移动到回收站?')">丢弃</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1&page=${comments.number}','确定移动到回收站?')">丢弃</button>
<#break >
<#case 2>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=2">还原</a>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2','确定要永久删除?')">删除</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2&page=${comments.number}','确定要永久删除?')">删除</button>
<#break >
</#switch>
</td>

View File

@ -673,7 +673,7 @@
postSummary : $('#postSummary').val()
},
success: function (data) {
if(data==true){
if(data.code==1){
showMsg("所有文章摘要更新成功!","success",1000);
}else{
showMsg("更新失败!","success",2000);
@ -693,10 +693,22 @@
baiduToken : $('#baiduToken').val()
},
success: function (data) {
if(data==true){
if(data.code==1){
showMsg("推送所有文章成功!","success",1000);
}else{
showMsg("推送失败!","success",2000);
$.toast({
text: data.msg,
heading: '提示',
icon: icon,
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: hideAfter,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff'
});
}
}
});

View File

@ -183,7 +183,7 @@
'postUrl': $('#newPostUrl').val()
},
success: function (data) {
if(data==true){
if(data.code==0){
showMsg("该路径已经存在!","info",2000);
return;
}else{

View File

@ -94,7 +94,7 @@
galleryId : ${gallery.galleryId?c}
},
success: function (data) {
if(data==true){
if(data.code==1){
$.toast({
text: "删除成功!",
heading: '提示',
@ -124,4 +124,4 @@
parent.location.reload();
}
</script>
</html>
</html>

View File

@ -379,11 +379,15 @@
localStorage.setItem('url', url.val());
if(data.code==1){
$('.comment-input-content').val("");
$(".native-message").html("<span>"+data.msg+"</span>");
}else{
$(".native-message").html("<span style='color:red'>"+data.msg+"</span>");
}
$(".native-message").html("<span>"+data.msg+"</span>");
$(".native-message").fadeIn(1000);
setTimeout(function () {
window.location.reload();
$(".native-message").fadeOut(1000);
$("#btn-push").removeAttr("disabled");
$("#btn-push").html("提交");
},1500);
}
});