<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.CameraInfoDAO">
    <resultMap id="CameraInfoMap" type="com.jpsoft.shinestar.modules.base.entity.CameraInfo">
        <id property="id" column="id_"/>
        <result property="deviceSerial" column="device_serial"/>
        <result property="channelNo" column="channel_no"/>
        <result property="deviceName" column="device_name"/>
        <result property="status" column="status_"/>
        <result property="validCode" column="valid_code"/>
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="deviceVersion" column="device_version"/>
        <result property="roomAddress" column="room_address"/>
        <result property="delFlag" column="del_flag"/>
        <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="picUrl" column="pic_url"/>
        <result property="classify" column="classify_"/>
        <result property="personId" column="person_id"/>
        <result property="orderId" column="order_id"/>
        <result property="account" column="account_"/>
        <result property="password" column="password_"/>
        <result property="contactPhone" column="contact_phone"/>
        <result property="platform" column="platform_"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CameraInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_camera_info
	    (id_,device_serial,channel_no,device_name,status_,valid_code,company_id,device_version,del_flag,
	    create_by,create_time,update_by,update_time,pic_url,room_address,classify_,person_id,order_id,
	    account_,password_,contact_phone,platform_)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{deviceSerial,jdbcType=VARCHAR}
			,#{channelNo,jdbcType= NUMERIC }
			,#{deviceName,jdbcType=VARCHAR}
			,#{status,jdbcType= NUMERIC }
			,#{validCode,jdbcType=VARCHAR}
			,#{companyId,jdbcType=VARCHAR}
			,#{deviceVersion,jdbcType=VARCHAR}
			,#{delFlag,jdbcType= NUMERIC }
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{picUrl,jdbcType=VARCHAR}
			,#{roomAddress,jdbcType=VARCHAR}
			,#{classify,jdbcType=VARCHAR}
			,#{personId,jdbcType= BIGINT}
			,#{orderId,jdbcType=VARCHAR}
			,#{account,jdbcType=VARCHAR}
			,#{password,jdbcType=VARCHAR}
			,#{contactPhone,jdbcType=VARCHAR}
			,#{platform,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_camera_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CameraInfo">
        update base_camera_info
        <set>
            <if test="deviceSerial!=null">
                device_serial=#{deviceSerial,jdbcType=VARCHAR},
            </if>
            <if test="channelNo!=null">
                channel_no=#{channelNo,jdbcType= NUMERIC },
            </if>
            <if test="deviceName!=null">
                device_name=#{deviceName,jdbcType=VARCHAR},
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType= NUMERIC },
            </if>
            <if test="validCode!=null">
                valid_code=#{validCode,jdbcType=VARCHAR},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="deviceVersion!=null">
                device_version=#{deviceVersion,jdbcType=VARCHAR},
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="picUrl!=null">
                pic_url=#{picUrl,jdbcType=VARCHAR},
            </if>
            <if test="roomAddress!=null">
                room_address=#{roomAddress,jdbcType=VARCHAR},
            </if>
            <if test="classify!=null">
                classify_=#{classify,jdbcType=VARCHAR},
            </if>
            <if test="personId!=null">
                person_id=#{personId,jdbcType=BIGINT},
            </if>
            <if test="orderId!=null">
                order_id=#{orderId,jdbcType=VARCHAR},
            </if>
            <if test="account!=null">
                account_=#{account,jdbcType=VARCHAR},
            </if>
            <if test="password!=null">
                password_=#{password,jdbcType=VARCHAR},
            </if>
            <if test="contactPhone!=null">
                contact_phone=#{contactPhone,jdbcType=VARCHAR},
            </if>
            <if test="platform!=null">
                platform_=#{platform,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="CameraInfoMap">
        select * from base_camera_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_camera_info where id_=#{0}
    </select>
    <select id="list" resultMap="CameraInfoMap">
        select * from base_camera_info where del_flag=0
    </select>
    <select id="findByPersonId" parameterType="Long" resultMap="CameraInfoMap">
        select info.* from base_camera_info  info  where info.del_flag=0   and ( info.person_id=#{0} or info.person_id=0)
    </select>
    <select id="findBySchoolId" resultMap="CameraInfoMap">
        select * from base_camera_info where del_flag=0 and company_id = #{0}
        order by create_time asc
    </select>
    <select id="search" parameterType="hashmap" resultMap="CameraInfoMap">
        <![CDATA[
			select a.*,b.name_ as company_name from base_camera_info a
            left join base_company_info b on a.company_id = b.id_
		]]>
        <where>
            a.del_flag=0
            <if test="searchParams.deviceSerial != null">
                and a.device_serial like #{searchParams.deviceSerial}
            </if>
            <if test="searchParams.deviceName != null">
                and a.device_name like #{searchParams.deviceName}
            </if>
            <if test="searchParams.status != null">
                and a.status_ like #{searchParams.status}
            </if>
            <if test="searchParams.deviceSerial != null">
                and a.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.roomAddress != null">
                and a.room_address like #{searchParams.roomAddress}
            </if>
            <if test="searchParams.companyId != null">
                and b.id_ = #{searchParams.companyId}
            </if>
            <if test="searchParams.companyCode != null">
                and b.code_ like #{searchParams.companyCode}
            </if>
            <if test="searchParams.classify!=null">
                and a.classify_ =  #{searchParams.classify}
            </if>
            <if test="searchParams.platform!=null">
                and a.platform_ = #{searchParams.platform}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>