package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.ChatConversationMapper;
import com.gxwebsoft.common.system.service.ChatConversationService;
import com.gxwebsoft.common.system.entity.ChatConversation;
import com.gxwebsoft.common.system.param.ChatConversationParam;
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 15:57:27
 */
@Service
public class ChatConversationServiceImpl extends ServiceImpl<ChatConversationMapper, ChatConversation> implements ChatConversationService {

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

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

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

}
