diff --git a/src/main/java/com/service/NotesInfoCommentService.java b/src/main/java/com/service/NotesInfoCommentService.java new file mode 100644 index 0000000..51d120e --- /dev/null +++ b/src/main/java/com/service/NotesInfoCommentService.java @@ -0,0 +1,60 @@ +package com.example.service; + +import com.example.exception.CustomException; +import com.example.dao.NotesInfoCommentDao; +import org.springframework.stereotype.Service; +import com.example.entity.NotesInfoComment; +import com.example.vo.NotesInfoCommentVo; +import com.example.entity.Account; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@Service +public class NotesInfoCommentService { + + @Resource + private NotesInfoCommentDao notesInfoCommentDao; + + public NotesInfoComment add(NotesInfoComment commentInfo, HttpServletRequest request) { + Account user = (Account) request.getSession().getAttribute("user"); + if (user == null) { + throw new CustomException("1001", "请先登录!"); + } + commentInfo.setName(user.getName()); + commentInfo.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + notesInfoCommentDao.insertSelective(commentInfo); + return commentInfo; + } + + public void delete(Long id) { + notesInfoCommentDao.deleteByPrimaryKey(id); + } + + public void update(NotesInfoComment commentInfo) { + commentInfo.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + notesInfoCommentDao.updateByPrimaryKeySelective(commentInfo); + } + + public NotesInfoComment findById(Long id) { + return notesInfoCommentDao.selectByPrimaryKey(id); + } + + public List findAll() { + return notesInfoCommentDao.findAllVo(null); + } + + public PageInfo findPage(String name, Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum, pageSize); + List all = notesInfoCommentDao.findAllVo(name); + return PageInfo.of(all); + } + + public List findByForeignId (Long id) { + return notesInfoCommentDao.findByForeignId(id); + } +}