📄 replyserviceimpl.java
字号:
/*
* Created on 2007-3-23
* Last modified on 2007-11-3
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.topic;
import java.util.List;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.CacheFactory;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.ReContentDAO;
import com.yeqiangwei.club.dao.ReplyDAO;
import com.yeqiangwei.club.dao.TopicDAO;
import com.yeqiangwei.club.dao.model.ReContent;
import com.yeqiangwei.club.dao.model.Reply;
import com.yeqiangwei.club.dao.model.Topic;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.counter.CountService;
import com.yeqiangwei.club.service.model.CountersModel;
import com.yeqiangwei.club.service.model.ReContentModel;
import com.yeqiangwei.club.service.model.ReplyModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.club.controller.form.TopicTrashForm;
import com.yeqiangwei.util.FormatDateTime;
import com.yeqiangwei.util.Validator;
public class ReplyServiceImpl implements ReplyService {
private static final Logger logger = Logger.getLogger(ReplyServiceImpl.class);
/**
* Cache主题分页列表
* @param forumId
* @return
*/
private Cache getTopicCache(Integer forumId){
return CacheFactory.creator(CacheRegion.TOPIC+"-formId:"+forumId);
}
/**
* cache 主题回复数
* @param forumId
* @return
*/
private Cache getCache(Integer forumId){
return CacheFactory.creator(CacheRegion.REPLY+"-formId:"+forumId);
}
public int delete(List<Integer> ids) {
int c=0;
try {
c = this.getReplyDAO().delete(ids);
this.getReContentDAO().deleteByReplyId(ids);
} catch (DAOException e1) {
logger.error(e1.toString());
}
return c;
}
public int trash(List<Integer> list, boolean isDeleted){
int s = 0;
for(int i=0; i<list.size(); i++){
int id = list.get(i);
Reply item = this.getReplyDAO().findById(id);
ReContent citem = this.getReContentDAO().findByReplyId(id);
item.setIsDeleted(isDeleted);
citem.setIsDeleted(isDeleted);
try {
this.getReplyDAO().update(item);
this.getReContentDAO().update(citem);
s++;
} catch (DAOException e1) {
logger.error(e1.toString());
}
}
return s;
}
public ReplyModel trash(TopicTrashForm form) throws ClubException {
ReplyModel model = null;
Reply item = this.getReplyDAO().findById(form.getReplyId());
if(!Validator.isEmpty(item)){
item.setIsDeleted(form.getIsDeleted());
item.setIsManaged(true);
try {
this.getReplyDAO().update(item);
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.debug("trash() isDeleted:"+item.getIsDeleted());
logger.debug("trash() replyId:"+item.getReplyId());
ReContent citem = this.getReContentDAO().findByReplyId(form.getReplyId());
citem.setIsDeleted(form.getIsDeleted());
try {
this.getReContentDAO().update(citem);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
model = new ReplyModel();
BeanUtils.copyProperties(model,item);
return model;
}else{
//this.setMessage(MessageUtils.getMessage("error"));
throw new ClubException("ReplyModel("+form.getTopicId()+") is null!");
}
}
public List<ReplyModel> findReplyAndContent(TopicParameter param) {
List<ReplyModel> rlist = this.findReplyByTopicId(param);
List<ReContent> clist = this.getReContentDAO().findByParameter(param);
if(!Validator.isEmpty(rlist)&&!Validator.isEmpty(clist)){
for(int i=0; i<rlist.size(); i++){
ReContent rc = clist.get(i);
ReContentModel rcm = new ReContentModel();
BeanUtils.copyProperties(rcm,rc);
ReplyModel rm = rlist.get(i);
rm.setReContentModel(rcm);
}
}
return rlist;
}
public ReplyModel findReplyAndContentById(int id) {
ReplyModel model = this.findById(id);
if(!Validator.isEmpty(model)){
ReContent ritem = this.getReContentDAO().findByReplyId(id);
if(!Validator.isEmpty(ritem)){
ReContentModel rcmodel = new ReContentModel();
BeanUtils.copyProperties(rcmodel,ritem);
model.setReContentModel(rcmodel);
return model;
}else{
logger.error("ReContent("+model.getReplyId()+") is null!");
return null;
}
}else{
return null;
}
}
public List<ReplyModel> findReplyByTopicId(TopicParameter param) {
List<Reply> list = this.getReplyDAO().findByParameter(param);
List<ReplyModel> rlist = BeanUtils.<Reply,ReplyModel>copyList(list,BeanLocator.REPLYMODEL);
return rlist;
}
public ReplyModel findById(int id) {
if(id>0){
Reply item = this.getReplyDAO().findById(id);
if(!Validator.isEmpty(item)){
ReplyModel model = new ReplyModel();
BeanUtils.copyProperties(model,item);
return model;
}
}
return null;
}
public void createOrUpdate(ReplyModel model) throws ClubException {
if(model.getReplyId()>0){
this.update(model);
}else{
this.create(model);
}
}
private void updateParameter(ReplyModel replyModel) throws ClubException {
Reply reply = this.getReplyDAO().findById(replyModel.getReplyId());
if(!Validator.isEmpty(reply)){
BeanUtils.copyProperties(reply, replyModel);
try {
this.getReplyDAO().update(reply);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
}
}
private void treeUtils(ReplyModel model) throws ClubException{
int orderlist = 0;
int layer = 0;
int tree = 0;
int replys = 0;
//logger.debug("model.getReplyId():"+model.getReplyId());
if(model.getReplyId()>0){
ReplyModel replyModel = this.findById(model.getReplyId());
if(!Validator.isEmpty(replyModel)){
orderlist = replyModel.getOrderlist();
layer = replyModel.getLayer();
tree = replyModel.getTree();
replys = replyModel.getReplys();//更新前的回复次数
replyModel.setReplys(replyModel.getReplys()+1);//更新回复表回复次数
this.updateParameter(replyModel);
}
}else{
replys = this.getTopicService().findById(model.getTopicId()).getReplys();
}
Reply item = new Reply();
item.setTopicId(model.getTopicId());
item.setReplyId(model.getReplyId());
item.setOrderlist(orderlist);
try {
this.getReplyDAO().updatesOrderlistByTopicId(item);
} catch (DAOException e) {
logger.error(e.toString());
}
if(model.getReplyId()>0){
orderlist++;
}else{
orderlist = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -