🎨 代码优化

pull/33/merge
ruibaby 2018-07-21 00:51:16 +08:00
parent 56503532ae
commit 2c8f43c09b
9 changed files with 40 additions and 57 deletions

14
pom.xml
View File

@ -41,16 +41,11 @@
<upyun-java-sdk.version>4.0.1</upyun-java-sdk.version>
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
<thumbnailator.version>0.4.8</thumbnailator.version>
<jaxb-api.version>2.3.0</jaxb-api.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@ -176,6 +171,13 @@
<version>${thumbnailator.version}</version>
</dependency>
<!-- jaxb-api-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
</dependencies>
<repositories>

View File

@ -1,10 +1,8 @@
package cc.ryanc.halo.config;
import cc.ryanc.halo.model.domain.Attachment;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.Theme;
import cc.ryanc.halo.model.enums.BlogProperties;
import cc.ryanc.halo.service.AttachmentService;
import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.web.controller.core.BaseController;
@ -35,14 +33,10 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
@Autowired
private OptionsService optionsService;
@Autowired
private AttachmentService attachmentService;
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
this.loadActiveTheme();
this.loadOptions();
this.loadFiles();
this.loadThemes();
this.loadOwo();
//启动定时任务
@ -73,16 +67,6 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
}
}
/**
*
*/
private void loadFiles() {
List<Attachment> attachments = attachmentService.findAllAttachments();
if (null != attachments) {
HaloConst.ATTACHMENTS = attachments;
}
}
/**
*
*/

View File

@ -35,6 +35,7 @@ public class Comment implements Serializable {
*/
@ManyToOne(targetEntity = Post.class, fetch = FetchType.EAGER)
@JoinColumn(name = "post_id")
@JsonIgnore
private Post post;
/**

View File

@ -96,7 +96,6 @@ public class Post implements Serializable {
*
*/
@OneToMany(mappedBy = "post", cascade = {CascadeType.REMOVE}, fetch = FetchType.EAGER)
@JsonIgnore
private List<Comment> comments = new ArrayList<>();
/**

View File

@ -1,7 +1,5 @@
package cc.ryanc.halo.model.dto;
import cc.ryanc.halo.model.domain.Attachment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -27,11 +25,6 @@ public class HaloConst {
*/
public static Map<String, String> OWO = new HashMap<>();
/**
*
*/
public static List<Attachment> ATTACHMENTS = new ArrayList<>();
/**
*
*/

View File

@ -99,7 +99,27 @@ public enum BlogProperties {
/**
*
*/
COMMENT_SYSTEM("comment_system");
COMMENT_SYSTEM("comment_system"),
/**
*
*/
WIDGET_POSTCOUNT("widget_postcount"),
/**
*
*/
WIDGET_COMMENTCOUNT("widget_commentcount"),
/**
*
*/
WIDGET_ATTACHMENTCOUNT("widget_attachmentcount"),
/**
*
*/
WIDGET_DAYCOUNT("widget_daycount");
private String prop;

View File

@ -7,13 +7,9 @@ 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.model.enums.ResultCode;
import cc.ryanc.halo.model.enums.TrueFalse;
import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.service.*;
import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
@ -62,6 +58,9 @@ public class AdminController extends BaseController {
@Autowired
private CommentService commentService;
@Autowired
private AttachmentService attachmentService;
/**
*
*
@ -70,10 +69,7 @@ public class AdminController extends BaseController {
* @return admin/admin_index
*/
@GetMapping(value = {"", "/index"})
public String index(Model model, HttpSession session) {
//查询文章条数
Integer postCount = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()).size();
model.addAttribute("postCount", postCount);
public String index(Model model) {
//查询评论的条数
Integer commentCount = commentService.findAllComments().size();
@ -91,8 +87,10 @@ public class AdminController extends BaseController {
List<Comment> comments = commentService.findCommentsLatest();
model.addAttribute("comments", comments);
model.addAttribute("mediaCount", HaloConst.ATTACHMENTS.size());
//附件数量
model.addAttribute("mediaCount", attachmentService.findAllAttachments().size());
//文章阅读总数
Long postViewsSum = postService.getPostViews();
model.addAttribute("postViewsSum", postViewsSum);
return "admin/admin_index";
@ -120,7 +118,7 @@ public class AdminController extends BaseController {
* @param loginName
* @param loginPwd loginPwd
* @param session session session
* @return String
* @return JsonResult JsonResult
*/
@PostMapping(value = "/getLogin")
@ResponseBody

View File

@ -2,7 +2,6 @@ package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Attachment;
import cc.ryanc.halo.model.domain.Logs;
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;
@ -50,14 +49,6 @@ public class AttachmentController {
@Autowired
private LogsService logsService;
/**
* HaloConst
*/
private void updateConst() {
HaloConst.ATTACHMENTS.clear();
HaloConst.ATTACHMENTS = attachmentService.findAllAttachments();
}
/**
* upload
*
@ -168,7 +159,6 @@ public class AttachmentController {
attachment.setAttachSize(HaloUtils.parseSize(new File(mediaPath, fileName).length()));
attachment.setAttachWh(HaloUtils.getImageWh(new File(mediaPath, fileName)));
attachmentService.saveByAttachment(attachment);
updateConst();
log.info("上传文件[{}]到[{}]成功", fileName, mediaPath.getAbsolutePath());
logsService.saveByLogs(
new Logs(LogsRecord.UPLOAD_FILE, fileName, ServletUtil.getClientIP(request), DateUtil.date())
@ -179,7 +169,6 @@ public class AttachmentController {
result.put("url", attachment.getAttachPath());
} catch (Exception e) {
log.error("上传文件失败:{}", e.getMessage());
e.printStackTrace();
result.put("success", 0);
result.put("message", "上传失败!");
}
@ -220,8 +209,6 @@ public class AttachmentController {
try {
//删除数据库中的内容
attachmentService.removeByAttachId(attachId);
//刷新HaloConst变量
updateConst();
//删除文件
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
File mediaPath = new File(basePath.getAbsolutePath(), attachment.get().getAttachPath().substring(0, attachment.get().getAttachPath().lastIndexOf('/')));
@ -229,7 +216,6 @@ public class AttachmentController {
File delSmallFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delSmallFileName).toString());
if (delFile.exists() && delFile.isFile()) {
if (delFile.delete() && delSmallFile.delete()) {
updateConst();
log.info("删除文件[{}]成功!", delFileName);
logsService.saveByLogs(
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())

View File

@ -127,7 +127,7 @@
<#if options.widget_postcount?default("true")=="true">
<div class="col-lg-3 col-xs-6" id="widgetPostCountBody">
<div class="small-box bg-aqua">
<div class="inner"><h3>${postCount?default(0)}</h3><p>文章</p></div>
<div class="inner"><h3><@articleTag method="postsCount">${postsCount?default(0)}</@articleTag></h3><p>文章</p></div>
<div class="icon"><i class="ion ion-bag"></i></div>
<a data-pjax="true" href="/admin/posts" class="small-box-footer">查看所有 <i class="fa fa-arrow-circle-right"></i></a>
</div>