<?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.ximai.mes.md.mapper.MdVehicleMapper">
    <resultMap type="MdVehicle" id="MdVehicleResult">
        <result property="vehicleId" column="vehicle_id"/>
        <result property="vehicleCode" column="vehicle_code"/>
        <result property="vehicleName" column="vehicle_name"/>
        <result property="licensePlate" column="license_plate"/>
        <result property="vehicleModel" column="vehicle_model"/>
        <result property="seating" column="seating"/>
        <result property="purchaseDate" column="purchase_date"/>
        <result property="inspectionDate" column="inspection_date"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <sql id="selectMdVehicleVo"> select vehicle_id, vehicle_code, vehicle_name, license_plate, vehicle_model, seating, purchase_date, inspection_date, remark, create_by, create_time, update_by, update_time from md_vehicle </sql>
    <select id="selectMdVehicleList" parameterType="MdVehicle" resultMap="MdVehicleResult">
        <include refid="selectMdVehicleVo"/>
        <where>
            <if test="vehicleName != null and vehicleName != ''"> and vehicle_name like concat('%', #{vehicleName}, '%')</if>
            <if test="licensePlate != null and licensePlate != ''"> and license_plate = #{licensePlate}</if>
            <if test="vehicleModel != null and vehicleModel != ''"> and vehicle_model = #{vehicleModel}</if>
            <if test="params.beginSeating != null and params.beginSeating != '' and params.endSeating != null and params.endSeating != ''"> and seating between #{params.beginSeating} and #{params.endSeating}</if>
            <if test="params.beginPurchaseDate != null and params.beginPurchaseDate != '' and params.endPurchaseDate != null and params.endPurchaseDate != ''"> and purchase_date between #{params.beginPurchaseDate} and #{params.endPurchaseDate}</if>
            <if test="params.beginInspectionDate != null and params.beginInspectionDate != '' and params.endInspectionDate != null and params.endInspectionDate != ''"> and inspection_date between #{params.beginInspectionDate} and #{params.endInspectionDate}</if>
        </where>
    </select>
    <select id="selectMdVehicleByVehicleId" parameterType="Long" resultMap="MdVehicleResult">
        <include refid="selectMdVehicleVo"/>
        where vehicle_id = #{vehicleId}
    </select>
    <insert id="insertMdVehicle" parameterType="MdVehicle" useGeneratedKeys="true" keyProperty="vehicleId">
        insert into md_vehicle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vehicleCode != null">vehicle_code,</if>
            <if test="vehicleName != null">vehicle_name,</if>
            <if test="licensePlate != null">license_plate,</if>
            <if test="vehicleModel != null">vehicle_model,</if>
            <if test="seating != null">seating,</if>
            <if test="purchaseDate != null">purchase_date,</if>
            <if test="inspectionDate != null">inspection_date,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vehicleCode != null">#{vehicleCode},</if>
            <if test="vehicleName != null">#{vehicleName},</if>
            <if test="licensePlate != null">#{licensePlate},</if>
            <if test="vehicleModel != null">#{vehicleModel},</if>
            <if test="seating != null">#{seating},</if>
            <if test="purchaseDate != null">#{purchaseDate},</if>
            <if test="inspectionDate != null">#{inspectionDate},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <update id="updateMdVehicle" parameterType="MdVehicle">
        update md_vehicle
        <trim prefix="SET" suffixOverrides=",">
            <if test="vehicleCode != null">vehicle_code = #{vehicleCode},</if>
            <if test="vehicleName != null">vehicle_name = #{vehicleName},</if>
            <if test="licensePlate != null">license_plate = #{licensePlate},</if>
            <if test="vehicleModel != null">vehicle_model = #{vehicleModel},</if>
            <if test="seating != null">seating = #{seating},</if>
            <if test="purchaseDate != null">purchase_date = #{purchaseDate},</if>
            <if test="inspectionDate != null">inspection_date = #{inspectionDate},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where vehicle_id = #{vehicleId}
    </update>
    <delete id="deleteMdVehicleByVehicleId" parameterType="Long"> delete from md_vehicle where vehicle_id = #{vehicleId} </delete>
    <delete id="deleteMdVehicleByVehicleIds" parameterType="String">
        delete from md_vehicle where vehicle_id in
        <foreach item="vehicleId" collection="array" open="(" separator="," close=")"> #{vehicleId} </foreach>
    </delete>
</mapper>
