package com.muyu.fault.domain;

import com.muyu.fault.domain.message.Message;
import lombok.Data;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @className: MessageDao  ️✈️
 * @author: Yang 鹏  🦅
 * @date: 2024/9/23 20:58 ⏰
 * @Version: 1.0
 * @description:
 */
@Data
public class MessageDao {
    private Connection connection;

    public MessageDao(Connection connection){
        this.connection=connection;
    }

    public void sendMessage(Message message) throws Exception{
        String sql="INSERT INTO `eight`.`car_fault_message` (`id`, `sender`, `receiver`, `content`, `status`, `create_time`, `user_id`) " +
                "VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
        try(PreparedStatement pstmt=connection.prepareStatement(sql)){
            pstmt.setString(1, message.getContent());
            pstmt.setString(2, message.getSender());
            pstmt.setString(3, message.getReceiver());
            pstmt.setObject(4, message.getCreateTime());
            pstmt.executeUpdate();
        }


    }
}
