Skip to content

Commit

Permalink
👻 daily excrement code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Sep 17, 2017
1 parent 7bf499b commit ca93f4f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.tale.model.dto.LogActions;
import com.tale.model.dto.Types;
import com.tale.model.entity.Contents;
import com.tale.model.entity.Logs;
import com.tale.model.entity.Metas;
import com.tale.model.entity.Users;
import com.tale.service.ContentsService;
import com.tale.service.LogService;
import com.tale.service.MetasService;
import com.tale.service.SiteService;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -38,9 +38,6 @@ public class ArticleController extends BaseController {
@Inject
private MetasService metasService;

@Inject
private LogService logService;

@Inject
private SiteService siteService;

Expand Down Expand Up @@ -135,7 +132,7 @@ public RestResponse publishArticle(@Valid Contents contents) {
@JSON
public RestResponse modifyArticle(@Valid Contents contents) {
try {
if(null == contents || null == contents.getCid()){
if (null == contents || null == contents.getCid()) {
return RestResponse.fail("缺少参数,请重试");
}
contentsService.updateArticle(contents);
Expand Down Expand Up @@ -164,7 +161,7 @@ public RestResponse delete(@Param int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
logService.save(LogActions.DEL_ARTICLE, cid + "", request.address(), this.getUid());
new Logs(LogActions.DEL_ARTICLE, cid + "", request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "文章删除失败";
if (e instanceof TipException) {
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/tale/controller/admin/AttachController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.tale.model.dto.LogActions;
import com.tale.model.dto.Types;
import com.tale.model.entity.Attach;
import com.tale.model.entity.Logs;
import com.tale.model.entity.Users;
import com.tale.service.LogService;
import com.tale.service.SiteService;
import com.tale.utils.TaleUtils;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -44,9 +44,6 @@ public class AttachController extends BaseController {

public static final String CLASSPATH = new File(AttachController.class.getResource("/").getPath()).getPath() + File.separatorChar;

@Inject
private LogService logService;

@Inject
private SiteService siteService;

Expand Down Expand Up @@ -153,7 +150,7 @@ public RestResponse delete(@Param Integer id, Request request) {
siteService.cleanCache(Types.C_STATISTICS);
String upDir = CLASSPATH.substring(0, CLASSPATH.length() - 1);
Files.delete(Paths.get(upDir + attach.getFkey()));
logService.save(LogActions.DEL_ATTACH, attach.getFkey(), request.address(), this.getUid());
new Logs(LogActions.DEL_ATTACH, attach.getFkey(), request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "附件删除失败";
if (e instanceof TipException) msg = e.getMessage();
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/tale/controller/admin/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tale.controller.admin;

import com.blade.ioc.annotation.Inject;
import com.blade.kit.DateKit;
import com.blade.kit.EncrypKit;
import com.blade.kit.StringKit;
Expand All @@ -19,7 +18,6 @@
import com.tale.model.entity.Logs;
import com.tale.model.entity.Users;
import com.tale.model.param.LoginParam;
import com.tale.service.LogService;
import com.tale.utils.TaleUtils;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -31,9 +29,6 @@
@Path("admin")
public class AuthController extends BaseController {

@Inject
private LogService logService;

@Route(value = "login", method = HttpMethod.GET)
public String login(Response response) {
if (null != this.user()) {
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/com/tale/controller/admin/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.tale.model.entity.Contents;
import com.tale.model.entity.Logs;
import com.tale.model.entity.Users;
import com.tale.service.LogService;
import com.tale.service.OptionsService;
import com.tale.service.SiteService;
import jetbrick.util.ShellUtils;
Expand All @@ -51,9 +50,6 @@ public class IndexController extends BaseController {
@Inject
private SiteService siteService;

@Inject
private LogService logService;

/**
* 仪表盘
*/
Expand Down Expand Up @@ -96,7 +92,7 @@ public RestResponse saveSetting(@Param String site_theme, Request request) {
Environment config = Environment.of(optionsService.getOptions());
TaleConst.OPTIONS = config;

logService.save(LogActions.SYS_SETTING, JsonKit.toString(querys), request.address(), this.getUid());
new Logs(LogActions.SYS_SETTING, JsonKit.toString(querys), request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "保存设置失败";
Expand Down Expand Up @@ -129,7 +125,7 @@ public RestResponse saveProfile(@Param String screen_name, @Param String email,
temp.setScreen_name(screen_name);
temp.setEmail(email);
temp.update(users.getUid());
logService.save(LogActions.UP_INFO, JsonKit.toString(temp), request.address(), this.getUid());
new Logs(LogActions.UP_INFO, JsonKit.toString(temp), request.address(), this.getUid()).save();
}
return RestResponse.ok();
}
Expand All @@ -153,11 +149,11 @@ public RestResponse upPwd(@Param String old_password, @Param String password, Re
}

try {
Users temp = new Users();
String pwd = EncrypKit.md5(users.getUsername() + password);
Users temp = new Users();
String pwd = EncrypKit.md5(users.getUsername() + password);
temp.setPassword(pwd);
temp.update(users.getUid());
logService.save(LogActions.UP_PWD, null, request.address(), this.getUid());
new Logs(LogActions.UP_PWD, null, request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "密码修改失败";
Expand Down Expand Up @@ -185,7 +181,7 @@ public RestResponse backup(@Param String bk_type, @Param String bk_path,

try {
BackResponse backResponse = siteService.backup(bk_type, bk_path, "yyyyMMddHHmm");
logService.save(LogActions.SYS_BACKUP, null, request.address(), this.getUid());
new Logs(LogActions.SYS_BACKUP, null, request.address(), this.getUid()).save();
return RestResponse.ok(backResponse);
} catch (Exception e) {
String msg = "备份失败";
Expand Down Expand Up @@ -261,7 +257,7 @@ public void reload(@Param(defaultValue = "0") int sleep, Request request) {
String cmd = "sh " + webHome + "/bin tale.sh reload " + sleep;
log.info("execute shell: {}", cmd);
ShellUtils.shell(cmd);
logService.save(LogActions.RELOAD_SYS, "", request.address(), this.getUid());
new Logs(LogActions.RELOAD_SYS, "", request.address(), this.getUid()).save();
TimeUnit.SECONDS.sleep(sleep);
} catch (Exception e) {
log.error("重启系统失败", e);
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/tale/controller/admin/PageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import com.tale.model.dto.LogActions;
import com.tale.model.dto.Types;
import com.tale.model.entity.Contents;
import com.tale.model.entity.Logs;
import com.tale.model.entity.Users;
import com.tale.service.ContentsService;
import com.tale.service.LogService;
import com.tale.service.SiteService;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -34,9 +34,6 @@ public class PageController extends BaseController {
@Inject
private ContentsService contentsService;

@Inject
private LogService logService;

@Inject
private SiteService siteService;

Expand Down Expand Up @@ -90,7 +87,7 @@ public RestResponse publishPage(@Valid Contents contents) {
@Route(value = "modify", method = HttpMethod.POST)
@JSON
public RestResponse modifyArticle(@Valid Contents contents) {
if(null == contents || null == contents.getCid()){
if (null == contents || null == contents.getCid()) {
return RestResponse.fail("缺少参数,请重试");
}
try {
Expand All @@ -114,7 +111,7 @@ public RestResponse delete(@Param int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
logService.save(LogActions.DEL_PAGE, cid + "", request.address(), this.getUid());
new Logs(LogActions.DEL_PAGE, cid + "", request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "页面删除失败";
if (e instanceof TipException) {
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/tale/controller/admin/ThemeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import com.blade.mvc.http.Request;
import com.blade.mvc.ui.RestResponse;
import com.tale.controller.BaseController;
import com.tale.model.dto.LogActions;
import com.tale.model.dto.ThemeDto;
import com.tale.exception.TipException;
import com.tale.extension.Commons;
import com.tale.init.TaleConst;
import com.tale.init.TaleLoader;
import com.tale.service.LogService;
import com.tale.model.dto.LogActions;
import com.tale.model.dto.ThemeDto;
import com.tale.model.entity.Logs;
import com.tale.service.OptionsService;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -35,25 +35,23 @@ public class ThemeController extends BaseController {
@Inject
private OptionsService optionsService;

@Inject
private LogService logService;

@GetRoute(value = "")
public String index(Request request) {
// 读取主题
String themesDir = AttachController.CLASSPATH + "templates/themes";
File[] themesFile = new File(themesDir).listFiles();
List<ThemeDto> themes = new ArrayList<>(themesFile.length);
for(File f : themesFile){
if(f.isDirectory()){
String themesDir = AttachController.CLASSPATH + "templates/themes";
File[] themesFile = new File(themesDir).listFiles();
List<ThemeDto> themes = new ArrayList<>(themesFile.length);
for (File f : themesFile) {
if (f.isDirectory()) {
ThemeDto themeDto = new ThemeDto(f.getName());
if (Files.exists(Paths.get(f.getPath() + "/setting.html"))) {
themeDto.setHasSetting(true);
}
themes.add(themeDto);
try {
Blade.me().addStatics("/templates/themes/" + f.getName() + "/screenshot.png");
} catch (Exception e){}
} catch (Exception e) {
}
}
}
request.attribute("current_theme", Commons.site_theme());
Expand All @@ -63,6 +61,7 @@ public String index(Request request) {

/**
* 主题设置页面
*
* @param request
* @return
*/
Expand All @@ -75,6 +74,7 @@ public String setting(Request request) {

/**
* 保存主题配置项
*
* @param request
* @return
*/
Expand All @@ -84,10 +84,8 @@ public RestResponse saveSetting(Request request) {
try {
Map<String, List<String>> querys = request.parameters();
optionsService.saveOptions(querys);

TaleConst.OPTIONS = Environment.of(optionsService.getOptions());

logService.save(LogActions.THEME_SETTING, JsonKit.toString(querys), request.address(), this.getUid());
new Logs(LogActions.THEME_SETTING, JsonKit.toString(querys), request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "主题设置失败";
Expand All @@ -102,6 +100,7 @@ public RestResponse saveSetting(Request request) {

/**
* 激活主题
*
* @param request
* @param site_theme
* @return
Expand All @@ -119,8 +118,9 @@ public RestResponse activeTheme(Request request, @Param String site_theme) {
String themePath = "/templates/themes/" + site_theme;
try {
TaleLoader.loadTheme(themePath);
} catch (Exception e){}
logService.save(LogActions.THEME_SETTING, site_theme, request.address(), this.getUid());
} catch (Exception e) {
}
new Logs(LogActions.THEME_SETTING, site_theme, request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "主题启用失败";
Expand Down

0 comments on commit ca93f4f

Please sign in to comment.