package com.luozhihui.project.mapper;
import com.luozhihui.project.entity.Repair;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface RepairShowMapper {
    // 查询所有维修信息
    @Select("select `repair`.*,`car`.* from  `repair` INNER JOIN `car` ON `repair`.CarId=`car`.CarId")
    List<Repair> FindAllRepair();
    @Select("select * from  `repair` where RepairId = #{RepairId}")
    Repair FindRepairById(String RepairId);
//    新增维修信息
    @Insert("insert into `repair`(`CarId`,`RepairReason`,`RepairMoney`,`RepairStatus`) VALUES(#{CarId},#{RepairReason},#{RepairMoney},#{RepairStatus})")
    @Transactional
    void addRepair(Repair repair);

    //通过RepairId删除用户信息
    @Delete("delete  from  `repair` where `RepairId`=#{RepairId}")
    boolean DeleteRepairById(String CarId);
    //    更新车辆信息
    @Update("UPDATE repair SET RepairReason = #{RepairReason}, RepairMoney = #{RepairMoney}, RepairStatus = #{RepairStatus} where RepairId = #{RepairId}")
    void update(Repair repair);
    //更新维修车辆状态为2 修理中
    @Update("UPDATE `car` SET carStatus = 2 WHERE carId = #{carId}")
    void updateCarStatusToRepair(Integer carId);
    // 更新车辆状态为可用
    @Update("UPDATE `car` SET carStatus = 0 WHERE carId = #{carId}")
    void updateCarStatusToAvailable(int carId);
}
