📄 articleserviceimpl.java
字号:
package com.test.bbs.service.impl;
import java.util.Date;
import java.util.List;
import com.test.bbs.dao.ArticleDao;
import com.test.bbs.domain.Reply;
import com.test.bbs.domain.Subject;
import com.test.bbs.domain.User;
import com.test.bbs.exception.ServiceException;
import com.test.bbs.service.ArticleService;
public class ArticleServiceImpl implements ArticleService {
private ArticleDao articleDao = null;
public ArticleServiceImpl(ArticleDao articleDao) {
this.articleDao = articleDao;
}
public void addReply(Reply reply) {
Subject subject = reply.getSubject();
reply.setFloor(subject.getReplyCount() + 1);
this.articleDao.addReply(reply);
subject.setReplyCount(subject.getReplyCount() + 1);
subject.setReplyDate(new Date());
this.articleDao.updateSubject(subject);
}
public void addSubject(Subject subject) {
this.articleDao.addSubject(subject);
}
public Reply delReply(User operator, Integer replyId) {
Reply reply = this.articleDao.getReply(replyId);
if (operator.getId() != reply.getAuthor().getId())
throw new ServiceException("不能删除别人的回复");
this.articleDao.delReply(reply);
return reply;
}
public void delSubject(User operator, Integer subjectId) {
Subject subject = this.articleDao.getSubject(subjectId);
if (operator.getId() != subject.getAuthor().getId())
throw new ServiceException("不能删除别人的文章");
this.articleDao.delSubject(subject);
}
public Subject getSubject(Integer id) {
Subject subject = this.articleDao.getSubject(id);
if (subject == null)
throw new ServiceException("文章" + id + "不存在");
return subject;
}
public List getHotSubjects() {
return this.articleDao.getHotSubjects();
}
public Page getPage(Subject subject, int pageNo, int pageSize) {
return this.articleDao.getPage(subject, pageNo, pageSize);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -