<?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.TLpgVehicleInfoMapper">
    
    <resultMap type="TLpgVehicleInfo" id="TLpgVehicleInfoResult">
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="carNumber"    column="car_number"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="vehicleCode"    column="vehicle_code"    />
        <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="personLiable"    column="person_liable"    />
        <result property="onState"    column="on_state"    />
        <result property="vehicleUser"    column="vehicle_user"    />
        <result property="phone"    column="phone"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterpriseName"    />
    </resultMap>

    <sql id="selectTLpgVehicleInfoVo">
        select vehicle.vehicle_id, vehicle.station_name, vehicle.car_number, vehicle.beyond_enterprise_id, vehicle.vehicle_code, vehicle.car_num,
               vehicle.brand_model, vehicle.vehicle_type, vehicle.vehicle_load, vehicle.vehicle_size, vehicle.vehicle_limt, vehicle.vehicle_inspect,
               vehicle.person_liable, vehicle.on_state, vehicle.vehicle_user, vehicle.phone, vehicle.is_del, vehicle.remarks,enterprise.enterprise_name as enterpriseName
        from t_lpg_vehicle_info vehicle
        left join t_enterprise_info enterprise on vehicle.enterprise_id = enterprise.enterprise_id
    </sql>

    <select id="selectTLpgVehicleInfoList" parameterType="TLpgVehicleInfo" resultMap="TLpgVehicleInfoResult">
        <include refid="selectTLpgVehicleInfoVo"/>
        <where>  
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="carNumber != null  and carNumber != ''"> and car_number = #{carNumber}</if>
            <if test="beyondEnterpriseId != null "> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="vehicleCode != null  and vehicleCode != ''"> and vehicle_code = #{vehicleCode}</if>
            <if test="carNum != null  and carNum != ''"> and car_num like concat('%', #{carNum}, '%')</if>
            <if test="brandModel != null  and brandModel != ''"> and brand_model = #{brandModel}</if>
            <if test="vehicleType != null  and vehicleType != ''"> and vehicle_type = #{vehicleType}</if>
            <if test="vehicleLoad != null  and vehicleLoad != ''"> and vehicle_load = #{vehicleLoad}</if>
            <if test="vehicleSize != null  and vehicleSize != ''"> and vehicle_size = #{vehicleSize}</if>
            <if test="vehicleLimt != null  and vehicleLimt != ''"> and vehicle_limt = #{vehicleLimt}</if>
            <if test="vehicleInspect != null  and vehicleInspect != ''"> and vehicle_inspect = #{vehicleInspect}</if>
            <if test="personLiable != null  and personLiable != ''"> and person_liable like concat('%', #{personLiable}, '%')</if>
            <if test="onState != null  and onState != ''"> and on_state = #{onState}</if>
            <if test="vehicleUser != null "> and vehicle_user = #{vehicleUser}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="queryByCarNumsAndEnterpriseId" resultMap="TLpgVehicleInfoResult">
        <include refid="selectTLpgVehicleInfoVo"/>
        where vehicle.enterprise_id = #{enterpriseId} and vehicle.car_num in
            <foreach collection="carNums" index="i" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
    </select>

    <select id="selectTLpgVehicleInfoById" parameterType="Long" resultMap="TLpgVehicleInfoResult">
        <include refid="selectTLpgVehicleInfoVo"/>
        where vehicle_id = #{vehicleId}
    </select>

    <insert id="insertBatch" parameterType="list">

        insert into t_lpg_vehicle_info (station_name, car_number,vehicle_code,car_num,brand_model,vehicle_type,
        vehicle_load,vehicle_size,vehicle_limt,vehicle_inspect,person_liable,on_state,vehicle_user,
        phone,remarks,enterprise_id)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.stationName,jdbcType=VARCHAR}, #{item.carNumber}, #{item.vehicleCode,jdbcType=VARCHAR},
            #{item.carNum,jdbcType=VARCHAR}, #{item.brandModel,jdbcType=VARCHAR}, #{item.vehicleType},
            #{item.vehicleLoad},#{item.vehicleSize},#{item.vehicleLimt},#{item.vehicleInspect},
            #{item.personLiable},#{item.onState},#{item.vehicleUser},#{item.phone},#{item.remarks},#{item.enterpriseId})
        </foreach>
    </insert>

    <update id="updateBatch" parameterType="list">

        <foreach collection="list" item="item"  index="index" separator=";">
            UPDATE t_lpg_vehicle_info
            <set>
                station_name = #{item.stationName},
                car_number = #{item.carNumber},
                vehicle_code = #{item.vehicleCode},
                brand_model = #{item.brandModel},
                vehicle_type = #{item.vehicleType},
                vehicle_load = #{item.vehicleLoad},
                vehicle_size = #{item.vehicleSize},
                vehicle_limt = #{item.vehicleLimt},
                vehicle_inspect = #{item.vehicleInspect},
                person_liable = #{item.personLiable},
                on_state = #{item.onState},
                vehicle_user = #{item.vehicleUser},
                phone = #{item.phone},
                remarks = #{item.remarks}
            </set>
            WHERE car_num = #{item.carNum} and enterprise_id = #{item.enterpriseId}
        </foreach>
    </update>

    <insert id="insertTLpgVehicleInfo" parameterType="TLpgVehicleInfo" useGeneratedKeys="true" keyProperty="vehicleId">
        insert into t_lpg_vehicle_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationName != null">station_name,</if>
            <if test="carNumber != null">car_number,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="vehicleCode != null">vehicle_code,</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="personLiable != null">person_liable,</if>
            <if test="onState != null">on_state,</if>
            <if test="vehicleUser != null">vehicle_user,</if>
            <if test="phone != null">phone,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationName != null">#{stationName},</if>
            <if test="carNumber != null">#{carNumber},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="vehicleCode != null">#{vehicleCode},</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="personLiable != null">#{personLiable},</if>
            <if test="onState != null">#{onState},</if>
            <if test="vehicleUser != null">#{vehicleUser},</if>
            <if test="phone != null">#{phone},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
         </trim>
    </insert>

    <update id="updateTLpgVehicleInfo" parameterType="TLpgVehicleInfo">
        update t_lpg_vehicle_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="carNumber != null">car_number = #{carNumber},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="vehicleCode != null">vehicle_code = #{vehicleCode},</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="personLiable != null">person_liable = #{personLiable},</if>
            <if test="onState != null">on_state = #{onState},</if>
            <if test="vehicleUser != null">vehicle_user = #{vehicleUser},</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="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
        </trim>
        where vehicle_id = #{vehicleId}
    </update>

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


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