package com.salpa.subject.service.impl;

import com.github.pagehelper.PageHelper;
import com.salpa.common.utils.SecurityUtils;
import com.salpa.subject.domain.MonitorDocumentDiscussion;
import com.salpa.subject.mapper.DocumentDiscussionMapper;
import com.salpa.subject.service.DocumentDiscussionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DocumentDiscussionServiceImpl implements DocumentDiscussionService {

    @Autowired
    private DocumentDiscussionMapper documentDiscussionMapper;

    /**
     * 新增评论
     * @param monitorDocumentDiscussion
     * @return
     */
    @Override
    public int add(MonitorDocumentDiscussion monitorDocumentDiscussion) {

        return documentDiscussionMapper.add(monitorDocumentDiscussion);
    }
    /**
     * 获取评论列表
     * */
    @Override
    public List<MonitorDocumentDiscussion> getList(MonitorDocumentDiscussion monitorDocumentDiscussion) {
        PageHelper.startPage(monitorDocumentDiscussion.getPageNum(),monitorDocumentDiscussion.getPageSize());
        List<MonitorDocumentDiscussion> list = documentDiscussionMapper.getList(monitorDocumentDiscussion);
        for (MonitorDocumentDiscussion documentDiscussion : list) {
            documentDiscussion.setLoginUser(SecurityUtils.getLoginUser().getUser().getUserName());
        }
        return list;
    }
    /**
     * 删除评论
     * @author hzl
     * @param id
     * @return
     */
    @Override
    public int deleteComment(Integer id) {return documentDiscussionMapper.deleteComment(id);}
}
