package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.CommentMapper;
import com.gxwebsoft.shop.service.CommentService;
import com.gxwebsoft.shop.entity.Comment;
import com.gxwebsoft.shop.param.CommentParam;
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 2022-11-23 21:18:56
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

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

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

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

}
