Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nonacosa authored Feb 28, 2017
2 parents 614b672 + 9057f1e commit c771bad
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/tale/controller/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public String page(@PathParam String pagename, Request request) {
@Route(value = "page/:p", method = HttpMethod.GET)
public String index(Request request, @PathParam int p, @QueryParam(value = "limit", defaultValue = "12") int limit) {
p = p < 0 || p > TaleConst.MAX_PAGE ? 1 : p;
Take take = new Take(Contents.class).eq("type", Types.ARTICLE)
.eq("status", Types.PUBLISH).page(p, limit, "created desc");
Take take = new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).page(p, limit, "created desc");
Paginator<Contents> articles = contentsService.getArticles(take);
request.attribute("articles", articles);
if (p > 1) {
Expand Down Expand Up @@ -352,6 +351,7 @@ public RestResponse comment(Request request, Response response,
}
// 设置对每个文章1分钟可以评论一次
cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 60);
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
} catch (Exception e) {
String msg = "评论发布失败";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.tale.service.ContentsService;
import com.tale.service.LogService;
import com.tale.service.MetasService;
import com.tale.service.SiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -40,6 +41,9 @@ public class ArticleController extends BaseController {
@Inject
private LogService logService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(@QueryParam(value = "page", defaultValue = "1") int page,
@QueryParam(value = "limit", defaultValue = "15") int limit, Request request) {
Expand Down Expand Up @@ -99,6 +103,7 @@ public RestResponse publishArticle(@QueryParam String title, @QueryParam String

try {
contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "文章发布失败";
if (e instanceof TipException) {
Expand Down Expand Up @@ -157,6 +162,7 @@ public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String ti
public RestResponse delete(@QueryParam int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
logService.save(LogActions.DEL_ARTICLE, cid+"", request.address(), this.getUid());
} catch (Exception e) {
String msg = "文章删除失败";
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/tale/controller/admin/AttachController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.tale.model.Users;
import com.tale.service.AttachService;
import com.tale.service.LogService;
import com.tale.service.SiteService;
import com.tale.utils.TaleUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -49,6 +50,9 @@ public class AttachController extends BaseController {
@Inject
private LogService logService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(Request request, @QueryParam(value = "page", defaultValue = "1") int page,
@QueryParam(value = "limit", defaultValue = "12") int limit) {
Expand Down Expand Up @@ -91,6 +95,7 @@ public RestResponse upload(Request request) {
e.printStackTrace();
}
attachService.save(fname, fkey, ftype, uid);
siteService.cleanCache(Types.C_STATISTICS);
});
} catch (Exception e) {
return RestResponse.fail();
Expand All @@ -107,6 +112,7 @@ public RestResponse delete(@QueryParam Integer id, Request request) {
return RestResponse.fail("不存在该附件");
}
attachService.delete(id);
siteService.cleanCache(Types.C_STATISTICS);
String upDir = CLASSPATH.substring(0, CLASSPATH.length() - 1);
FileKit.delete(upDir + attach.getFkey());
logService.save(LogActions.DEL_ARTICLE, attach.getFkey(), request.address(), this.getUid());
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/tale/controller/admin/CategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.tale.exception.TipException;
import com.tale.init.TaleConst;
import com.tale.service.MetasService;
import com.tale.service.SiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -30,10 +31,13 @@ public class CategoryController extends BaseController {
@Inject
private MetasService metasService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
List<MetaDto> categories = metasService.getMetaList(Types.CATEGORY, null, TaleConst.MAX_POSTS);
List<MetaDto> tags = metasService.getMetaList(Types.TAG, null, TaleConst.MAX_POSTS);
List<MetaDto> categories = siteService.getMetas(Types.RECENT_META, Types.CATEGORY, TaleConst.MAX_POSTS);
List<MetaDto> tags = siteService.getMetas(Types.RECENT_META, Types.TAG, TaleConst.MAX_POSTS);
request.attribute("categories", categories);
request.attribute("tags", tags);
return "admin/category";
Expand All @@ -44,6 +48,7 @@ public String index(Request request) {
public RestResponse saveCategory(@QueryParam String cname, @QueryParam Integer mid) {
try {
metasService.saveMeta(Types.CATEGORY, cname, mid);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "分类保存失败";
if (e instanceof TipException) {
Expand All @@ -61,6 +66,7 @@ public RestResponse saveCategory(@QueryParam String cname, @QueryParam Integer m
public RestResponse delete(@QueryParam int mid) {
try {
metasService.delete(mid);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "删除失败";
if (e instanceof TipException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import com.blade.mvc.view.RestResponse;
import com.tale.controller.BaseController;
import com.tale.dto.Comment;
import com.tale.dto.Types;
import com.tale.exception.TipException;
import com.tale.model.Comments;
import com.tale.model.Users;
import com.tale.service.CommentsService;
import com.tale.service.SiteService;
import com.tale.utils.TaleUtils;
import com.vdurmont.emoji.EmojiParser;
import org.slf4j.Logger;
Expand All @@ -33,6 +35,9 @@ public class CommentController extends BaseController {
@Inject
private CommentsService commentsService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(@QueryParam(value = "page", defaultValue = "1") int page,
@QueryParam(value = "limit", defaultValue = "15") int limit, Request request) {
Expand All @@ -56,6 +61,7 @@ public RestResponse delete(@QueryParam Integer coid) {
return RestResponse.fail("不存在该评论");
}
commentsService.delete(coid, comments.getCid());
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "评论删除失败";
if (e instanceof TipException) {
Expand All @@ -76,6 +82,7 @@ public RestResponse delete(@QueryParam Integer coid, @QueryParam String status)
comments.setCoid(coid);
comments.setStatus(status);
commentsService.update(comments);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "操作失败";
if (e instanceof TipException) {
Expand Down Expand Up @@ -121,6 +128,7 @@ public RestResponse reply(@QueryParam Integer coid, @QueryParam String content,
comments.setParent(coid);
try {
commentsService.saveComment(comments);
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
} catch (Exception e) {
String msg = "回复失败";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/tale/controller/admin/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tale.dto.BackResponse;
import com.tale.dto.LogActions;
import com.tale.dto.Statistics;
import com.tale.dto.Types;
import com.tale.exception.TipException;
import com.tale.init.TaleConst;
import com.tale.model.Comments;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class IndexController extends BaseController {
@Route(value = {"/", "index"}, method = HttpMethod.GET)
public String index(Request request) {
List<Comments> comments = siteService.recentComments(5);
List<Contents> contents = siteService.recentContents(5);
List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
Statistics statistics = siteService.getStatistics();
// 取最新的20条日志
List<Logs> logs = logService.getLogs(1, 20);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/tale/controller/admin/LinksController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tale.exception.TipException;
import com.tale.model.Metas;
import com.tale.service.MetasService;
import com.tale.service.SiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,6 +30,9 @@ public class LinksController extends BaseController {
@Inject
private MetasService metasService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
List<Metas> metass = metasService.getMetas(Types.LINK);
Expand All @@ -54,6 +58,7 @@ public RestResponse saveLink(@QueryParam String title, @QueryParam String url,
} else {
metasService.saveMeta(metas);
}
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "友链保存失败";
if (e instanceof TipException) {
Expand All @@ -71,6 +76,7 @@ public RestResponse saveLink(@QueryParam String title, @QueryParam String url,
public RestResponse delete(@QueryParam int mid) {
try {
metasService.delete(mid);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "友链删除失败";
if (e instanceof TipException) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/tale/controller/admin/PageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tale.service.ContentsService;
import com.tale.service.LogService;
import com.tale.service.MetasService;
import com.tale.service.SiteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,6 +38,9 @@ public class PageController extends BaseController {
@Inject
private LogService logService;

@Inject
private SiteService siteService;

@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
Paginator<Contents> contentsPaginator = contentsService.getArticles(new Take(Contents.class).eq("type", Types.PAGE).page(1, TaleConst.MAX_POSTS, "created desc"));
Expand Down Expand Up @@ -79,6 +83,7 @@ public RestResponse publishPage(@QueryParam String title, @QueryParam String con

try {
contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "页面发布失败";
if (e instanceof TipException) {
Expand Down Expand Up @@ -132,6 +137,7 @@ public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String ti
public RestResponse delete(@QueryParam int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
logService.save(LogActions.DEL_PAGE, cid+"", request.address(), this.getUid());
} catch (Exception e) {
String msg = "页面删除失败";
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/tale/dto/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@
*/
public class Statistics implements Serializable {

// 文章数
private int articles;
// 页面数
private int pages;
// 评论数
private int comments;
// 分类数
private int categories;
// 标签数
private int tags;
// 链接数
private int links;
// 附件数
private int attachs;

public int getArticles() {
Expand Down Expand Up @@ -45,4 +55,28 @@ public int getAttachs() {
public void setAttachs(int attachs) {
this.attachs = attachs;
}

public int getCategories() {
return categories;
}

public void setCategories(int categories) {
this.categories = categories;
}

public int getTags() {
return tags;
}

public void setTags(int tags) {
this.tags = tags;
}

public int getPages() {
return pages;
}

public void setPages(int pages) {
this.pages = pages;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/tale/dto/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public interface Types {
String FILE = "file";
String CSRF_TOKEN = "csrf_token";
String COMMENTS_FREQUENCY = "comments:frequency";

String RECENT_ARTICLE = "recent_article";
String RANDOM_ARTICLE = "random_article";

String RECENT_META = "recent_meta";
String RANDOM_META = "random_meta";

String C_STATISTICS = "sys:statistics";

}
Loading

0 comments on commit c771bad

Please sign in to comment.