<?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.weighbridge.mapper.DibangCarMapper">
    
    <resultMap type="DibangCar" id="DibangCarResult">
        <result property="carId"    column="car_id"    />
        <result property="carName"    column="car_name"    />
        <result property="plateNo"    column="plate_no"    />
        <result property="carBrand"    column="car_brand"    />
        <result property="carSpecs"    column="car_specs"    />
        <result property="createTime"    column="create_time"    />
        <result property="modifyTime"    column="modify_time"    />
    </resultMap>

    <sql id="selectDibangCarVo">
        select car_id, car_name, plate_no, car_brand, car_specs, create_time, modify_time from dibang_car
    </sql>

    <select id="selectDibangCarList" parameterType="DibangCar" resultMap="DibangCarResult">
        <include refid="selectDibangCarVo"/>
        <where>  
            <if test="carName != null  and carName != ''"> and car_name like concat('%', #{carName}, '%')</if>
            <if test="plateNo != null  and plateNo != ''"> and plate_no like concat('%', #{plateNo}, '%')</if>
            <if test="carBrand != null  and carBrand != ''"> and car_brand like concat('%', #{carBrand}, '%')</if>
            <if test="carSpecs != null  and carSpecs != ''"> and car_specs like concat('%', #{carSpecs}, '%')</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
        </where>
    </select>
    
    <select id="selectDibangCarByCarId" parameterType="String" resultMap="DibangCarResult">
        <include refid="selectDibangCarVo"/>
        where car_id = #{carId}
    </select>

    <select id="selectDibangCarByPlateNo" parameterType="String" resultMap="DibangCarResult">
        <include refid="selectDibangCarVo"/>
        where plate_po = #{plateNo}
    </select>
        
    <insert id="insertDibangCar" parameterType="DibangCar">
        insert into dibang_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carId != null">car_id,</if>
            <if test="carName != null">car_name,</if>
            <if test="plateNo != null">plate_no,</if>
            <if test="carBrand != null">car_brand,</if>
            <if test="carSpecs != null">car_specs,</if>
            <if test="createTime != null">create_time,</if>
            <if test="modifyTime != null">modify_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carId != null">#{carId},</if>
            <if test="carName != null">#{carName},</if>
            <if test="plateNo != null">#{plateNo},</if>
            <if test="carBrand != null">#{carBrand},</if>
            <if test="carSpecs != null">#{carSpecs},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="modifyTime != null">#{modifyTime},</if>
         </trim>
    </insert>

    <update id="updateDibangCar" parameterType="DibangCar">
        update dibang_car
        <trim prefix="SET" suffixOverrides=",">
            <if test="carName != null">car_name = #{carName},</if>
            <if test="plateNo != null">plate_no = #{plateNo},</if>
            <if test="carBrand != null">car_brand = #{carBrand},</if>
            <if test="carSpecs != null">car_specs = #{carSpecs},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
        </trim>
        where car_id = #{carId}
    </update>

    <delete id="deleteDibangCarByCarId" parameterType="String">
        delete from dibang_car where car_id = #{carId}
    </delete>

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