📄 replyserviceimpl.java
字号:
/* 计算树型参数 */
int tTree = 0;
if(replys>0){
tTree = (tree * 2 +1 );
}else{
tTree = tree * 2;
}
layer += 1;
model.setLayer(layer);
model.setOrderlist(orderlist);
model.setTree(tTree);
model.setReplys(0);
}
public void create(ReplyModel model) throws ClubException {
if(Validator.isEmpty(model)||Validator.isEmpty(model.getTitle())){
//this.setMessage(super.getMessage("error_empty"));
throw new ClubException(MessageUtils.getMessage("error_empty"));
}else{
//logger.debug("回帖时间:"+model.getCreateDateTime());
this.treeUtils(model);
//logger.debug("回帖时间:"+model.getCreateDateTime());
ReContentModel cmodel = model.getReContentModel();
model.setContentLength(cmodel.getContent().length());
Reply item = new Reply();
BeanUtils.copyProperties(item,model);
if(model.getTitle().length()>100||model.getContentLength()>100000){
logger.error("too long title: "+model.getTitle());
logger.error("content.length: "+model.getContentLength());
//this.setMessage(super.getMessage("error_toolong"));
throw new ClubException(MessageUtils.getMessage("error_toolong"));
}
int replyId = model.getReplyId(); //保持回复创建之前的replyId
/*
Topic topic = this.getTopicService().getTopicDAO().findById(model.getTopicId());
if(model.getReplyId()==0){
topic.setReplys(topic.getReplys()+1);
}
*/
try {
this.getReplyDAO().create(item);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
BeanUtils.copyProperties(model,item); //PO->BO
cmodel.setTopicId(item.getTopicId());
cmodel.setReplyId(item.getReplyId());
//创建回复的内容
ReContent citem = new ReContent();
BeanUtils.copyProperties(citem,cmodel);
try {
this.getReContentDAO().create(citem);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
BeanUtils.copyProperties(cmodel,citem); //PO->BO
model.setReContentModel(cmodel);
/*更新最后回复ID的Cache*/
this.getTopicService().setLastReplyId(new Integer(model.getReplyId()));
/* 更新回复次数最后更新时间等 */
Topic topic = this.getTopicService().getTopicDAO().findById(model.getTopicId());
if(Validator.isEmpty(topic)){
throw new ClubException(MessageUtils.getMessage("error_notfind_topic"));
}else{
if(replyId==0){
topic.setReplys(topic.getReplys()+1);
}
topic.setLastReplyDateTime(FormatDateTime.now());
topic.setLastReplyUserName(model.getUserName());
topic.setLastReplyUserId(model.getUserId());
topic.setReplyId(model.getReplyId());
try {
this.getTopicService().getTopicDAO().update(topic);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
this.getTopicCache(model.getForumId()).clear(); //清除主题列表缓存
this.getTopicCache(null).clear(); //清除主题列表缓存
/*
* 更新被回复的主帖的用户参数
*/
UserModel tuser = this.getUserService().findById(topic.getUserId());
if(!Validator.isEmpty(tuser)){
this.getUserService().ruleUtils(tuser,model.getForumId(),6); //文章被回复的参数变化
this.getUserService().update(tuser);
logger.debug("Topic.userId: "+tuser.getUserId());
}
}
this.getCache(model.getForumId()).clear(); //清除count统计Cache
/* 回帖用户的积分变动 */
UserModel user = model.getUserModel();
user.setReplys(user.getReplys()+1); //回帖次数加1
this.getUserService().ruleUtils(user,model.getForumId(),3); //根据社区回复制度更新用户参数
model.setUserModel(user);
/* 更新统计信息 */
CountersModel counters = new CountersModel();
counters.setReplys(1);
counters.setForumId(model.getForumId());
this.getCountService().doCount(counters);
//this.setMessage(super.getMessage("success"));
}
}
public void update(ReplyModel model) throws ClubException {
if(Validator.isEmpty(model)||Validator.isEmpty(model.getTitle())){
//this.setMessage(super.getMessage("error_empty"));
throw new ClubException(MessageUtils.getMessage("error_empty"));
}
else if(model.getTopicId()==0){
model = null;
//this.setMessage("error_system");
throw new ClubException(MessageUtils.getMessage("error_system"));
}
else{
ReContentModel cmodel = model.getReContentModel();
model.setContentLength(cmodel.getContent().length());
Reply item = this.getReplyDAO().findById(model.getReplyId());
BeanUtils.copyProperties(item,model);
if(model.getTitle().length()>100||model.getContentLength()>50000){
//this.setMessage(super.getMessage("error_toolong"));
throw new ClubException(MessageUtils.getMessage("error_toolong"));
}
try {
this.getReplyDAO().create(item);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
BeanUtils.copyProperties(model,item); //PO->BO
cmodel.setTopicId(item.getTopicId());
cmodel.setReplyId(item.getReplyId());
ReContent citem = this.getReContentDAO().findByReplyId(model.getReplyId());
BeanUtils.copyProperties(citem,cmodel);
try {
this.getReContentDAO().update(citem);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
BeanUtils.copyProperties(cmodel,citem); //PO->BO
model.setReContentModel(cmodel);
}
}
public int delete(ReplyModel model) {
return 0;
}
public int delete(String[] ids) {
return 0;
}
public List<ReplyModel> findByParameter(TopicParameter param) {
List<Reply> list = this.getReplyDAO().findByParameter(param);
List<ReplyModel> mlist = BeanUtils.<Reply,ReplyModel>copyList(list,BeanLocator.REPLYMODEL);
return mlist;
}
public long countByParameter(TopicParameter param) {
Long ln = (Long) this.getCache(param.getForumId()).get(param.getCacheKeyOfCount());
Boolean isput = (Boolean) this.getCache(param.getForumId()).get(param.getCacheKeyOfCount()+"-isput");
if(Validator.isEmpty(ln)&&Validator.isEmpty(isput)){
long c = this.getReplyDAO().countByParameter(param);
this.getCache(param.getForumId()).put(param.getCacheKeyOfCount(),new Long(c));
this.getCache(param.getForumId()).put(param.getCacheKeyOfCount()+"-isput",new Boolean(true));
return c;
}else{
return ln.longValue();
}
}
public ReplyDAO getReplyDAO() {
return DAOWrapper.<ReplyDAO>getSingletonInstance(DAOLocator.REPLY);
}
public ReContentDAO getReContentDAO() {
return DAOWrapper.<ReContentDAO>getSingletonInstance(DAOLocator.RECONTENT);
}
public TopicService getTopicService() {
return ServiceWrapper.<TopicService>getSingletonInstance(ServiceLocator.TOPIC);
}
public UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
public CountService getCountService() {
return ServiceWrapper.<CountService>getSingletonInstance(ServiceLocator.COUNT);
}
public TopicDAO getTopicDAO() {
return DAOWrapper.<TopicDAO>getSingletonInstance(DAOLocator.TOPIC);
}
public static void main(String args[]){
com.yeqiangwei.club.dao.hibernate.ConnectionManager.init();
ReplyServiceImpl r = new ReplyServiceImpl();
ReplyModel model = r.findById(18);
//r.treeUtils(model);
System.out.println(model.getTitle());
/*
TopicParameter param = new TopicParameter();
param.setForumId(10);
param.setTopicId(599);
param.setPage(1);
List<ReplyModel> mlist = r.findReplyAndContent(param);
for(int i=0; i<mlist.size(); i++){
ReplyModel model = mlist.get(i);
System.out.println(model.getReContentModel().getContent());
}
/*
ReplyModel rm = new ReplyModel();
rm.setTitle("ddddddd");
rm.setTopicId(11);
ReContentModel rc = new ReContentModel();
rc.setContent("ddddddddddddddddd");
rm.setReContentModel(rc);
r.create(rm);
System.out.println(r.getMessage());
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -