<?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.ruoyi.system.mapper.ProprietorCarMapper">
    
    <resultMap type="ProprietorCar" id="ProprietorCarResult">
        <result property="carId"    column="car_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="plateNumber"    column="plate_number"    />
        <result property="vehicleBrand"    column="vehicle_brand"    />
        <result property="vehicleType"    column="vehicle_type"    />
        <result property="vehicleColour"    column="vehicle_colour"    />
        <result property="engineNumber"    column="engine_number"    />
        <result property="identificationNumber"    column="identification_number"    />
        <result property="registrationDate"    column="registration_date"    />
        <result property="issueDate"    column="issue_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProprietorCarVo">
        select car_id, user_id, user_name, plate_number, vehicle_brand, vehicle_type, vehicle_colour, engine_number, identification_number, registration_date, issue_date, create_by, create_time, update_by, update_time, remark from proprietor_car
    </sql>

    <select id="selectProprietorCarList" parameterType="ProprietorCar" resultMap="ProprietorCarResult">
        <include refid="selectProprietorCarVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="plateNumber != null  and plateNumber != ''"> and plate_number = #{plateNumber}</if>
            <if test="vehicleBrand != null  and vehicleBrand != ''"> and vehicle_brand = #{vehicleBrand}</if>
            <if test="vehicleType != null  and vehicleType != ''"> and vehicle_type = #{vehicleType}</if>
            <if test="vehicleColour != null  and vehicleColour != ''"> and vehicle_colour = #{vehicleColour}</if>
            <if test="engineNumber != null  and engineNumber != ''"> and engine_number = #{engineNumber}</if>
            <if test="identificationNumber != null  and identificationNumber != ''"> and identification_number = #{identificationNumber}</if>
            <if test="registrationDate != null  and registrationDate != ''"> and registration_date = #{registrationDate}</if>
            <if test="issueDate != null  and issueDate != ''"> and issue_date = #{issueDate}</if>
        </where>
    </select>
    
    <select id="selectProprietorCarByCarId" parameterType="Long" resultMap="ProprietorCarResult">
        <include refid="selectProprietorCarVo"/>
        where car_id = #{carId}
    </select>

    <insert id="insertProprietorCar" parameterType="ProprietorCar" useGeneratedKeys="true" keyProperty="carId">
        insert into proprietor_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="plateNumber != null and plateNumber != ''">plate_number,</if>
            <if test="vehicleBrand != null">vehicle_brand,</if>
            <if test="vehicleType != null">vehicle_type,</if>
            <if test="vehicleColour != null">vehicle_colour,</if>
            <if test="engineNumber != null">engine_number,</if>
            <if test="identificationNumber != null">identification_number,</if>
            <if test="registrationDate != null">registration_date,</if>
            <if test="issueDate != null">issue_date,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="plateNumber != null and plateNumber != ''">#{plateNumber},</if>
            <if test="vehicleBrand != null">#{vehicleBrand},</if>
            <if test="vehicleType != null">#{vehicleType},</if>
            <if test="vehicleColour != null">#{vehicleColour},</if>
            <if test="engineNumber != null">#{engineNumber},</if>
            <if test="identificationNumber != null">#{identificationNumber},</if>
            <if test="registrationDate != null">#{registrationDate},</if>
            <if test="issueDate != null">#{issueDate},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProprietorCar" parameterType="ProprietorCar">
        update proprietor_car
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="plateNumber != null and plateNumber != ''">plate_number = #{plateNumber},</if>
            <if test="vehicleBrand != null">vehicle_brand = #{vehicleBrand},</if>
            <if test="vehicleType != null">vehicle_type = #{vehicleType},</if>
            <if test="vehicleColour != null">vehicle_colour = #{vehicleColour},</if>
            <if test="engineNumber != null">engine_number = #{engineNumber},</if>
            <if test="identificationNumber != null">identification_number = #{identificationNumber},</if>
            <if test="registrationDate != null">registration_date = #{registrationDate},</if>
            <if test="issueDate != null">issue_date = #{issueDate},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where car_id = #{carId}
    </update>

    <delete id="deleteProprietorCarByCarId" parameterType="Long">
        delete from proprietor_car where car_id = #{carId}
    </delete>

    <delete id="deleteProprietorCarByCarIds" parameterType="String">
        delete from proprietor_car where car_id in 
        <foreach item="carId" collection="array" open="(" separator="," close=")">
            #{carId}
        </foreach>
    </delete>
</mapper>