package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ChatMessageMapper;
import com.gxwebsoft.shop.service.ChatMessageService;
import com.gxwebsoft.shop.entity.ChatMessage;
import com.gxwebsoft.shop.param.ChatMessageParam;
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 2024-04-27 16:08:04
 */
@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements ChatMessageService {

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

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

    @Override
    public ChatMessage getByIdRel(Integer id) {
        ChatMessageParam param = new ChatMessageParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
