package com.luozhihui.project.mapper;
import com.luozhihui.project.entity.Car;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

public interface CarShowMapper {
    // 查询所有车辆信息
    @Select("select car.*,`parking`.parkingName,`brand`.brand_name_ch from  `car` JOIN `parking` ON `car`.parking_id=`parking`.id JOIN `brand` ON `car`.brand_id=`brand`.id")
    List<Car> FindAllCar();
    //通过id查询车辆
    @Select("select * from  `car` where `CarId`=#{CarId}")
    List<Car> FindCarById(String CarId);
    //增加车辆
    @Insert("insert into `car`(`CarModel`,`CarStatus`,`CarColour`,`CarContent`,`CarDayMoney`,`CarHoursMoney`,`CarLicense`,`CarPhoto`,`CarSecurityDeposit`,`parking_id`,`energy`,`emass`,`omass`,`km`,`brand_id`) VALUES(#{CarModel},#{CarStatus},#{CarColour},#{CarContent},#{CarDayMoney},#{CarHoursMoney},#{CarLicense},#{CarPhoto},#{CarSecurityDeposit},#{parking_id},#{energy},#{emass},#{omass},#{km},#{brand_id})")
    @Transactional
    void addCar(Car car);
    //通过carid删除用户信息
    @Delete("delete  from  `car` where `CarId`=#{CarId}")
    boolean DeleteCarById(String CarId);
    //通过id查询车辆信息
    @Select("select * from  `car` where `CarId`=#{CarId}")
    Car CarId(Integer CarId);
    //更新车辆信息
    @Update("UPDATE car SET CarModel = #{CarModel}, CarStatus = #{CarStatus}, CarColour = #{CarColour}, CarContent = #{CarContent}, CarDayMoney = #{CarDayMoney}, CarHoursMoney = #{CarHoursMoney}, CarLicense = #{CarLicense}, CarPhoto = #{CarPhoto}, CarSecurityDeposit = #{CarSecurityDeposit}, parking_id = #{parking_id}, energy = #{energy}, emass = #{emass}, omass = #{omass}, km = #{km}, brand_id = #{brand_id} where CarId = #{CarId}")
    void update(Car car);
    //查询车辆停车场
    @Select("SELECT car.CarId, car.CarLicense, car.CarModel, car.CarPhoto, car.energy, car.emass, car.omass, car.km, CarHoursMoney, CarDayMoney, brand_logo, parkingName " +
            "FROM car, brand, parking " +
            "WHERE parking.id = car.parking_id AND car.parking_id = #{parking_id} AND car.brand_id = brand.id AND car.CarStatus=1 " +
            "GROUP BY car.CarId")
    List<Map<String, Object>> findCarsByParkingId(@Param("parking_id") int parking_id);
}
