mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
56503532ae
commit
2c8f43c09b
14
pom.xml
14
pom.xml
|
@ -41,16 +41,11 @@
|
||||||
<upyun-java-sdk.version>4.0.1</upyun-java-sdk.version>
|
<upyun-java-sdk.version>4.0.1</upyun-java-sdk.version>
|
||||||
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
|
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
|
||||||
<thumbnailator.version>0.4.8</thumbnailator.version>
|
<thumbnailator.version>0.4.8</thumbnailator.version>
|
||||||
|
<jaxb-api.version>2.3.0</jaxb-api.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<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>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
@ -176,6 +171,13 @@
|
||||||
<version>${thumbnailator.version}</version>
|
<version>${thumbnailator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jaxb-api-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>${jaxb-api.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package cc.ryanc.halo.config;
|
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.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.Theme;
|
import cc.ryanc.halo.model.dto.Theme;
|
||||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||||
import cc.ryanc.halo.service.AttachmentService;
|
|
||||||
import cc.ryanc.halo.service.OptionsService;
|
import cc.ryanc.halo.service.OptionsService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
|
@ -35,14 +33,10 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
||||||
@Autowired
|
@Autowired
|
||||||
private OptionsService optionsService;
|
private OptionsService optionsService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AttachmentService attachmentService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||||
this.loadActiveTheme();
|
this.loadActiveTheme();
|
||||||
this.loadOptions();
|
this.loadOptions();
|
||||||
this.loadFiles();
|
|
||||||
this.loadThemes();
|
this.loadThemes();
|
||||||
this.loadOwo();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载所有主题
|
* 加载所有主题
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class Comment implements Serializable {
|
||||||
*/
|
*/
|
||||||
@ManyToOne(targetEntity = Post.class, fetch = FetchType.EAGER)
|
@ManyToOne(targetEntity = Post.class, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "post_id")
|
@JoinColumn(name = "post_id")
|
||||||
|
@JsonIgnore
|
||||||
private Post post;
|
private Post post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -96,7 +96,6 @@ public class Post implements Serializable {
|
||||||
* 文章的评论
|
* 文章的评论
|
||||||
*/
|
*/
|
||||||
@OneToMany(mappedBy = "post", cascade = {CascadeType.REMOVE}, fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "post", cascade = {CascadeType.REMOVE}, fetch = FetchType.EAGER)
|
||||||
@JsonIgnore
|
|
||||||
private List<Comment> comments = new ArrayList<>();
|
private List<Comment> comments = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package cc.ryanc.halo.model.dto;
|
package cc.ryanc.halo.model.dto;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Attachment;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -27,11 +25,6 @@ public class HaloConst {
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> OWO = new HashMap<>();
|
public static Map<String, String> OWO = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 所有文件
|
|
||||||
*/
|
|
||||||
public static List<Attachment> ATTACHMENTS = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有主题
|
* 所有主题
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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;
|
private String prop;
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,9 @@ import cc.ryanc.halo.model.domain.User;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.JsonResult;
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
import cc.ryanc.halo.model.enums.PostType;
|
|
||||||
import cc.ryanc.halo.model.enums.ResultCode;
|
import cc.ryanc.halo.model.enums.ResultCode;
|
||||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||||
import cc.ryanc.halo.service.CommentService;
|
import cc.ryanc.halo.service.*;
|
||||||
import cc.ryanc.halo.service.LogsService;
|
|
||||||
import cc.ryanc.halo.service.PostService;
|
|
||||||
import cc.ryanc.halo.service.UserService;
|
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
@ -62,6 +58,9 @@ public class AdminController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommentService commentService;
|
private CommentService commentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AttachmentService attachmentService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求后台页面
|
* 请求后台页面
|
||||||
*
|
*
|
||||||
|
@ -70,10 +69,7 @@ public class AdminController extends BaseController {
|
||||||
* @return 模板路径admin/admin_index
|
* @return 模板路径admin/admin_index
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = {"", "/index"})
|
@GetMapping(value = {"", "/index"})
|
||||||
public String index(Model model, HttpSession session) {
|
public String index(Model model) {
|
||||||
//查询文章条数
|
|
||||||
Integer postCount = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()).size();
|
|
||||||
model.addAttribute("postCount", postCount);
|
|
||||||
|
|
||||||
//查询评论的条数
|
//查询评论的条数
|
||||||
Integer commentCount = commentService.findAllComments().size();
|
Integer commentCount = commentService.findAllComments().size();
|
||||||
|
@ -91,8 +87,10 @@ public class AdminController extends BaseController {
|
||||||
List<Comment> comments = commentService.findCommentsLatest();
|
List<Comment> comments = commentService.findCommentsLatest();
|
||||||
model.addAttribute("comments", comments);
|
model.addAttribute("comments", comments);
|
||||||
|
|
||||||
model.addAttribute("mediaCount", HaloConst.ATTACHMENTS.size());
|
//附件数量
|
||||||
|
model.addAttribute("mediaCount", attachmentService.findAllAttachments().size());
|
||||||
|
|
||||||
|
//文章阅读总数
|
||||||
Long postViewsSum = postService.getPostViews();
|
Long postViewsSum = postService.getPostViews();
|
||||||
model.addAttribute("postViewsSum", postViewsSum);
|
model.addAttribute("postViewsSum", postViewsSum);
|
||||||
return "admin/admin_index";
|
return "admin/admin_index";
|
||||||
|
@ -120,7 +118,7 @@ public class AdminController extends BaseController {
|
||||||
* @param loginName 登录名:邮箱/用户名
|
* @param loginName 登录名:邮箱/用户名
|
||||||
* @param loginPwd loginPwd 密码
|
* @param loginPwd loginPwd 密码
|
||||||
* @param session session session
|
* @param session session session
|
||||||
* @return String 登录状态
|
* @return JsonResult JsonResult
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/getLogin")
|
@PostMapping(value = "/getLogin")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|
|
@ -2,7 +2,6 @@ package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Attachment;
|
import cc.ryanc.halo.model.domain.Attachment;
|
||||||
import cc.ryanc.halo.model.domain.Logs;
|
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.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
import cc.ryanc.halo.model.enums.PostType;
|
import cc.ryanc.halo.model.enums.PostType;
|
||||||
|
@ -50,14 +49,6 @@ public class AttachmentController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LogsService logsService;
|
private LogsService logsService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新HaloConst
|
|
||||||
*/
|
|
||||||
private void updateConst() {
|
|
||||||
HaloConst.ATTACHMENTS.clear();
|
|
||||||
HaloConst.ATTACHMENTS = attachmentService.findAllAttachments();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取upload的所有图片资源并渲染页面
|
* 获取upload的所有图片资源并渲染页面
|
||||||
*
|
*
|
||||||
|
@ -168,7 +159,6 @@ public class AttachmentController {
|
||||||
attachment.setAttachSize(HaloUtils.parseSize(new File(mediaPath, fileName).length()));
|
attachment.setAttachSize(HaloUtils.parseSize(new File(mediaPath, fileName).length()));
|
||||||
attachment.setAttachWh(HaloUtils.getImageWh(new File(mediaPath, fileName)));
|
attachment.setAttachWh(HaloUtils.getImageWh(new File(mediaPath, fileName)));
|
||||||
attachmentService.saveByAttachment(attachment);
|
attachmentService.saveByAttachment(attachment);
|
||||||
updateConst();
|
|
||||||
log.info("上传文件[{}]到[{}]成功", fileName, mediaPath.getAbsolutePath());
|
log.info("上传文件[{}]到[{}]成功", fileName, mediaPath.getAbsolutePath());
|
||||||
logsService.saveByLogs(
|
logsService.saveByLogs(
|
||||||
new Logs(LogsRecord.UPLOAD_FILE, fileName, ServletUtil.getClientIP(request), DateUtil.date())
|
new Logs(LogsRecord.UPLOAD_FILE, fileName, ServletUtil.getClientIP(request), DateUtil.date())
|
||||||
|
@ -179,7 +169,6 @@ public class AttachmentController {
|
||||||
result.put("url", attachment.getAttachPath());
|
result.put("url", attachment.getAttachPath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("上传文件失败:{}", e.getMessage());
|
log.error("上传文件失败:{}", e.getMessage());
|
||||||
e.printStackTrace();
|
|
||||||
result.put("success", 0);
|
result.put("success", 0);
|
||||||
result.put("message", "上传失败!");
|
result.put("message", "上传失败!");
|
||||||
}
|
}
|
||||||
|
@ -220,8 +209,6 @@ public class AttachmentController {
|
||||||
try {
|
try {
|
||||||
//删除数据库中的内容
|
//删除数据库中的内容
|
||||||
attachmentService.removeByAttachId(attachId);
|
attachmentService.removeByAttachId(attachId);
|
||||||
//刷新HaloConst变量
|
|
||||||
updateConst();
|
|
||||||
//删除文件
|
//删除文件
|
||||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||||
File mediaPath = new File(basePath.getAbsolutePath(), attachment.get().getAttachPath().substring(0, attachment.get().getAttachPath().lastIndexOf('/')));
|
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());
|
File delSmallFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delSmallFileName).toString());
|
||||||
if (delFile.exists() && delFile.isFile()) {
|
if (delFile.exists() && delFile.isFile()) {
|
||||||
if (delFile.delete() && delSmallFile.delete()) {
|
if (delFile.delete() && delSmallFile.delete()) {
|
||||||
updateConst();
|
|
||||||
log.info("删除文件[{}]成功!", delFileName);
|
log.info("删除文件[{}]成功!", delFileName);
|
||||||
logsService.saveByLogs(
|
logsService.saveByLogs(
|
||||||
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
|
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
<#if options.widget_postcount?default("true")=="true">
|
<#if options.widget_postcount?default("true")=="true">
|
||||||
<div class="col-lg-3 col-xs-6" id="widgetPostCountBody">
|
<div class="col-lg-3 col-xs-6" id="widgetPostCountBody">
|
||||||
<div class="small-box bg-aqua">
|
<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>
|
<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>
|
<a data-pjax="true" href="/admin/posts" class="small-box-footer">查看所有 <i class="fa fa-arrow-circle-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue