package com.ruoyi.cai.service.impl;

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

import java.time.LocalDateTime;

/**
 * 聊天记录Service业务层处理
 *
 * @author 77
 * @date 2024-01-09
 */
@RequiredArgsConstructor
@Service
public class UserChatRecordServiceImpl extends ServiceImpl<UserChatRecordMapper,UserChatRecord> implements UserChatRecordService {

    @Override
    public UserChatRecord saveRecord(User fromUser, User toUser,Long traceId, 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());
        userChatRecord.setTraceId(traceId);
        this.save(userChatRecord);
        return userChatRecord;
    }
}
