<?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.jsowell.pile.mapper.PileCameraInfoMapper">
    <resultMap type="com.jsowell.pile.domain.PileCameraInfo" id="PileCameraInfoResult">
        <result property="id" column="id"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceIp" column="device_ip"/>
        <result property="deviceSn" column="device_sn"/>
        <result property="plateNumber" column="plate_number"/>
        <result property="parkingState" column="parking_state"/>
        <result property="zoneId" column="zone_id"/>
        <result property="zoneName" column="zone_name"/>
        <result property="color" column="color"/>
        <result property="plateType" column="plate_type"/>
        <result property="image" column="image"/>
        <result property="createTime" column="create_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectPileCameraInfoVo">
        select id,
               device_name,
               device_ip,
               device_sn,
               plate_number,
               parking_state,
               zone_id,
               zone_name,
               color,
               plate_type,
               image,
               create_time,
               del_flag
        from pile_camera_info
    </sql>

    <select id="selectPileCameraInfoList" parameterType="com.jsowell.pile.domain.PileCameraInfo" resultMap="PileCameraInfoResult">
        <include refid="selectPileCameraInfoVo"/>
        <where>
            <if test="deviceName != null  and deviceName != ''">
                and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="deviceIp != null  and deviceIp != ''">
                and device_ip = #{deviceIp}
            </if>
            <if test="deviceSn != null  and deviceSn != ''">
                and device_sn = #{deviceSn}
            </if>
            <if test="plateNumber != null  and plateNumber != ''">
                and plate_number = #{plateNumber}
            </if>
            <if test="parkingState != null  and parkingState != ''">
                and parking_state = #{parkingState}
            </if>
            <if test="zoneId != null">
                and zone_id = #{zoneId}
            </if>
            <if test="zoneName != null  and zoneName != ''">
                and zone_name like concat('%', #{zoneName}, '%')
            </if>
            <if test="color != null">
                and color = #{color}
            </if>
            <if test="plateType != null">
                and plate_type = #{plateType}
            </if>
            <if test="image != null  and image != ''">
                and image = #{image}
            </if>
        </where>
    </select>

    <select id="selectPileCameraInfoById" parameterType="Long" resultMap="PileCameraInfoResult">
        <include refid="selectPileCameraInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPileCameraInfo" parameterType="com.jsowell.pile.domain.PileCameraInfo" useGeneratedKeys="true" keyProperty="id">
        insert into pile_camera_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">
                device_name,
            </if>
            <if test="deviceIp != null">
                device_ip,
            </if>
            <if test="deviceSn != null">
                device_sn,
            </if>
            <if test="plateNumber != null">
                plate_number,
            </if>
            <if test="parkingState != null">
                parking_state,
            </if>
            <if test="zoneId != null">
                zone_id,
            </if>
            <if test="zoneName != null">
                zone_name,
            </if>
            <if test="color != null">
                color,
            </if>
            <if test="plateType != null">
                plate_type,
            </if>
            <if test="image != null">
                image,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">
                #{deviceName},
            </if>
            <if test="deviceIp != null">
                #{deviceIp},
            </if>
            <if test="deviceSn != null">
                #{deviceSn},
            </if>
            <if test="plateNumber != null">
                #{plateNumber},
            </if>
            <if test="parkingState != null">
                #{parkingState},
            </if>
            <if test="zoneId != null">
                #{zoneId},
            </if>
            <if test="zoneName != null">
                #{zoneName},
            </if>
            <if test="color != null">
                #{color},
            </if>
            <if test="plateType != null">
                #{plateType},
            </if>
            <if test="image != null">
                #{image},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="delFlag != null">
                #{delFlag},
            </if>
        </trim>
    </insert>

    <update id="updatePileCameraInfo" parameterType="com.jsowell.pile.domain.PileCameraInfo">
        update pile_camera_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceName != null">
                device_name = #{deviceName},
            </if>
            <if test="deviceIp != null">
                device_ip = #{deviceIp},
            </if>
            <if test="deviceSn != null">
                device_sn = #{deviceSn},
            </if>
            <if test="plateNumber != null">
                plate_number = #{plateNumber},
            </if>
            <if test="parkingState != null">
                parking_state = #{parkingState},
            </if>
            <if test="zoneId != null">
                zone_id = #{zoneId},
            </if>
            <if test="zoneName != null">
                zone_name = #{zoneName},
            </if>
            <if test="color != null">
                color = #{color},
            </if>
            <if test="plateType != null">
                plate_type = #{plateType},
            </if>
            <if test="image != null">
                image = #{image},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePileCameraInfoById" parameterType="Long">
        delete
        from pile_camera_info
        where id = #{id}
    </delete>

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