<?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.dcsoft.system.vehicle.mapper.CarParkItemMapper">

    <resultMap type="CarParkItem" id="CarParkItemResult">
        <result property="id"    column="id"    />
        <result property="equipmentId"    column="equipment_id"    />
        <result property="parkId"    column="park_id"    />
        <result property="way"    column="way"    />
        <result property="area"    column="area"    />
    </resultMap>

    <sql id="selectCarParkItemVo">
        select id, equipment_id, park_id, way,area from car_park_item
    </sql>

    <select id="selectCarParkItemList" parameterType="CarParkItem" resultMap="CarParkItemResult">
        <include refid="selectCarParkItemVo"/>
        <where>
            <if test="equipmentId != null "> and equipment_id = #{equipmentId}</if>
            <if test="parkId != null "> and park_id = #{parkId}</if>
            <if test="way != null  and way != ''"> and way = #{way}</if>
        </where>
    </select>

    <select id="selectCarParkItemById" parameterType="Long" resultMap="CarParkItemResult">
        <include refid="selectCarParkItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertCarParkItem" parameterType="CarParkItem">
        insert into car_park_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="equipmentId != null">equipment_id,</if>
            <if test="parkId != null">park_id,</if>
            <if test="way != null">way,</if>
            <if test="area != null">area,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="equipmentId != null">#{equipmentId},</if>
            <if test="parkId != null">#{parkId},</if>
            <if test="way != null">#{way},</if>
            <if test="area != null">#{area},</if>
         </trim>
    </insert>

    <update id="updateCarParkItem" parameterType="CarParkItem">
        update car_park_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="parkId != null">park_id = #{parkId},</if>
            <if test="way != null">way = #{way},</if>
            <if test="area != null">area = #{area},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCarParkItemById" parameterType="Long">
        delete from car_park_item where id = #{id}
    </delete>

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

    <delete id="deleteParkItemByParkId" parameterType="Long">
        delete from car_park_item where park_id = #{parkId}
    </delete>
</mapper>
