<?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.TVehicleInfoMapper">

    <resultMap type="TVehicleInfo" id="TVehicleInfoResult">
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="carNum"    column="car_num"    />
        <result property="brandModel"    column="brand_model"    />
        <result property="vehicleType"    column="vehicle_type"    />
        <result property="vehicleLoad"    column="vehicle_load"    />
        <result property="vehicleSize"    column="vehicle_size"    />
        <result property="vehicleLimt"    column="vehicle_limt"    />
        <result property="vehicleInspect"    column="vehicle_inspect"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="personLiable"    column="person_liable"    />
        <result property="phone"    column="phone"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="beyondEnterpriseName"    column="enterprise_name"    />
        <result property="siteStationName"    column="site_station_name"    />
        <result property="carNumber"    column="car_number"    />
        <result property="onState"    column="on_state"    />
        <result property="vehicleUserId"    column="vehicle_uiser_id"    />
        <result property="stationId"    column="stationId"    />
        <result property="stationName"    column="station_name"    />
    </resultMap>

    <sql id="selectTVehicleInfoVo">
        select vehicle_id, car_number,car_num, brand_model, vehicle_type, vehicle_load, vehicle_size, vehicle_limt, vehicle_inspect, beyond_enterprise_id, person_liable, phone, is_del,on_state, remarks from t_vehicle_info
    </sql>

    <select id="selectTVehicleInfoList" parameterType="TVehicleInfo" resultMap="TVehicleInfoResult">
        select a.*,b.enterprise_name,c.site_station_name,d.station_name
        from t_vehicle_info a
        left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        left join t_site_station_info c on c.site_station_id=a.station_id
        left join t_gas_storage_station_info d on d.station_id=a.stationId
        <where>
            <if test="carNum != null  and carNum != ''"> and car_num like concat('%', #{carNum}, '%') </if>
            <if test="brandModel != null  and brandModel != ''"> and a.brand_model = #{brandModel}</if>
            <if test="vehicleType != null  and vehicleType != ''"> and a.vehicle_type = #{vehicleType}</if>
            <if test="vehicleLoad != null  and vehicleLoad != ''"> and a.vehicle_load = #{vehicleLoad}</if>
            <if test="vehicleSize != null  and vehicleSize != ''"> and a.vehicle_size = #{vehicleSize}</if>
            <if test="vehicleLimt != null  and vehicleLimt != ''"> and a.vehicle_limt = #{vehicleLimt}</if>
            <if test="vehicleInspect != null  and vehicleInspect != ''"> and a.vehicle_inspect = #{vehicleInspect}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and a.beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="personLiable != null  and personLiable != ''"> and a.person_liable = #{personLiable}</if>
            <if test="phone != null  and phone != ''"> and a.phone = #{phone}</if>
            <if test="isDel != null  and isDel != ''"> and a.is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and a.remarks = #{remarks}</if>
        </where>
        order by a.vehicle_id desc
    </select>

    <select id="selectTVehicleInfoById" parameterType="Long" resultMap="TVehicleInfoResult">
        select a.*,b.enterprise_name
        from t_vehicle_info a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        where vehicle_id = #{vehicleId}
    </select>

    <insert id="insertTVehicleInfo" parameterType="TVehicleInfo" useGeneratedKeys="true" keyProperty="vehicleId">
        insert into t_vehicle_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carNumber != null">car_number,</if>
            <if test="carNum != null">car_num,</if>
            <if test="brandModel != null">brand_model,</if>
            <if test="vehicleType != null">vehicle_type,</if>
            <if test="vehicleLoad != null">vehicle_load,</if>
            <if test="vehicleSize != null">vehicle_size,</if>
            <if test="vehicleLimt != null">vehicle_limt,</if>
            <if test="vehicleInspect != null">vehicle_inspect,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="personLiable != null">person_liable,</if>
            <if test="phone != null">phone,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="onState != null">on_state,</if>
            <if test="stationId != null">stationId,</if>

         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carNumber != null">#{carNumber},</if>
            <if test="carNum != null">#{carNum},</if>
            <if test="brandModel != null">#{brandModel},</if>
            <if test="vehicleType != null">#{vehicleType},</if>
            <if test="vehicleLoad != null">#{vehicleLoad},</if>
            <if test="vehicleSize != null">#{vehicleSize},</if>
            <if test="vehicleLimt != null">#{vehicleLimt},</if>
            <if test="vehicleInspect != null">#{vehicleInspect},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="personLiable != null">#{personLiable},</if>
            <if test="phone != null">#{phone},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="onState != null">#{onState},</if>
            <if test="stationId != null">#{stationId},</if>
         </trim>
    </insert>

    <update id="updateTVehicleInfo" parameterType="TVehicleInfo">
        update t_vehicle_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="carNumber != null">car_number = #{carNumber},</if>
            <if test="carNum != null">car_num = #{carNum},</if>
            <if test="brandModel != null">brand_model = #{brandModel},</if>
            <if test="vehicleType != null">vehicle_type = #{vehicleType},</if>
            <if test="vehicleLoad != null">vehicle_load = #{vehicleLoad},</if>
            <if test="vehicleSize != null">vehicle_size = #{vehicleSize},</if>
            <if test="vehicleLimt != null">vehicle_limt = #{vehicleLimt},</if>
            <if test="vehicleInspect != null">vehicle_inspect = #{vehicleInspect},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="personLiable != null">person_liable = #{personLiable},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="onState != null">on_state =#{onState},</if>
            <if test="onState != null">on_state =#{onState},</if>
            <if test="name != null">name =#{name},</if>
            <if test="vehicleUserId != null">vehicle_uiser_id =#{vehicleUserId},</if>
            <if test="stationId != null">stationId = #{stationId},</if>
        </trim>
        where vehicle_id = #{vehicleId}
    </update>

    <delete id="deleteTVehicleInfoById" parameterType="Long">
        delete from t_vehicle_info where vehicle_id = #{vehicleId}
    </delete>

    <delete id="deleteTVehicleInfoByIds" parameterType="String">
        delete from t_vehicle_info where vehicle_id in
        <foreach item="vehicleId" collection="array" open="(" separator="," close=")">
            #{vehicleId}
        </foreach>
    </delete>

    <!--微信小程序  车辆详细信息查询接口-->
    <select id="getTVehicleInfo" resultMap="TVehicleInfoResult">
       select a.*,b.enterprise_name
        from t_vehicle_info a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
        where a.car_number = #{carNumber}
    </select>
</mapper>
