forked from zhouit/Zblog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhou
committed
Mar 9, 2015
1 parent
0387128
commit 67046ad
Showing
48 changed files
with
653 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.zblog.biz; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.zblog.core.plugin.MapContainer; | ||
import com.zblog.core.plugin.TreeUtils; | ||
import com.zblog.core.util.constants.CommentConstants; | ||
import com.zblog.service.CommentService; | ||
import com.zblog.service.PostService; | ||
|
||
@Component | ||
public class CommentManager{ | ||
@Autowired | ||
private CommentService commentService; | ||
@Autowired | ||
private PostService postService; | ||
|
||
public List<MapContainer> getAsTree(String postid, String creator){ | ||
List<MapContainer> list = commentService.listByPost(postid, creator); | ||
TreeUtils.rebuildTree(list); | ||
|
||
return list; | ||
} | ||
|
||
/** | ||
* 更改评论状态,同时更改该评论对应的post的评论数 | ||
* | ||
* @param commentid | ||
* @param newStatus | ||
*/ | ||
@Transactional | ||
public void setStatus(String commentid, String newStatus){ | ||
commentService.setStatus(commentid, newStatus); | ||
postService.addCcount(commentid, CommentConstants.TYPE_APPROVE.equals(newStatus) ? 1 : -1); | ||
} | ||
|
||
/** | ||
* 删除评论,同时删除对应文章的评论数 | ||
* | ||
* @param commentid | ||
*/ | ||
@Transactional | ||
public void deleteComment(String commentid){ | ||
commentService.deleteById(commentid); | ||
postService.addCcount(commentid, -1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.zblog.biz; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.zblog.service.PostService; | ||
|
||
/** | ||
* 文章的访问统计 | ||
* | ||
* @author zhou | ||
* | ||
*/ | ||
@Component | ||
public class VisitStatManager{ | ||
private static final Logger logger = LoggerFactory.getLogger(VisitStatManager.class); | ||
@Autowired | ||
private PostService postService; | ||
private ConcurrentMap<String, Integer> visit = new ConcurrentHashMap<>(); | ||
|
||
public void flush(){ | ||
ConcurrentMap<String, Integer> copy = visit; | ||
visit = new ConcurrentHashMap<String, Integer>(); | ||
if(!copy.isEmpty()){ | ||
logger.debug("flush visit stat to database"); | ||
} | ||
|
||
for(Map.Entry<String, Integer> entry : copy.entrySet()){ | ||
postService.addRcount(entry.getKey(), entry.getValue()); | ||
} | ||
copy.clear(); | ||
copy = null; | ||
} | ||
|
||
public void record(String postid){ | ||
Integer count = visit.get(postid); | ||
/* 该数据,并发问题忽略 */ | ||
visit.put(postid, count == null ? 1 : count + 1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.