package com.luozhihui.project.mapper;
import com.luozhihui.project.entity.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderShowMapper {
    // 查询所有车辆信息r
    @Select("SELECT `order`.*, `car`.CarModel, `car`.CarLicense, `user`.UserName " +
            "FROM `order` " +
            "JOIN car ON `order`.CarId = `car`.CarId " +
            "JOIN user ON `order`.UserId = `user`.UserId")
    List<Order> FindAllOrder();
    //查询所有订单信息
    @Select("SELECT `OrderId` , `OrderMoney` ,`Mode` , `OrderStatus`,"
            +" `InTime`, `car`.CarModel ,`car`.CarLicense,`user`.UserName  FROM `order` "
            +"JOIN `car` ON `car`.CarId=`order`.CarId "
            +"JOIN `user` ON `user`.UserId=`order`.UserId"
            +" ORDER BY `OrderId` DESC LIMIT 16")
    List<Order> GetOrder();
//    @Select("select * from  `order` )
//@Select("SELECT `OrderId` , `InPicture`,`OutPicture`,`OrderMoney` ,`Mode` , `OrderStatus`,`car`.CarDayMoney,car.CarHoursMoney, `order`.OutTime,`order`.`CarId` ,`order`.UserId,`InTime`,`car`.CarModel,`order`.`PactId` ,`car`.CarLicense,`user`.UserName  FROM `order` "
//        +"JOIN `car` ON `car`.CarId=`order`.CarId "
//        +"JOIN `user` ON `user`.UserId=`order`.UserId"
//        +" Where `order`.`UserId`=#{UserId}  ORDER BY `OrderId` ")
//List<Order> FindOrderById(String userId);
@Select("SELECT `OrderId` , `InPicture`,`OutPicture`,`OrderMoney` ,`Mode` , `OrderStatus`,`car`.CarDayMoney,car.CarHoursMoney, `order`.OutTime,`order`.`CarId` ,`order`.UserId,`InTime`,`car`.CarModel,`order`.`PactId` ,`car`.CarLicense,`user`.UserName  FROM `order` "
        +"JOIN `car` ON `car`.CarId=`order`.CarId "
        +"JOIN `user` ON `user`.UserId=`order`.UserId"
        +" Where `order`.`UserId`=#{userId}  ORDER BY `OrderId` LIMIT #{pageNum}, #{pageSize}")
List<Order> findOrdersByUserId(@Param("userId") Integer userId, @Param("pageNum") int pageNum, @Param("pageSize") int pageSize);
    @Delete("delete  from  `order` where `OrderId`=#{OrderId}")
    boolean DeleteOrderById(String orderId);
//    通过orderid查询
    @Select("select * from  `order` where `OrderId`=#{OrderId}")
    Order OrderId(Integer OrderId);
    @Update("UPDATE `order` SET OrderMoney = #{OrderMoney}, OrderStatus = #{OrderStatus} where OrderId = #{OrderId}")
    void update(Order order);
    @Select(" SELECT COUNT(*) FROM `order` WHERE `userId` = #{userId}")
    int countOrdersByUserId(String userId);
}
