package com.muyu.server.service.message;


import com.muyu.domain.message.Message;

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

/**
 * 数据访问层，使用JDBC进行基本的数据库操作
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.service.messageDao
 * @Project：cloud-server-8
 * @name：MessageDao
 * @Date：2024/9/23 9:42
 */

public class MessageDao {


    private Connection connection;


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

    public void sendMessage(Message message) throws Exception{
        String sql="INSERT INTO `xxy`.`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();
        }


    }
}
