<?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.ho.filecenter.mapper.CameraMapper">

    <resultMap id="BaseResultMap" type="com.ho.filecenter.entity.Camera">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="groupId" column="group_id" jdbcType="INTEGER"/>
        <result property="stationId" column="station_id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="address" column="address" jdbcType="VARCHAR"/>
        <result property="appkey" column="appkey" jdbcType="VARCHAR"/>
        <result property="appSecret" column="app_secret" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="validateCode" column="validate_code" jdbcType="VARCHAR"/>
        <result property="deviceSerial" column="device_serial" jdbcType="VARCHAR"/>
        <result property="accessToken" column="access_token" jdbcType="VARCHAR"/>
        <result property="appTime" column="app_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,group_id,station_id,
        name,address,appkey,
        app_secret,code,validate_code,
        device_serial,access_token,app_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from camera
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="selectByCondition" resultType="com.ho.filecenter.entity.Camera">
        select
        <include refid="Base_Column_List"/>
        from camera
        <where>
            <if test="stationId != null">
                station_id = #{stationId}
            </if>
            <if test="name != null and name != ''">
                name LIKE concat('%',#{name},'%')
            </if>
        </where>
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from camera
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByIds">
        delete
        from camera
        <where>
            <if test="ids != null and ids.size() != 0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.Camera"
            useGeneratedKeys="true">
        insert into camera
        ( id, group_id, station_id
        , name, address, appkey
        , app_secret, code, validate_code
        , device_serial, access_token, app_time)
        values ( #{id,jdbcType=INTEGER}, #{groupId,jdbcType=INTEGER}, #{stationId,jdbcType=INTEGER}
               , #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{appkey,jdbcType=VARCHAR}
               , #{appSecret,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{validateCode,jdbcType=VARCHAR}
               , #{deviceSerial,jdbcType=VARCHAR}, #{accessToken,jdbcType=VARCHAR}, #{appTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.Camera"
            useGeneratedKeys="true">
        insert into camera
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="stationId != null">station_id,</if>
            <if test="name != null">name,</if>
            <if test="address != null">address,</if>
            <if test="appkey != null">appkey,</if>
            <if test="appSecret != null">app_secret,</if>
            <if test="code != null">code,</if>
            <if test="validateCode != null">validate_code,</if>
            <if test="deviceSerial != null">device_serial,</if>
            <if test="accessToken != null">access_token,</if>
            <if test="appTime != null">app_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=INTEGER},</if>
            <if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
            <if test="stationId != null">#{stationId,jdbcType=INTEGER},</if>
            <if test="name != null">#{name,jdbcType=VARCHAR},</if>
            <if test="address != null">#{address,jdbcType=VARCHAR},</if>
            <if test="appkey != null">#{appkey,jdbcType=VARCHAR},</if>
            <if test="appSecret != null">#{appSecret,jdbcType=VARCHAR},</if>
            <if test="code != null">#{code,jdbcType=VARCHAR},</if>
            <if test="validateCode != null">#{validateCode,jdbcType=VARCHAR},</if>
            <if test="deviceSerial != null">#{deviceSerial,jdbcType=VARCHAR},</if>
            <if test="accessToken != null">#{accessToken,jdbcType=VARCHAR},</if>
            <if test="appTime != null">#{appTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.Camera">
        update camera
        <set>
            <if test="groupId != null">
                group_id = #{groupId,jdbcType=INTEGER},
            </if>
            <if test="stationId != null">
                station_id = #{stationId,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                address = #{address,jdbcType=VARCHAR},
            </if>
            <if test="appkey != null">
                appkey = #{appkey,jdbcType=VARCHAR},
            </if>
            <if test="appSecret != null">
                app_secret = #{appSecret,jdbcType=VARCHAR},
            </if>
            <if test="code != null">
                code = #{code,jdbcType=VARCHAR},
            </if>
            <if test="validateCode != null">
                validate_code = #{validateCode,jdbcType=VARCHAR},
            </if>
            <if test="deviceSerial != null">
                device_serial = #{deviceSerial,jdbcType=VARCHAR},
            </if>
            <if test="accessToken != null">
                access_token = #{accessToken,jdbcType=VARCHAR},
            </if>
            <if test="appTime != null">
                app_time = #{appTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.Camera">
        update camera
        set group_id      = #{groupId,jdbcType=INTEGER},
            station_id    = #{stationId,jdbcType=INTEGER},
            name          = #{name,jdbcType=VARCHAR},
            address       = #{address,jdbcType=VARCHAR},
            appkey        = #{appkey,jdbcType=VARCHAR},
            app_secret    = #{appSecret,jdbcType=VARCHAR},
            code          = #{code,jdbcType=VARCHAR},
            validate_code = #{validateCode,jdbcType=VARCHAR},
            device_serial = #{deviceSerial,jdbcType=VARCHAR},
            access_token  = #{accessToken,jdbcType=VARCHAR},
            app_time      = #{appTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>
