package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleCommentMapper;
import com.gxwebsoft.cms.service.ArticleCommentService;
import com.gxwebsoft.cms.entity.ArticleComment;
import com.gxwebsoft.cms.param.ArticleCommentParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章评论表Service实现
 *
 * @author 科技小王子
 * @since 2023-10-22 15:47:09
 */
@Service
public class ArticleCommentServiceImpl extends ServiceImpl<ArticleCommentMapper, ArticleComment> implements ArticleCommentService {

    @Override
    public PageResult<ArticleComment> pageRel(ArticleCommentParam param) {
        PageParam<ArticleComment, ArticleCommentParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<ArticleComment> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<ArticleComment> listRel(ArticleCommentParam param) {
        List<ArticleComment> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<ArticleComment, ArticleCommentParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public ArticleComment getByIdRel(Integer commentId) {
        ArticleCommentParam param = new ArticleCommentParam();
        param.setCommentId(commentId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
