<?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.zehong.system.mapper.TVehicleUseRecordMapper">

    <resultMap type="TVehicleUseRecord" id="TVehicleUseRecordResult">
        <result property="vehicleUseRecordId"    column="vehicle_use_record_id"    />
        <result property="stationId"    column="station_id"    />
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="vehicleUserId"    column="vehicle_user_id"    />
        <result property="vehicleUseDate"    column="vehicle_use_date"    />
        <result property="vehicleReturnDate"    column="vehicle_return_date"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
        <result property="carNum"    column="car_num"    />
        <result property="siteStationName"    column="station_name"    />
        <result property="name"    column="nick_name"    />
        <result property="vehicleCode"    column="vehicle_code"    />

    </resultMap>

    <sql id="selectTVehicleUseRecordVo">
        select vehicle_use_record_id, station_id, vehicle_id, vehicle_user_id, vehicle_use_date, vehicle_return_date, create_time, update_time, is_del, remark from t_vehicle_use_record
    </sql>

    <select id="selectTVehicleUseRecordList" parameterType="TVehicleUseRecord" resultMap="TVehicleUseRecordResult">
        select a.vehicle_use_record_id, a.station_id, a.vehicle_id, a.vehicle_user_id, a.vehicle_use_date, a.vehicle_return_date, a.create_time, a.update_time, a.is_del, a.remark,
        b.station_name,c.car_number,c.car_num,d.name as nick_name
        from t_vehicle_use_record a
        left join t_gas_storage_station_info b on  a.station_id=b.station_id
        left join t_vehicle_info  c  on a.vehicle_id=c.vehicle_id
        left join t_practitioner_info d on a.vehicle_user_id=d.practitioner_id
        <where>
            <if test="stationId != null "> and a.station_id = #{stationId}</if>
            <if test="vehicleId != null "> and a.vehicle_id = #{vehicleId}</if>
            <if test="vehicleUserId != null "> and a.vehicle_user_id = #{vehicleUserId}</if>
            <if test="vehicleUseDate != null "> and a.vehicle_use_date = #{vehicleUseDate}</if>
            <if test="vehicleReturnDate != null "> and a.vehicle_return_date = #{vehicleReturnDate}</if>
            <if test="isDel != null  and isDel != ''"> and a.is_del = #{isDel}</if>
        </where>
        order by a.vehicle_use_record_id desc
    </select>

    <select id="selectTVehicleUseRecordById" parameterType="Long" resultMap="TVehicleUseRecordResult">
       select a.vehicle_use_record_id, a.station_id, a.vehicle_id, a.vehicle_user_id, a.vehicle_use_date, a.vehicle_return_date, a.create_time, a.update_time, a.is_del, a.remark,
        b.station_name,c.car_number as vehicle_code,c.car_num,d.name as nick_name
        from t_vehicle_use_record a
		left join t_vehicle_info  c  on a.vehicle_id=c.vehicle_id
        left join t_gas_storage_station_info b on  c.stationId=b.station_id
        left join t_practitioner_info d on a.vehicle_user_id=d.practitioner_id
        where a.vehicle_use_record_id = #{vehicleUseRecordId}
    </select>

    <insert id="insertTVehicleUseRecord" parameterType="TVehicleUseRecord" useGeneratedKeys="true" keyProperty="vehicleUseRecordId">
        insert into t_vehicle_use_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="vehicleUserId != null">vehicle_user_id,</if>
            <if test="vehicleUseDate != null">vehicle_use_date,</if>
            <if test="vehicleReturnDate != null">vehicle_return_date,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="vehicleUserId != null">#{vehicleUserId},</if>
            <if test="vehicleUseDate != null">#{vehicleUseDate},</if>
            <if test="vehicleReturnDate != null">#{vehicleReturnDate},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTVehicleUseRecord" parameterType="TVehicleUseRecord">
        update t_vehicle_use_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="vehicleId != null">vehicle_id = #{vehicleId},</if>
            <if test="vehicleUserId != null">vehicle_user_id = #{vehicleUserId},</if>
            <if test="vehicleUseDate != null">vehicle_use_date = #{vehicleUseDate},</if>
            <if test="vehicleReturnDate != null">vehicle_return_date = #{vehicleReturnDate},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where vehicle_use_record_id = #{vehicleUseRecordId}
    </update>

    <delete id="deleteTVehicleUseRecordById" parameterType="Long">
        delete from t_vehicle_use_record where vehicle_use_record_id = #{vehicleUseRecordId}
    </delete>

    <delete id="deleteTVehicleUseRecordByIds" parameterType="String">
        delete from t_vehicle_use_record where vehicle_use_record_id in
        <foreach item="vehicleUseRecordId" collection="array" open="(" separator="," close=")">
            #{vehicleUseRecordId}
        </foreach>
    </delete>
</mapper>
