<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
	namespace="com.yeejoin.equipmanage.mapper.WlCarMileageMapper">
	<select id="totalMileage" resultType="Double">
		SELECT SUM(travel) FROM wl_car_mileage WHERE iot_code = #{iotCode}
	</select>

	<select id="page"
		resultType="com.yeejoin.equipmanage.common.entity.WlCarMileage">
		SELECT 
		wl_car_mileage.id,
		wl_car_mileage.iot_code,
		travel,
		date,
	    start_time,
		end_time,
		take_time,
		start_name,
		end_name,
		start_longitude,
		start_latitude,
		end_longitude,
		end_latitude,
		start_speed,
		end_speed,
		wl_car_mileage.create_date,
		date AS name
		FROM wl_car_mileage
		LEFT JOIN wl_car ON wl_car.iot_code = wl_car_mileage.iot_code
		<where>
			wl_car_mileage.travel >= #{mileageParameter}
			<if test="wlCarMileage.carId != null">
				AND wl_car.id = #{wlCarMileage.carId}
			</if>
			<if test="wlCarMileage.iotCode != null">
				AND wl_car_mileage.iot_code = #{wlCarMileage.iotCode}
			</if>
			<if test="wlCarMileage.filterDate != null">
				AND wl_car_mileage.date = #{wlCarMileage.filterDate}
			</if>
			<if test="wlCarMileage.complete">
				AND wl_car_mileage.start_time IS NOT NULL AND wl_car_mileage.end_time IS NOT NULL
			</if>
		</where>
	</select>
	<select id="list" resultType="com.yeejoin.equipmanage.common.entity.WlCarMileage">
		SELECT
			*
		FROM
			`wl_car_mileage` wcm
		WHERE
			wcm.date = #{date}
		  AND wcm.start_time IS NOT NULL
		  AND wcm.end_time IS NULL
	</select>
	<select id ="getTotalTravelByIotCodeAndDate" resultType="Double">
		SELECT SUM(travel)
		FROM wl_car_mileage
		WHERE date  LIKE concat('%',#{date},'%')
		AND
		iot_code = #{iotCode}
	</select>

	<select id ="getTotalTravelByIotCodeAndDateProd" resultType="Double">
		SELECT SUM(travel)
		FROM wl_car_mileage
		WHERE date  &lt;= #{startDate} AND date &gt;= #{endDate}
		AND
		iot_code = #{iotCode}
	</select>
</mapper>
