🎨 代码优化

pull/87/head
ruibaby 2019-01-30 15:23:11 +08:00
parent 58e91d6e14
commit 7ffbc93ea5
13 changed files with 22 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
/**
* <pre>
@ -17,6 +18,7 @@ import org.springframework.context.ApplicationContext;
@Slf4j
@SpringBootApplication
@EnableCaching
@EnableJpaAuditing
public class Application {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);

View File

@ -1,11 +1,10 @@
package cc.ryanc.halo.model.domain;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@ -20,6 +19,7 @@ import java.util.Date;
@Data
@Entity
@Table(name = "halo_attachment")
@EntityListeners(AuditingEntityListener.class)
public class Attachment implements Serializable {
private static final long serialVersionUID = 3060117944880138064L;
@ -59,6 +59,7 @@ public class Attachment implements Serializable {
/**
*
*/
@CreatedDate
private Date attachCreated;
/**

View File

@ -2,6 +2,8 @@ package cc.ryanc.halo.model.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.Email;
@ -21,6 +23,7 @@ import java.util.List;
@Data
@Entity
@Table(name = "halo_comment")
@EntityListeners(AuditingEntityListener.class)
public class Comment implements Serializable {
private static final long serialVersionUID = -6639021627094260505L;
@ -72,6 +75,7 @@ public class Comment implements Serializable {
/**
*
*/
@CreatedDate
private Date commentDate;
/**

View File

@ -1,11 +1,10 @@
package cc.ryanc.halo.model.domain;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@ -20,6 +19,7 @@ import java.util.Date;
@Data
@Entity
@Table(name = "halo_logs")
@EntityListeners(AuditingEntityListener.class)
public class Logs implements Serializable {
private static final long serialVersionUID = -2571815432301283171L;
@ -49,6 +49,7 @@ public class Logs implements Serializable {
/**
*
*/
@CreatedDate
private Date logCreated;
public Logs() {

View File

@ -2,6 +2,9 @@ package cc.ryanc.halo.model.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
@ -20,6 +23,7 @@ import java.util.List;
@Data
@Entity
@Table(name = "halo_post")
@EntityListeners(AuditingEntityListener.class)
public class Post implements Serializable {
private static final long serialVersionUID = -6019684584665869629L;
@ -105,11 +109,13 @@ public class Post implements Serializable {
/**
*
*/
@CreatedDate
private Date postDate;
/**
*
*/
@LastModifiedDate
private Date postUpdate;
/**

View File

@ -39,7 +39,6 @@ public class LogsServiceImpl implements LogsService {
final Logs logs = new Logs();
logs.setLogTitle(logTitle);
logs.setLogContent(logContent);
logs.setLogCreated(new Date());
logs.setLogIp(ServletUtil.getClientIP(request));
logsRepository.save(logs);
}

View File

@ -73,7 +73,6 @@ public class PostServiceImpl implements PostService {
} else {
post.setPostSummary(summaryText);
}
post.setPostUpdate(DateUtil.date());
return postRepository.save(post);
}

View File

@ -133,7 +133,6 @@ public class AttachmentController {
attachment.setAttachSmallPath(resultMap.get("smallPath"));
attachment.setAttachType(file.getContentType());
attachment.setAttachSuffix(resultMap.get("suffix"));
attachment.setAttachCreated(DateUtil.date());
attachment.setAttachSize(resultMap.get("size"));
attachment.setAttachWh(resultMap.get("wh"));
attachment.setAttachLocation(resultMap.get("location"));

View File

@ -182,7 +182,6 @@ public class CommentController extends BaseController {
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
comment.setCommentDate(DateUtil.date());
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
buildContent.append(lastComment.getCommentId());

View File

@ -261,10 +261,7 @@ public class PageController {
}
post.setPostViews(oldPost.getPostViews());
msg = localeMessageUtil.getMessage("code.admin.common.update-success");
} else {
post.setPostDate(DateUtil.date());
}
post.setPostUpdate(DateUtil.date());
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {

View File

@ -183,7 +183,6 @@ public class PostController extends BaseController {
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
try {
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
post.setPostDate(DateUtil.date());
post.setUser(user);
post = postService.buildCategoriesAndTags(post, cateList, tagList);
post.setPostUrl(urlFilter(post.getPostUrl()));

View File

@ -137,7 +137,6 @@ public class InstallController {
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
post.setPostSummary("欢迎使用Halo进行创作删除这篇文章后赶紧开始吧。");
post.setPostStatus(0);
post.setPostDate(DateUtil.date());
post.setPostUrl("hello-halo");
post.setUser(user);
post.setCategories(categories);
@ -152,7 +151,6 @@ public class InstallController {
comment.setCommentAuthorUrl("https://ryanc.cc");
comment.setCommentAuthorIp("127.0.0.1");
comment.setCommentAuthorAvatarMd5(SecureUtil.md5("i@ryanc.cc"));
comment.setCommentDate(DateUtil.date());
comment.setCommentContent("欢迎,欢迎!");
comment.setCommentStatus(0);
comment.setCommentAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");

View File

@ -86,7 +86,6 @@ public class FrontCommentController {
post = postService.findByPostId(post.getPostId()).orElse(new Post());
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()).toLowerCase());
comment.setPost(post);
comment.setCommentDate(DateUtil.date());
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
comment.setIsAdmin(0);
comment.setCommentAuthor(HtmlUtil.escape(comment.getCommentAuthor()));