mirror of https://github.com/halo-dev/halo
Remove unrelated files
parent
6ae4f43922
commit
b9e4aea7e8
|
@ -21,7 +21,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableCaching
|
||||
@EnableJpaAuditing
|
||||
@EnableScheduling
|
||||
@EnableJpaRepositories(basePackages = "cc.ryanc.halo.repository", repositoryBaseClass = BaseRepositoryImpl.class)
|
||||
@EnableJpaRepositories(basePackages = {"cc.ryanc.halo.repository"}, repositoryBaseClass = BaseRepositoryImpl.class)
|
||||
public class Application {
|
||||
|
||||
private final static Logger LOG = Logger.getLogger(Application.class);
|
||||
|
|
|
@ -1,19 +1,8 @@
|
|||
package cc.ryanc.halo.config;
|
||||
|
||||
import cc.ryanc.halo.model.freemarker.method.RandomMethod;
|
||||
import cc.ryanc.halo.model.freemarker.method.RecentCommentsMethod;
|
||||
import cc.ryanc.halo.model.freemarker.method.RecentPostsMethod;
|
||||
import cc.ryanc.halo.model.freemarker.tag.ArticleTagDirective;
|
||||
import cc.ryanc.halo.model.freemarker.tag.CommonTagDirective;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* FreeMarker配置
|
||||
|
@ -26,43 +15,43 @@ import javax.annotation.PostConstruct;
|
|||
@Configuration
|
||||
public class FreeMarkerAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private freemarker.template.Configuration configuration;
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CommonTagDirective commonTagDirective;
|
||||
|
||||
@Autowired
|
||||
private ArticleTagDirective articleTagDirective;
|
||||
|
||||
@Autowired
|
||||
private RandomMethod randomMethod;
|
||||
|
||||
@Autowired
|
||||
private RecentPostsMethod recentPostsMethod;
|
||||
|
||||
@Autowired
|
||||
private RecentCommentsMethod recentCommentsMethod;
|
||||
|
||||
@PostConstruct
|
||||
public void setSharedVariable() {
|
||||
try {
|
||||
//自定义标签
|
||||
configuration.setSharedVariable("commonTag", commonTagDirective);
|
||||
configuration.setSharedVariable("articleTag", articleTagDirective);
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
configuration.setSharedVariable("user", userService.findUser());
|
||||
configuration.setSharedVariable("randomMethod", randomMethod);
|
||||
configuration.setSharedVariable("recentPostsMethod", recentPostsMethod);
|
||||
configuration.setSharedVariable("recentCommentsMethod", recentCommentsMethod);
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("Custom tags failed to load:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
// @Autowired
|
||||
// private freemarker.template.Configuration configuration;
|
||||
//
|
||||
// @Autowired
|
||||
// private OptionsService optionsService;
|
||||
//
|
||||
// @Autowired
|
||||
// private UserService userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private CommonTagDirective commonTagDirective;
|
||||
//
|
||||
// @Autowired
|
||||
// private ArticleTagDirective articleTagDirective;
|
||||
//
|
||||
// @Autowired
|
||||
// private RandomMethod randomMethod;
|
||||
//
|
||||
// @Autowired
|
||||
// private RecentPostsMethod recentPostsMethod;
|
||||
//
|
||||
// @Autowired
|
||||
// private RecentCommentsMethod recentCommentsMethod;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void setSharedVariable() {
|
||||
// try {
|
||||
// //自定义标签
|
||||
// configuration.setSharedVariable("commonTag", commonTagDirective);
|
||||
// configuration.setSharedVariable("articleTag", articleTagDirective);
|
||||
// configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
// configuration.setSharedVariable("user", userService.findUser());
|
||||
// configuration.setSharedVariable("randomMethod", randomMethod);
|
||||
// configuration.setSharedVariable("recentPostsMethod", recentPostsMethod);
|
||||
// configuration.setSharedVariable("recentCommentsMethod", recentCommentsMethod);
|
||||
// } catch (TemplateModelException e) {
|
||||
// log.error("Custom tags failed to load:{}", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package cc.ryanc.halo.config;
|
||||
|
||||
import cc.ryanc.halo.config.properties.HaloProperties;
|
||||
import cc.ryanc.halo.web.interceptor.ApiInterceptor;
|
||||
import cc.ryanc.halo.web.interceptor.InstallInterceptor;
|
||||
import cc.ryanc.halo.web.interceptor.LocaleInterceptor;
|
||||
import cc.ryanc.halo.web.interceptor.LoginInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -36,53 +32,53 @@ import java.util.Locale;
|
|||
@PropertySource(value = "classpath:application.yaml", ignoreResourceNotFound = true, encoding = "UTF-8")
|
||||
public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private LoginInterceptor loginInterceptor;
|
||||
|
||||
@Autowired
|
||||
private InstallInterceptor installInterceptor;
|
||||
|
||||
@Autowired
|
||||
private ApiInterceptor apiInterceptor;
|
||||
|
||||
@Autowired
|
||||
private LocaleInterceptor localeInterceptor;
|
||||
|
||||
// @Autowired
|
||||
// private LoginInterceptor loginInterceptor;
|
||||
//
|
||||
// @Autowired
|
||||
// private InstallInterceptor installInterceptor;
|
||||
//
|
||||
// @Autowired
|
||||
// private ApiInterceptor apiInterceptor;
|
||||
//
|
||||
// @Autowired
|
||||
// private LocaleInterceptor localeInterceptor;
|
||||
//
|
||||
@Autowired
|
||||
private HaloProperties haloProperties;
|
||||
|
||||
/**
|
||||
* 注册拦截器
|
||||
*
|
||||
* @param registry registry
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(loginInterceptor)
|
||||
.addPathPatterns("/admin.*")
|
||||
.addPathPatterns("/admin/**")
|
||||
.addPathPatterns("/backup/**")
|
||||
.excludePathPatterns("/admin/login")
|
||||
.excludePathPatterns("/admin/getLogin")
|
||||
.excludePathPatterns("/admin/findPassword")
|
||||
.excludePathPatterns("/admin/sendResetPasswordEmail")
|
||||
.excludePathPatterns("/admin/toResetPassword")
|
||||
.excludePathPatterns("/admin/resetPassword")
|
||||
.excludePathPatterns("/static/**");
|
||||
registry.addInterceptor(installInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/install")
|
||||
.excludePathPatterns("/install/do")
|
||||
.excludePathPatterns("/static/**");
|
||||
registry.addInterceptor(apiInterceptor)
|
||||
.addPathPatterns("/api/**");
|
||||
registry.addInterceptor(localeInterceptor)
|
||||
.addPathPatterns("/admin.*")
|
||||
.addPathPatterns("/admin/**")
|
||||
.addPathPatterns("/install");
|
||||
registry.addInterceptor(localeChangeInterceptor())
|
||||
.addPathPatterns("/install");
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 注册拦截器
|
||||
// *
|
||||
// * @param registry registry
|
||||
// */
|
||||
// @Override
|
||||
// public void addInterceptors(InterceptorRegistry registry) {
|
||||
// registry.addInterceptor(loginInterceptor)
|
||||
// .addPathPatterns("/admin.*")
|
||||
// .addPathPatterns("/admin/**")
|
||||
// .addPathPatterns("/backup/**")
|
||||
// .excludePathPatterns("/admin/login")
|
||||
// .excludePathPatterns("/admin/getLogin")
|
||||
// .excludePathPatterns("/admin/findPassword")
|
||||
// .excludePathPatterns("/admin/sendResetPasswordEmail")
|
||||
// .excludePathPatterns("/admin/toResetPassword")
|
||||
// .excludePathPatterns("/admin/resetPassword")
|
||||
// .excludePathPatterns("/static/**");
|
||||
// registry.addInterceptor(installInterceptor)
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns("/install")
|
||||
// .excludePathPatterns("/install/do")
|
||||
// .excludePathPatterns("/static/**");
|
||||
// registry.addInterceptor(apiInterceptor)
|
||||
// .addPathPatterns("/api/**");
|
||||
// registry.addInterceptor(localeInterceptor)
|
||||
// .addPathPatterns("/admin.*")
|
||||
// .addPathPatterns("/admin/**")
|
||||
// .addPathPatterns("/install");
|
||||
// registry.addInterceptor(localeChangeInterceptor())
|
||||
// .addPathPatterns("/install");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 配置静态资源路径
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package cc.ryanc.halo.listener;
|
||||
|
||||
import cc.ryanc.halo.config.properties.HaloProperties;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.support.HaloConst;
|
||||
import cc.ryanc.halo.model.support.Theme;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
|
@ -16,12 +10,6 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 应用启动完成后所执行的方法
|
||||
|
@ -34,9 +22,6 @@ import static cc.ryanc.halo.model.support.HaloConst.*;
|
|||
@Configuration
|
||||
public class StartedListener implements ApplicationListener<ApplicationStartedEvent> {
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private freemarker.template.Configuration configuration;
|
||||
|
||||
|
@ -49,15 +34,11 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
// save halo version to database
|
||||
optionsService.saveOption("version", HALO_VERSION);
|
||||
try {
|
||||
this.loadActiveTheme();
|
||||
} catch (TemplateModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.loadOptions();
|
||||
this.loadThemes();
|
||||
this.loadOwo();
|
||||
// TODO Complete cache option value
|
||||
// TODO Complete load active theme
|
||||
// TODO Complete load option
|
||||
// TODO Load themes
|
||||
// TODO Load owo
|
||||
|
||||
this.printStartInfo();
|
||||
}
|
||||
|
@ -84,7 +65,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
// Get server port
|
||||
String serverPort = applicationContext.getEnvironment().getProperty("server.port");
|
||||
|
||||
String blogUrl = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
|
||||
String blogUrl = null;
|
||||
|
||||
if (StrUtil.isNotBlank(blogUrl)) {
|
||||
blogUrl = StrUtil.removeSuffix(blogUrl, "/");
|
||||
|
@ -94,182 +75,4 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
|
||||
return blogUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载主题设置
|
||||
*/
|
||||
private void loadActiveTheme() throws TemplateModelException {
|
||||
final String themeValue = optionsService.findOneOption(BlogPropertiesEnum.THEME.getProp());
|
||||
if (StrUtil.isNotEmpty(themeValue) && !StrUtil.equals(themeValue, null)) {
|
||||
BaseController.THEME = themeValue;
|
||||
} else {
|
||||
//如果没有设置主题,则默认
|
||||
BaseController.THEME = "anatole";
|
||||
}
|
||||
configuration.setSharedVariable("themeName", BaseController.THEME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载设置选项
|
||||
*/
|
||||
private void loadOptions() {
|
||||
final Map<String, String> options = optionsService.findAllOptions();
|
||||
if (options != null && !options.isEmpty()) {
|
||||
OPTIONS = options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载所有主题
|
||||
*/
|
||||
private void loadThemes() {
|
||||
THEMES.clear();
|
||||
final List<Theme> themes = HaloUtils.getThemes();
|
||||
if (null != themes) {
|
||||
THEMES = themes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载OwO表情
|
||||
*/
|
||||
private void loadOwo() {
|
||||
final Map<String, String> map = new HashMap<>(135);
|
||||
map.put("@[nico]", "<img src='/static/halo-common/OwO/paopao/nico.png' alt='nico.png' style='vertical-align: middle;'>");
|
||||
map.put("@[OK]", "<img src='/static/halo-common/OwO/paopao/OK.png' alt='OK.png' style='vertical-align: middle;'>");
|
||||
map.put("@[what]", "<img src='/static/halo-common/OwO/paopao/what.png' alt='what.png' style='vertical-align: middle;'>");
|
||||
map.put("@[三道杠]", "<img src='/static/halo-common/OwO/paopao/三道杠.png' alt='三道杠.png' style='vertical-align: middle;'>");
|
||||
map.put("@[不高兴]", "<img src='/static/halo-common/OwO/paopao/不高兴.png' alt='不高兴.png' style='vertical-align: middle;'>");
|
||||
map.put("@[乖]", "<img src='/static/halo-common/OwO/paopao/乖.png' alt='乖.png' style='vertical-align: middle;'>");
|
||||
map.put("@[你懂的]", "<img src='/static/halo-common/OwO/paopao/你懂的.png' alt='你懂的.png' style='vertical-align: middle;'>");
|
||||
map.put("@[便便]", "<img src='/static/halo-common/OwO/paopao/便便.png' alt='便便.png' style='vertical-align: middle;'>");
|
||||
map.put("@[冷]", "<img src='/static/halo-common/OwO/paopao/冷.png' alt='冷.png' style='vertical-align: middle;'>");
|
||||
map.put("@[勉强]", "<img src='/static/halo-common/OwO/paopao/勉强.png' alt='勉强.png' style='vertical-align: middle;'>");
|
||||
map.put("@[吃瓜]", "<img src='/static/halo-common/OwO/paopao/吃瓜.png' alt='吃瓜.png' style='vertical-align: middle;'>");
|
||||
map.put("@[吃翔]", "<img src='/static/halo-common/OwO/paopao/吃翔.png' alt='吃翔.png' style='vertical-align: middle;'>");
|
||||
map.put("@[吐]", "<img src='/static/halo-common/OwO/paopao/吐.png' alt='吐.png' style='vertical-align: middle;'>");
|
||||
map.put("@[吐舌]", "<img src='/static/halo-common/OwO/paopao/吐舌.png' alt='吐舌.png' style='vertical-align: middle;'>");
|
||||
map.put("@[呀咩爹]", "<img src='/static/halo-common/OwO/paopao/呀咩爹.png' alt='呀咩爹.png' style='vertical-align: middle;'>");
|
||||
map.put("@[呵呵]", "<img src='/static/halo-common/OwO/paopao/呵呵.png' alt='呵呵.png' style='vertical-align: middle;'>");
|
||||
map.put("@[呼]", "<img src='/static/halo-common/OwO/paopao/呼.png' alt='呼.png' style='vertical-align: middle;'>");
|
||||
map.put("@[咦]", "<img src='/static/halo-common/OwO/paopao/咦.png' alt='咦.png' style='vertical-align: middle;'>");
|
||||
map.put("@[哈哈]", "<img src='/static/halo-common/OwO/paopao/哈哈.png' alt='哈哈.png' style='vertical-align: middle;'>");
|
||||
map.put("@[啊]", "<img src='/static/halo-common/OwO/paopao/啊.png' alt='啊.png' style='vertical-align: middle;'>");
|
||||
map.put("@[喷]", "<img src='/static/halo-common/OwO/paopao/喷.png' alt='喷.png' style='vertical-align: middle;'>");
|
||||
map.put("@[嘚瑟]", "<img src='/static/halo-common/OwO/paopao/嘚瑟.png' alt='嘚瑟.png' style='vertical-align: middle;'>");
|
||||
map.put("@[大拇指]", "<img src='/static/halo-common/OwO/paopao/大拇指.png' alt='大拇指.png' style='vertical-align: middle;'>");
|
||||
map.put("@[太开心]", "<img src='/static/halo-common/OwO/paopao/太开心.png' alt='太开心.png' style='vertical-align: middle;'>");
|
||||
map.put("@[太阳]", "<img src='/static/halo-common/OwO/paopao/太阳.png' alt='太阳.png' style='vertical-align: middle;'>");
|
||||
map.put("@[委屈]", "<img src='/static/halo-common/OwO/paopao/委屈.png' alt='委屈.png' style='vertical-align: middle;'>");
|
||||
map.put("@[小乖]", "<img src='/static/halo-common/OwO/paopao/小乖.png' alt='小乖.png' style='vertical-align: middle;'>");
|
||||
map.put("@[小红脸]", "<img src='/static/halo-common/OwO/paopao/小红脸.png' alt='小红脸.png' style='vertical-align: middle;'>");
|
||||
map.put("@[开心]", "<img src='/static/halo-common/OwO/paopao/开心.png' alt='开心.png' style='vertical-align: middle;'>");
|
||||
map.put("@[弱]", "<img src='/static/halo-common/OwO/paopao/弱.png' alt='弱.png' style='vertical-align: middle;'>");
|
||||
map.put("@[彩虹]", "<img src='/static/halo-common/OwO/paopao/彩虹.png' alt='彩虹.png' style='vertical-align: middle;'>");
|
||||
map.put("@[心碎]", "<img src='/static/halo-common/OwO/paopao/心碎.png' alt='心碎.png' style='vertical-align: middle;'>");
|
||||
map.put("@[怒]", "<img src='/static/halo-common/OwO/paopao/怒.png' alt='怒.png' style='vertical-align: middle;'>");
|
||||
map.put("@[惊哭]", "<img src='/static/halo-common/OwO/paopao/惊哭.png' alt='惊哭.png' style='vertical-align: middle;'>");
|
||||
map.put("@[惊恐]", "<img src='/static/halo-common/OwO/paopao/惊恐.png' alt='惊恐.png' style='vertical-align: middle;'>");
|
||||
map.put("@[惊讶]", "<img src='/static/halo-common/OwO/paopao/惊讶.png' alt='惊讶.png' style='vertical-align: middle;'>");
|
||||
map.put("@[懒得理]", "<img src='/static/halo-common/OwO/paopao/懒得理.png' alt='懒得理.png' style='vertical-align: middle;'>");
|
||||
map.put("@[手纸]", "<img src='/static/halo-common/OwO/paopao/手纸.png' alt='手纸.png' style='vertical-align: middle;'>");
|
||||
map.put("@[挖鼻]", "<img src='/static/halo-common/OwO/paopao/挖鼻.png' alt='挖鼻.png' style='vertical-align: middle;'>");
|
||||
map.put("@[捂嘴笑]", "<img src='/static/halo-common/OwO/paopao/捂嘴笑.png' alt='捂嘴笑.png' style='vertical-align: middle;'>");
|
||||
map.put("@[星星月亮]", "<img src='/static/halo-common/OwO/paopao/星星月亮.png' alt='星星月亮.png' style='vertical-align: middle;'>");
|
||||
map.put("@[汗]", "<img src='/static/halo-common/OwO/paopao/汗.png' alt='汗.png' style='vertical-align: middle;'>");
|
||||
map.put("@[沙发]", "<img src='/static/halo-common/OwO/paopao/沙发.png' alt='沙发.png' style='vertical-align: middle;'>");
|
||||
map.put("@[泪]", "<img src='/static/halo-common/OwO/paopao/泪.png' alt='泪.png' style='vertical-align: middle;'>");
|
||||
map.put("@[滑稽]", "<img src='/static/halo-common/OwO/paopao/滑稽.png' alt='滑稽.png' style='vertical-align: middle;'>");
|
||||
map.put("@[灯泡]", "<img src='/static/halo-common/OwO/paopao/灯泡.png' alt='灯泡.png' style='vertical-align: middle;'>");
|
||||
map.put("@[爱心]", "<img src='/static/halo-common/OwO/paopao/爱心.png' alt='爱心.png' style='vertical-align: middle;'>");
|
||||
map.put("@[犀利]", "<img src='/static/halo-common/OwO/paopao/犀利.png' alt='犀利.png' style='vertical-align: middle;'>");
|
||||
map.put("@[狂汗]", "<img src='/static/halo-common/OwO/paopao/狂汗.png' alt='狂汗.png' style='vertical-align: middle;'>");
|
||||
map.put("@[玫瑰]", "<img src='/static/halo-common/OwO/paopao/玫瑰.png' alt='玫瑰.png' style='vertical-align: middle;'>");
|
||||
map.put("@[生气]", "<img src='/static/halo-common/OwO/paopao/生气.png' alt='生气.png' style='vertical-align: middle;'>");
|
||||
map.put("@[疑问]", "<img src='/static/halo-common/OwO/paopao/疑问.png' alt='疑问.png' style='vertical-align: middle;'>");
|
||||
map.put("@[真棒]", "<img src='/static/halo-common/OwO/paopao/真棒.png' alt='真棒.png' style='vertical-align: middle;'>");
|
||||
map.put("@[睡觉]", "<img src='/static/halo-common/OwO/paopao/睡觉.png' alt='睡觉.png' style='vertical-align: middle;'>");
|
||||
map.put("@[礼物]", "<img src='/static/halo-common/OwO/paopao/礼物.png' alt='礼物.png' style='vertical-align: middle;'>");
|
||||
map.put("@[笑尿]", "<img src='/static/halo-common/OwO/paopao/笑尿.png' alt='笑尿.png' style='vertical-align: middle;'>");
|
||||
map.put("@[笑眼]", "<img src='/static/halo-common/OwO/paopao/笑眼.png' alt='笑眼.png' style='vertical-align: middle;'>");
|
||||
map.put("@[红领巾]", "<img src='/static/halo-common/OwO/paopao/红领巾.png' alt='红领巾.png' style='vertical-align: middle;'>");
|
||||
map.put("@[胜利]", "<img src='/static/halo-common/OwO/paopao/胜利.png' alt='胜利.png' style='vertical-align: middle;'>");
|
||||
map.put("@[花心]", "<img src='/static/halo-common/OwO/paopao/花心.png' alt='花心.png' style='vertical-align: middle;'>");
|
||||
map.put("@[茶杯]", "<img src='/static/halo-common/OwO/paopao/茶杯.png' alt='茶杯.png' style='vertical-align: middle;'>");
|
||||
map.put("@[药丸]", "<img src='/static/halo-common/OwO/paopao/药丸.png' alt='药丸.png' style='vertical-align: middle;'>");
|
||||
map.put("@[蛋糕]", "<img src='/static/halo-common/OwO/paopao/蛋糕.png' alt='蛋糕.png' style='vertical-align: middle;'>");
|
||||
map.put("@[蜡烛]", "<img src='/static/halo-common/OwO/paopao/蜡烛.png' alt='蜡烛.png' style='vertical-align: middle;'>");
|
||||
map.put("@[鄙视]", "<img src='/static/halo-common/OwO/paopao/鄙视.png' alt='鄙视.png' style='vertical-align: middle;'>");
|
||||
map.put("@[酷]", "<img src='/static/halo-common/OwO/paopao/酷.png' alt='酷.png' style='vertical-align: middle;'>");
|
||||
map.put("@[酸爽]", "<img src='/static/halo-common/OwO/paopao/酸爽.png' alt='酸爽.png' style='vertical-align: middle;'>");
|
||||
map.put("@[钱]", "<img src='/static/halo-common/OwO/paopao/钱.png' alt='钱.png' style='vertical-align: middle;'>");
|
||||
map.put("@[钱币]", "<img src='/static/halo-common/OwO/paopao/钱币.png' alt='钱币.png' style='vertical-align: middle;'>");
|
||||
map.put("@[阴险]", "<img src='/static/halo-common/OwO/paopao/阴险.png' alt='阴险.png' style='vertical-align: middle;'>");
|
||||
map.put("@[音乐]", "<img src='/static/halo-common/OwO/paopao/音乐.png' alt='音乐.png' style='vertical-align: middle;'>");
|
||||
map.put("@[香蕉]", "<img src='/static/halo-common/OwO/paopao/香蕉.png' alt='香蕉.png' style='vertical-align: middle;'>");
|
||||
map.put("@[黑线]", "<img src='/static/halo-common/OwO/paopao/黑线.png' alt='黑线.png' style='vertical-align: middle;'>");
|
||||
map.put("@(不出所料)", "<img src='/static/halo-common/OwO/alu/不出所料.png' alt='不出所料.png' style='vertical-align: middle;'>");
|
||||
map.put("@(不说话)", "<img src='/static/halo-common/OwO/alu/不说话.png' alt='不说话.png' style='vertical-align: middle;'>");
|
||||
map.put("@(不高兴)", "<img src='/static/halo-common/OwO/alu/不高兴.png' alt='不高兴.png' style='vertical-align: middle;'>");
|
||||
map.put("@(中刀)", "<img src='/static/halo-common/OwO/alu/中刀.png' alt='中刀.png' style='vertical-align: middle;'>");
|
||||
map.put("@(中指)", "<img src='/static/halo-common/OwO/alu/中指.png' alt='中指.png' style='vertical-align: middle;'>");
|
||||
map.put("@(中枪)", "<img src='/static/halo-common/OwO/alu/中枪.png' alt='中枪.png' style='vertical-align: middle;'>");
|
||||
map.put("@(亲亲)", "<img src='/static/halo-common/OwO/alu/亲亲.png' alt='亲亲.png' style='vertical-align: middle;'>");
|
||||
map.put("@(便便)", "<img src='/static/halo-common/OwO/alu/便便.png' alt='便便.png' style='vertical-align: middle;'>");
|
||||
map.put("@(傻笑)", "<img src='/static/halo-common/OwO/alu/傻笑.png' alt='傻笑.png' style='vertical-align: middle;'>");
|
||||
map.put("@(内伤)", "<img src='/static/halo-common/OwO/alu/内伤.png' alt='内伤.png' style='vertical-align: middle;'>");
|
||||
map.put("@(击掌)", "<img src='/static/halo-common/OwO/alu/击掌.png' alt='击掌.png' style='vertical-align: middle;'>");
|
||||
map.put("@(口水)", "<img src='/static/halo-common/OwO/alu/口水.png' alt='口水.png' style='vertical-align: middle;'>");
|
||||
map.put("@(吐)", "<img src='/static/halo-common/OwO/alu/吐.png' alt='吐.png' style='vertical-align: middle;'>");
|
||||
map.put("@(吐舌)", "<img src='/static/halo-common/OwO/alu/吐舌.png' alt='吐舌.png' style='vertical-align: middle;'>");
|
||||
map.put("@(吐血倒地)", "<img src='/static/halo-common/OwO/alu/吐血倒地.png' alt='吐血倒地.png' style='vertical-align: middle;'>");
|
||||
map.put("@(呲牙)", "<img src='/static/halo-common/OwO/alu/呲牙.png' alt='呲牙.png' style='vertical-align: middle;'>");
|
||||
map.put("@(咽气)", "<img src='/static/halo-common/OwO/alu/咽气.png' alt='咽气.png' style='vertical-align: middle;'>");
|
||||
map.put("@(哭泣)", "<img src='/static/halo-common/OwO/alu/哭泣.png' alt='哭泣.png' style='vertical-align: middle;'>");
|
||||
map.put("@(喜极而泣)", "<img src='/static/halo-common/OwO/alu/喜极而泣.png' alt='喜极而泣.png' style='vertical-align: middle;'>");
|
||||
map.put("@(喷水)", "<img src='/static/halo-common/OwO/alu/喷水.png' alt='喷水.png' style='vertical-align: middle;'>");
|
||||
map.put("@(喷血)", "<img src='/static/halo-common/OwO/alu/喷血.png' alt='喷血.png' style='vertical-align: middle;'>");
|
||||
map.put("@(坐等)", "<img src='/static/halo-common/OwO/alu/坐等.png' alt='坐等.png' style='vertical-align: middle;'>");
|
||||
map.put("@(大囧)", "<img src='/static/halo-common/OwO/alu/大囧.png' alt='大囧.png' style='vertical-align: middle;'>");
|
||||
map.put("@(害羞)", "<img src='/static/halo-common/OwO/alu/害羞.png' alt='害羞.png' style='vertical-align: middle;'>");
|
||||
map.put("@(小怒)", "<img src='/static/halo-common/OwO/alu/小怒.png' alt='小怒.png' style='vertical-align: middle;'>");
|
||||
map.put("@(小眼睛)", "<img src='/static/halo-common/OwO/alu/小眼睛.png' alt='小眼睛.png' style='vertical-align: middle;'>");
|
||||
map.put("@(尴尬)", "<img src='/static/halo-common/OwO/alu/尴尬.png' alt='尴尬.png' style='vertical-align: middle;'>");
|
||||
map.put("@(得意)", "<img src='/static/halo-common/OwO/alu/得意.png' alt='得意.png' style='vertical-align: middle;'>");
|
||||
map.put("@(惊喜)", "<img src='/static/halo-common/OwO/alu/惊喜.png' alt='惊喜.png' style='vertical-align: middle;'>");
|
||||
map.put("@(想一想)", "<img src='/static/halo-common/OwO/alu/想一想.png' alt='想一想.png' style='vertical-align: middle;'>");
|
||||
map.put("@(愤怒)", "<img src='/static/halo-common/OwO/alu/愤怒.png' alt='愤怒.png' style='vertical-align: middle;'>");
|
||||
map.put("@(扇耳光)", "<img src='/static/halo-common/OwO/alu/扇耳光.png' alt='扇耳光.png' style='vertical-align: middle;'>");
|
||||
map.put("@(投降)", "<img src='/static/halo-common/OwO/alu/投降.png' alt='投降.png' style='vertical-align: middle;'>");
|
||||
map.put("@(抠鼻)", "<img src='/static/halo-common/OwO/alu/抠鼻.png' alt='抠鼻.png' style='vertical-align: middle;'>");
|
||||
map.put("@(抽烟)", "<img src='/static/halo-common/OwO/alu/抽烟.png' alt='抽烟.png' style='vertical-align: middle;'>");
|
||||
map.put("@(无奈)", "<img src='/static/halo-common/OwO/alu/无奈.png' alt='无奈.png' style='vertical-align: middle;'>");
|
||||
map.put("@(无所谓)", "<img src='/static/halo-common/OwO/alu/无所谓.png' alt='无所谓.png' style='vertical-align: middle;'>");
|
||||
map.put("@(无语)", "<img src='/static/halo-common/OwO/alu/无语.png' alt='无语.png' style='vertical-align: middle;'>");
|
||||
map.put("@(暗地观察)", "<img src='/static/halo-common/OwO/alu/暗地观察.png' alt='暗地观察.png' style='vertical-align: middle;'>");
|
||||
map.put("@(期待)", "<img src='/static/halo-common/OwO/alu/期待.png' alt='期待.png' style='vertical-align: middle;'>");
|
||||
map.put("@(欢呼)", "<img src='/static/halo-common/OwO/alu/欢呼.png' alt='欢呼.png' style='vertical-align: middle;'>");
|
||||
map.put("@(汗)", "<img src='/static/halo-common/OwO/alu/汗.png' alt='汗.png' style='vertical-align: middle;'>");
|
||||
map.put("@(深思)", "<img src='/static/halo-common/OwO/alu/深思.png' alt='深思.png' style='vertical-align: middle;'>");
|
||||
map.put("@(狂汗)", "<img src='/static/halo-common/OwO/alu/狂汗.png' alt='狂汗.png' style='vertical-align: middle;'>");
|
||||
map.put("@(献花)", "<img src='/static/halo-common/OwO/alu/献花.png' alt='献花.png' style='vertical-align: middle;'>");
|
||||
map.put("@(献黄瓜)", "<img src='/static/halo-common/OwO/alu/献黄瓜.png' alt='献黄瓜.png' style='vertical-align: middle;'>");
|
||||
map.put("@(皱眉)", "<img src='/static/halo-common/OwO/alu/皱眉.png' alt='皱眉.png' style='vertical-align: middle;'>");
|
||||
map.put("@(看不见)", "<img src='/static/halo-common/OwO/alu/看不见.png' alt='看不见.png' style='vertical-align: middle;'>");
|
||||
map.put("@(看热闹)", "<img src='/static/halo-common/OwO/alu/看热闹.png' alt='看热闹.png' style='vertical-align: middle;'>");
|
||||
map.put("@(肿包)", "<img src='/static/halo-common/OwO/alu/肿包.png' alt='肿包.png' style='vertical-align: middle;'>");
|
||||
map.put("@(脸红)", "<img src='/static/halo-common/OwO/alu/脸红.png' alt='脸红.png' style='vertical-align: middle;'>");
|
||||
map.put("@(蜡烛)", "<img src='/static/halo-common/OwO/alu/蜡烛.png' alt='蜡烛.png' style='vertical-align: middle;'>");
|
||||
map.put("@(装大款)", "<img src='/static/halo-common/OwO/alu/装大款.png' alt='装大款.png' style='vertical-align: middle;'>");
|
||||
map.put("@(观察)", "<img src='/static/halo-common/OwO/alu/观察.png' alt='观察.png' style='vertical-align: middle;'>");
|
||||
map.put("@(赞一个)", "<img src='/static/halo-common/OwO/alu/赞一个.png' alt='赞一个.png' style='vertical-align: middle;'>");
|
||||
map.put("@(邪恶)", "<img src='/static/halo-common/OwO/alu/邪恶.png' alt='邪恶.png' style='vertical-align: middle;'>");
|
||||
map.put("@(锁眉)", "<img src='/static/halo-common/OwO/alu/锁眉.png' alt='锁眉.png' style='vertical-align: middle;'>");
|
||||
map.put("@(长草)", "<img src='/static/halo-common/OwO/alu/长草.png' alt='长草.png' style='vertical-align: middle;'>");
|
||||
map.put("@(阴暗)", "<img src='/static/halo-common/OwO/alu/阴暗.png' alt='阴暗.png' style='vertical-align: middle;'>");
|
||||
map.put("@(高兴)", "<img src='/static/halo-common/OwO/alu/高兴.png' alt='高兴.png' style='vertical-align: middle;'>");
|
||||
map.put("@(黑线)", "<img src='/static/halo-common/OwO/alu/黑线.png' alt='黑线.png' style='vertical-align: middle;'>");
|
||||
map.put("@(鼓掌)", "<img src='/static/halo-common/OwO/alu/鼓掌.png' alt='鼓掌.png' style='vertical-align: middle;'>");
|
||||
OWO = map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附件
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/10
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_attachment")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Deprecated
|
||||
public class Attachment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3060117944880138064L;
|
||||
|
||||
/**
|
||||
* 附件编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long attachId;
|
||||
|
||||
/**
|
||||
* 附件名
|
||||
*/
|
||||
private String attachName;
|
||||
|
||||
/**
|
||||
* 附件路径
|
||||
*/
|
||||
private String attachPath;
|
||||
|
||||
/**
|
||||
* 附件缩略图路径
|
||||
*/
|
||||
private String attachSmallPath;
|
||||
|
||||
/**
|
||||
* 附件类型
|
||||
*/
|
||||
private String attachType;
|
||||
|
||||
/**
|
||||
* 附件后缀
|
||||
*/
|
||||
private String attachSuffix;
|
||||
|
||||
/**
|
||||
* 上传时间
|
||||
*/
|
||||
@CreatedDate
|
||||
private Date attachCreated;
|
||||
|
||||
/**
|
||||
* 附件大小
|
||||
*/
|
||||
private String attachSize;
|
||||
|
||||
/**
|
||||
* 附件长宽
|
||||
*/
|
||||
private String attachWh;
|
||||
|
||||
/**
|
||||
* 附件存储地址
|
||||
*/
|
||||
private String attachLocation;
|
||||
|
||||
/**
|
||||
* 附件来源,0:上传,1:外部链接
|
||||
*/
|
||||
private Integer attachOrigin = 0;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章分类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_category")
|
||||
@Deprecated
|
||||
public class Category implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8383678847517271505L;
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long cateId;
|
||||
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotBlank(message = "分类名称不能为空")
|
||||
private String cateName;
|
||||
|
||||
/**
|
||||
* 分类路径
|
||||
*/
|
||||
@NotBlank(message = "分类路径不能为空")
|
||||
private String cateUrl;
|
||||
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String cateDesc;
|
||||
|
||||
@ManyToMany(mappedBy = "categories")
|
||||
@JsonIgnore
|
||||
private List<Post> posts = new ArrayList<>();
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/22
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_comment")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Deprecated
|
||||
public class Comment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6639021627094260505L;
|
||||
|
||||
/**
|
||||
* 评论id 自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long commentId;
|
||||
|
||||
/**
|
||||
* 评论文章
|
||||
*/
|
||||
@ManyToOne(targetEntity = Post.class, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "post_id")
|
||||
@JsonIgnore
|
||||
private Post post;
|
||||
|
||||
/**
|
||||
* 评论人
|
||||
*/
|
||||
@NotBlank(message = "评论用户名不能为空")
|
||||
private String commentAuthor;
|
||||
|
||||
/**
|
||||
* 评论人的邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@JsonIgnore
|
||||
private String commentAuthorEmail;
|
||||
|
||||
/**
|
||||
* 评论人的主页
|
||||
*/
|
||||
private String commentAuthorUrl;
|
||||
|
||||
/**
|
||||
* 评论人的ip
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String commentAuthorIp;
|
||||
|
||||
/**
|
||||
* 评论人的头像,用于gavatar
|
||||
*/
|
||||
private String commentAuthorAvatarMd5;
|
||||
|
||||
/**
|
||||
* 评论时间
|
||||
*/
|
||||
@CreatedDate
|
||||
private Date commentDate;
|
||||
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
@NotBlank(message = "评论内容不能为空")
|
||||
@Lob
|
||||
private String commentContent;
|
||||
|
||||
/**
|
||||
* 评论者ua信息
|
||||
*/
|
||||
@Column(length = 512)
|
||||
private String commentAgent;
|
||||
|
||||
/**
|
||||
* 上一级
|
||||
*/
|
||||
private Long commentParent = 0L;
|
||||
|
||||
/**
|
||||
* 评论状态,0:正常,1:待审核,2:回收站
|
||||
*/
|
||||
private Integer commentStatus = 1;
|
||||
|
||||
/**
|
||||
* 是否是博主的评论 0:不是 1:是
|
||||
*/
|
||||
private Integer isAdmin;
|
||||
|
||||
/**
|
||||
* 当前评论下的所有子评论
|
||||
*/
|
||||
@Transient
|
||||
private List<Comment> childComments;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
public Date getCommentDate() {
|
||||
return commentDate;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 相册
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/2/26
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_gallery")
|
||||
@Deprecated
|
||||
public class Gallery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1646093266970933841L;
|
||||
|
||||
/**
|
||||
* 图片编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long galleryId;
|
||||
|
||||
/**
|
||||
* 图片名称
|
||||
*/
|
||||
private String galleryName;
|
||||
|
||||
/**
|
||||
* 图片描述
|
||||
*/
|
||||
private String galleryDesc;
|
||||
|
||||
/**
|
||||
* 图片日期/拍摄日期
|
||||
*/
|
||||
private String galleryDate;
|
||||
|
||||
/**
|
||||
* 图片拍摄地点
|
||||
*/
|
||||
private String galleryLocation;
|
||||
|
||||
/**
|
||||
* 图片缩略图地址
|
||||
*/
|
||||
private String galleryThumbnailUrl;
|
||||
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String galleryUrl;
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_link")
|
||||
@Deprecated
|
||||
public class Link implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5441686055841177588L;
|
||||
|
||||
/**
|
||||
* 友情链接编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long linkId;
|
||||
|
||||
/**
|
||||
* 友情链接名称
|
||||
*/
|
||||
@NotEmpty(message = "友情链接名称不能为空!")
|
||||
private String linkName;
|
||||
|
||||
/**
|
||||
* 友情链接地址
|
||||
*/
|
||||
@NotEmpty(message = "友情链接地址不能为空!")
|
||||
private String linkUrl;
|
||||
|
||||
/**
|
||||
* 友情链接头像
|
||||
*/
|
||||
private String linkPic;
|
||||
|
||||
/**
|
||||
* 友情链接描述
|
||||
*/
|
||||
private String linkDesc;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 操作日志
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/19
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_logs")
|
||||
@Deprecated
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class Logs implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2571815432301283171L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long logId;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String logTitle;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String logContent;
|
||||
|
||||
/**
|
||||
* 产生日志的ip
|
||||
*/
|
||||
private String logIp;
|
||||
|
||||
/**
|
||||
* 产生的时间
|
||||
*/
|
||||
@CreatedDate
|
||||
private Date logCreated;
|
||||
|
||||
public Logs() {
|
||||
}
|
||||
|
||||
public Logs(String logTitle, String logContent, String logIp, Date logCreated) {
|
||||
this.logTitle = logTitle;
|
||||
this.logContent = logContent;
|
||||
this.logIp = logIp;
|
||||
this.logCreated = logCreated;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 菜单
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/24
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_menu")
|
||||
@Deprecated
|
||||
public class Menu implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7726233157376388786L;
|
||||
|
||||
/**
|
||||
* 编号 自增
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@NotEmpty(message = "菜单名称不能为空!")
|
||||
private String menuName;
|
||||
|
||||
/**
|
||||
* 菜单路径
|
||||
*/
|
||||
@NotEmpty(message = "菜单路径不能为空!")
|
||||
private String menuUrl;
|
||||
|
||||
/**
|
||||
* 排序编号
|
||||
*/
|
||||
@NotNull(message = "排序编号不能为空!")
|
||||
private Integer menuSort;
|
||||
|
||||
/**
|
||||
* 图标,可选,部分主题可显示
|
||||
*/
|
||||
private String menuIcon;
|
||||
|
||||
/**
|
||||
* 打开方式
|
||||
*/
|
||||
private String menuTarget;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 系统设置
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_options")
|
||||
@Deprecated
|
||||
public class Options implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4065369084341893446L;
|
||||
|
||||
/**
|
||||
* 设置项名称
|
||||
*/
|
||||
@Id
|
||||
@Column(length = 127)
|
||||
private String optionName;
|
||||
|
||||
/**
|
||||
* 设置项的值
|
||||
*/
|
||||
@Lob
|
||||
private String optionValue;
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章/页面
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_post")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Deprecated
|
||||
public class Post implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6019684584665869629L;
|
||||
|
||||
/**
|
||||
* 文章编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long postId;
|
||||
|
||||
/**
|
||||
* 发表用户 多对一
|
||||
*/
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* 文章标题
|
||||
*/
|
||||
private String postTitle;
|
||||
|
||||
/**
|
||||
* 文章类型
|
||||
* post 文章
|
||||
* page 页面
|
||||
* journal 日志
|
||||
*/
|
||||
private String postType = "post";
|
||||
|
||||
/**
|
||||
* 文章内容 Markdown格式
|
||||
*/
|
||||
@Lob
|
||||
private String postContentMd;
|
||||
|
||||
/**
|
||||
* 文章内容 html格式
|
||||
*/
|
||||
@Lob
|
||||
@JsonIgnore
|
||||
private String postContent;
|
||||
|
||||
/**
|
||||
* 文章路径
|
||||
*/
|
||||
@Column(unique = true)
|
||||
private String postUrl;
|
||||
|
||||
/**
|
||||
* 文章摘要
|
||||
*/
|
||||
private String postSummary;
|
||||
|
||||
/**
|
||||
* 文章所属分类
|
||||
*/
|
||||
@ManyToMany(cascade = {CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
@JoinTable(name = "halo_posts_categories",
|
||||
joinColumns = {@JoinColumn(name = "post_id", nullable = false)},
|
||||
inverseJoinColumns = {@JoinColumn(name = "cate_id", nullable = false)})
|
||||
private List<Category> categories = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 文章所属标签
|
||||
*/
|
||||
@ManyToMany(cascade = {CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
@JoinTable(name = "halo_posts_tags",
|
||||
joinColumns = {@JoinColumn(name = "post_id", nullable = false)},
|
||||
inverseJoinColumns = {@JoinColumn(name = "tag_id", nullable = false)})
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 文章的评论
|
||||
*/
|
||||
@OneToMany(mappedBy = "post", cascade = {CascadeType.REMOVE}, fetch = FetchType.EAGER)
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 缩略图
|
||||
*/
|
||||
private String postThumbnail;
|
||||
|
||||
/**
|
||||
* 发表日期
|
||||
*/
|
||||
private Date postDate;
|
||||
|
||||
/**
|
||||
* 最后一次更新时间
|
||||
*/
|
||||
@LastModifiedDate
|
||||
private Date postUpdate;
|
||||
|
||||
/**
|
||||
* 0 已发布
|
||||
* 1 草稿
|
||||
* 2 回收站
|
||||
*/
|
||||
private Integer postStatus = 0;
|
||||
|
||||
/**
|
||||
* 文章访问量
|
||||
*/
|
||||
private Long postViews = 0L;
|
||||
|
||||
/**
|
||||
* 是否允许评论
|
||||
*/
|
||||
private Integer allowComment = 0;
|
||||
|
||||
/**
|
||||
* 文章访问密码
|
||||
*/
|
||||
private String postPassword;
|
||||
|
||||
/**
|
||||
* 指定渲染模板
|
||||
*/
|
||||
private String customTpl;
|
||||
|
||||
/**
|
||||
* Post priority (default is 0)
|
||||
*/
|
||||
private Integer postPriority;
|
||||
|
||||
/**
|
||||
* 发布来源 (default is admin)
|
||||
*/
|
||||
private String postSource;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
public Date getPostDate() {
|
||||
return postDate;
|
||||
}
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
public Date getPostUpdate() {
|
||||
return postUpdate;
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
DateTime now = DateUtil.date();
|
||||
|
||||
if (postDate == null) {
|
||||
postDate = now;
|
||||
}
|
||||
|
||||
if (postUpdate == null) {
|
||||
postUpdate = now;
|
||||
}
|
||||
|
||||
if (postPriority == null) {
|
||||
postPriority = 0;
|
||||
}
|
||||
|
||||
if (postSource == null) {
|
||||
postSource = "admin";
|
||||
}
|
||||
|
||||
postId = null;
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章标签
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/12
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_tag")
|
||||
@Deprecated
|
||||
public class Tag implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7501342327884372194L;
|
||||
|
||||
/**
|
||||
* 标签编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long tagId;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
@NotEmpty(message = "标签名称不能为空!")
|
||||
private String tagName;
|
||||
|
||||
/**
|
||||
* 标签路径
|
||||
*/
|
||||
@NotEmpty(message = "标签路径不能为空!")
|
||||
private String tagUrl;
|
||||
|
||||
@ManyToMany(mappedBy = "tags")
|
||||
@JsonIgnore
|
||||
private List<Post> posts = new ArrayList<>();
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package cc.ryanc.halo.model.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 博主信息
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "halo_user")
|
||||
@Deprecated
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5144055068797033748L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@JsonIgnore
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 显示名称
|
||||
*/
|
||||
private String userDisplayName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String userPass;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String userEmail;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 说明
|
||||
*/
|
||||
private String userDesc;
|
||||
|
||||
/**
|
||||
* 是否禁用登录
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String loginEnable = "true";
|
||||
|
||||
/**
|
||||
* 最后一次登录时间
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Date loginLast;
|
||||
|
||||
/**
|
||||
* 登录错误次数记录
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Integer loginError = 0;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-10
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentAdminOutputDTO implements OutputConverter<AttachmentAdminOutputDTO, Attachment> {
|
||||
|
||||
private Long attachId;
|
||||
|
||||
private String attachPath;
|
||||
|
||||
private String attachSmallPath;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-09
|
||||
*/
|
||||
@Data
|
||||
public class CommentAdminOutputDTO implements OutputConverter<CommentAdminOutputDTO, Comment> {
|
||||
|
||||
private Long commentId;
|
||||
|
||||
private Post post;
|
||||
|
||||
private String commentAuthor;
|
||||
|
||||
private String commentAuthorUrl;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date commentDate;
|
||||
|
||||
private String commentContent;
|
||||
|
||||
private Integer commentStatus;
|
||||
|
||||
private Integer isAdmin;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-09
|
||||
*/
|
||||
@Data
|
||||
public class CommentViewOutputDTO implements OutputConverter<CommentViewOutputDTO, Comment> {
|
||||
|
||||
private Long commentId;
|
||||
|
||||
private Post post;
|
||||
|
||||
private String commentAuthor;
|
||||
|
||||
private Date commentDate;
|
||||
|
||||
private String commentContent;
|
||||
|
||||
private Integer commentStatus;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-09
|
||||
*/
|
||||
@Data
|
||||
public class PageAdminOutputDTO implements OutputConverter<PageAdminOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postType;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postDate;
|
||||
|
||||
private Integer postStatus;
|
||||
|
||||
private Long postViews;
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post admin output dto.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostAdminOutputDTO implements OutputConverter<PostAdminOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postType;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date postDate;
|
||||
|
||||
private Integer postStatus;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer postPriority;
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.*;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post detail output dto.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostDetailOutputDTO implements OutputConverter<PostDetailOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private User user;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postType;
|
||||
|
||||
private String postContent;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private String postSummary;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
private String postThumbnail;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postDate;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postUpdate;
|
||||
|
||||
private Integer postStatus;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer allowComment;
|
||||
|
||||
private String postPassword;
|
||||
|
||||
private String customTpl;
|
||||
|
||||
private Integer postPriority;
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.*;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post output dto for post list
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostListOutputDTO implements OutputConverter<PostListOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private User user;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private String postSummary;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
private String postThumbnail;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postDate;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postUpdate;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer allowComment;
|
||||
|
||||
private Integer postPriority;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
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.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post output dto without markdown and content.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostSimpleOutputDTO implements OutputConverter<PostSimpleOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postType;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private String postSummary;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private String postThumbnail;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postDate;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postUpdate;
|
||||
|
||||
private Integer postStatus;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer allowComment;
|
||||
|
||||
private String postPassword;
|
||||
|
||||
private String customTpl;
|
||||
|
||||
private Integer postPriority;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-09
|
||||
*/
|
||||
@Data
|
||||
public class PostViewOutputDTO implements OutputConverter<PostViewOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date postDate;
|
||||
|
||||
private Integer postStatus;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章是否允许评论enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/9
|
||||
*/
|
||||
public enum AllowCommentEnum {
|
||||
|
||||
/**
|
||||
* 允许评论
|
||||
*/
|
||||
ALLOW(1),
|
||||
|
||||
/**
|
||||
* 不允许评论
|
||||
*/
|
||||
DISALLOW(0);
|
||||
|
||||
private Integer code;
|
||||
|
||||
AllowCommentEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附件存储地址enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : Yawn
|
||||
* @date : 2018/12/4
|
||||
*/
|
||||
public enum AttachLocationEnum {
|
||||
|
||||
/**
|
||||
* 服务器
|
||||
*/
|
||||
SERVER(0, "server"),
|
||||
|
||||
/**
|
||||
* 七牛
|
||||
*/
|
||||
QINIU(1, "qiniu"),
|
||||
|
||||
/**
|
||||
* 又拍云
|
||||
*/
|
||||
UPYUN(2, "upyun");
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
AttachLocationEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 备份类型enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/22
|
||||
*/
|
||||
public enum BackupTypeEnum {
|
||||
|
||||
/**
|
||||
* 资源文件
|
||||
*/
|
||||
RESOURCES("resources"),
|
||||
|
||||
/**
|
||||
* 数据库
|
||||
*/
|
||||
DATABASES("databases"),
|
||||
|
||||
/**
|
||||
* 文章
|
||||
*/
|
||||
POSTS("posts");
|
||||
|
||||
private String desc;
|
||||
|
||||
BackupTypeEnum(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 常用博客设置enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/14
|
||||
*/
|
||||
public enum BlogPropertiesEnum {
|
||||
|
||||
/**
|
||||
* 博客语言
|
||||
*/
|
||||
BLOG_LOCALE("blog_locale"),
|
||||
|
||||
/**
|
||||
* 博客标题
|
||||
*/
|
||||
BLOG_TITLE("blog_title"),
|
||||
|
||||
/**
|
||||
* 博客地址
|
||||
*/
|
||||
BLOG_URL("blog_url"),
|
||||
|
||||
/**
|
||||
* 文章摘要字数
|
||||
*/
|
||||
POST_SUMMARY("post_summary"),
|
||||
|
||||
/**
|
||||
* 首页文章条数
|
||||
*/
|
||||
INDEX_POSTS("index_posts"),
|
||||
|
||||
/**
|
||||
* 每页评论条数
|
||||
*/
|
||||
INDEX_COMMENTS("index_comments"),
|
||||
|
||||
/**
|
||||
* 是否已经安装
|
||||
*/
|
||||
IS_INSTALL("is_install"),
|
||||
|
||||
/**
|
||||
* RSS显示文章条数
|
||||
*/
|
||||
RSS_POSTS("rss_posts"),
|
||||
|
||||
/**
|
||||
* API状态
|
||||
*/
|
||||
API_STATUS("api_status"),
|
||||
|
||||
/**
|
||||
* 邮箱服务器地址
|
||||
*/
|
||||
MAIL_SMTP_HOST("mail_smtp_host"),
|
||||
|
||||
/**
|
||||
* 邮箱地址
|
||||
*/
|
||||
MAIL_SMTP_USERNAME("mail_smtp_username"),
|
||||
|
||||
/**
|
||||
* 邮箱密码/授权码
|
||||
*/
|
||||
MAIL_SMTP_PASSWORD("mail_smtp_password"),
|
||||
|
||||
/**
|
||||
* 发送者名称
|
||||
*/
|
||||
MAIL_FROM_NAME("mail_from_name"),
|
||||
|
||||
/**
|
||||
* 启用邮件服务
|
||||
*/
|
||||
SMTP_EMAIL_ENABLE("smtp_email_enable"),
|
||||
|
||||
/**
|
||||
* 邮件回复通知
|
||||
*/
|
||||
COMMENT_REPLY_NOTICE("comment_reply_notice"),
|
||||
|
||||
/**
|
||||
* 新评论是否需要审核
|
||||
*/
|
||||
NEW_COMMENT_NEED_CHECK("new_comment_need_check"),
|
||||
|
||||
/**
|
||||
* 新评论通知
|
||||
*/
|
||||
NEW_COMMENT_NOTICE("new_comment_notice"),
|
||||
|
||||
/**
|
||||
* 邮件审核通过通知
|
||||
*/
|
||||
COMMENT_PASS_NOTICE("comment_pass_notice"),
|
||||
|
||||
/**
|
||||
* 站点描述
|
||||
*/
|
||||
SEO_DESC("seo_desc"),
|
||||
|
||||
/**
|
||||
* 博客主题
|
||||
*/
|
||||
THEME("theme"),
|
||||
|
||||
/**
|
||||
* 博客搭建日期
|
||||
*/
|
||||
BLOG_START("blog_start"),
|
||||
|
||||
/**
|
||||
* 仪表盘部件 文章总数
|
||||
*/
|
||||
WIDGET_POSTCOUNT("widget_postcount"),
|
||||
|
||||
/**
|
||||
* 仪表盘部件 评论总数
|
||||
*/
|
||||
WIDGET_COMMENTCOUNT("widget_commentcount"),
|
||||
|
||||
/**
|
||||
* 仪表盘部件 附件总数
|
||||
*/
|
||||
WIDGET_ATTACHMENTCOUNT("widget_attachmentcount"),
|
||||
|
||||
/**
|
||||
* 仪表盘部件 成立天数
|
||||
*/
|
||||
WIDGET_DAYCOUNT("widget_daycount"),
|
||||
|
||||
/**
|
||||
* 默认缩略图地址
|
||||
*/
|
||||
DEFAULT_THUMBNAIL("/static/halo-content/images/thumbnail/thumbnail.png"),
|
||||
|
||||
/**
|
||||
* 自动备份
|
||||
*/
|
||||
AUTO_BACKUP("auto_backup"),
|
||||
|
||||
/**
|
||||
* API Token
|
||||
*/
|
||||
API_TOKEN("api_token"),
|
||||
|
||||
/**
|
||||
* 附件存储位置
|
||||
*/
|
||||
ATTACH_LOC("attach_loc");
|
||||
|
||||
private String prop;
|
||||
|
||||
BlogPropertiesEnum(String prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public String getProp() {
|
||||
return prop;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论状态enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum CommentStatusEnum {
|
||||
|
||||
/**
|
||||
* 已发布
|
||||
*/
|
||||
PUBLISHED(0, "已发布"),
|
||||
|
||||
/**
|
||||
* 待审核
|
||||
*/
|
||||
CHECKING(1, "待审核"),
|
||||
|
||||
/**
|
||||
* 回收站
|
||||
*/
|
||||
RECYCLE(2, "回收站");
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
CommentStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 常用数字
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/8/1
|
||||
*/
|
||||
public enum CommonParamsEnum {
|
||||
|
||||
/**
|
||||
* 数字10
|
||||
*/
|
||||
TEN(10),
|
||||
|
||||
/**
|
||||
* 数字5
|
||||
*/
|
||||
FIVE(5),
|
||||
|
||||
/**
|
||||
* 数字404
|
||||
*/
|
||||
NOT_FOUND(404),
|
||||
|
||||
/**
|
||||
* 数字1024
|
||||
*/
|
||||
BYTE(1024);
|
||||
|
||||
private Integer value;
|
||||
|
||||
CommonParamsEnum(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* @author : wangry
|
||||
* @version : 1.0
|
||||
* @date : 2018年09月08日
|
||||
*/
|
||||
public enum LocaleEnum {
|
||||
|
||||
/**
|
||||
* 简体中文
|
||||
*/
|
||||
ZH_CN("zh_CN"),
|
||||
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
EN_US("en_US");
|
||||
|
||||
private String value;
|
||||
|
||||
LocaleEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章状态enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum PostStatusEnum {
|
||||
|
||||
/**
|
||||
* 已发布
|
||||
*/
|
||||
PUBLISHED(0, "已发布"),
|
||||
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT(1, "草稿"),
|
||||
|
||||
/**
|
||||
* 回收站
|
||||
*/
|
||||
RECYCLE(2, "回收站");
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
PostStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章类型enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum PostTypeEnum {
|
||||
|
||||
/**
|
||||
* 文章
|
||||
*/
|
||||
POST_TYPE_POST("post"),
|
||||
|
||||
/**
|
||||
* 页面
|
||||
*/
|
||||
POST_TYPE_PAGE("page"),
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
POST_TYPE_JOURNAL("journal");
|
||||
|
||||
private String desc;
|
||||
|
||||
PostTypeEnum(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 七牛配置enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/14
|
||||
*/
|
||||
public enum QiniuPropertiesEnum {
|
||||
|
||||
/**
|
||||
* 七牛云域名
|
||||
*/
|
||||
QINIU_DOMAIN("qiniu_domain"),
|
||||
|
||||
/**
|
||||
* 七牛云AccessKey
|
||||
*/
|
||||
QINIU_ACCESS_KEY("qiniu_access_key"),
|
||||
|
||||
/**
|
||||
* 七牛云SecretKey
|
||||
*/
|
||||
QINIU_SECRET_KEY("qiniu_secret_key"),
|
||||
|
||||
/**
|
||||
* 七牛云空间名
|
||||
*/
|
||||
QINIU_BUCKET("qiniu_bucket");
|
||||
|
||||
private String prop;
|
||||
|
||||
QiniuPropertiesEnum(String prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public String getProp() {
|
||||
return prop;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 返回结果enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/14
|
||||
*/
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
SUCCESS(1),
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
FAIL(0);
|
||||
|
||||
Integer code;
|
||||
|
||||
ResultCodeEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* true or false enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/16
|
||||
*/
|
||||
public enum TrueFalseEnum {
|
||||
|
||||
/**
|
||||
* 真
|
||||
*/
|
||||
TRUE("true"),
|
||||
|
||||
/**
|
||||
* 假
|
||||
*/
|
||||
FALSE("false");
|
||||
|
||||
private String desc;
|
||||
|
||||
TrueFalseEnum(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package cc.ryanc.halo.model.freemarker.method;
|
||||
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import freemarker.template.SimpleNumber;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,21 +12,9 @@ import java.util.List;
|
|||
*/
|
||||
@Component
|
||||
public class RecentCommentsMethod implements TemplateMethodModelEx {
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
/**
|
||||
* 获取最近的评论
|
||||
*
|
||||
* @param arguments 参数
|
||||
* @return Object
|
||||
* @throws TemplateModelException TemplateModelException
|
||||
*/
|
||||
@Override
|
||||
public Object exec(List arguments) throws TemplateModelException {
|
||||
SimpleNumber argOne = (SimpleNumber) arguments.get(0);
|
||||
int limit = argOne.getAsNumber().intValue();
|
||||
return commentService.getRecentComments(limit);
|
||||
// TODO Complete recent comments method.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package cc.ryanc.halo.model.freemarker.method;
|
||||
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import freemarker.template.SimpleNumber;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,21 +12,9 @@ import java.util.List;
|
|||
*/
|
||||
@Component
|
||||
public class RecentPostsMethod implements TemplateMethodModelEx {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 获取最近的文章
|
||||
*
|
||||
* @param arguments 参数
|
||||
* @return Object
|
||||
* @throws TemplateModelException TemplateModelException
|
||||
*/
|
||||
@Override
|
||||
public Object exec(List arguments) throws TemplateModelException {
|
||||
SimpleNumber argOne = (SimpleNumber) arguments.get(0);
|
||||
int limit = argOne.getAsNumber().intValue();
|
||||
return postService.getRecentPosts(limit);
|
||||
// TODO Complete recent post method.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package cc.ryanc.halo.model.freemarker.tag;
|
||||
|
||||
import cc.ryanc.halo.model.enums.PostStatusEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import freemarker.template.TemplateDirectiveBody;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -24,31 +23,9 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
|
|||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Override
|
||||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
if (map.containsKey(METHOD_KEY)) {
|
||||
String method = map.get(METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "postsCount":
|
||||
environment.setVariable("postsCount", builder.build().wrap(postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc()).size()));
|
||||
break;
|
||||
case "archives":
|
||||
environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth()));
|
||||
break;
|
||||
case "archivesLess":
|
||||
environment.setVariable("archivesLess", builder.build().wrap(postService.findPostGroupByYear()));
|
||||
break;
|
||||
case "hotPosts":
|
||||
environment.setVariable("hotPosts", builder.build().wrap(postService.hotPosts()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
templateDirectiveBody.render(environment.getOut());
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
// TODO Complete article tag directive.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package cc.ryanc.halo.model.freemarker.tag;
|
||||
|
||||
import cc.ryanc.halo.service.*;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import freemarker.template.TemplateDirectiveBody;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,46 +23,9 @@ public class CommonTagDirective implements TemplateDirectiveModel {
|
|||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
@Autowired
|
||||
private MenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
@Autowired
|
||||
private TagService tagService;
|
||||
|
||||
@Autowired
|
||||
private LinkService linkService;
|
||||
|
||||
@Override
|
||||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
if (map.containsKey(METHOD_KEY)) {
|
||||
String method = map.get(METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "menus":
|
||||
environment.setVariable("menus", builder.build().wrap(menuService.listAll()));
|
||||
break;
|
||||
case "categories":
|
||||
environment.setVariable("categories", builder.build().wrap(categoryService.listAll()));
|
||||
break;
|
||||
case "tags":
|
||||
environment.setVariable("tags", builder.build().wrap(tagService.listAll()));
|
||||
break;
|
||||
case "links":
|
||||
environment.setVariable("links", builder.build().wrap(linkService.listAll()));
|
||||
break;
|
||||
case "newComments":
|
||||
environment.setVariable("newComments", builder.build().wrap(commentService.findAll(1)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
templateDirectiveBody.render(environment.getOut());
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
// TODO Complete comment tag directive.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package cc.ryanc.halo.model.params;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.InputConverter;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Parameter of journal.
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/03/04
|
||||
*/
|
||||
@Data
|
||||
public class JournalParam implements InputConverter<Post> {
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 发布来源
|
||||
*/
|
||||
private String source;
|
||||
|
||||
@Override
|
||||
public Post convertTo() {
|
||||
Post post = new Post();
|
||||
post.setPostTitle(title);
|
||||
post.setPostContentMd(content);
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(content));
|
||||
post.setPostSource(source);
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_JOURNAL.getDesc());
|
||||
return post;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package cc.ryanc.halo.model.params;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* Parameter of password resetting.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PasswordResetParam {
|
||||
|
||||
@NotBlank(message = "Password must not be blank")
|
||||
@Size(min = 6, max = 18, message = "Length of password must be between {min} to {max}")
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "Confirm password must not be blank")
|
||||
@Size(min = 6, max = 18, message = "Length of confirm password must be between {min} to {max}")
|
||||
private String definePassword;
|
||||
|
||||
@NotBlank(message = "Reset code must not be blank")
|
||||
private String code;
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package cc.ryanc.halo.model.support;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章归档
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/20
|
||||
*/
|
||||
@Data
|
||||
public class Archive implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 年份
|
||||
*/
|
||||
private String year;
|
||||
|
||||
/**
|
||||
* 月份
|
||||
*/
|
||||
private String month;
|
||||
|
||||
/**
|
||||
* 对应的文章数
|
||||
*/
|
||||
private String count;
|
||||
|
||||
/**
|
||||
* 对应的文章
|
||||
*/
|
||||
private List<Post> posts;
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package cc.ryanc.halo.model.support;
|
||||
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
@ -115,55 +114,55 @@ public class JsonResult {
|
|||
return ok(message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an fail result with message only.
|
||||
*
|
||||
* @param message message of result must not be blank
|
||||
* @return fail result with message only
|
||||
*/
|
||||
public static JsonResult fail(@NonNull String message) {
|
||||
Assert.hasText(message, "Message of result must not be blank");
|
||||
// /**
|
||||
// * Creates an fail result with message only.
|
||||
// *
|
||||
// * @param message message of result must not be blank
|
||||
// * @return fail result with message only
|
||||
// */
|
||||
// public static JsonResult fail(@NonNull String message) {
|
||||
// Assert.hasText(message, "Message of result must not be blank");
|
||||
//
|
||||
// return new JsonResult(ResultCodeEnum.FAIL.getCode(), message);
|
||||
// }
|
||||
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), message);
|
||||
}
|
||||
// /**
|
||||
// * Creates an fail result.
|
||||
// *
|
||||
// * @param message message of result must not be blank
|
||||
// * @return fail result
|
||||
// */
|
||||
// public static JsonResult fail(@NonNull String message, @NonNull Object data) {
|
||||
// Assert.notNull(data, "Data of result must not be null");
|
||||
//
|
||||
// JsonResult failResult = fail(message);
|
||||
// failResult.setResult(data);
|
||||
// return failResult;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Creates an fail result.
|
||||
*
|
||||
* @param message message of result must not be blank
|
||||
* @return fail result
|
||||
*/
|
||||
public static JsonResult fail(@NonNull String message, @NonNull Object data) {
|
||||
Assert.notNull(data, "Data of result must not be null");
|
||||
// /**
|
||||
// * Creates an success result with message only.
|
||||
// *
|
||||
// * @param message message of result must not be blank
|
||||
// * @return success result with message only
|
||||
// */
|
||||
// public static JsonResult success(@NonNull String message) {
|
||||
// Assert.hasText(message, "Message of result must not be blank");
|
||||
//
|
||||
// return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), message);
|
||||
// }
|
||||
|
||||
JsonResult failResult = fail(message);
|
||||
failResult.setResult(data);
|
||||
return failResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an success result with message only.
|
||||
*
|
||||
* @param message message of result must not be blank
|
||||
* @return success result with message only
|
||||
*/
|
||||
public static JsonResult success(@NonNull String message) {
|
||||
Assert.hasText(message, "Message of result must not be blank");
|
||||
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an success result.
|
||||
*
|
||||
* @param message message of result must not be blank
|
||||
* @return success result
|
||||
*/
|
||||
public static JsonResult success(@NonNull String message, @NonNull Object data) {
|
||||
Assert.notNull(data, "Data of result must not be null");
|
||||
|
||||
JsonResult successResult = success(message);
|
||||
successResult.setResult(data);
|
||||
return successResult;
|
||||
}
|
||||
// /**
|
||||
// * Creates an success result.
|
||||
// *
|
||||
// * @param message message of result must not be blank
|
||||
// * @return success result
|
||||
// */
|
||||
// public static JsonResult success(@NonNull String message, @NonNull Object data) {
|
||||
// Assert.notNull(data, "Data of result must not be null");
|
||||
//
|
||||
// JsonResult successResult = success(message);
|
||||
// successResult.setResult(data);
|
||||
// return successResult;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附件持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/10
|
||||
*/
|
||||
public interface AttachmentRepository extends BaseRepository<Attachment, Long> {
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分类持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
public interface CategoryRepository extends BaseRepository<Category, Long> {
|
||||
|
||||
/**
|
||||
* 根据分类目录路径查询,用于验证是否已经存在该路径
|
||||
*
|
||||
* @param cateUrl cateUrl 文章url
|
||||
* @return Category
|
||||
*/
|
||||
Category findCategoryByCateUrl(String cateUrl);
|
||||
|
||||
/**
|
||||
* 根据分类名称查询
|
||||
*
|
||||
* @param cateName 分类名称
|
||||
* @return Category
|
||||
*/
|
||||
Category findCategoryByCateName(String cateName);
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/22
|
||||
*/
|
||||
public interface CommentRepository extends BaseRepository<Comment, Long> {
|
||||
|
||||
/**
|
||||
* 根据评论状态查询所有评论 分页
|
||||
*
|
||||
* @param status 文章状态
|
||||
* @param pageable 分页信息
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findCommentsByCommentStatus(Integer status, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据评论状态查询所有评论 不分页
|
||||
*
|
||||
* @param status 文章状态
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsByCommentStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章查询评论
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论 分页
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @param status status
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status);
|
||||
|
||||
/**
|
||||
* 查询最新的前五条评论
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_comment ORDER BY comment_date DESC LIMIT 5", nativeQuery = true)
|
||||
List<Comment> findTopFive();
|
||||
|
||||
/**
|
||||
* 根据评论状态查询数量
|
||||
*
|
||||
* @param status 评论状态
|
||||
* @return 评论数量
|
||||
*/
|
||||
Integer countAllByCommentStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 获取指定条数的评论
|
||||
*
|
||||
* @param limit 条数
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_comment WHERE comment_status = 0 ORDER BY comment_date DESC LIMIT :limit", nativeQuery = true)
|
||||
List<Comment> getCommentsByLimit(@Param(value = "limit") int limit);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 图库持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/2/26
|
||||
*/
|
||||
public interface GalleryRepository extends BaseRepository<Gallery, Long> {
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface LinkRepository extends BaseRepository<Link, Long> {
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Logs;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 日志持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/19
|
||||
*/
|
||||
public interface LogsRepository extends BaseRepository<Logs, Long> {
|
||||
|
||||
/**
|
||||
* 查询最新的五条数据
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_logs ORDER BY log_created DESC LIMIT 5", nativeQuery = true)
|
||||
List<Logs> findTopFive();
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 菜单持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/24
|
||||
*/
|
||||
public interface MenuRepository extends BaseRepository<Menu, Long> {
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Options;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 系统设置持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface OptionsRepository extends BaseRepository<Options, String> {
|
||||
|
||||
/**
|
||||
* 根据key查询单个option
|
||||
*
|
||||
* @param key key
|
||||
* @return Options
|
||||
*/
|
||||
Options findOptionsByOptionName(String key);
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
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.repository.base.BaseRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface PostRepository extends BaseRepository<Post, Long>, JpaSpecificationExecutor<Post> {
|
||||
|
||||
/**
|
||||
* 查询所有文章 根据文章类型
|
||||
*
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostsByPostType(String postType);
|
||||
|
||||
/**
|
||||
* 根据文章的状态查询 分页
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @param pageable 分页信息
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostsByPostStatusAndPostType(Integer status, String postType, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章的状态查询
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostsByPostStatusAndPostType(Integer status, String postType);
|
||||
|
||||
/**
|
||||
* 根据路径查询文章
|
||||
*
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findPostByPostUrlAndPostType(String postUrl, String postType);
|
||||
|
||||
/**
|
||||
* 根据文章编号查询
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findPostByPostIdAndPostType(Long postId, String postType);
|
||||
|
||||
/**
|
||||
* 查询指定日期之前的文章
|
||||
*
|
||||
* @param postDate 日期
|
||||
* @return Post
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date < :postDate ORDER BY post_date DESC LIMIT 1", nativeQuery = true)
|
||||
Post queryPrePost(@Param("postDate") Date postDate);
|
||||
|
||||
/**
|
||||
* 查询指定日期之后的文章
|
||||
*
|
||||
* @param postDate 日期
|
||||
* @return Post
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date > :postDate ORDER BY post_date ASC LIMIT 1", nativeQuery = true)
|
||||
Post queryNextPost(@Param("postDate") Date postDate);
|
||||
|
||||
/**
|
||||
* 查询文章归档信息 根据年份和月份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT YEAR(post_date) AS YEAR,MONTH(post_date) AS MONTH,COUNT(*) AS COUNT FROM halo_post WHERE post_status=0 and post_type='post' GROUP BY YEAR(post_date),MONTH(post_date) ORDER BY YEAR DESC,MONTH DESC", nativeQuery = true)
|
||||
List<Object[]> findPostGroupByYearAndMonth();
|
||||
|
||||
/**
|
||||
* 查询文章归档信息 根据年份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT YEAR(post_date) AS YEAR,COUNT(*) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post' GROUP BY YEAR(post_date) ORDER BY YEAR DESC", nativeQuery = true)
|
||||
List<Object[]> findPostGroupByYear();
|
||||
|
||||
|
||||
/**
|
||||
* @return List
|
||||
* @Author Aquan
|
||||
* @Description 查询文章归档信息 查询所有文章
|
||||
* @Date 2019.1.4 11:19
|
||||
* @Param
|
||||
**/
|
||||
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' ORDER BY post_date DESC", nativeQuery = true)
|
||||
List<Post> findAllPost();
|
||||
|
||||
/**
|
||||
* @return Integer
|
||||
* @Author Aquan
|
||||
* @Description 查询文章总数
|
||||
* @Date 2019.1.4 15:03
|
||||
* @Param
|
||||
**/
|
||||
@Query(value = "SELECT count(1) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post'", nativeQuery = true)
|
||||
Integer totalAllPostCount();
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @param month month
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT *,YEAR(post_date) AS YEAR,MONTH(post_date) AS MONTH FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", nativeQuery = true)
|
||||
List<Post> findPostByYearAndMonth(@Param("year") String year, @Param("month") String month);
|
||||
|
||||
/**
|
||||
* 根据年份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' AND YEAR(post_date)=:year ORDER BY post_date DESC", nativeQuery = true)
|
||||
List<Post> findPostByYear(@Param("year") String year);
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章 分页
|
||||
*
|
||||
* @param year year
|
||||
* @param month month
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", countQuery = "SELECT COUNT(*) FROM halo_post WHERE post_status=0 AND YEAR(post_date)=:year AND MONTH(post_date)=:month", nativeQuery = true)
|
||||
Page<Post> findPostByYearAndMonth(@Param("year") String year, @Param("month") String month, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据分类目录查询文章
|
||||
*
|
||||
* @param category category
|
||||
* @param status status
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据标签查询文章,分页
|
||||
*
|
||||
* @param tag tag
|
||||
* @param status status
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostsByTagsAndPostStatus(Tag tag, Integer status, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据标签查询文章
|
||||
*
|
||||
* @param tag tag
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostsByTags(Tag tag);
|
||||
|
||||
/**
|
||||
* 按热度从大到小排序
|
||||
*
|
||||
* @param postStatus 文章状态
|
||||
* @return List<Post>
|
||||
*/
|
||||
List<Post> findPostsByPostTypeOrderByPostViewsDesc(String postStatus);
|
||||
|
||||
/**
|
||||
* 获取所有文章阅读量总和
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
@Query(value = "SELECT SUM(post_views) FROM halo_post", nativeQuery = true)
|
||||
Long getPostViewsSum();
|
||||
|
||||
/**
|
||||
* 根据文章状态查询数量
|
||||
*
|
||||
* @param status 文章状态
|
||||
* @param postType 文章类型
|
||||
* @return 文章数量
|
||||
*/
|
||||
Integer countAllByPostStatusAndPostType(Integer status, String postType);
|
||||
|
||||
/**
|
||||
* 获取指定条数的文章
|
||||
*
|
||||
* @param limit 条数
|
||||
* @return List
|
||||
*/
|
||||
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true)
|
||||
List<Post> getPostsByLimit(@Param(value = "limit") int limit);
|
||||
|
||||
/**
|
||||
* Finds all posts by post type.
|
||||
*
|
||||
* @param postType post type must not be blank
|
||||
* @param pageable page info must not be null
|
||||
* @return a page of posts
|
||||
*/
|
||||
@NonNull
|
||||
Page<Post> findAllByPostType(@NonNull String postType, @NonNull Pageable pageable);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 标签持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/12
|
||||
*/
|
||||
public interface TagRepository extends BaseRepository<Tag, Long> {
|
||||
|
||||
/**
|
||||
* 根据标签路径查询,用于验证是否已经存在该路径
|
||||
*
|
||||
* @param tagUrl tagUrl
|
||||
* @return Tag
|
||||
*/
|
||||
Tag findTagByTagUrl(String tagUrl);
|
||||
|
||||
/**
|
||||
* 根据标签名称查询
|
||||
*
|
||||
* @param tagName 标签名
|
||||
* @return Tag
|
||||
*/
|
||||
Tag findTagByTagName(String tagName);
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package cc.ryanc.halo.repository;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.repository.base.BaseRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用户持久层
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface UserRepository extends BaseRepository<User, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户名和密码查询
|
||||
*
|
||||
* @param userName userName
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
User findByUserNameAndUserPass(String userName, String userPass);
|
||||
|
||||
/**
|
||||
* 根据邮箱和密码查询
|
||||
*
|
||||
* @param userEmail userEmail
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
User findByUserEmailAndUserPass(String userEmail, String userPass);
|
||||
|
||||
/**
|
||||
* 根据用户编号和密码查询
|
||||
*
|
||||
* @param userId userId
|
||||
* @param userPass userpass
|
||||
* @return User
|
||||
*/
|
||||
User findByUserIdAndUserPass(Long userId, String userPass);
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附件业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/10
|
||||
*/
|
||||
public interface AttachmentService extends CrudService<Attachment, Long> {
|
||||
|
||||
/**
|
||||
* 上传转发
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, String> upload(MultipartFile file, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 原生服务器上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 七牛云上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 又拍云上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 七牛云删除附件
|
||||
*
|
||||
* @param key key
|
||||
* @return boolean
|
||||
*/
|
||||
boolean deleteQiNiuAttachment(String key);
|
||||
|
||||
/**
|
||||
* 又拍云删除附件
|
||||
*
|
||||
* @param fileName fileName
|
||||
* @return boolean
|
||||
*/
|
||||
boolean deleteUpYunAttachment(String fileName);
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分类业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
public interface CategoryService extends CrudService<Category, Long> {
|
||||
|
||||
/**
|
||||
* 根据分类目录路径查询,用于验证是否已经存在该路径
|
||||
*
|
||||
* @param cateUrl cateUrl
|
||||
* @return category
|
||||
*/
|
||||
Category findByCateUrl(String cateUrl);
|
||||
|
||||
/**
|
||||
* 根据分类名称查询
|
||||
*
|
||||
* @param cateName 分类名称
|
||||
* @return Category
|
||||
*/
|
||||
Category findByCateName(String cateName);
|
||||
|
||||
/**
|
||||
* 将分类字符串集合转化为Category泛型集合
|
||||
*
|
||||
* @param strings strings
|
||||
* @return List
|
||||
*/
|
||||
List<Category> strListToCateList(List<String> strings);
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/22
|
||||
*/
|
||||
public interface CommentService extends CrudService<Comment, Long> {
|
||||
|
||||
/**
|
||||
* 查询所有的评论,用于后台管理
|
||||
*
|
||||
* @param status status
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findAll(Integer status, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据评论状态查询评论
|
||||
*
|
||||
* @param status 评论状态
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findAll(Integer status);
|
||||
|
||||
/**
|
||||
* 更改评论的状态
|
||||
*
|
||||
* @param commentId commentId
|
||||
* @param status status
|
||||
* @return Comment
|
||||
*/
|
||||
Comment updateCommentStatus(Long commentId, Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章查询评论
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论 分页
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @param status status
|
||||
* @return Page
|
||||
*/
|
||||
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status);
|
||||
|
||||
/**
|
||||
* 查询最新的前五条评论
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> findCommentsLatest();
|
||||
|
||||
/**
|
||||
* 根据评论状态查询数量
|
||||
*
|
||||
* @param status 评论状态
|
||||
* @return 评论数量
|
||||
*/
|
||||
Integer getCountByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 获取最近的评论
|
||||
*
|
||||
* @param limit limit
|
||||
* @return List
|
||||
*/
|
||||
List<Comment> getRecentComments(int limit);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 图库业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/2/26
|
||||
*/
|
||||
public interface GalleryService extends CrudService<Gallery, Long> {
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface LinkService extends CrudService<Link, Long> {
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Logs;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 日志业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/19
|
||||
*/
|
||||
public interface LogsService extends CrudService<Logs, Long> {
|
||||
|
||||
/**
|
||||
* 保存日志
|
||||
*
|
||||
* @param logTitle logTitle
|
||||
* @param logContent logContent
|
||||
* @param request request
|
||||
*/
|
||||
void save(String logTitle, String logContent, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 查询最新的五条日志
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Logs> findLogsLatest();
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 邮件发送业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/23
|
||||
*/
|
||||
public interface MailService {
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
*/
|
||||
void sendMail(String to, String subject, String content);
|
||||
|
||||
/**
|
||||
* 发送模板邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
* @param templateName 模板路径
|
||||
*/
|
||||
void sendTemplateMail(String to, String subject, Map<String, Object> content, String templateName);
|
||||
|
||||
/**
|
||||
* 发送带有附件的邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
* @param templateName 模板路径
|
||||
* @param attachSrc 附件路径
|
||||
*/
|
||||
void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachSrc);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 菜单业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/24
|
||||
*/
|
||||
public interface MenuService extends CrudService<Menu, Long> {
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Options;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 系统设置业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface OptionsService extends CrudService<Options, String> {
|
||||
|
||||
/**
|
||||
* 保存单个设置选项
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
void saveOption(String key, String value);
|
||||
|
||||
/**
|
||||
* 保存多个设置选项
|
||||
*
|
||||
* @param options options
|
||||
*/
|
||||
void saveOptions(Map<String, String> options);
|
||||
|
||||
/**
|
||||
* 获取所有设置选项
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, String> findAllOptions();
|
||||
|
||||
/**
|
||||
* 根据key查询单个设置
|
||||
*
|
||||
* @param key key
|
||||
* @return String
|
||||
*/
|
||||
String findOneOption(String key);
|
||||
}
|
|
@ -1,256 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
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.support.Archive;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章/页面业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface PostService extends CrudService<Post, Long> {
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
*
|
||||
* @param postId postId
|
||||
* @param status status
|
||||
* @return Post
|
||||
*/
|
||||
Post updatePostStatus(Long postId, Integer status);
|
||||
|
||||
/**
|
||||
* 批量修改摘要
|
||||
*
|
||||
* @param postSummary postSummary
|
||||
*/
|
||||
void updateAllSummary(Integer postSummary);
|
||||
|
||||
/**
|
||||
* 获取文章列表 不分页
|
||||
*
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findAll(String postType);
|
||||
|
||||
/**
|
||||
* 模糊查询文章
|
||||
*
|
||||
* @param keyword 关键词
|
||||
* @param postType 文章类型
|
||||
* @param postStatus 文章状态
|
||||
* @param pageable 分页信息
|
||||
* @return a page of posts
|
||||
*/
|
||||
@NonNull
|
||||
Page<Post> searchPosts(@Nullable String keyword, @Nullable String postType, @Nullable Integer postStatus, @NonNull Pageable pageable);
|
||||
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,用于后台管理
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @param pageable 分页信息
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,首页分页
|
||||
*
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByStatus(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据文章状态查询
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostByStatus(Integer status, String postType);
|
||||
|
||||
|
||||
/**
|
||||
* 根据编号和类型查询文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @param postType postType
|
||||
* @return Post
|
||||
*/
|
||||
Post findByPostId(Long postId, String postType);
|
||||
|
||||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findByPostUrl(String postUrl, String postType);
|
||||
|
||||
/**
|
||||
* 查询前五条数据
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostLatest();
|
||||
|
||||
/**
|
||||
* 获取下一篇文章 较新
|
||||
*
|
||||
* @param postDate postDate
|
||||
* @return Post
|
||||
*/
|
||||
Post getNextPost(Date postDate);
|
||||
|
||||
/**
|
||||
* 获取下一篇文章 较老
|
||||
*
|
||||
* @param postDate postDate
|
||||
* @return Post
|
||||
*/
|
||||
Post getPrePost(Date postDate);
|
||||
|
||||
/**
|
||||
* 查询归档信息 根据年份和月份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Archive> findPostGroupByYearAndMonth();
|
||||
|
||||
/**
|
||||
* 查询归档信息 根据年份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Archive> findPostGroupByYear();
|
||||
|
||||
/**
|
||||
* @return List
|
||||
* @Author Aquan
|
||||
* @Description 查询归档信息 查看所有文章
|
||||
* @Date 2019.1.4 11:14
|
||||
* @Param
|
||||
**/
|
||||
List<Archive> findAllPost();
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @param month month
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostByYearAndMonth(String year, String month);
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章 分页
|
||||
*
|
||||
* @param year year
|
||||
* @param month month
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByYearAndMonth(String year, String month, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据年份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @return List
|
||||
*/
|
||||
List<Post> findPostByYear(String year);
|
||||
|
||||
/**
|
||||
* 根据分类目录查询文章
|
||||
*
|
||||
* @param category category
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostByCategories(Category category, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据标签查询文章
|
||||
*
|
||||
* @param tag tag
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
Page<Post> findPostsByTags(Tag tag, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 热门文章
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
List<Post> hotPosts();
|
||||
|
||||
/**
|
||||
* 当前文章的相似文章
|
||||
*
|
||||
* @param post post
|
||||
* @return List
|
||||
*/
|
||||
List<Post> relatedPosts(Post post);
|
||||
|
||||
/**
|
||||
* 获取所有文章的阅读量
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
Long getPostViews();
|
||||
|
||||
/**
|
||||
* 根据文章状态查询数量
|
||||
*
|
||||
* @param status 文章状态
|
||||
* @return 文章数量
|
||||
*/
|
||||
Integer getCountByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 缓存阅读数
|
||||
*
|
||||
* @param postId postId
|
||||
*/
|
||||
void cacheViews(Long postId);
|
||||
|
||||
/**
|
||||
* 组装分类目录和标签
|
||||
*
|
||||
* @param post post
|
||||
* @param cateList cateList
|
||||
* @param tagList tagList
|
||||
* @return Post Post
|
||||
*/
|
||||
Post buildCategoriesAndTags(Post post, List<String> cateList, @RequestParam("tagList") String tagList);
|
||||
|
||||
/**
|
||||
* 获取最近的文章
|
||||
*
|
||||
* @param limit 条数
|
||||
* @return List
|
||||
*/
|
||||
List<Post> getRecentPosts(int limit);
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 标签业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/12
|
||||
*/
|
||||
public interface TagService extends CrudService<Tag, Long> {
|
||||
|
||||
/**
|
||||
* 根据标签路径查询
|
||||
*
|
||||
* @param tagUrl tagUrl
|
||||
* @return Tag
|
||||
*/
|
||||
Tag findByTagUrl(String tagUrl);
|
||||
|
||||
/**
|
||||
* 根据标签名称查询
|
||||
*
|
||||
* @param tagName tagName
|
||||
* @return Tag
|
||||
*/
|
||||
Tag findTagByTagName(String tagName);
|
||||
|
||||
/**
|
||||
* 转换标签字符串为实体集合
|
||||
*
|
||||
* @param tagList tagList
|
||||
* @return List
|
||||
*/
|
||||
List<Tag> strListToTagList(String tagList);
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用户业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
public interface UserService extends CrudService<User, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户名和密码查询,用于登录
|
||||
*
|
||||
* @param userName userName
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
User userLoginByName(String userName, String userPass);
|
||||
|
||||
/**
|
||||
* 根据邮箱和密码查询,用户登录
|
||||
*
|
||||
* @param userEmail userEmail
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
User userLoginByEmail(String userEmail, String userPass);
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
User findUser();
|
||||
|
||||
/**
|
||||
* 根据用户编号和密码查询
|
||||
*
|
||||
* @param userId userid
|
||||
* @param userPass userpass
|
||||
* @return User
|
||||
*/
|
||||
User findByUserIdAndUserPass(Long userId, String userPass);
|
||||
|
||||
/**
|
||||
* 修改禁用状态
|
||||
*
|
||||
* @param enable enable
|
||||
*/
|
||||
void updateUserLoginEnable(String enable);
|
||||
|
||||
/**
|
||||
* 修改最后登录时间
|
||||
*
|
||||
* @param lastDate 最后登录时间
|
||||
* @return User
|
||||
*/
|
||||
User updateUserLoginLast(Date lastDate);
|
||||
|
||||
/**
|
||||
* 增加登录错误次数
|
||||
*
|
||||
* @return 登录错误次数
|
||||
*/
|
||||
Integer updateUserLoginError();
|
||||
|
||||
/**
|
||||
* 修改用户的状态为正常
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
User updateUserNormal();
|
||||
}
|
|
@ -1,411 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.logging.Logger;
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.model.enums.AttachLocationEnum;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.support.QiNiuPutSet;
|
||||
import cc.ryanc.halo.repository.AttachmentRepository;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.Md5Util;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.UpYun;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.persistent.FileRecorder;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.qiniu.util.StringMap;
|
||||
import com.upyun.UpException;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
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;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附件业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/10
|
||||
*/
|
||||
@Service
|
||||
public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Long> implements AttachmentService {
|
||||
|
||||
private final Logger log = Logger.getLogger(getClass());
|
||||
|
||||
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
|
||||
|
||||
private final AttachmentRepository attachmentRepository;
|
||||
|
||||
public AttachmentServiceImpl(AttachmentRepository attachmentRepository) {
|
||||
super(attachmentRepository);
|
||||
this.attachmentRepository = attachmentRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增附件信息
|
||||
*
|
||||
* @param attachment attachment
|
||||
* @return Attachment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Attachment create(Attachment attachment) {
|
||||
return super.create(attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有附件信息
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = ATTACHMENTS_CACHE_NAME, key = "'attachment'")
|
||||
public List<Attachment> listAll() {
|
||||
return super.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有附件信息 分页
|
||||
*
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Attachment> listAll(Pageable pageable) {
|
||||
return attachmentRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据附件id查询附件
|
||||
*
|
||||
* @param attachId attachId
|
||||
* @return Optional
|
||||
*/
|
||||
@Override
|
||||
public Optional<Attachment> fetchById(Long attachId) {
|
||||
return attachmentRepository.findById(attachId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号移除附件
|
||||
*
|
||||
* @param attachId attachId
|
||||
* @return Attachment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = ATTACHMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Attachment removeById(Long attachId) {
|
||||
return super.removeById(attachId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传转发
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> upload(MultipartFile file, HttpServletRequest request) {
|
||||
Map<String, String> resultMap;
|
||||
String attachLoc = OPTIONS.get(BlogPropertiesEnum.ATTACH_LOC.getProp());
|
||||
if (StrUtil.isEmpty(attachLoc)) {
|
||||
attachLoc = "server";
|
||||
}
|
||||
switch (attachLoc) {
|
||||
case "server":
|
||||
resultMap = this.attachUpload(file, request);
|
||||
break;
|
||||
case "qiniu":
|
||||
resultMap = this.attachQiNiuUpload(file, request);
|
||||
break;
|
||||
case "upyun":
|
||||
resultMap = this.attachUpYunUpload(file, request);
|
||||
break;
|
||||
default:
|
||||
resultMap = this.attachUpload(file, request);
|
||||
break;
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 原生服务器上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request) {
|
||||
Assert.notNull(file, "MultipartFile must not be null");
|
||||
Assert.notNull(request, "Http servlet request must not be null");
|
||||
|
||||
final Map<String, String> resultMap = new HashMap<>(6);
|
||||
final String dateString = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
try {
|
||||
//用户目录
|
||||
final StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
uploadPath.append("/halo/");
|
||||
uploadPath.append("upload/");
|
||||
|
||||
//获取当前年月以创建目录,如果没有该目录则创建
|
||||
uploadPath.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
|
||||
final File mediaPath = new File(uploadPath.toString());
|
||||
if (!mediaPath.exists()) {
|
||||
if (!mediaPath.mkdirs()) {
|
||||
resultMap.put("success", "0");
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
//不带后缀
|
||||
final StrBuilder nameWithOutSuffix = new StrBuilder(file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", ""));
|
||||
nameWithOutSuffix.append(dateString);
|
||||
nameWithOutSuffix.append(new Random().nextInt(1000));
|
||||
|
||||
//文件后缀
|
||||
final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
||||
|
||||
//带后缀
|
||||
final StrBuilder fileName = new StrBuilder(nameWithOutSuffix);
|
||||
fileName.append(".");
|
||||
fileName.append(fileSuffix);
|
||||
|
||||
file.transferTo(new File(mediaPath.getAbsoluteFile(), fileName.toString()));
|
||||
|
||||
//文件原路径
|
||||
final StrBuilder fullPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullPath.append("/");
|
||||
fullPath.append(fileName);
|
||||
|
||||
//压缩文件路径
|
||||
final StrBuilder fullSmallPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullSmallPath.append("/");
|
||||
fullSmallPath.append(nameWithOutSuffix);
|
||||
fullSmallPath.append("_small.");
|
||||
fullSmallPath.append(fileSuffix);
|
||||
|
||||
//压缩图片
|
||||
Thumbnails.of(fullPath.toString()).size(256, 256).keepAspectRatio(false).toFile(fullSmallPath.toString());
|
||||
|
||||
//映射路径
|
||||
final StrBuilder filePath = new StrBuilder("/upload/");
|
||||
filePath.append(DateUtil.thisYear());
|
||||
filePath.append("/");
|
||||
filePath.append(DateUtil.thisMonth());
|
||||
filePath.append("/");
|
||||
filePath.append(fileName);
|
||||
|
||||
//缩略图映射路径
|
||||
final StrBuilder fileSmallPath = new StrBuilder("/upload/");
|
||||
fileSmallPath.append(DateUtil.thisYear());
|
||||
fileSmallPath.append("/");
|
||||
fileSmallPath.append(DateUtil.thisMonth());
|
||||
fileSmallPath.append("/");
|
||||
fileSmallPath.append(nameWithOutSuffix);
|
||||
fileSmallPath.append("_small.");
|
||||
fileSmallPath.append(fileSuffix);
|
||||
|
||||
final String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
||||
final String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
||||
|
||||
resultMap.put("fileName", fileName.toString());
|
||||
resultMap.put("filePath", filePath.toString());
|
||||
resultMap.put("smallPath", fileSmallPath.toString());
|
||||
resultMap.put("suffix", fileSuffix);
|
||||
resultMap.put("size", size);
|
||||
resultMap.put("wh", wh);
|
||||
resultMap.put("location", AttachLocationEnum.SERVER.getDesc());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 七牛云上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
||||
final Map<String, String> resultMap = new HashMap<>(7);
|
||||
try {
|
||||
// TODO Wait for testing (七牛云上传附件失败 #110)
|
||||
final Configuration cfg = new Configuration(HaloUtils.getDefaultQiniuZone());
|
||||
final String key = Md5Util.getMD5Checksum(file);
|
||||
final String accessKey = OPTIONS.get("qiniu_access_key");
|
||||
final String secretKey = OPTIONS.get("qiniu_secret_key");
|
||||
final String domain = OPTIONS.get("qiniu_domain");
|
||||
final String bucket = OPTIONS.get("qiniu_bucket");
|
||||
final String smallUrl = OPTIONS.get("qiniu_small_url");
|
||||
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket)) {
|
||||
return resultMap;
|
||||
}
|
||||
final Auth auth = Auth.create(accessKey, secretKey);
|
||||
final StringMap putPolicy = new StringMap();
|
||||
putPolicy.put("returnBody", "{\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height)}");
|
||||
final String upToken = auth.uploadToken(bucket, null, 3600, putPolicy);
|
||||
final String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket).toString();
|
||||
QiNiuPutSet putSet = new QiNiuPutSet();
|
||||
try {
|
||||
final FileRecorder fileRecorder = new FileRecorder(localTempDir);
|
||||
final UploadManager uploadManager = new UploadManager(cfg, fileRecorder);
|
||||
final Response response = uploadManager.put(file.getInputStream(), key, upToken, null, null);
|
||||
//解析上传成功的结果
|
||||
putSet = new Gson().fromJson(response.bodyString(), QiNiuPutSet.class);
|
||||
} catch (QiniuException e) {
|
||||
final Response r = e.response;
|
||||
log.error("Qiniu error response: [{}]", r);
|
||||
} catch (JsonSyntaxException | IOException e) {
|
||||
log.error("Failed to attach QiNiu resource", e);
|
||||
}
|
||||
|
||||
final String filePath = domain.trim() + "/" + key;
|
||||
resultMap.put("fileName", file.getOriginalFilename());
|
||||
resultMap.put("filePath", filePath.trim());
|
||||
resultMap.put("smallPath", smallUrl == null ? filePath.trim() : (filePath + smallUrl).trim());
|
||||
resultMap.put("suffix", file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')));
|
||||
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
|
||||
resultMap.put("wh", putSet.getW() + "x" + putSet.getH());
|
||||
resultMap.put("location", AttachLocationEnum.QINIU.getDesc());
|
||||
} catch (Exception e) {
|
||||
log.debug("Failed to generate md5 check sum", e);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 又拍云上传
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) {
|
||||
final Map<String, String> resultMap = new HashMap<>(6);
|
||||
try {
|
||||
final String key = Md5Util.getMD5Checksum(file);
|
||||
final String ossSrc = OPTIONS.get("upyun_oss_src");
|
||||
final String ossPwd = OPTIONS.get("upyun_oss_pwd");
|
||||
final String bucket = OPTIONS.get("upyun_oss_bucket");
|
||||
final String domain = OPTIONS.get("upyun_oss_domain");
|
||||
final String operator = OPTIONS.get("upyun_oss_operator");
|
||||
final String smallUrl = OPTIONS.get("upyun_oss_small");
|
||||
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||
return resultMap;
|
||||
}
|
||||
final String fileName = file.getOriginalFilename();
|
||||
final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
||||
final UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
upYun.setTimeout(60);
|
||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||
upYun.setDebug(true);
|
||||
upYun.writeFile(ossSrc + key + fileSuffix, file.getBytes(), true, null);
|
||||
final String filePath = domain.trim() + ossSrc + key + fileSuffix;
|
||||
String smallPath = filePath;
|
||||
if (smallUrl != null) {
|
||||
smallPath += smallUrl;
|
||||
}
|
||||
final BufferedImage image = ImageIO.read(file.getInputStream());
|
||||
if (image != null) {
|
||||
resultMap.put("wh", image.getWidth() + "x" + image.getHeight());
|
||||
}
|
||||
resultMap.put("fileName", fileName);
|
||||
resultMap.put("filePath", filePath.trim());
|
||||
resultMap.put("smallPath", smallPath.trim());
|
||||
resultMap.put("suffix", fileSuffix);
|
||||
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
|
||||
resultMap.put("location", AttachLocationEnum.UPYUN.getDesc());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to attach UpYun resource", e);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 七牛云删除附件
|
||||
*
|
||||
* @param key key
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteQiNiuAttachment(String key) {
|
||||
boolean flag = true;
|
||||
final Configuration cfg = new Configuration(Zone.zone0());
|
||||
final String accessKey = OPTIONS.get("qiniu_access_key");
|
||||
final String secretKey = OPTIONS.get("qiniu_secret_key");
|
||||
final String bucket = OPTIONS.get("qiniu_bucket");
|
||||
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
|
||||
return false;
|
||||
}
|
||||
final Auth auth = Auth.create(accessKey, secretKey);
|
||||
final BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
bucketManager.delete(bucket, key);
|
||||
} catch (QiniuException ex) {
|
||||
System.err.println(ex.code());
|
||||
System.err.println(ex.response.toString());
|
||||
flag = false;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 又拍云删除附件
|
||||
*
|
||||
* @param fileName fileName
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUpYunAttachment(String fileName) {
|
||||
boolean flag = true;
|
||||
final String ossSrc = OPTIONS.get("upyun_oss_src");
|
||||
final String ossPwd = OPTIONS.get("upyun_oss_pwd");
|
||||
final String bucket = OPTIONS.get("upyun_oss_bucket");
|
||||
final String operator = OPTIONS.get("upyun_oss_operator");
|
||||
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||
return false;
|
||||
}
|
||||
final UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||
try {
|
||||
flag = upYun.deleteFile(ossSrc + fileName);
|
||||
} catch (IOException | UpException e) {
|
||||
log.error("Failed to delete UpYun attachment", e);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.repository.CategoryRepository;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分类业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
@Service
|
||||
public class CategoryServiceImpl extends AbstractCrudService<Category, Long> implements CategoryService {
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
public CategoryServiceImpl(CategoryRepository categoryRepository) {
|
||||
super(categoryRepository);
|
||||
this.categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存/修改分类目录
|
||||
*
|
||||
* @param category 分类目录
|
||||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Category create(Category category) {
|
||||
return super.create(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号移除分类目录
|
||||
*
|
||||
* @param cateId 分类目录编号
|
||||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Category removeById(Long cateId) {
|
||||
return super.removeById(cateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类目录路径查询,用于验证是否已经存在该路径
|
||||
*
|
||||
* @param cateUrl cateUrl
|
||||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
public Category findByCateUrl(String cateUrl) {
|
||||
return categoryRepository.findCategoryByCateUrl(cateUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类名称查询
|
||||
*
|
||||
* @param cateName 分类名称
|
||||
* @return Category
|
||||
*/
|
||||
@Override
|
||||
public Category findByCateName(String cateName) {
|
||||
return categoryRepository.findCategoryByCateName(cateName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将分类字符串集合转化为Category泛型集合
|
||||
*
|
||||
* @param strings strings
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Category> strListToCateList(List<String> strings) {
|
||||
if (null == strings) {
|
||||
return null;
|
||||
}
|
||||
final List<Category> categories = new ArrayList<>();
|
||||
for (String str : strings) {
|
||||
// TODO There maybe cause NoSuchElementException
|
||||
categories.add(fetchById(Long.parseLong(str)).get());
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
}
|
|
@ -1,181 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.repository.CommentRepository;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/22
|
||||
*/
|
||||
@Service
|
||||
public class CommentServiceImpl extends AbstractCrudService<Comment, Long> implements CommentService {
|
||||
|
||||
private static final String COMMENTS_CACHE_NAME = "comments";
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
private final CommentRepository commentRepository;
|
||||
|
||||
public CommentServiceImpl(CommentRepository commentRepository) {
|
||||
super(commentRepository);
|
||||
this.commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增评论
|
||||
*
|
||||
* @param comment comment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||
public Comment create(Comment comment) {
|
||||
return super.create(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有的评论,用于后台管理
|
||||
*
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Comment> findAll(Integer status, Pageable pageable) {
|
||||
return commentRepository.findCommentsByCommentStatus(status, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据评论状态查询评论
|
||||
*
|
||||
* @param status 评论状态
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = COMMENTS_CACHE_NAME, key = "'comments_status_'+#status")
|
||||
public List<Comment> findAll(Integer status) {
|
||||
return commentRepository.findCommentsByCommentStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有评论,不分页
|
||||
*
|
||||
* @return List<Comment></>
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = COMMENTS_CACHE_NAME, key = "'comment'")
|
||||
public List<Comment> listAll() {
|
||||
return commentRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改评论的状态
|
||||
*
|
||||
* @param commentId commentId
|
||||
* @param status status
|
||||
* @return Comment
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Comment updateCommentStatus(Long commentId, Integer status) {
|
||||
final Optional<Comment> comment = fetchById(commentId);
|
||||
comment.get().setCommentStatus(status);
|
||||
return commentRepository.save(comment.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章查询评论
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Comment> findCommentsByPost(Post post, Pageable pageable) {
|
||||
return commentRepository.findCommentsByPost(post, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论
|
||||
*
|
||||
* @param post post
|
||||
* @param pageable pageable
|
||||
* @param status status
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status) {
|
||||
return commentRepository.findCommentsByPostAndCommentStatus(post, pageable, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status) {
|
||||
return commentRepository.findCommentsByPostAndCommentStatus(post, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||
*
|
||||
* @param post post
|
||||
* @param status status
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status) {
|
||||
return commentRepository.findCommentsByPostAndCommentStatusNot(post, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最新的前五条评论
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = COMMENTS_CACHE_NAME, key = "'comments_latest'")
|
||||
public List<Comment> findCommentsLatest() {
|
||||
return commentRepository.findTopFive();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据评论状态查询数量
|
||||
*
|
||||
* @param status 评论状态
|
||||
* @return 评论数量
|
||||
*/
|
||||
@Override
|
||||
public Integer getCountByStatus(Integer status) {
|
||||
return commentRepository.countAllByCommentStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的评论
|
||||
*
|
||||
* @param limit limit
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Comment> getRecentComments(int limit) {
|
||||
return commentRepository.getCommentsByLimit(limit);
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.repository.GalleryRepository;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 图库业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/2/26
|
||||
*/
|
||||
@Service
|
||||
public class GalleryServiceImpl extends AbstractCrudService<Gallery, Long> implements GalleryService {
|
||||
|
||||
private static final String GALLERIES_CACHE_NAME = "galleries";
|
||||
|
||||
private final GalleryRepository galleryRepository;
|
||||
|
||||
public GalleryServiceImpl(GalleryRepository galleryRepository) {
|
||||
super(galleryRepository);
|
||||
this.galleryRepository = galleryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图片
|
||||
*
|
||||
* @param gallery gallery
|
||||
* @return Gallery
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery create(Gallery gallery) {
|
||||
return super.create(gallery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号删除图片
|
||||
*
|
||||
* @param galleryId galleryId
|
||||
* @return Gallery
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery removeById(Long galleryId) {
|
||||
return super.removeById(galleryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有图片 不分页
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = GALLERIES_CACHE_NAME, key = "'gallery'")
|
||||
public List<Gallery> listAll() {
|
||||
return super.listAll();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.repository.LinkRepository;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Service
|
||||
public class LinkServiceImpl extends AbstractCrudService<Link, Long> implements LinkService {
|
||||
|
||||
private static final String LINKS_CACHE_KEY = "'link'";
|
||||
|
||||
private static final String LINKS_CACHE_NAME = "links";
|
||||
|
||||
private final LinkRepository linkRepository;
|
||||
|
||||
public LinkServiceImpl(LinkRepository linkRepository) {
|
||||
super(linkRepository);
|
||||
this.linkRepository = linkRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改友情链接
|
||||
*
|
||||
* @param link link
|
||||
* @return Link
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = LINKS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Link create(Link link) {
|
||||
return super.create(link);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除友情链接
|
||||
*
|
||||
* @param linkId linkId
|
||||
* @return Link
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = LINKS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Link removeById(Long linkId) {
|
||||
return super.removeById(linkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有友情链接
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = LINKS_CACHE_NAME, key = LINKS_CACHE_KEY)
|
||||
public List<Link> listAll() {
|
||||
return super.listAll();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Logs;
|
||||
import cc.ryanc.halo.repository.LogsRepository;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 日志业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/19
|
||||
*/
|
||||
@Service
|
||||
public class LogsServiceImpl extends AbstractCrudService<Logs, Long> implements LogsService {
|
||||
|
||||
private final LogsRepository logsRepository;
|
||||
|
||||
public LogsServiceImpl(LogsRepository logsRepository) {
|
||||
super(logsRepository);
|
||||
this.logsRepository = logsRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存日志
|
||||
*
|
||||
* @param logTitle logTitle
|
||||
* @param logContent logContent
|
||||
* @param request request
|
||||
*/
|
||||
@Override
|
||||
public void save(String logTitle, String logContent, HttpServletRequest request) {
|
||||
final Logs logs = new Logs();
|
||||
logs.setLogTitle(logTitle);
|
||||
logs.setLogContent(logContent);
|
||||
logs.setLogIp(ServletUtil.getClientIP(request));
|
||||
logsRepository.save(logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最新的五条日志
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Logs> findLogsLatest() {
|
||||
return logsRepository.findTopFive();
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import freemarker.template.Template;
|
||||
import io.github.biezhi.ome.OhMyEmail;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 邮件发送业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/23
|
||||
*/
|
||||
@Service
|
||||
public class MailServiceImpl implements MailService {
|
||||
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer freeMarker;
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param to to 接收者
|
||||
* @param subject subject 标题
|
||||
* @param content content 内容
|
||||
*/
|
||||
@Override
|
||||
public void sendMail(String to, String subject, String content) {
|
||||
//配置邮件服务器
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_HOST.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_USERNAME.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_PASSWORD.getProp()));
|
||||
try {
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogPropertiesEnum.MAIL_FROM_NAME.getProp()))
|
||||
.to(to)
|
||||
.text(content)
|
||||
.send();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送模板邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
* @param templateName 模板路径
|
||||
*/
|
||||
@Override
|
||||
public void sendTemplateMail(String to, String subject, Map<String, Object> content, String templateName) {
|
||||
//配置邮件服务器
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_HOST.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_USERNAME.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_PASSWORD.getProp()));
|
||||
StrBuilder text = new StrBuilder();
|
||||
try {
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text.append(FreeMarkerTemplateUtils.processTemplateIntoString(template, content));
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogPropertiesEnum.MAIL_FROM_NAME.getProp()))
|
||||
.to(to)
|
||||
.html(text.toString())
|
||||
.send();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送带有附件的邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
* @param templateName 模板路径
|
||||
* @param attachSrc 附件路径
|
||||
*/
|
||||
@Override
|
||||
public void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachSrc) {
|
||||
//配置邮件服务器
|
||||
HaloUtils.configMail(
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_HOST.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_USERNAME.getProp()),
|
||||
OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_PASSWORD.getProp()));
|
||||
File file = new File(attachSrc);
|
||||
StrBuilder text = new StrBuilder();
|
||||
try {
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text.append(FreeMarkerTemplateUtils.processTemplateIntoString(template, content));
|
||||
OhMyEmail.subject(subject)
|
||||
.from(OPTIONS.get(BlogPropertiesEnum.MAIL_FROM_NAME.getProp()))
|
||||
.to(to)
|
||||
.html(text.toString())
|
||||
.attach(file, file.getName())
|
||||
.send();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.repository.MenuRepository;
|
||||
import cc.ryanc.halo.service.MenuService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 菜单业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/24
|
||||
*/
|
||||
@Service
|
||||
public class MenuServiceImpl extends AbstractCrudService<Menu, Long> implements MenuService {
|
||||
|
||||
private static final String MENUS_CACHE_KEY = "'menu'";
|
||||
|
||||
private static final String MENUS_CACHE_NAME = "menus";
|
||||
|
||||
private final MenuRepository menuRepository;
|
||||
|
||||
public MenuServiceImpl(MenuRepository menuRepository) {
|
||||
super(menuRepository);
|
||||
this.menuRepository = menuRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = MENUS_CACHE_NAME, key = MENUS_CACHE_KEY)
|
||||
public List<Menu> listAll() {
|
||||
return super.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改菜单
|
||||
*
|
||||
* @param menu menu
|
||||
* @return Menu
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = MENUS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Menu create(Menu menu) {
|
||||
return super.create(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param menuId menuId
|
||||
* @return Menu
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = MENUS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Menu removeById(Long menuId) {
|
||||
return super.removeById(menuId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Options;
|
||||
import cc.ryanc.halo.repository.OptionsRepository;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import cc.ryanc.halo.utils.ServiceUtils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 系统设置业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Service
|
||||
public class OptionsServiceImpl extends AbstractCrudService<Options, String> implements OptionsService {
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
private final OptionsRepository optionsRepository;
|
||||
|
||||
public OptionsServiceImpl(OptionsRepository optionsRepository) {
|
||||
super(optionsRepository);
|
||||
this.optionsRepository = optionsRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存设置
|
||||
*
|
||||
* @param options options
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public void saveOptions(Map<String, String> options) {
|
||||
if (!CollectionUtils.isEmpty(options)) {
|
||||
options.forEach(this::saveOption);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存单个设置选项
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
@Override
|
||||
public void saveOption(String key, String value) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
// If value is empty
|
||||
removeByIdOfNullable(key);
|
||||
} else if (StrUtil.isNotEmpty(key)) {
|
||||
//如果查询到有该设置选项则做更新操作,反之保存新的设置选项
|
||||
Options options = fetchById(key).map(option -> {
|
||||
// Exist
|
||||
option.setOptionValue(value);
|
||||
return option;
|
||||
}).orElseGet(() -> {
|
||||
// Not exist
|
||||
Options option = new Options();
|
||||
option.setOptionName(key);
|
||||
option.setOptionValue(value);
|
||||
return option;
|
||||
});
|
||||
|
||||
// Save or update the options
|
||||
optionsRepository.save(options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置选项
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> findAllOptions() {
|
||||
return ServiceUtils.convertToMap(listAll(), Options::getOptionName, Options::getOptionValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key查询单个设置选项
|
||||
*
|
||||
* @param key key
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String findOneOption(String key) {
|
||||
return fetchById(key).map(Options::getOptionValue).orElse(null);
|
||||
}
|
||||
}
|
|
@ -1,584 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
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.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.PostStatusEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.support.Archive;
|
||||
import cc.ryanc.halo.repository.PostRepository;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
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.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.POSTS_VIEWS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Service
|
||||
public class PostServiceImpl extends AbstractCrudService<Post, Long> implements PostService {
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
private static final String COMMENTS_CACHE_NAME = "comments";
|
||||
|
||||
private final PostRepository postRepository;
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
private final TagService tagService;
|
||||
|
||||
public PostServiceImpl(PostRepository postRepository,
|
||||
CategoryService categoryService,
|
||||
TagService tagService) {
|
||||
super(postRepository);
|
||||
this.postRepository = postRepository;
|
||||
this.categoryService = categoryService;
|
||||
this.tagService = tagService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存文章
|
||||
*
|
||||
* @param post Post
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||
public Post create(Post post) {
|
||||
int postSummary = 50;
|
||||
if (StrUtil.isNotEmpty(OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()))) {
|
||||
postSummary = Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()));
|
||||
}
|
||||
final String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (summaryText.length() > postSummary) {
|
||||
final String summary = summaryText.substring(0, postSummary);
|
||||
post.setPostSummary(summary);
|
||||
} else {
|
||||
post.setPostSummary(summaryText);
|
||||
}
|
||||
return super.create(post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号移除文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||
public Post removeById(Long postId) {
|
||||
final Optional<Post> post = fetchById(postId);
|
||||
postRepository.delete(post.get());
|
||||
return post.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
*
|
||||
* @param postId postId
|
||||
* @param status status
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Post updatePostStatus(Long postId, Integer status) {
|
||||
final Optional<Post> post = fetchById(postId);
|
||||
post.get().setPostStatus(status);
|
||||
return postRepository.save(post.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新文章摘要
|
||||
*
|
||||
* @param postSummary postSummary
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public void updateAllSummary(Integer postSummary) {
|
||||
final List<Post> posts = this.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
for (Post post : posts) {
|
||||
String text = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (text.length() > postSummary) {
|
||||
post.setPostSummary(text.substring(0, postSummary));
|
||||
} else {
|
||||
post.setPostSummary(text);
|
||||
}
|
||||
postRepository.save(post);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章列表 不分页
|
||||
*
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_type_'+#postType")
|
||||
public List<Post> findAll(String postType) {
|
||||
return postRepository.findPostsByPostType(postType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Post> searchPosts(String keyword, String postType, Integer postStatus, Pageable pageable) {
|
||||
return postRepository.findAll(buildSearchSpecification(keyword, postType, postStatus), pageable)
|
||||
.map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,用于后台管理
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @param pageable 分页信息
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable) {
|
||||
return postRepository.findPostsByPostStatusAndPostType(status, postType, pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询 分页,首页分页
|
||||
*
|
||||
* @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(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询
|
||||
*
|
||||
* @param status 0,1,2
|
||||
* @param postType post or page
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_status_type_'+#status+'_'+#postType")
|
||||
public List<Post> findPostByStatus(Integer status, String postType) {
|
||||
return postRepository.findPostsByPostStatusAndPostType(status, postType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号和类型查询文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
public Post findByPostId(Long postId, String postType) {
|
||||
return postRepository.findPostByPostIdAndPostType(postId, postType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
* @param postUrl 路径
|
||||
* @param postType post or page
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最新的5篇文章
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_latest'")
|
||||
public List<Post> findPostLatest() {
|
||||
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "postDate"));
|
||||
|
||||
Page<Post> postPage = postRepository.findAllByPostType("post", pageable);
|
||||
|
||||
return postPage.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一篇文章 较新
|
||||
*
|
||||
* @param postDate postDate
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
public Post getNextPost(Date postDate) {
|
||||
return postRepository.queryNextPost(postDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一篇文章 较老
|
||||
*
|
||||
* @param postDate postDate
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
public Post getPrePost(Date postDate) {
|
||||
return postRepository.queryPrePost(postDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询归档信息 根据年份和月份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year_month'")
|
||||
public List<Archive> findPostGroupByYearAndMonth() {
|
||||
final List<Object[]> objects = postRepository.findPostGroupByYearAndMonth();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
for (Object[] obj : objects) {
|
||||
archive = new Archive();
|
||||
archive.setYear(obj[0].toString());
|
||||
archive.setMonth(obj[1].toString());
|
||||
archive.setCount(obj[2].toString());
|
||||
archive.setPosts(this.findPostByYearAndMonth(obj[0].toString(), obj[1].toString()));
|
||||
archives.add(archive);
|
||||
}
|
||||
return archives;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询归档信息 根据年份
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year'")
|
||||
public List<Archive> findPostGroupByYear() {
|
||||
final List<Object[]> objects = postRepository.findPostGroupByYear();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
for (Object[] obj : objects) {
|
||||
archive = new Archive();
|
||||
archive.setYear(obj[0].toString());
|
||||
archive.setCount(obj[1].toString());
|
||||
archive.setPosts(this.findPostByYear(obj[0].toString()));
|
||||
archives.add(archive);
|
||||
}
|
||||
return archives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List
|
||||
* @Author Aquan
|
||||
* @Description 查询归档信息 返回所有文章
|
||||
* @Date 2019.1.4 11:16
|
||||
* @Param
|
||||
**/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'")
|
||||
public List<Archive> findAllPost() {
|
||||
final List<Post> posts = postRepository.findAllPost();
|
||||
final Integer count = postRepository.totalAllPostCount();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
archive = new Archive();
|
||||
archive.setCount(String.valueOf(count));
|
||||
archive.setPosts(posts);
|
||||
archives.add(archive);
|
||||
|
||||
return archives;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @param month month
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年份查询文章
|
||||
*
|
||||
* @param year year
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_year_'+#year")
|
||||
public List<Post> findPostByYear(String year) {
|
||||
return postRepository.findPostByYear(year);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年份和月份索引文章
|
||||
*
|
||||
* @param year year year
|
||||
* @param month month month
|
||||
* @param pageable pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
public Page<Post> findPostByYearAndMonth(String year, String month, Pageable pageable) {
|
||||
return postRepository.findPostByYearAndMonth(year, month, null).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类目录查询文章
|
||||
*
|
||||
* @param category category
|
||||
* @param pageable pageable
|
||||
* @return Page
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_category_'+#category.cateId+'_'+#pageable.pageNumber")
|
||||
public Page<Post> findPostByCategories(Category category, Pageable pageable) {
|
||||
return postRepository.findPostByCategoriesAndPostStatus(category, PostStatusEnum.PUBLISHED.getCode(), pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签查询文章,分页
|
||||
*
|
||||
* @param tag tag
|
||||
* @param pageable pageable
|
||||
* @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.findPostsByTagsAndPostStatus(tag, PostStatusEnum.PUBLISHED.getCode(), pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 热门文章
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_hot'")
|
||||
public List<Post> hotPosts() {
|
||||
return postRepository.findPostsByPostTypeOrderByPostViewsDesc(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前文章的相似文章
|
||||
*
|
||||
* @param post post
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_related_'+#post.getPostId()")
|
||||
public List<Post> relatedPosts(Post post) {
|
||||
//获取当前文章的所有标签
|
||||
final List<Tag> tags = post.getTags();
|
||||
final List<Post> tempPosts = new ArrayList<>();
|
||||
for (Tag tag : tags) {
|
||||
tempPosts.addAll(postRepository.findPostsByTags(tag));
|
||||
}
|
||||
//去掉当前的文章
|
||||
tempPosts.remove(post);
|
||||
//去掉重复的文章
|
||||
final List<Post> allPosts = new ArrayList<>();
|
||||
for (int i = 0; i < tempPosts.size(); i++) {
|
||||
if (!allPosts.contains(tempPosts.get(i))) {
|
||||
allPosts.add(tempPosts.get(i));
|
||||
}
|
||||
}
|
||||
return allPosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有文章的阅读量
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
@Override
|
||||
public Long getPostViews() {
|
||||
return postRepository.getPostViewsSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章状态查询数量
|
||||
*
|
||||
* @param status 文章状态
|
||||
* @return 文章数量
|
||||
*/
|
||||
@Override
|
||||
public Integer getCountByStatus(Integer status) {
|
||||
return postRepository.countAllByPostStatusAndPostType(status, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存阅读数
|
||||
*
|
||||
* @param postId postId
|
||||
*/
|
||||
@Override
|
||||
public void cacheViews(Long postId) {
|
||||
if (null != POSTS_VIEWS.get(postId)) {
|
||||
POSTS_VIEWS.put(postId, POSTS_VIEWS.get(postId) + 1);
|
||||
} else {
|
||||
POSTS_VIEWS.put(postId, 1L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装分类目录和标签
|
||||
*
|
||||
* @param post post
|
||||
* @param cateList cateList
|
||||
* @param tagList tagList
|
||||
* @return Post Post
|
||||
*/
|
||||
@Override
|
||||
public Post buildCategoriesAndTags(Post post, List<String> cateList, String tagList) {
|
||||
final List<Category> categories = categoryService.strListToCateList(cateList);
|
||||
post.setCategories(categories);
|
||||
if (StrUtil.isNotEmpty(tagList)) {
|
||||
final List<Tag> tags = tagService.strListToTagList(StrUtil.trim(tagList));
|
||||
post.setTags(tags);
|
||||
}
|
||||
return post;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的文章
|
||||
*
|
||||
* @param limit 条数
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Post> getRecentPosts(int limit) {
|
||||
return postRepository.getPostsByLimit(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* build Specification for post
|
||||
*
|
||||
* @param keyword keyword
|
||||
* @param postType postType
|
||||
* @param postStatus postStatus
|
||||
* @return Specification
|
||||
*/
|
||||
@NonNull
|
||||
private Specification<Post> buildSearchSpecification(@NonNull String keyword,
|
||||
@NonNull String postType,
|
||||
@NonNull Integer postStatus) {
|
||||
return Specification
|
||||
.where(postTitleLike(keyword))
|
||||
.or(postContentLike(keyword))
|
||||
.and(postTypeEqual(postType))
|
||||
.and(postStatusEqual(postStatus));
|
||||
}
|
||||
|
||||
/**
|
||||
* build with postContent
|
||||
*
|
||||
* @param keyword keyword
|
||||
* @return Specification
|
||||
*/
|
||||
private Specification<Post> postContentLike(@NonNull String keyword) {
|
||||
Assert.hasText(keyword, "Keyword must not be blank");
|
||||
return (root, criteriaQuery, criteriaBuilder) ->
|
||||
criteriaBuilder.like(criteriaBuilder.lower(root.get("postContent")), "%" + keyword.toLowerCase() + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* build with postTitle
|
||||
*
|
||||
* @param keyword keyword
|
||||
* @return Specification
|
||||
*/
|
||||
private Specification<Post> postTitleLike(@NonNull String keyword) {
|
||||
Assert.hasText(keyword, "Keyword must not be blank");
|
||||
return (root, criteriaQuery, criteriaBuilder) ->
|
||||
criteriaBuilder.like(criteriaBuilder.lower(root.get("postTitle")), "%" + keyword.toLowerCase() + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* build with postType
|
||||
*
|
||||
* @param postType postType
|
||||
* @return Specification
|
||||
*/
|
||||
private Specification<Post> postTypeEqual(@NonNull String postType) {
|
||||
return (root, criteriaQuery, criteriaBuilder) ->
|
||||
criteriaBuilder.equal(root.get("postType"), postType);
|
||||
}
|
||||
|
||||
/**
|
||||
* build with postStatus
|
||||
*
|
||||
* @param postStatus postStatus
|
||||
* @return Specification
|
||||
*/
|
||||
private Specification<Post> postStatusEqual(@NonNull Integer postStatus) {
|
||||
return (root, criteriaQuery, criteriaBuilder) ->
|
||||
criteriaBuilder.equal(root.get("postStatus"), postStatus);
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.repository.TagRepository;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 标签业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/12
|
||||
*/
|
||||
@Service
|
||||
public class TagServiceImpl extends AbstractCrudService<Tag, Long> implements TagService {
|
||||
|
||||
private static final String POSTS_CACHE_NAME = "posts";
|
||||
|
||||
private final TagRepository tagRepository;
|
||||
|
||||
public TagServiceImpl(TagRepository tagRepository) {
|
||||
super(tagRepository);
|
||||
this.tagRepository = tagRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改标签
|
||||
*
|
||||
* @param tag tag
|
||||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Tag create(Tag tag) {
|
||||
return super.create(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号移除标签
|
||||
*
|
||||
* @param tagId tagId
|
||||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Tag removeById(Long tagId) {
|
||||
return super.removeById(tagId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签路径查询
|
||||
*
|
||||
* @param tagUrl tagUrl
|
||||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
public Tag findByTagUrl(String tagUrl) {
|
||||
return tagRepository.findTagByTagUrl(tagUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签名称查询
|
||||
*
|
||||
* @param tagName tagName
|
||||
* @return Tag
|
||||
*/
|
||||
@Override
|
||||
public Tag findTagByTagName(String tagName) {
|
||||
return tagRepository.findTagByTagName(tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换标签字符串为实体集合
|
||||
*
|
||||
* @param tagList tagList
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Tag> strListToTagList(String tagList) {
|
||||
final String[] tags = tagList.split(",");
|
||||
final List<Tag> tagsList = new ArrayList<>();
|
||||
for (String tag : tags) {
|
||||
final Tag t = findTagByTagName(tag);
|
||||
Tag nt = null;
|
||||
if (null != t) {
|
||||
tagsList.add(t);
|
||||
} else {
|
||||
nt = new Tag();
|
||||
nt.setTagName(tag);
|
||||
nt.setTagUrl(tag);
|
||||
tagsList.add(create(nt));
|
||||
}
|
||||
}
|
||||
return tagsList;
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.enums.TrueFalseEnum;
|
||||
import cc.ryanc.halo.repository.UserRepository;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用户业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends AbstractCrudService<User, Long> implements UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserServiceImpl(UserRepository userRepository) {
|
||||
super(userRepository);
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名和密码查询
|
||||
*
|
||||
* @param userName userName
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User userLoginByName(String userName, String userPass) {
|
||||
return userRepository.findByUserNameAndUserPass(userName, userPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据邮箱和密码查询,用户登录
|
||||
*
|
||||
* @param userEmail userEmail
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User userLoginByEmail(String userEmail, String userPass) {
|
||||
return userRepository.findByUserEmailAndUserPass(userEmail, userPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User findUser() {
|
||||
final List<User> users = userRepository.findAll();
|
||||
if (users != null && users.size() > 0) {
|
||||
return users.get(0);
|
||||
} else {
|
||||
return new User();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证修改密码时,密码是否正确
|
||||
*
|
||||
* @param userId userId
|
||||
* @param userPass userPass
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User findByUserIdAndUserPass(Long userId, String userPass) {
|
||||
return userRepository.findByUserIdAndUserPass(userId, userPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改禁用状态
|
||||
*
|
||||
* @param enable enable
|
||||
*/
|
||||
@Override
|
||||
public void updateUserLoginEnable(String enable) {
|
||||
final User user = this.findUser();
|
||||
user.setLoginError(0);
|
||||
user.setLoginEnable(enable);
|
||||
|
||||
// Update user
|
||||
update(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改最后登录时间
|
||||
*
|
||||
* @param lastDate 最后登录时间
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User updateUserLoginLast(Date lastDate) {
|
||||
final User user = this.findUser();
|
||||
user.setLoginLast(lastDate);
|
||||
|
||||
// Update user
|
||||
return update(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加登录错误次数
|
||||
*
|
||||
* @return 登录错误次数
|
||||
*/
|
||||
@Override
|
||||
public Integer updateUserLoginError() {
|
||||
final User user = this.findUser();
|
||||
user.setLoginError((user.getLoginError() == null ? 0 : user.getLoginError()) + 1);
|
||||
|
||||
// Update user
|
||||
update(user);
|
||||
|
||||
// Return login error times
|
||||
return user.getLoginError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户的状态为正常
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
@Override
|
||||
public User updateUserNormal() {
|
||||
final User user = this.findUser();
|
||||
user.setLoginEnable(TrueFalseEnum.TRUE.getDesc());
|
||||
user.setLoginError(0);
|
||||
user.setLoginLast(new Date());
|
||||
|
||||
return update(user);
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cc.ryanc.halo.task;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.POSTS_VIEWS;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/12/5
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PostSyncTask {
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
public PostSyncTask(PostService postService) {
|
||||
this.postService = postService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将缓存的图文浏览数写入数据库
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * *")
|
||||
public void postSync() {
|
||||
int count = 0;
|
||||
for (Long key : POSTS_VIEWS.keySet()) {
|
||||
Post post = postService.getByIdOfNullable(key);
|
||||
if (null != post) {
|
||||
post.setPostViews(post.getPostViews() + POSTS_VIEWS.get(key));
|
||||
postService.create(post);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
log.info("The number of visits to {} posts has been updated", count);
|
||||
POSTS_VIEWS.clear();
|
||||
}
|
||||
}
|
|
@ -1,13 +1,5 @@
|
|||
package cc.ryanc.halo.utils;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 拼装评论
|
||||
|
@ -18,63 +10,63 @@ import java.util.List;
|
|||
*/
|
||||
public class CommentUtil {
|
||||
|
||||
/**
|
||||
* 获取组装好的评论
|
||||
*
|
||||
* @param commentsRoot commentsRoot
|
||||
* @return List
|
||||
*/
|
||||
public static List<Comment> getComments(List<Comment> commentsRoot) {
|
||||
if (CollectionUtils.isEmpty(commentsRoot)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<Comment> commentsResult = new ArrayList<>();
|
||||
|
||||
for (Comment comment : commentsRoot) {
|
||||
if (comment.getCommentParent() == 0) {
|
||||
commentsResult.add(comment);
|
||||
}
|
||||
}
|
||||
|
||||
for (Comment comment : commentsResult) {
|
||||
comment.setChildComments(getChild(comment.getCommentId(), commentsRoot));
|
||||
}
|
||||
// 集合倒序,最新的评论在最前面
|
||||
Collections.reverse(commentsResult);
|
||||
return commentsResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论的子评论
|
||||
*
|
||||
* @param id 评论编号
|
||||
* @param commentsRoot commentsRoot
|
||||
* @return List
|
||||
*/
|
||||
private static List<Comment> getChild(Long id, List<Comment> commentsRoot) {
|
||||
Assert.notNull(id, "comment id must not be null");
|
||||
|
||||
if (CollectionUtils.isEmpty(commentsRoot)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<Comment> commentsChild = new ArrayList<>();
|
||||
for (Comment comment : commentsRoot) {
|
||||
if (comment.getCommentParent() != 0) {
|
||||
if (comment.getCommentParent().equals(id)) {
|
||||
commentsChild.add(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Comment comment : commentsChild) {
|
||||
if (comment.getCommentParent() != 0) {
|
||||
comment.setChildComments(getChild(comment.getCommentId(), commentsRoot));
|
||||
}
|
||||
}
|
||||
if (commentsChild.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return commentsChild;
|
||||
}
|
||||
// /**
|
||||
// * 获取组装好的评论
|
||||
// *
|
||||
// * @param commentsRoot commentsRoot
|
||||
// * @return List
|
||||
// */
|
||||
// public static List<Comment> getComments(List<Comment> commentsRoot) {
|
||||
// if (CollectionUtils.isEmpty(commentsRoot)) {
|
||||
// return Collections.emptyList();
|
||||
// }
|
||||
//
|
||||
// final List<Comment> commentsResult = new ArrayList<>();
|
||||
//
|
||||
// for (Comment comment : commentsRoot) {
|
||||
// if (comment.getCommentParent() == 0) {
|
||||
// commentsResult.add(comment);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (Comment comment : commentsResult) {
|
||||
// comment.setChildComments(getChild(comment.getCommentId(), commentsRoot));
|
||||
// }
|
||||
// // 集合倒序,最新的评论在最前面
|
||||
// Collections.reverse(commentsResult);
|
||||
// return commentsResult;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取评论的子评论
|
||||
// *
|
||||
// * @param id 评论编号
|
||||
// * @param commentsRoot commentsRoot
|
||||
// * @return List
|
||||
// */
|
||||
// private static List<Comment> getChild(Long id, List<Comment> commentsRoot) {
|
||||
// Assert.notNull(id, "comment id must not be null");
|
||||
//
|
||||
// if (CollectionUtils.isEmpty(commentsRoot)) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// final List<Comment> commentsChild = new ArrayList<>();
|
||||
// for (Comment comment : commentsRoot) {
|
||||
// if (comment.getCommentParent() != 0) {
|
||||
// if (comment.getCommentParent().equals(id)) {
|
||||
// commentsChild.add(comment);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for (Comment comment : commentsChild) {
|
||||
// if (comment.getCommentParent() != 0) {
|
||||
// comment.setChildComments(getChild(comment.getCommentId(), commentsRoot));
|
||||
// }
|
||||
// }
|
||||
// if (commentsChild.size() == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// return commentsChild;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package cc.ryanc.halo.utils;
|
||||
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||
import cc.ryanc.halo.model.support.BackupDto;
|
||||
import cc.ryanc.halo.model.support.Theme;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
@ -59,18 +57,18 @@ public class HaloUtils {
|
|||
return machineAddress.getHostAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets default page size.
|
||||
*
|
||||
* @return default page size
|
||||
*/
|
||||
public static int getDefaultPageSize() {
|
||||
if (StrUtil.isNotBlank(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
return Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
|
||||
return DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
// /**
|
||||
// * Gets default page size.
|
||||
// *
|
||||
// * @return default page size
|
||||
// */
|
||||
// public static int getDefaultPageSize() {
|
||||
// if (StrUtil.isNotBlank(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
// return Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
// }
|
||||
//
|
||||
// return DEFAULT_PAGE_SIZE;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets default qiniuyun zone.
|
||||
|
@ -112,65 +110,65 @@ public class HaloUtils {
|
|||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取备份文件信息
|
||||
*
|
||||
* @param dir dir
|
||||
* @return List
|
||||
*/
|
||||
public static List<BackupDto> getBackUps(String dir) {
|
||||
final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
srcPathStr.append("/halo/backup/");
|
||||
srcPathStr.append(dir);
|
||||
final File srcPath = new File(srcPathStr.toString());
|
||||
final File[] files = srcPath.listFiles();
|
||||
final List<BackupDto> backupDtos = new ArrayList<>();
|
||||
BackupDto backupDto;
|
||||
// 遍历文件
|
||||
if (null != files) {
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
if (StrUtil.equals(file.getName(), ".DS_Store")) {
|
||||
continue;
|
||||
}
|
||||
backupDto = new BackupDto();
|
||||
backupDto.setFileName(file.getName());
|
||||
backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
|
||||
backupDto.setFileType(FileUtil.getType(file));
|
||||
backupDto.setFileSize(parseSize(file.length()));
|
||||
backupDto.setBackupType(dir);
|
||||
backupDtos.add(backupDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
return backupDtos;
|
||||
}
|
||||
// /**
|
||||
// * 获取备份文件信息
|
||||
// *
|
||||
// * @param dir dir
|
||||
// * @return List
|
||||
// */
|
||||
// public static List<BackupDto> getBackUps(String dir) {
|
||||
// final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
// srcPathStr.append("/halo/backup/");
|
||||
// srcPathStr.append(dir);
|
||||
// final File srcPath = new File(srcPathStr.toString());
|
||||
// final File[] files = srcPath.listFiles();
|
||||
// final List<BackupDto> backupDtos = new ArrayList<>();
|
||||
// BackupDto backupDto;
|
||||
// // 遍历文件
|
||||
// if (null != files) {
|
||||
// for (File file : files) {
|
||||
// if (file.isFile()) {
|
||||
// if (StrUtil.equals(file.getName(), ".DS_Store")) {
|
||||
// continue;
|
||||
// }
|
||||
// backupDto = new BackupDto();
|
||||
// backupDto.setFileName(file.getName());
|
||||
// backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
|
||||
// backupDto.setFileType(FileUtil.getType(file));
|
||||
// backupDto.setFileSize(parseSize(file.length()));
|
||||
// backupDto.setBackupType(dir);
|
||||
// backupDtos.add(backupDto);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return backupDtos;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 转换文件大小
|
||||
*
|
||||
* @param size size
|
||||
* @return String
|
||||
*/
|
||||
public static String parseSize(long size) {
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
return size + "B";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
return size + "KB";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
size = size * 100;
|
||||
return size / 100 + "." + size % 100 + "MB";
|
||||
} else {
|
||||
size = size * 100 / 1024;
|
||||
return size / 100 + "." + size % 100 + "GB";
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * 转换文件大小
|
||||
// *
|
||||
// * @param size size
|
||||
// * @return String
|
||||
// */
|
||||
// public static String parseSize(long size) {
|
||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
// return size + "B";
|
||||
// } else {
|
||||
// size = size / 1024;
|
||||
// }
|
||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
// return size + "KB";
|
||||
// } else {
|
||||
// size = size / 1024;
|
||||
// }
|
||||
// if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
// size = size * 100;
|
||||
// return size / 100 + "." + size % 100 + "MB";
|
||||
// } else {
|
||||
// size = size * 100 / 1024;
|
||||
// return size / 100 + "." + size % 100 + "GB";
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取文件创建时间
|
||||
|
|
|
@ -1,462 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.logging.Logger;
|
||||
import cc.ryanc.halo.model.domain.*;
|
||||
import cc.ryanc.halo.model.dto.CommentViewOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.PostViewOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.model.params.PasswordResetParam;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台首页控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/5
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin")
|
||||
public class AdminController extends BaseController {
|
||||
|
||||
private final static String RESET_PASSWORD_SESSION_KEY = "resetPasswordCode";
|
||||
|
||||
private final Logger log = Logger.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
@Autowired
|
||||
private AttachmentService attachmentService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private TagService tagService;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
/**
|
||||
* 请求后台页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_index
|
||||
*/
|
||||
@GetMapping(value = {"", "/index"})
|
||||
public String index(Model model) {
|
||||
|
||||
//查询评论的条数
|
||||
final Long commentCount = commentService.count();
|
||||
model.addAttribute("commentCount", commentCount);
|
||||
|
||||
//附件数量
|
||||
model.addAttribute("mediaCount", attachmentService.count());
|
||||
|
||||
//文章阅读总数
|
||||
final Long postViewsSum = postService.getPostViews();
|
||||
model.addAttribute("postViewsSum", postViewsSum);
|
||||
|
||||
//查询最新的文章
|
||||
final List<PostViewOutputDTO> postsLatest = postService.findPostLatest()
|
||||
.stream()
|
||||
.map(post -> (PostViewOutputDTO) new PostViewOutputDTO().convertFrom(post))
|
||||
.collect(Collectors.toList());
|
||||
model.addAttribute("postsLatest", postsLatest);
|
||||
|
||||
//查询最新的日志
|
||||
final List<Logs> logsLatest = logsService.findLogsLatest();
|
||||
model.addAttribute("logsLatest", logsLatest);
|
||||
|
||||
//查询最新的评论
|
||||
final List<CommentViewOutputDTO> commentsLatest = commentService.findCommentsLatest()
|
||||
.stream()
|
||||
.map(comment -> (CommentViewOutputDTO) new CommentViewOutputDTO().convertFrom(comment))
|
||||
.collect(Collectors.toList());
|
||||
model.addAttribute("commentsLatest", commentsLatest);
|
||||
|
||||
//成立天数
|
||||
final Date blogStart = DateUtil.parse(OPTIONS.get(BlogPropertiesEnum.BLOG_START.getProp()));
|
||||
final long hadDays = DateUtil.between(blogStart, DateUtil.date(), DateUnit.DAY);
|
||||
model.addAttribute("hadDays", hadDays);
|
||||
return "admin/admin_index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理跳转到登录页的请求
|
||||
*
|
||||
* @param session session
|
||||
* @return 模板路径admin/admin_login
|
||||
*/
|
||||
@GetMapping(value = "/login")
|
||||
public String login(HttpSession session) {
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
//如果session存在,跳转到后台首页
|
||||
return user != null ? "redirect:/admin" : "admin/admin_login";
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录信息
|
||||
*
|
||||
* @param loginName 登录名:邮箱/用户名
|
||||
* @param loginPwd loginPwd 密码
|
||||
* @param session session session
|
||||
* @return JsonResult JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/getLogin")
|
||||
@ResponseBody
|
||||
public JsonResult getLogin(@ModelAttribute("loginName") String loginName,
|
||||
@ModelAttribute("loginPwd") String loginPwd,
|
||||
HttpSession session) {
|
||||
//已注册账号,单用户,只有一个
|
||||
final User aUser = userService.findUser();
|
||||
|
||||
//首先判断是否已经被禁用已经是否已经过了10分钟
|
||||
Date loginLast = DateUtil.date();
|
||||
if (null != aUser.getLoginLast()) {
|
||||
loginLast = aUser.getLoginLast();
|
||||
}
|
||||
final Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
|
||||
if (StrUtil.equals(aUser.getLoginEnable(), TrueFalseEnum.FALSE.getDesc()) && (between < CommonParamsEnum.TEN.getValue())) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.login.disabled"));
|
||||
}
|
||||
|
||||
//验证用户名和密码
|
||||
User user;
|
||||
if (Validator.isEmail(loginName)) {
|
||||
user = userService.userLoginByEmail(loginName, SecureUtil.md5(loginPwd));
|
||||
} else {
|
||||
user = userService.userLoginByName(loginName, SecureUtil.md5(loginPwd));
|
||||
}
|
||||
userService.updateUserLoginLast(DateUtil.date());
|
||||
|
||||
//判断User对象是否相等
|
||||
if (Objects.equals(aUser, user)) {
|
||||
session.setAttribute(USER_SESSION_KEY, aUser);
|
||||
//重置用户的登录状态为正常
|
||||
userService.updateUserNormal();
|
||||
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, request);
|
||||
log.info("User {} login succeeded.", aUser.getUserDisplayName());
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.login.success"));
|
||||
} else {
|
||||
//更新失败次数
|
||||
final Integer errorCount = userService.updateUserLoginError();
|
||||
|
||||
Integer limitCount = CommonParamsEnum.FIVE.getValue();
|
||||
|
||||
log.error("Login failure count: [{}], but limit count: [{}]", errorCount, limitCount);
|
||||
|
||||
//超过五次禁用账户
|
||||
if (errorCount >= limitCount) {
|
||||
log.error("Exceeded login limit. You have been locked permanently");
|
||||
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
||||
}
|
||||
|
||||
// Log login error detail
|
||||
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
|
||||
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.login.failed", new Integer[]{5 - errorCount}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/findPassword")
|
||||
public String findPassword() {
|
||||
return "admin/admin_findpassword";
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送重置密码邮件
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param email 邮箱
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/sendResetPasswordEmail")
|
||||
@ResponseBody
|
||||
public JsonResult sendResetPasswordEmail(@RequestParam(value = "userName") String userName,
|
||||
@RequestParam(value = "email") String email,
|
||||
HttpSession session) {
|
||||
final User user = userService.findUser();
|
||||
if (StrUtil.isEmpty(userName) || StrUtil.isEmpty(email)) {
|
||||
return JsonResult.fail("请输入完整信息!");
|
||||
}
|
||||
if (!user.getUserEmail().equals(email) || !user.getUserName().equals(userName)) {
|
||||
return JsonResult.fail("用户名或电子邮箱错误,请确定你的身份!");
|
||||
}
|
||||
try {
|
||||
long time = System.currentTimeMillis();
|
||||
String randomString = RandomUtil.randomString(10);
|
||||
String code = SecureUtil.md5(time + randomString);
|
||||
StrBuilder url = new StrBuilder(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
url.append("/admin/toResetPassword?code=");
|
||||
url.append(code);
|
||||
mailService.sendMail(user.getUserEmail(), "请根据该链接重置你的博客密码", "请点击该链接重置你的密码:" + url);
|
||||
session.setAttribute(RESET_PASSWORD_SESSION_KEY, code);
|
||||
return JsonResult.success("邮件发送成功,请登录您的邮箱进行下一步操作");
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to send password email", e);
|
||||
return JsonResult.fail("邮件发送失败,请确定已经配置好了发信服务器信息");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码页面
|
||||
*
|
||||
* @param code code
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/toResetPassword")
|
||||
public String toResetPassword(@RequestParam(value = "code", defaultValue = "") String code,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
String sessionCode = (String) session.getAttribute(RESET_PASSWORD_SESSION_KEY);
|
||||
|
||||
model.addAttribute("isRight", StrUtil.equals(sessionCode, code));
|
||||
|
||||
model.addAttribute("code", code);
|
||||
return "admin/admin_resetpassword";
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param resetParam password reset param
|
||||
* @return String
|
||||
*/
|
||||
@PostMapping(value = "/resetPassword")
|
||||
@ResponseBody
|
||||
public JsonResult resetPassword(@RequestBody PasswordResetParam resetParam,
|
||||
HttpSession session) {
|
||||
final String sessionCode = (String) session.getAttribute(RESET_PASSWORD_SESSION_KEY);
|
||||
if (null == sessionCode || !StrUtil.equals(sessionCode, resetParam.getCode())) {
|
||||
return JsonResult.fail("不允许该操作!");
|
||||
}
|
||||
|
||||
if (!StrUtil.equals(resetParam.getPassword(), resetParam.getDefinePassword())) {
|
||||
return JsonResult.fail("两次密码不一样!");
|
||||
}
|
||||
final User user = userService.findUser();
|
||||
user.setUserPass(SecureUtil.md5(resetParam.getPassword()));
|
||||
userService.update(user);
|
||||
userService.updateUserNormal();
|
||||
session.removeAttribute(RESET_PASSWORD_SESSION_KEY);
|
||||
return JsonResult.success("重置密码成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录 销毁session
|
||||
*
|
||||
* @param session session
|
||||
* @return 重定向到/admin/login
|
||||
*/
|
||||
@GetMapping(value = "/logOut")
|
||||
public String logOut(HttpSession session) {
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
session.removeAttribute(USER_SESSION_KEY);
|
||||
logsService.save(LogsRecord.LOGOUT, user.getUserName(), request);
|
||||
log.info("User {} has logged out", user.getUserName());
|
||||
return "redirect:/admin/login";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看所有日志
|
||||
*
|
||||
* @param model model model
|
||||
* @return 模板路径admin/widget/_logs-all
|
||||
*/
|
||||
@GetMapping(value = "/logs")
|
||||
public String logs(Model model, @PageableDefault Pageable pageable) {
|
||||
final Page<Logs> logs = logsService.listAll(pageable);
|
||||
model.addAttribute("logs", logs);
|
||||
return "admin/widget/_logs-all";
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有日志
|
||||
*
|
||||
* @return 重定向到/admin
|
||||
*/
|
||||
@GetMapping(value = "/logs/clear")
|
||||
public String logsClear() {
|
||||
try {
|
||||
logsService.removeAll();
|
||||
} catch (Exception e) {
|
||||
log.error("Clear log failed", e);
|
||||
}
|
||||
return "redirect:/admin";
|
||||
}
|
||||
|
||||
/**
|
||||
* Halo关于页面
|
||||
*
|
||||
* @return 模板路径admin/admin_halo
|
||||
*/
|
||||
@GetMapping(value = "/halo")
|
||||
public String halo() {
|
||||
return "admin/admin_halo";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个Token
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/getToken")
|
||||
@ResponseBody
|
||||
public JsonResult getToken() {
|
||||
final String token = String.valueOf(System.currentTimeMillis() + RandomUtil.randomInt(Integer.MAX_VALUE));
|
||||
return JsonResult.success(HttpStatus.OK.getReasonPhrase(), SecureUtil.md5(token));
|
||||
}
|
||||
|
||||
/**
|
||||
* 小工具
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/tools")
|
||||
public String tools() {
|
||||
return "admin/admin_tools";
|
||||
}
|
||||
|
||||
/**
|
||||
* Markdown 导入页面
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/tools/markdownImport")
|
||||
public String markdownImport() {
|
||||
return "admin/widget/_markdown_import";
|
||||
}
|
||||
|
||||
/**
|
||||
* Markdown 导入
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/tools/markdownImport")
|
||||
@ResponseBody
|
||||
public JsonResult markdownImport(@RequestParam("file") MultipartFile file,
|
||||
HttpServletRequest request,
|
||||
HttpSession session) throws IOException {
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
final String markdown = IoUtil.read(file.getInputStream(), "UTF-8");
|
||||
final String content = MarkdownUtils.renderMarkdown(markdown);
|
||||
final Map<String, List<String>> frontMatters = MarkdownUtils.getFrontMatter(markdown);
|
||||
final Post post = new Post();
|
||||
final List<Tag> tags = new LinkedList<>();
|
||||
final List<Category> categories = new LinkedList<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(frontMatters)) {
|
||||
// Iterate the map and inner list
|
||||
frontMatters.forEach((key, elementValue) -> elementValue.forEach(ele -> {
|
||||
switch (key) {
|
||||
case "title":
|
||||
post.setPostTitle(ele);
|
||||
break;
|
||||
case "date":
|
||||
post.setPostDate(DateUtil.parse(ele));
|
||||
break;
|
||||
case "updated":
|
||||
post.setPostUpdate(DateUtil.parse(ele));
|
||||
break;
|
||||
case "tags":
|
||||
Tag tag = Optional.ofNullable(tagService.findTagByTagName(ele)).orElseGet(() -> {
|
||||
Tag aTag = new Tag();
|
||||
aTag.setTagName(ele);
|
||||
aTag.setTagUrl(ele);
|
||||
return tagService.create(aTag);
|
||||
});
|
||||
tags.add(tag);
|
||||
break;
|
||||
case "categories":
|
||||
Category category = Optional.ofNullable(categoryService.findByCateName(ele)).orElseGet(() -> {
|
||||
Category catg = new Category();
|
||||
catg.setCateName(ele);
|
||||
catg.setCateUrl(ele);
|
||||
catg.setCateDesc(ele);
|
||||
return categoryService.create(catg);
|
||||
});
|
||||
categories.add(category);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(post.getPostTitle())) {
|
||||
post.setPostTitle(file.getOriginalFilename());
|
||||
}
|
||||
|
||||
post.setPostContentMd(markdown);
|
||||
post.setPostContent(content);
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
post.setAllowComment(AllowCommentEnum.ALLOW.getCode());
|
||||
post.setUser(user);
|
||||
post.setTags(tags);
|
||||
post.setCategories(categories);
|
||||
post.setPostUrl(StrUtil.removeSuffix(file.getOriginalFilename(), ".md"));
|
||||
|
||||
log.debug("Post you imported just now: [{}]", post);
|
||||
|
||||
postService.create(post);
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode());
|
||||
}
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.model.dto.AttachmentAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cc.ryanc.halo.model.enums.AttachLocationEnum.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台附件控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/attachments")
|
||||
public class AttachmentController {
|
||||
|
||||
@Autowired
|
||||
private AttachmentService attachmentService;
|
||||
|
||||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 附件列表
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_attachment
|
||||
*/
|
||||
@GetMapping
|
||||
public String attachments(Model model,
|
||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
final Page<AttachmentAdminOutputDTO> attachments = attachmentService.listAll(pageable)
|
||||
.map(attachment -> new AttachmentAdminOutputDTO().convertFrom(attachment));
|
||||
model.addAttribute("attachments", attachments);
|
||||
return "admin/admin_attachment";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转选择附件页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/widget/_attachment-select
|
||||
*/
|
||||
@GetMapping(value = "/select")
|
||||
public String selectAttachment(Model model,
|
||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "id", defaultValue = "none") String id,
|
||||
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
||||
final Page<AttachmentAdminOutputDTO> attachments = attachmentService.listAll(pageable)
|
||||
.map(attachment -> new AttachmentAdminOutputDTO().convertFrom(attachment));
|
||||
model.addAttribute("attachments", attachments);
|
||||
model.addAttribute("id", id);
|
||||
if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
return "admin/widget/_attachment-select-post";
|
||||
}
|
||||
|
||||
return "admin/widget/_attachment-select";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传附件窗口
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/uploadModal")
|
||||
public String uploadModal() {
|
||||
return "admin/widget/_attachment-upload";
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传附件
|
||||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
* @return Map
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ResponseBody
|
||||
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
||||
HttpServletRequest request) {
|
||||
final Map<String, Object> result = new HashMap<>(4);
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
final Map<String, String> resultMap = attachmentService.upload(file, request);
|
||||
if (resultMap == null || resultMap.isEmpty()) {
|
||||
log.error("File upload failed");
|
||||
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
||||
return result;
|
||||
}
|
||||
//保存在数据库
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.setAttachName(resultMap.get("fileName"));
|
||||
attachment.setAttachPath(resultMap.get("filePath"));
|
||||
attachment.setAttachSmallPath(resultMap.get("smallPath"));
|
||||
attachment.setAttachType(file.getContentType());
|
||||
attachment.setAttachSuffix(resultMap.get("suffix"));
|
||||
attachment.setAttachSize(resultMap.get("size"));
|
||||
attachment.setAttachWh(resultMap.get("wh"));
|
||||
attachment.setAttachLocation(resultMap.get("location"));
|
||||
attachmentService.create(attachment);
|
||||
log.info("Upload file {} to {} successfully", resultMap.get("fileName"), resultMap.get("filePath"));
|
||||
result.put("success", ResultCodeEnum.SUCCESS.getCode());
|
||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
|
||||
result.put("url", attachment.getAttachPath());
|
||||
result.put("filename", resultMap.get("filePath"));
|
||||
logsService.save(LogsRecord.UPLOAD_FILE, resultMap.get("fileName"), request);
|
||||
} catch (Exception e) {
|
||||
log.error("Upload file failed", e);
|
||||
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
||||
}
|
||||
} else {
|
||||
log.error("File cannot be empty! File name: [{}]", file.getOriginalFilename());
|
||||
|
||||
// Return error message
|
||||
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||
result.put("message", "File cannot be empty");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理获取附件详情的请求
|
||||
*
|
||||
* @param model model
|
||||
* @param attachId 附件编号
|
||||
* @return 模板路径admin/widget/_attachment-detail
|
||||
*/
|
||||
@GetMapping(value = "/attachment")
|
||||
public String attachmentDetail(Model model, @RequestParam("attachId") Long attachId) {
|
||||
final Optional<Attachment> attachment = attachmentService.fetchById(attachId);
|
||||
model.addAttribute("attachment", attachment.orElse(new Attachment()));
|
||||
return "admin/widget/_attachment-detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除附件的请求
|
||||
*
|
||||
* @param attachId 附件编号
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
@ResponseBody
|
||||
public JsonResult removeAttachment(@RequestParam("attachId") Long attachId,
|
||||
HttpServletRequest request) {
|
||||
final Attachment attachment = attachmentService.fetchById(attachId).orElse(new Attachment());
|
||||
final String attachLocation = attachment.getAttachLocation();
|
||||
final String attachName = attachment.getAttachName();
|
||||
final String attachPath = attachment.getAttachPath();
|
||||
boolean flag = true;
|
||||
try {
|
||||
if (attachLocation != null) {
|
||||
if (attachLocation.equals(SERVER.getDesc())) {
|
||||
StrBuilder userPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
userPath.append("/halo");
|
||||
//图片物理地址
|
||||
StrBuilder delPath = new StrBuilder(userPath);
|
||||
delPath.append(attachPath);
|
||||
//缩略图物理地址
|
||||
StrBuilder delSmallPath = new StrBuilder(userPath);
|
||||
delSmallPath.append(attachment.getAttachSmallPath());
|
||||
File delFile = new File(delPath.toString());
|
||||
File delSmallFile = new File(delSmallPath.toString());
|
||||
if (delFile.exists() && delFile.isFile()) {
|
||||
flag = delFile.delete() && delSmallFile.delete();
|
||||
}
|
||||
} else if (attachLocation.equals(QINIU.getDesc())) {
|
||||
String key = attachPath.substring(attachPath.lastIndexOf("/") + 1);
|
||||
flag = attachmentService.deleteQiNiuAttachment(key);
|
||||
} else if (attachLocation.equals(UPYUN.getDesc())) {
|
||||
String fileName = attachPath.substring(attachPath.lastIndexOf("/") + 1);
|
||||
flag = attachmentService.deleteUpYunAttachment(fileName);
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
attachmentService.removeById(attachId);
|
||||
log.info("Deleted attachment [{}] successfully", attachName);
|
||||
logsService.save(LogsRecord.REMOVE_FILE, attachName, request);
|
||||
} else {
|
||||
log.error("Failed to delete attachment: [{}]", attachName);
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to deleted " + attachName, e);
|
||||
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||
}
|
||||
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.delete-success"));
|
||||
}
|
||||
}
|
|
@ -1,282 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
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.domain.User;
|
||||
import cc.ryanc.halo.model.support.BackupDto;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台备份控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/21
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/backup")
|
||||
public class BackupController {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 渲染备份页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_backup
|
||||
*/
|
||||
@GetMapping
|
||||
public String backup(@RequestParam(value = "type", defaultValue = "resources") String type, Model model) {
|
||||
List<BackupDto> backups;
|
||||
if (StrUtil.equals(type, BackupTypeEnum.RESOURCES.getDesc())) {
|
||||
backups = HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc());
|
||||
} else if (StrUtil.equals(type, BackupTypeEnum.DATABASES.getDesc())) {
|
||||
backups = HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc());
|
||||
} else if (StrUtil.equals(type, BackupTypeEnum.POSTS.getDesc())) {
|
||||
backups = HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc());
|
||||
} else {
|
||||
backups = Collections.emptyList();
|
||||
}
|
||||
model.addAttribute("backups", backups);
|
||||
model.addAttribute("type", type);
|
||||
return "admin/admin_backup";
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行备份
|
||||
*
|
||||
* @param type 备份类型
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "doBackup")
|
||||
@ResponseBody
|
||||
public JsonResult doBackup(@RequestParam("type") String type) {
|
||||
if (StrUtil.equals(BackupTypeEnum.RESOURCES.getDesc(), type)) {
|
||||
return this.backupResources();
|
||||
}
|
||||
|
||||
if (StrUtil.equals(BackupTypeEnum.DATABASES.getDesc(), type)) {
|
||||
return this.backupDatabase();
|
||||
}
|
||||
|
||||
if (StrUtil.equals(BackupTypeEnum.POSTS.getDesc(), type)) {
|
||||
return this.backupPosts();
|
||||
}
|
||||
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据库
|
||||
*
|
||||
* @return 重定向到/admin/backup
|
||||
*/
|
||||
private JsonResult backupDatabase() {
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
|
||||
}
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
|
||||
final String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//压缩文件
|
||||
ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
|
||||
log.info("Current time: {}, database backup was performed.", DateUtil.now());
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.backup.backup-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to backup database", e);
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份资源文件
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
private JsonResult backupResources() {
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/resources/");
|
||||
}
|
||||
final File path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final String srcPath = path.getAbsolutePath();
|
||||
final String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//执行打包
|
||||
ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
|
||||
log.info("Current time: {}, the resource file backup was performed.", DateUtil.now());
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.backup.backup-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to backup resource file", e);
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份文章,导出markdown文件
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
private JsonResult backupPosts() {
|
||||
final List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
posts.addAll(postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc()));
|
||||
try {
|
||||
final StrBuilder rootDir = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
rootDir.append("/halo/backup/posts/");
|
||||
if (HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(rootDir.toString());
|
||||
}
|
||||
//打包好的文件名
|
||||
final StrBuilder distName = new StrBuilder("posts_backup_");
|
||||
distName.append(DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"));
|
||||
final StrBuilder srcPath = rootDir.append(distName);
|
||||
final StrBuilder content = new StrBuilder("---\n");
|
||||
for (Post post : posts) {
|
||||
content.append("title: ").append(post.getPostTitle()).append("\n");
|
||||
content.append("date: ").append(post.getPostDate()).append("\n");
|
||||
content.append("updated: ").append(post.getPostUpdate()).append("\n");
|
||||
content.append("thumbnail: ").append(post.getPostThumbnail()).append("\n");
|
||||
if (post.getTags().size() > 0) {
|
||||
content.append("tags:").append("\n");
|
||||
final List<Tag> tags = post.getTags();
|
||||
for (Tag tag : tags) {
|
||||
content.append(" - ").append(tag.getTagName()).append("\n");
|
||||
}
|
||||
}
|
||||
if (post.getCategories().size() > 0) {
|
||||
content.append("categories:").append("\n");
|
||||
final List<Category> categories = post.getCategories();
|
||||
for (Category category : categories) {
|
||||
content.append(" - ").append(category.getCateName()).append("\n");
|
||||
}
|
||||
}
|
||||
content.append("---\n\n");
|
||||
content.append(post.getPostContentMd());
|
||||
HaloUtils.postToFile(content.toString(), srcPath.toString(), post.getPostTitle() + ".md");
|
||||
content.clear();
|
||||
content.append("---\n");
|
||||
}
|
||||
//打包导出好的文章
|
||||
ZipUtil.zip(srcPath.toString(), srcPath.toString() + ".zip");
|
||||
FileUtil.del(srcPath.toString());
|
||||
log.info("Current time: {}, performed an article backup.", DateUtil.now());
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.backup.backup-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to backup article", e);
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除备份
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @param type 备份类型
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "delBackup")
|
||||
@ResponseBody
|
||||
public JsonResult delBackup(@RequestParam("fileName") String fileName,
|
||||
@RequestParam("type") String type) {
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
try {
|
||||
FileUtil.del(srcPath);
|
||||
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.delete-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to delete backup file: " + fileName + ", type: " + type, e);
|
||||
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将备份发送到邮箱
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @param type 备份类型
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "sendToEmail")
|
||||
@ResponseBody
|
||||
public JsonResult sendToEmail(@RequestParam("fileName") String fileName,
|
||||
@RequestParam("type") String type,
|
||||
HttpSession session) {
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
if (null == user.getUserEmail() || StrUtil.isEmpty(user.getUserEmail())) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.backup.no-email"));
|
||||
}
|
||||
if (StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.FALSE.getDesc())) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.no-post"));
|
||||
}
|
||||
new EmailToAdmin(srcPath, user).start();
|
||||
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.backup.email-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步发送附件到邮箱
|
||||
*/
|
||||
class EmailToAdmin extends Thread {
|
||||
private String srcPath;
|
||||
private User user;
|
||||
|
||||
private EmailToAdmin(String srcPath, User user) {
|
||||
this.srcPath = srcPath;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final File file = new File(srcPath);
|
||||
final Map<String, Object> content = new HashMap<>(3);
|
||||
try {
|
||||
content.put("fileName", file.getName());
|
||||
content.put("createAt", HaloUtils.getCreateTime(srcPath));
|
||||
content.put("size", HaloUtils.parseSize(file.length()));
|
||||
mailService.sendAttachMail(user.getUserEmail(), localeMessageUtil.getMessage("code.admin.backup.have-new-backup"), content, "common/mail_template/mail_attach.ftl", srcPath);
|
||||
} catch (Exception e) {
|
||||
log.error("Mail server was not configured", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台分类管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/category")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 查询所有分类并渲染category页面
|
||||
*
|
||||
* @return 模板路径admin/admin_category
|
||||
*/
|
||||
@GetMapping
|
||||
public String categories() {
|
||||
return "admin/admin_category";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改分类目录
|
||||
*
|
||||
* @param category category对象
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveCategory(@Valid Category category, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return JsonResult.fail(error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
final Category tempCategory = categoryService.findByCateUrl(category.getCateUrl());
|
||||
if (null != category.getCateId()) {
|
||||
if (null != tempCategory && !category.getCateId().equals(tempCategory.getCateId())) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
} else {
|
||||
if (null != tempCategory) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
}
|
||||
category = categoryService.create(category);
|
||||
if (null == category) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理删除分类目录的请求
|
||||
*
|
||||
* @param cateId cateId
|
||||
* @return 重定向到/admin/category
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removeCategory(@RequestParam("cateId") Long cateId) {
|
||||
try {
|
||||
categoryService.removeById(cateId);
|
||||
} catch (Exception e) {
|
||||
log.error("Delete category failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/category";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改页面
|
||||
*
|
||||
* @param cateId cateId
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_category
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String toEditCategory(Model model, @RequestParam("cateId") Long cateId) {
|
||||
final Optional<Category> category = categoryService.fetchById(cateId);
|
||||
model.addAttribute("updateCategory", category.orElse(new Category()));
|
||||
return "admin/admin_category";
|
||||
}
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
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.CommentAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.OwoUtil;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台评论管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/comments")
|
||||
public class CommentController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 渲染评论管理页面
|
||||
*
|
||||
* @param model model
|
||||
* @param status status 评论状态
|
||||
* @return 模板路径admin/admin_comment
|
||||
*/
|
||||
@GetMapping
|
||||
public String comments(Model model,
|
||||
@PageableDefault(sort = "commentDate", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status) {
|
||||
final Page<CommentAdminOutputDTO> comments = commentService.findAll(status, pageable)
|
||||
.map(comment -> new CommentAdminOutputDTO().convertFrom(comment));
|
||||
model.addAttribute("comments", comments);
|
||||
model.addAttribute("publicCount", commentService.getCountByStatus(CommentStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("checkCount", commentService.getCountByStatus(CommentStatusEnum.CHECKING.getCode()));
|
||||
model.addAttribute("trashCount", commentService.getCountByStatus(CommentStatusEnum.RECYCLE.getCode()));
|
||||
model.addAttribute("status", status);
|
||||
return "admin/admin_comment";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将评论移到回收站
|
||||
*
|
||||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/throw")
|
||||
public String moveToTrash(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") String status,
|
||||
@PageableDefault Pageable pageable) {
|
||||
try {
|
||||
commentService.updateCommentStatus(commentId, CommentStatusEnum.RECYCLE.getCode());
|
||||
} catch (Exception e) {
|
||||
log.error("Delete comment failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + pageable.getPageNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将评论改变为发布状态
|
||||
*
|
||||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
* @param session session
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/revert")
|
||||
public String moveToPublish(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") Integer status,
|
||||
HttpSession session) {
|
||||
final Comment comment = commentService.updateCommentStatus(commentId, CommentStatusEnum.PUBLISHED.getCode());
|
||||
final Post post = comment.getPost();
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
|
||||
//判断是否启用邮件服务
|
||||
new NoticeToAuthor(comment, post, user, status).start();
|
||||
return "redirect:/admin/comments?status=" + status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论
|
||||
*
|
||||
* @param commentId commentId 评论编号
|
||||
* @param status status 评论状态
|
||||
* @return string 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String moveToAway(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") Integer status,
|
||||
@PageableDefault Pageable pageable) {
|
||||
try {
|
||||
commentService.removeById(commentId);
|
||||
} catch (Exception e) {
|
||||
log.error("Delete comment failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status + "&page=" + pageable.getPageNumber();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员回复评论
|
||||
*
|
||||
* @param commentId 被回复的评论
|
||||
* @param commentContent 回复的内容
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/reply")
|
||||
@ResponseBody
|
||||
public JsonResult replyComment(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("postId") Long postId,
|
||||
@RequestParam("commentContent") String commentContent,
|
||||
@RequestParam("userAgent") String userAgent,
|
||||
HttpServletRequest request,
|
||||
HttpSession session) {
|
||||
try {
|
||||
final Post post = postService.fetchById(postId).orElse(new Post());
|
||||
|
||||
//博主信息
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
|
||||
//被回复的评论
|
||||
final Comment lastComment = commentService.fetchById(commentId).orElse(new Comment());
|
||||
|
||||
//修改被回复的评论的状态
|
||||
lastComment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
||||
commentService.create(lastComment);
|
||||
|
||||
//保存评论
|
||||
final Comment comment = new Comment();
|
||||
comment.setPost(post);
|
||||
comment.setCommentAuthor(user.getUserDisplayName());
|
||||
comment.setCommentAuthorEmail(user.getUserEmail());
|
||||
comment.setCommentAuthorUrl(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
||||
|
||||
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
buildContent.append(lastComment.getCommentId());
|
||||
buildContent.append("'>@");
|
||||
buildContent.append(lastComment.getCommentAuthor());
|
||||
buildContent.append("</a> ");
|
||||
buildContent.append(OwoUtil.markToImg(HtmlUtil.escape(commentContent).replace("<br/>", "<br/>")));
|
||||
|
||||
comment.setCommentContent(buildContent.toString());
|
||||
comment.setCommentAgent(userAgent);
|
||||
comment.setCommentParent(commentId);
|
||||
comment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
||||
comment.setIsAdmin(1);
|
||||
commentService.create(comment);
|
||||
|
||||
//邮件通知
|
||||
new EmailToAuthor(comment, lastComment, post, user, commentContent).start();
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode());
|
||||
} catch (Exception e) {
|
||||
log.error("Reply to comment failed: {}", e.getMessage());
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步发送邮件回复给评论者
|
||||
*/
|
||||
class EmailToAuthor extends Thread {
|
||||
|
||||
private Comment comment;
|
||||
private Comment lastComment;
|
||||
private Post post;
|
||||
private User user;
|
||||
private String commentContent;
|
||||
|
||||
private EmailToAuthor(Comment comment, Comment lastComment, Post post, User user, String commentContent) {
|
||||
this.comment = comment;
|
||||
this.lastComment = lastComment;
|
||||
this.post = post;
|
||||
this.user = user;
|
||||
this.commentContent = commentContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
||||
final Map<String, Object> map = new HashMap<>(8);
|
||||
map.put("blogTitle", OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
||||
map.put("commentAuthor", lastComment.getCommentAuthor());
|
||||
map.put("pageName", lastComment.getPost().getPostTitle());
|
||||
|
||||
final StrBuilder pageUrl = new StrBuilder(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
} else {
|
||||
pageUrl.append("/p/");
|
||||
}
|
||||
pageUrl.append(post.getPostUrl());
|
||||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("commentContent", lastComment.getCommentContent());
|
||||
map.put("replyAuthor", user.getUserDisplayName());
|
||||
map.put("replyContent", commentContent);
|
||||
map.put("blogUrl", OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
mailService.sendTemplateMail(
|
||||
lastComment.getCommentAuthorEmail(), "您在" + OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步通知评论者审核通过
|
||||
*/
|
||||
class NoticeToAuthor extends Thread {
|
||||
|
||||
private Comment comment;
|
||||
private Post post;
|
||||
private User user;
|
||||
private Integer status;
|
||||
|
||||
private NoticeToAuthor(Comment comment, Post post, User user, Integer status) {
|
||||
this.comment = comment;
|
||||
this.post = post;
|
||||
this.user = user;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
try {
|
||||
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
|
||||
final Map<String, Object> map = new HashMap<>(6);
|
||||
|
||||
final StrBuilder pageUrl = new StrBuilder(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
} else {
|
||||
pageUrl.append("/p/");
|
||||
}
|
||||
pageUrl.append(post.getPostUrl());
|
||||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("pageName", post.getPostTitle());
|
||||
map.put("commentContent", comment.getCommentContent());
|
||||
map.put("blogUrl", OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
map.put("blogTitle", OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
||||
map.put("author", user.getUserDisplayName());
|
||||
mailService.sendTemplateMail(
|
||||
comment.getCommentAuthorEmail(),
|
||||
"您在" + OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论已审核通过!", map, "common/mail_template/mail_passed.ftl");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Mail server not configured: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.PostViewOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.MenuService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台菜单管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/1/30
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/menus")
|
||||
public class MenuController {
|
||||
|
||||
@Autowired
|
||||
private MenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 渲染菜单设置页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径/admin/admin_menu
|
||||
*/
|
||||
@GetMapping
|
||||
public String menus(Model model) {
|
||||
List<PostViewOutputDTO> posts = postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc())
|
||||
.stream()
|
||||
.map(post -> (PostViewOutputDTO) new PostViewOutputDTO().convertFrom(post))
|
||||
.collect(Collectors.toList());
|
||||
model.addAttribute("posts", posts);
|
||||
return "admin/admin_menu";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改菜单
|
||||
*
|
||||
* @param menu menu
|
||||
* @return 重定向到/admin/menus
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveMenu(@Valid Menu menu, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return JsonResult.fail(error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
menu = menuService.create(menu);
|
||||
if (null != menu) {
|
||||
return JsonResult.success("菜单保存成功!");
|
||||
} else {
|
||||
return JsonResult.fail("菜单保存失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改页面
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
* @param model model
|
||||
* @return 模板路径/admin/admin_menu
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String updateMenu(@RequestParam("menuId") Long menuId, Model model) {
|
||||
final Menu menu = menuService.fetchById(menuId).orElse(new Menu());
|
||||
model.addAttribute("updateMenu", menu);
|
||||
return "admin/admin_menu";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
* @return 重定向到/admin/menus
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removeMenu(@RequestParam("menuId") Long menuId) {
|
||||
try {
|
||||
menuService.removeById(menuId);
|
||||
} catch (Exception e) {
|
||||
log.error("Deleting menu failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/menus";
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Map;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台设置选项控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/13
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/admin/option")
|
||||
public class OptionController {
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private Configuration configuration;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 请求跳转到option页面并完成渲染
|
||||
*
|
||||
* @return 模板路径admin/admin_option
|
||||
*/
|
||||
@GetMapping
|
||||
public String options() {
|
||||
return "admin/admin_option";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设置选项
|
||||
*
|
||||
* @param options options
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveOptions(@RequestParam Map<String, String> options, HttpSession session) {
|
||||
try {
|
||||
optionsService.saveOptions(options);
|
||||
//刷新options
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
OPTIONS.clear();
|
||||
OPTIONS = optionsService.findAllOptions();
|
||||
session.removeAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
|
||||
log.info("List of saved options: " + options);
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Save settings option failed: " + e.getMessage(), e);
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,311 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.PageAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台页面管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/page")
|
||||
public class PageController {
|
||||
|
||||
@Autowired
|
||||
LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
@Autowired
|
||||
private LinkService linkService;
|
||||
|
||||
@Autowired
|
||||
private GalleryService galleryService;
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
/**
|
||||
* 页面管理页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_page
|
||||
*/
|
||||
@GetMapping
|
||||
public String pages(Model model) {
|
||||
final List<PageAdminOutputDTO> posts = postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc())
|
||||
.stream()
|
||||
.map(post -> (PageAdminOutputDTO) new PageAdminOutputDTO().convertFrom(post))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
model.addAttribute("pages", posts);
|
||||
return "admin/admin_page";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取友情链接列表并渲染页面
|
||||
*
|
||||
* @return 模板路径admin/admin_page_link
|
||||
*/
|
||||
@GetMapping(value = "/links")
|
||||
public String links() {
|
||||
return "admin/admin_page_link";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改页面
|
||||
*
|
||||
* @param model model
|
||||
* @param linkId linkId 友情链接编号
|
||||
* @return String 模板路径admin/admin_page_link
|
||||
*/
|
||||
@GetMapping(value = "/links/edit")
|
||||
public String toEditLink(Model model, @RequestParam("linkId") Long linkId) {
|
||||
final Optional<Link> link = linkService.fetchById(linkId);
|
||||
model.addAttribute("updateLink", link.orElse(new Link()));
|
||||
return "admin/admin_page_link";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理添加/修改友链的请求并渲染页面
|
||||
*
|
||||
* @param link Link实体
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/links/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveLink(@Valid Link link, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return JsonResult.fail(error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
link = linkService.create(link);
|
||||
if (null == link) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理删除友情链接的请求并重定向
|
||||
*
|
||||
* @param linkId 友情链接编号
|
||||
* @return 重定向到/admin/page/links
|
||||
*/
|
||||
@GetMapping(value = "/links/remove")
|
||||
public String removeLink(@RequestParam("linkId") Long linkId) {
|
||||
try {
|
||||
linkService.removeById(linkId);
|
||||
} catch (Exception e) {
|
||||
log.error("Deleting a friendship link failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/page/links";
|
||||
}
|
||||
|
||||
/**
|
||||
* 图库管理
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_page_gallery
|
||||
*/
|
||||
@GetMapping(value = "/galleries")
|
||||
public String gallery(Model model,
|
||||
@PageableDefault(size = 18, sort = "galleryId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
final Page<Gallery> galleries = galleryService.listAll(pageable);
|
||||
model.addAttribute("galleries", galleries);
|
||||
return "admin/admin_page_gallery";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图片
|
||||
*
|
||||
* @param gallery gallery
|
||||
* @return 重定向到/admin/page/gallery
|
||||
*/
|
||||
@PostMapping(value = "/gallery/save")
|
||||
public String saveGallery(@ModelAttribute Gallery gallery) {
|
||||
try {
|
||||
if (StrUtil.isEmpty(gallery.getGalleryThumbnailUrl())) {
|
||||
gallery.setGalleryThumbnailUrl(gallery.getGalleryUrl());
|
||||
}
|
||||
galleryService.create(gallery);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "redirect:/admin/page/galleries";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理获取图片详情的请求
|
||||
*
|
||||
* @param model model
|
||||
* @param galleryId 图片编号
|
||||
* @return 模板路径admin/widget/_gallery-detail
|
||||
*/
|
||||
@GetMapping(value = "/gallery")
|
||||
public String gallery(Model model, @RequestParam("galleryId") Long galleryId) {
|
||||
final Optional<Gallery> gallery = galleryService.fetchById(galleryId);
|
||||
model.addAttribute("gallery", gallery.orElse(new Gallery()));
|
||||
return "admin/widget/_gallery-detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图库中的图片
|
||||
*
|
||||
* @param galleryId 图片编号
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/gallery/remove")
|
||||
@ResponseBody
|
||||
public JsonResult removeGallery(@RequestParam("galleryId") Long galleryId) {
|
||||
try {
|
||||
galleryService.removeById(galleryId);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to delete image: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.delete-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到新建页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/new")
|
||||
public String newPage(Model model) {
|
||||
final List<String> customTpls = HaloUtils.getCustomTpl(OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
model.addAttribute("customTpls", customTpls);
|
||||
return "admin/admin_page_md_editor";
|
||||
}
|
||||
|
||||
/**
|
||||
* 发表页面
|
||||
*
|
||||
* @param post post
|
||||
* @param session session
|
||||
*/
|
||||
@PostMapping(value = "/new/push")
|
||||
@ResponseBody
|
||||
public JsonResult pushPage(@ModelAttribute Post post, HttpSession session) {
|
||||
String msg = localeMessageUtil.getMessage("code.admin.common.save-success");
|
||||
try {
|
||||
//发表用户
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
post.setUser(user);
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post.getPostId()) {
|
||||
final Post oldPost = postService.fetchById(post.getPostId()).get();
|
||||
if (null == post.getPostDate()) {
|
||||
post.setPostDate(DateUtil.date());
|
||||
}
|
||||
post.setPostViews(oldPost.getPostViews());
|
||||
msg = localeMessageUtil.getMessage("code.admin.common.update-success");
|
||||
}
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
|
||||
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
|
||||
post.setPostThumbnail(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/static/halo-content/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 11) + ".jpg");
|
||||
}
|
||||
postService.create(post);
|
||||
logsService.save(LogsRecord.PUSH_PAGE, post.getPostTitle(), request);
|
||||
return JsonResult.success(msg);
|
||||
} catch (Exception e) {
|
||||
log.error("Save page failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改页面
|
||||
*
|
||||
* @param pageId 页面编号
|
||||
* @param model model
|
||||
* @return admin/admin_page_md_editor
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPage(@RequestParam("pageId") Long pageId, Model model) {
|
||||
final Optional<Post> post = postService.fetchById(pageId);
|
||||
final List<String> customTpls = HaloUtils.getCustomTpl(OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
model.addAttribute("post", post.orElse(new Post()));
|
||||
model.addAttribute("customTpls", customTpls);
|
||||
return "admin/admin_page_md_editor";
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查该路径是否已经存在
|
||||
*
|
||||
* @param postUrl postUrl
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public JsonResult checkUrlExists(@RequestParam("postUrl") String postUrl) {
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "");
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(ServletRequestDataBinder binder) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
|
||||
}
|
||||
}
|
|
@ -1,357 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.PostAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.PostViewOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.PostStatusEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.BeanUtils;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台文章管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/posts")
|
||||
public class PostController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 去除html,htm后缀,以及将空格替换成-
|
||||
*
|
||||
* @param url url
|
||||
* @return String
|
||||
*/
|
||||
private static String urlFilter(String url) {
|
||||
if (null != url) {
|
||||
final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm");
|
||||
if (urlEndsWithHtmlPostFix) {
|
||||
return url.substring(0, url.lastIndexOf("."));
|
||||
}
|
||||
}
|
||||
return StrUtil.replace(url, " ", "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理后台获取文章列表的请求
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_post
|
||||
*/
|
||||
@GetMapping
|
||||
public String posts(Model model,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@SortDefault.SortDefaults({
|
||||
@SortDefault(sort = "postPriority", direction = DESC),
|
||||
@SortDefault(sort = "postDate", direction = DESC)
|
||||
}) Sort sort) {
|
||||
final Pageable pageable = PageRequest.of(page, 10, sort);
|
||||
final Page<PostAdminOutputDTO> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable)
|
||||
.map(post -> new PostAdminOutputDTO().convertFrom(post));
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("publishCount", postService.getCountByStatus(PostStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("draftCount", postService.getCountByStatus(PostStatusEnum.DRAFT.getCode()));
|
||||
model.addAttribute("trashCount", postService.getCountByStatus(PostStatusEnum.RECYCLE.getCode()));
|
||||
model.addAttribute("status", status);
|
||||
return "admin/admin_post";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理跳转到新建文章页面
|
||||
*
|
||||
* @return 模板路径admin/admin_editor
|
||||
*/
|
||||
@GetMapping(value = "/write")
|
||||
public String writePost() {
|
||||
return "admin/admin_post_new";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到编辑文章页面
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_editor
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPost(@RequestParam("postId") Long postId, Model model) {
|
||||
final Optional<Post> post = postService.fetchById(postId);
|
||||
model.addAttribute("post", post.orElse(new Post()));
|
||||
return "admin/admin_post_edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文章
|
||||
*
|
||||
* @param post post
|
||||
* @param cateList 分类列表
|
||||
* @param tagList 标签
|
||||
* @param session session
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult save(@ModelAttribute Post post,
|
||||
@RequestParam("cateList") List<String> cateList,
|
||||
@RequestParam("tagList") String tagList,
|
||||
// @RequestParam("metas") List<PostMeta> metas,
|
||||
HttpSession session) {
|
||||
// post.setPostMetas(metas);
|
||||
final User user = (User) session.getAttribute(USER_SESSION_KEY);
|
||||
try {
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
post.setUser(user);
|
||||
post = postService.buildCategoriesAndTags(post, cateList, tagList);
|
||||
post.setPostUrl(urlFilter(post.getPostUrl()));
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostPassword(SecureUtil.md5(post.getPostPassword()));
|
||||
}
|
||||
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
|
||||
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
|
||||
post.setPostThumbnail(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/static/halo-content/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 11) + ".jpg");
|
||||
}
|
||||
postService.create(post);
|
||||
logsService.save(LogsRecord.PUSH_POST, post.getPostTitle(), request);
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
} catch (Exception e) {
|
||||
log.error("Save article failed: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param post post
|
||||
* @param cateList 分类目录
|
||||
* @param tagList 标签
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/update")
|
||||
@ResponseBody
|
||||
public JsonResult update(@ModelAttribute Post post,
|
||||
@RequestParam("cateList") List<String> cateList,
|
||||
@RequestParam("tagList") String tagList) {
|
||||
//old data
|
||||
final Post oldPost = postService.fetchById(post.getPostId()).orElse(new Post());
|
||||
BeanUtils.updateProperties(oldPost, post);
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
if (null == post.getPostDate()) {
|
||||
post.setPostDate(new Date());
|
||||
}
|
||||
post = postService.buildCategoriesAndTags(post, cateList, tagList);
|
||||
if (StrUtil.isNotEmpty(post.getPostPassword())) {
|
||||
post.setPostPassword(SecureUtil.md5(post.getPostPassword()));
|
||||
}
|
||||
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
|
||||
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
|
||||
post.setPostThumbnail(OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/static/halo-content/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 11) + ".jpg");
|
||||
}
|
||||
post = postService.create(post);
|
||||
if (null != post) {
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.update-success"));
|
||||
} else {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.update-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理移至回收站的请求
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @return 重定向到/admin/posts
|
||||
*/
|
||||
@GetMapping(value = "/throw")
|
||||
public String moveToTrash(@RequestParam("postId") Long postId, @RequestParam("status") Integer status) {
|
||||
try {
|
||||
postService.updatePostStatus(postId, PostStatusEnum.RECYCLE.getCode());
|
||||
log.info("Article number {} has been moved to the recycle bin", postId);
|
||||
} catch (Exception e) {
|
||||
log.error("Deleting article to recycle bin failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/posts?status=" + status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文章为发布的状态
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @return 重定向到/admin/posts
|
||||
*/
|
||||
@GetMapping(value = "/revert")
|
||||
public String moveToPublish(@RequestParam("postId") Long postId,
|
||||
@RequestParam("status") Integer status) {
|
||||
try {
|
||||
postService.updatePostStatus(postId, PostStatusEnum.PUBLISHED.getCode());
|
||||
log.info("Article number {} has been changed to release status", postId);
|
||||
} catch (Exception e) {
|
||||
log.error("Publishing article failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/posts?status=" + status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理删除文章的请求
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @return 重定向到/admin/posts
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removePost(@RequestParam("postId") Long postId, @RequestParam("postType") String postType) {
|
||||
try {
|
||||
final Optional<Post> post = postService.fetchById(postId);
|
||||
postService.removeById(postId);
|
||||
logsService.save(LogsRecord.REMOVE_POST, post.get().getPostTitle(), request);
|
||||
} catch (Exception e) {
|
||||
log.error("Delete article failed: {}", e.getMessage());
|
||||
}
|
||||
if (StrUtil.equals(PostTypeEnum.POST_TYPE_POST.getDesc(), postType)) {
|
||||
return "redirect:/admin/posts?status=2";
|
||||
}
|
||||
return "redirect:/admin/page";
|
||||
}
|
||||
|
||||
/**
|
||||
* 置顶/取消置顶文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @param priority priority
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/topPost")
|
||||
public String topPost(@RequestParam("postId") Long postId,
|
||||
@RequestParam("priority") Integer priority) {
|
||||
Post post = postService.getById(postId);
|
||||
post.setPostPriority(priority);
|
||||
postService.update(post);
|
||||
return "redirect:/admin/posts";
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新所有摘要
|
||||
*
|
||||
* @param postSummary 文章摘要字数
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/updateSummary")
|
||||
@ResponseBody
|
||||
public JsonResult updateSummary(@RequestParam("postSummary") Integer postSummary) {
|
||||
try {
|
||||
postService.updateAllSummary(postSummary);
|
||||
} catch (Exception e) {
|
||||
log.error("Update summary failed: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.update-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.update-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证文章路径是否已经存在
|
||||
*
|
||||
* @param postUrl 文章路径
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public JsonResult checkUrlExists(@RequestParam("postUrl") String postUrl) {
|
||||
postUrl = urlFilter(postUrl);
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
if (null != post) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有文章推送到百度
|
||||
*
|
||||
* @param baiduToken baiduToken
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/pushAllToBaidu")
|
||||
@ResponseBody
|
||||
public JsonResult pushAllToBaidu(@RequestParam("baiduToken") String baiduToken) {
|
||||
if (StrUtil.isBlank(baiduToken)) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.post.no-baidu-token"));
|
||||
}
|
||||
final String blogUrl = OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
|
||||
final List<PostViewOutputDTO> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc())
|
||||
.stream()
|
||||
.map(post -> (PostViewOutputDTO) new PostViewOutputDTO().convertFrom(post))
|
||||
.collect(Collectors.toList());
|
||||
final StringBuilder urls = new StringBuilder();
|
||||
for (PostViewOutputDTO post : posts) {
|
||||
urls.append(blogUrl);
|
||||
urls.append("/archives/");
|
||||
urls.append(post.getPostUrl());
|
||||
urls.append("\n");
|
||||
}
|
||||
final String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString());
|
||||
if (StrUtil.isEmpty(result)) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.post.push-to-baidu-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.post.push-to-baidu-success"));
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(ServletRequestDataBinder binder) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台标签管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/tag")
|
||||
public class TagController {
|
||||
|
||||
@Autowired
|
||||
private TagService tagService;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 渲染标签管理页面
|
||||
*
|
||||
* @return 模板路径admin/admin_tag
|
||||
*/
|
||||
@GetMapping
|
||||
public String tags() {
|
||||
return "admin/admin_tag";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改标签
|
||||
*
|
||||
* @param tag tag
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveTag(@Valid Tag tag, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return JsonResult.fail(error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
final Tag tempTag = tagService.findByTagUrl(tag.getTagUrl());
|
||||
if (null != tag.getTagId()) {
|
||||
if (null != tempTag && !tag.getTagId().equals(tempTag.getTagId())) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
} else {
|
||||
if (null != tempTag) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
}
|
||||
tag = tagService.create(tag);
|
||||
if (null == tag) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理删除标签的请求
|
||||
*
|
||||
* @param tagId 标签编号
|
||||
* @return 重定向到/admin/tag
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removeTag(@RequestParam("tagId") Long tagId) {
|
||||
try {
|
||||
tagService.removeById(tagId);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to delete tag: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/tag";
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到修改标签页面
|
||||
*
|
||||
* @param model model
|
||||
* @param tagId 标签编号
|
||||
* @return 模板路径admin/admin_tag
|
||||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String toEditTag(Model model, @RequestParam("tagId") Long tagId) {
|
||||
final Tag tag = tagService.fetchById(tagId).orElse(new Tag());
|
||||
model.addAttribute("updateTag", tag);
|
||||
return "admin/admin_tag";
|
||||
}
|
||||
}
|
|
@ -1,308 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.TrueFalseEnum;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileReader;
|
||||
import cn.hutool.core.io.file.FileWriter;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
import static cc.ryanc.halo.model.support.HaloConst.THEMES;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台主题管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/themes")
|
||||
public class ThemeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private Configuration configuration;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 渲染主题设置页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_theme
|
||||
*/
|
||||
@GetMapping
|
||||
public String themes(Model model) {
|
||||
model.addAttribute("activeTheme", BaseController.THEME);
|
||||
if (null != THEMES) {
|
||||
model.addAttribute("themes", THEMES);
|
||||
}
|
||||
return "admin/admin_theme";
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活主题
|
||||
*
|
||||
* @param siteTheme 主题名称
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/set")
|
||||
@ResponseBody
|
||||
@CacheEvict(value = "posts", allEntries = true, beforeInvocation = true)
|
||||
public JsonResult activeTheme(@RequestParam("siteTheme") String siteTheme,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
//保存主题设置项
|
||||
optionsService.saveOption(BlogPropertiesEnum.THEME.getProp(), siteTheme);
|
||||
//设置主题
|
||||
BaseController.THEME = siteTheme;
|
||||
OPTIONS.clear();
|
||||
OPTIONS = optionsService.findAllOptions();
|
||||
configuration.setSharedVariable("themeName", siteTheme);
|
||||
configuration.setSharedVariable("options", OPTIONS);
|
||||
log.info("Changed theme to {}", siteTheme);
|
||||
logsService.save(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, request);
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.theme.change-success", new Object[]{siteTheme}));
|
||||
} catch (Exception e) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.change-failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传主题
|
||||
*
|
||||
* @param file 文件
|
||||
* @return JsonResult
|
||||
*/
|
||||
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public JsonResult uploadTheme(@RequestParam("file") MultipartFile file,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
if (!file.isEmpty()) {
|
||||
//获取项目根路径
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), new StrBuilder("templates/themes/").append(file.getOriginalFilename()).toString());
|
||||
file.transferTo(themePath);
|
||||
log.info("Upload topic success, path is " + themePath.getAbsolutePath());
|
||||
logsService.save(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), request);
|
||||
ZipUtil.unzip(themePath, new File(basePath.getAbsolutePath(), "templates/themes/"));
|
||||
FileUtil.del(themePath);
|
||||
THEMES.clear();
|
||||
THEMES = HaloUtils.getThemes();
|
||||
} else {
|
||||
log.error("Upload theme failed, no file selected");
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.upload-no-file"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Upload theme failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.upload-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.theme.upload-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除主题
|
||||
*
|
||||
* @param themeName 主题文件夹名
|
||||
* @return string 重定向到/admin/themes
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removeTheme(@RequestParam("themeName") String themeName) {
|
||||
try {
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes/" + themeName);
|
||||
FileUtil.del(themePath);
|
||||
THEMES.clear();
|
||||
THEMES = HaloUtils.getThemes();
|
||||
} catch (Exception e) {
|
||||
log.error("Delete theme failed: {}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/themes";
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装主题弹出层
|
||||
*
|
||||
* @return 目录路径admin/widget/_theme-install
|
||||
*/
|
||||
@GetMapping(value = "/install")
|
||||
public String install() {
|
||||
return "admin/widget/_theme-install";
|
||||
}
|
||||
|
||||
/**
|
||||
* 在线拉取主题
|
||||
*
|
||||
* @param remoteAddr 远程地址
|
||||
* @param themeName 主题名称
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/clone")
|
||||
@ResponseBody
|
||||
public JsonResult cloneFromRemote(@RequestParam(value = "remoteAddr") String remoteAddr,
|
||||
@RequestParam(value = "themeName") String themeName) {
|
||||
if (StrUtil.isBlank(remoteAddr) || StrUtil.isBlank(themeName)) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.info-no-complete"));
|
||||
}
|
||||
try {
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
RuntimeUtil.execForStr("git clone " + remoteAddr + " " + themePath.getAbsolutePath() + "/" + themeName);
|
||||
THEMES.clear();
|
||||
THEMES = HaloUtils.getThemes();
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error("Cloning theme failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.clone-theme-failed") + e.getMessage());
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.install-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新主题
|
||||
*
|
||||
* @param themeName 主题名
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/pull")
|
||||
@ResponseBody
|
||||
public JsonResult pullFromRemote(@RequestParam(value = "themeName") String themeName) {
|
||||
try {
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
RuntimeUtil.execForStr("cd " + themePath.getAbsolutePath() + "/" + themeName, "git pull");
|
||||
THEMES.clear();
|
||||
THEMES = HaloUtils.getThemes();
|
||||
} catch (Exception e) {
|
||||
log.error("Update theme failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.update-theme-failed") + e.getMessage());
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.update-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到主题设置
|
||||
*
|
||||
* @param theme theme名称
|
||||
*/
|
||||
@GetMapping(value = "/options")
|
||||
public String setting(Model model,
|
||||
@RequestParam("theme") String theme,
|
||||
@RequestParam("hasUpdate") String hasUpdate) {
|
||||
model.addAttribute("themeDir", theme);
|
||||
if (StrUtil.equals(hasUpdate, TrueFalseEnum.TRUE.getDesc())) {
|
||||
model.addAttribute("hasUpdate", true);
|
||||
} else {
|
||||
model.addAttribute("hasUpdate", false);
|
||||
}
|
||||
return "themes/" + theme + "/module/options";
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑主题
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_theme-editor
|
||||
*/
|
||||
@GetMapping(value = "/editor")
|
||||
public String editor(Model model) {
|
||||
final List<String> tpls = HaloUtils.getTplName(BaseController.THEME);
|
||||
model.addAttribute("tpls", tpls);
|
||||
return "admin/admin_theme-editor";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板文件内容
|
||||
*
|
||||
* @param tplName 模板文件名
|
||||
* @return 模板内容
|
||||
*/
|
||||
@GetMapping(value = "/getTpl", produces = "text/text;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public String getTplContent(@RequestParam("tplName") String tplName) {
|
||||
String tplContent = "";
|
||||
try {
|
||||
//获取项目根路径
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
//获取主题路径
|
||||
final StrBuilder themePath = new StrBuilder("templates/themes/");
|
||||
themePath.append(BaseController.THEME);
|
||||
themePath.append("/");
|
||||
themePath.append(tplName);
|
||||
final File themesPath = new File(basePath.getAbsolutePath(), themePath.toString());
|
||||
final FileReader fileReader = new FileReader(themesPath);
|
||||
tplContent = fileReader.readString();
|
||||
} catch (Exception e) {
|
||||
log.error("Get template file error: {}", e.getMessage());
|
||||
}
|
||||
return tplContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改模板
|
||||
*
|
||||
* @param tplName 模板名称
|
||||
* @param tplContent 模板内容
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/editor/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveTpl(@RequestParam("tplName") String tplName,
|
||||
@RequestParam("tplContent") String tplContent) {
|
||||
if (StrUtil.isBlank(tplContent)) {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.theme.edit.no-content"));
|
||||
}
|
||||
try {
|
||||
//获取项目根路径
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
//获取主题路径
|
||||
final StrBuilder themePath = new StrBuilder("templates/themes/");
|
||||
themePath.append(BaseController.THEME);
|
||||
themePath.append("/");
|
||||
themePath.append(tplName);
|
||||
final File tplPath = new File(basePath.getAbsolutePath(), themePath.toString());
|
||||
final FileWriter fileWriter = new FileWriter(tplPath);
|
||||
fileWriter.write(tplContent);
|
||||
} catch (Exception e) {
|
||||
log.error("Template save failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.save-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台用户管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/24
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping(value = "/admin/profile")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private Configuration configuration;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
/**
|
||||
* 获取用户信息并跳转
|
||||
*
|
||||
* @return 模板路径admin/admin_profile
|
||||
*/
|
||||
@GetMapping
|
||||
public String profile() {
|
||||
return "admin/admin_profile";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理修改用户资料的请求
|
||||
*
|
||||
* @param user user
|
||||
* @param session session
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "save")
|
||||
@ResponseBody
|
||||
public JsonResult saveProfile(@Valid @ModelAttribute User user, BindingResult result, HttpSession session) {
|
||||
try {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return JsonResult.fail(error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
userService.create(user);
|
||||
configuration.setSharedVariable("user", userService.findUser());
|
||||
session.removeAttribute(USER_SESSION_KEY);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to modify user profile: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.common.edit-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.common.edit-success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理修改密码的请求
|
||||
*
|
||||
* @param beforePass 旧密码
|
||||
* @param newPass 新密码
|
||||
* @param userId 用户编号
|
||||
* @param session session
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "changePass")
|
||||
@ResponseBody
|
||||
public JsonResult changePass(@ModelAttribute("beforePass") String beforePass,
|
||||
@ModelAttribute("newPass") String newPass,
|
||||
@ModelAttribute("userId") Long userId,
|
||||
HttpSession session) {
|
||||
try {
|
||||
final User user = userService.findByUserIdAndUserPass(userId, SecureUtil.md5(beforePass));
|
||||
if (null != user) {
|
||||
user.setUserPass(SecureUtil.md5(newPass));
|
||||
userService.update(user);
|
||||
session.removeAttribute(USER_SESSION_KEY);
|
||||
} else {
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.user.old-password-error"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Password change failed: {}", e.getMessage());
|
||||
return JsonResult.fail(localeMessageUtil.getMessage("code.admin.user.update-password-failed"));
|
||||
}
|
||||
return JsonResult.success(localeMessageUtil.getMessage("code.admin.user.update-password-success"));
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.support.Archive;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章归档API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/archives")
|
||||
public class ApiArchivesController {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 根据年份归档
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "year": "",
|
||||
* "month": "",
|
||||
* "count": "",
|
||||
* "posts": [
|
||||
* {
|
||||
* "postId": "",
|
||||
* "user": {},
|
||||
* "postTitle": "",
|
||||
* "postType": "",
|
||||
* "postContentMd": "",
|
||||
* "postContent": "",
|
||||
* "postUrl": "",
|
||||
* "postSummary": "",
|
||||
* "categories": [],
|
||||
* "tags": [],
|
||||
* "comments": [],
|
||||
* "postThumbnail": "",
|
||||
* "postDate": "",
|
||||
* "postUpdate": "",
|
||||
* "postStatus": 0,
|
||||
* "postViews": 0,
|
||||
* "allowComment": 1,
|
||||
* "customTpl": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/year")
|
||||
public List<Archive> archivesYear() {
|
||||
return postService.findPostGroupByYear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据月份归档
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "year": "",
|
||||
* "month": "",
|
||||
* "count": "",
|
||||
* "posts": [
|
||||
* {
|
||||
* "postId": "",
|
||||
* "user": {},
|
||||
* "postTitle": "",
|
||||
* "postType": "",
|
||||
* "postContentMd": "",
|
||||
* "postContent": "",
|
||||
* "postUrl": "",
|
||||
* "postSummary": "",
|
||||
* "categories": [],
|
||||
* "tags": [],
|
||||
* "comments": [],
|
||||
* "postThumbnail": "",
|
||||
* "postDate": "",
|
||||
* "postUpdate": "",
|
||||
* "postStatus": 0,
|
||||
* "postViews": 0,
|
||||
* "allowComment": 1,
|
||||
* "customTpl": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/year/month")
|
||||
public List<Archive> archivesYearAndMonth() {
|
||||
return postService.findPostGroupByYearAndMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResult
|
||||
* @Author Aquan
|
||||
* @Description 返回所有文章
|
||||
* @Date 2019.1.4 11:06
|
||||
* @Param
|
||||
**/
|
||||
@GetMapping(value = "/all")
|
||||
public List<Archive> archivesAllPost() {
|
||||
return postService.findAllPost();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 文章分类API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/categories")
|
||||
public class ApiCategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 获取所有分类
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "cateId": "",
|
||||
* "cateName": "",
|
||||
* "cateUrl": "",
|
||||
* "cateDesc": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping
|
||||
public List<Category> categories() {
|
||||
return categoryService.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个分类的信息
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": {
|
||||
* "cateId": "",
|
||||
* "cateName": "",
|
||||
* "cateUrl": "",
|
||||
* "cateDesc": ""
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param cateUrl 分类路径
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{cateUrl}")
|
||||
public Category categories(@PathVariable("cateUrl") String cateUrl) {
|
||||
return categoryService.findByCateUrl(cateUrl);
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.TrueFalseEnum;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.OwoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.OPTIONS;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 评论API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/comments")
|
||||
public class ApiCommentController {
|
||||
|
||||
/**
|
||||
* Comment format [formatter 1: commentId, formatter 2: commentAuthor, formatter 3: commentContent]
|
||||
*/
|
||||
private final static String COMMENT_FORMAT = "<a href='#comment-id-%s'>@%s</a> %s";
|
||||
|
||||
private final CommentService commentService;
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
public ApiCommentController(CommentService commentService, PostService postService) {
|
||||
this.commentService = commentService;
|
||||
this.postService = postService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增评论
|
||||
*
|
||||
* @param comment comment
|
||||
* @param postId postId
|
||||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
public JsonResult save(@Valid Comment comment,
|
||||
@RequestParam(value = "postId") Long postId,
|
||||
HttpServletRequest request) {
|
||||
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()).toLowerCase());
|
||||
comment.setPost(postService.fetchById(postId).orElse(new Post()));
|
||||
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
||||
comment.setIsAdmin(0);
|
||||
comment.setCommentAuthor(HtmlUtil.escape(comment.getCommentAuthor()));
|
||||
|
||||
if (StrUtil.isNotBlank(comment.getCommentAuthorEmail())) {
|
||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(comment.getCommentAuthorEmail()));
|
||||
}
|
||||
if (comment.getCommentParent() > 0) {
|
||||
// Get last comment
|
||||
Comment lastComment = commentService.fetchById(comment.getCommentParent()).orElse(new Comment());
|
||||
// Format and set comment content
|
||||
comment.setCommentContent(String.format(COMMENT_FORMAT, lastComment.getCommentId(), lastComment.getCommentAuthor(), convertToSecureString(comment.getCommentContent())));
|
||||
} else {
|
||||
//将评论内容的字符专为安全字符
|
||||
comment.setCommentContent(convertToSecureString(comment.getCommentContent()));
|
||||
}
|
||||
if (StrUtil.isNotEmpty(comment.getCommentAuthorUrl())) {
|
||||
comment.setCommentAuthorUrl(URLUtil.normalize(comment.getCommentAuthorUrl()));
|
||||
}
|
||||
|
||||
// Create the comment
|
||||
commentService.create(comment);
|
||||
|
||||
if (StrUtil.equals(OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
|
||||
return JsonResult.ok("你的评论已经提交,待博主审核之后可显示。");
|
||||
} else {
|
||||
return JsonResult.ok("你的评论已经提交,刷新后即可显示。");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts content to secure content.
|
||||
*
|
||||
* @param originalContent original content must not be null
|
||||
* @return secure content
|
||||
*/
|
||||
@NonNull
|
||||
private String convertToSecureString(@NonNull String originalContent) {
|
||||
Assert.hasText(originalContent, "Original content must not be blank");
|
||||
|
||||
return OwoUtil.markToImg(HtmlUtil.escape(originalContent).replace("<br/>", "<br/>"));
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 图库 API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/galleries")
|
||||
public class ApiGalleryController {
|
||||
|
||||
@Autowired
|
||||
private GalleryService galleryService;
|
||||
|
||||
/**
|
||||
* 获取所有图片
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "galleryId": ,
|
||||
* "galleryName": "",
|
||||
* "galleryDesc": "",
|
||||
* "galleryDate": "",
|
||||
* "galleryLocation": "",
|
||||
* "galleryThumbnailUrl": "",
|
||||
* "galleryUrl": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping
|
||||
public List<Gallery> galleries() {
|
||||
return galleryService.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单张图片的信息
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "galleryId": ,
|
||||
* "galleryName": "",
|
||||
* "galleryDesc": "",
|
||||
* "galleryDate": "",
|
||||
* "galleryLocation": "",
|
||||
* "galleryThumbnailUrl": "",
|
||||
* "galleryUrl": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param id id
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{id}")
|
||||
public Gallery galleries(@PathVariable("id") Long id) {
|
||||
return galleryService.getById(id);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.PostDetailOutputDTO;
|
||||
import cc.ryanc.halo.model.params.JournalParam;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import static cc.ryanc.halo.model.support.HaloConst.USER_SESSION_KEY;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 日志 API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/03/04
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/journals")
|
||||
public class ApiJournalController {
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public ApiJournalController(PostService postService,
|
||||
UserService userService) {
|
||||
this.postService = postService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布日志
|
||||
*
|
||||
* @param journalParam journalParam
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public PostDetailOutputDTO save(@RequestBody JournalParam journalParam, HttpSession session) {
|
||||
|
||||
User user = userService.findUser();
|
||||
|
||||
Post post = journalParam.convertTo();
|
||||
post.setUser(user);
|
||||
|
||||
return new PostDetailOutputDTO().convertFrom(postService.create(post));
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Link;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/6/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/links")
|
||||
public class ApiLinkController {
|
||||
|
||||
@Autowired
|
||||
private LinkService linkService;
|
||||
|
||||
/**
|
||||
* 获取所有友情链接
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
* "result": [
|
||||
* {
|
||||
* "linkId": ,
|
||||
* "linkName": "",
|
||||
* "linkUrl": "",
|
||||
* "linkPic": "",
|
||||
* "linkDesc": ""
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping
|
||||
public List<Link> links() {
|
||||
return linkService.listAll();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue