package com.muyu.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.domain.message.Message;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

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

/**
 * 消息dao
 *  * @className: MessageDao  ️✈️
 *  * @author: Yang 鹏  🦅
 *  * @date: 2024/9/23 20:58 ⏰
 *  * @Version: 1.0
 *  * @description:消息dao
 */
@TableName(value = "car_fault_message" , autoResultMap = true)
@SuperBuilder
@Builder
@NoArgsConstructor
@Data
@Tag(name = "消息模块")
public class MessageDao {
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(name = "消息id")
    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();
        }


    }
}
