package com.ruoyi.xq.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.xq.domain.User;
import com.ruoyi.xq.domain.UserChatRecord;
import com.ruoyi.xq.dto.app.im.ImMessageDTO;
import com.ruoyi.xq.mapper.UserChatRecordMapper;
import com.ruoyi.xq.service.UserChatRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 聊天记录Service业务层处理
 *
 * @author 77
 * @date 2024-03-26
 */
@Service
public class UserChatRecordServiceImpl extends ServiceImpl<UserChatRecordMapper,UserChatRecord> implements UserChatRecordService {
    @Override
    public UserChatRecord saveRecord(User fromUser, User toUser, ImMessageDTO message) {
        UserChatRecord userChatRecord = new UserChatRecord();
        userChatRecord.setFromUid(fromUser.getId());
        userChatRecord.setFromUsercode(fromUser.getUsercode());
        userChatRecord.setToUid(toUser.getId());
        userChatRecord.setToUsercode(toUser.getUsercode());
        userChatRecord.setContent(message.getContent());
        userChatRecord.setType(message.getType());
        userChatRecord.setCreateTime(LocalDateTime.now());
        this.save(userChatRecord);
        return userChatRecord;
    }
}
