<?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.ztmap.project.zhny.device.mapper.TDeviceMapper">
    
    <resultMap type="TDevice" id="TDeviceResult">
        <result property="id"    column="id"    />
        <result property="sortId"    column="sort_id"    />
        <result property="devicetype"    column="devicetype"    />
        <result property="subdevicetype"    column="subdevicetype"    />
        <result property="area"    column="area"    />
        <result property="build"    column="build"    />
        <result property="floor"    column="floor"    />
        <result property="devicename"    column="devicename"    />
        <result property="isface"    column="isface"    />
        <result property="areaid"    column="areaid"    />
        <result property="mapid"    column="mapid"    />
        <result property="address"    column="address"    />
        <result property="x"    column="x"    />
        <result property="y"    column="y"    />
        <result property="z"    column="z"    />
        <result property="devicecode"    column="devicecode"    />
        <result property="devicemodal"    column="devicemodal"    />
        <result property="devicebrand"    column="devicebrand"    />
        <result property="devicesupplier"    column="devicesupplier"    />
        <result property="contactdetails"    column="contactdetails"    />
        <result property="ip"    column="ip"    />
        <result property="port"    column="port"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="rtspurl"    column="rtspurl"    />
        <result property="doorno"    column="doorno"    />
        <result property="online"    column="online"    />
        <result property="status"    column="status"    />
        <result property="alarm"    column="alarm"    />
        <result property="isenable"    column="isenable"    />
        <result property="purchasetime"    column="purchasetime"    />
        <result property="installationtime"    column="installationtime"    />
        <result property="effectivetime"    column="effectivetime"    />
        <result property="remark"    column="remark"    />
        <result property="ctime"    column="ctime"    />
        <result property="positiontype"    column="positiontype"    />
        <result property="overInsurance"    column="over_insurance"    />
        <result property="data"    column="data"    />
        <result property="imageUrl"    column="image_url"    />
    </resultMap>

    <sql id="selectTDeviceVo">
        select id, sort_id, devicetype, subdevicetype, area, build, floor, devicename, isface, areaid, mapid, address, x, y, z, devicecode, devicemodal, devicebrand, devicesupplier, contactdetails, ip, port, username, password, rtspurl, doorno, online, status, alarm, isenable, purchasetime, installationtime, effectivetime, remark, ctime, positiontype, over_insurance, data, image_url from t_device
    </sql>

    <select id="selectTDeviceList" parameterType="TDevice" resultMap="TDeviceResult">
        <include refid="selectTDeviceVo"/>
        <where>  
            <if test="sortId != null "> and sort_id = #{sortId}</if>
            <if test="devicetype != null "> and devicetype = #{devicetype}</if>
            <if test="subdevicetype != null "> and subdevicetype = #{subdevicetype}</if>
            <if test="area != null "> and area = #{area}</if>
            <if test="build != null "> and build = #{build}</if>
            <if test="floor != null "> and floor = #{floor}</if>
            <if test="devicename != null  and devicename != ''"> and devicename like concat('%', #{devicename}, '%')</if>
            <if test="isface != null "> and isface = #{isface}</if>
            <if test="areaid != null "> and areaid = #{areaid}</if>
            <if test="mapid != null  and mapid != ''"> and mapid = #{mapid}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="x != null "> and x = #{x}</if>
            <if test="y != null "> and y = #{y}</if>
            <if test="z != null "> and z = #{z}</if>
            <if test="devicecode != null  and devicecode != ''"> and devicecode = #{devicecode}</if>
            <if test="devicemodal != null  and devicemodal != ''"> and devicemodal = #{devicemodal}</if>
            <if test="devicebrand != null  and devicebrand != ''"> and devicebrand = #{devicebrand}</if>
            <if test="devicesupplier != null  and devicesupplier != ''"> and devicesupplier = #{devicesupplier}</if>
            <if test="contactdetails != null  and contactdetails != ''"> and contactdetails = #{contactdetails}</if>
            <if test="ip != null  and ip != ''"> and ip = #{ip}</if>
            <if test="port != null "> and port = #{port}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="rtspurl != null  and rtspurl != ''"> and rtspurl = #{rtspurl}</if>
            <if test="doorno != null "> and doorno = #{doorno}</if>
            <if test="online != null "> and online = #{online}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="alarm != null "> and alarm = #{alarm}</if>
            <if test="isenable != null "> and isenable = #{isenable}</if>
            <if test="purchasetime != null "> and purchasetime = #{purchasetime}</if>
            <if test="installationtime != null "> and installationtime = #{installationtime}</if>
            <if test="effectivetime != null "> and effectivetime = #{effectivetime}</if>
            <if test="ctime != null "> and ctime = #{ctime}</if>
            <if test="positiontype != null "> and positiontype = #{positiontype}</if>
            <if test="overInsurance != null  and overInsurance != ''"> and over_insurance = #{overInsurance}</if>
            <if test="data != null  and data != ''"> and data = #{data}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
        </where>
    </select>
    
    <select id="selectTDeviceById" parameterType="Long" resultMap="TDeviceResult">
        <include refid="selectTDeviceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTDevice" parameterType="TDevice" useGeneratedKeys="true" keyProperty="id">
        insert into t_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sortId != null">sort_id,</if>
            <if test="devicetype != null">devicetype,</if>
            <if test="subdevicetype != null">subdevicetype,</if>
            <if test="area != null">area,</if>
            <if test="build != null">build,</if>
            <if test="floor != null">floor,</if>
            <if test="devicename != null">devicename,</if>
            <if test="isface != null">isface,</if>
            <if test="areaid != null">areaid,</if>
            <if test="mapid != null">mapid,</if>
            <if test="address != null">address,</if>
            <if test="x != null">x,</if>
            <if test="y != null">y,</if>
            <if test="z != null">z,</if>
            <if test="devicecode != null">devicecode,</if>
            <if test="devicemodal != null">devicemodal,</if>
            <if test="devicebrand != null">devicebrand,</if>
            <if test="devicesupplier != null">devicesupplier,</if>
            <if test="contactdetails != null">contactdetails,</if>
            <if test="ip != null">ip,</if>
            <if test="port != null">port,</if>
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="rtspurl != null">rtspurl,</if>
            <if test="doorno != null">doorno,</if>
            <if test="online != null">online,</if>
            <if test="status != null">status,</if>
            <if test="alarm != null">alarm,</if>
            <if test="isenable != null">isenable,</if>
            <if test="purchasetime != null">purchasetime,</if>
            <if test="installationtime != null">installationtime,</if>
            <if test="effectivetime != null">effectivetime,</if>
            <if test="remark != null">remark,</if>
            <if test="ctime != null">ctime,</if>
            <if test="positiontype != null">positiontype,</if>
            <if test="overInsurance != null">over_insurance,</if>
            <if test="data != null">data,</if>
            <if test="imageUrl != null">image_url,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sortId != null">#{sortId},</if>
            <if test="devicetype != null">#{devicetype},</if>
            <if test="subdevicetype != null">#{subdevicetype},</if>
            <if test="area != null">#{area},</if>
            <if test="build != null">#{build},</if>
            <if test="floor != null">#{floor},</if>
            <if test="devicename != null">#{devicename},</if>
            <if test="isface != null">#{isface},</if>
            <if test="areaid != null">#{areaid},</if>
            <if test="mapid != null">#{mapid},</if>
            <if test="address != null">#{address},</if>
            <if test="x != null">#{x},</if>
            <if test="y != null">#{y},</if>
            <if test="z != null">#{z},</if>
            <if test="devicecode != null">#{devicecode},</if>
            <if test="devicemodal != null">#{devicemodal},</if>
            <if test="devicebrand != null">#{devicebrand},</if>
            <if test="devicesupplier != null">#{devicesupplier},</if>
            <if test="contactdetails != null">#{contactdetails},</if>
            <if test="ip != null">#{ip},</if>
            <if test="port != null">#{port},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="rtspurl != null">#{rtspurl},</if>
            <if test="doorno != null">#{doorno},</if>
            <if test="online != null">#{online},</if>
            <if test="status != null">#{status},</if>
            <if test="alarm != null">#{alarm},</if>
            <if test="isenable != null">#{isenable},</if>
            <if test="purchasetime != null">#{purchasetime},</if>
            <if test="installationtime != null">#{installationtime},</if>
            <if test="effectivetime != null">#{effectivetime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="ctime != null">#{ctime},</if>
            <if test="positiontype != null">#{positiontype},</if>
            <if test="overInsurance != null">#{overInsurance},</if>
            <if test="data != null">#{data},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
         </trim>
    </insert>

    <update id="updateTDevice" parameterType="TDevice">
        update t_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="sortId != null">sort_id = #{sortId},</if>
            <if test="devicetype != null">devicetype = #{devicetype},</if>
            <if test="subdevicetype != null">subdevicetype = #{subdevicetype},</if>
            <if test="area != null">area = #{area},</if>
            <if test="build != null">build = #{build},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="devicename != null">devicename = #{devicename},</if>
            <if test="isface != null">isface = #{isface},</if>
            <if test="areaid != null">areaid = #{areaid},</if>
            <if test="mapid != null">mapid = #{mapid},</if>
            <if test="address != null">address = #{address},</if>
            <if test="x != null">x = #{x},</if>
            <if test="y != null">y = #{y},</if>
            <if test="z != null">z = #{z},</if>
            <if test="devicecode != null">devicecode = #{devicecode},</if>
            <if test="devicemodal != null">devicemodal = #{devicemodal},</if>
            <if test="devicebrand != null">devicebrand = #{devicebrand},</if>
            <if test="devicesupplier != null">devicesupplier = #{devicesupplier},</if>
            <if test="contactdetails != null">contactdetails = #{contactdetails},</if>
            <if test="ip != null">ip = #{ip},</if>
            <if test="port != null">port = #{port},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="rtspurl != null">rtspurl = #{rtspurl},</if>
            <if test="doorno != null">doorno = #{doorno},</if>
            <if test="online != null">online = #{online},</if>
            <if test="status != null">status = #{status},</if>
            <if test="alarm != null">alarm = #{alarm},</if>
            <if test="isenable != null">isenable = #{isenable},</if>
            <if test="purchasetime != null">purchasetime = #{purchasetime},</if>
            <if test="installationtime != null">installationtime = #{installationtime},</if>
            <if test="effectivetime != null">effectivetime = #{effectivetime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="ctime != null">ctime = #{ctime},</if>
            <if test="positiontype != null">positiontype = #{positiontype},</if>
            <if test="overInsurance != null">over_insurance = #{overInsurance},</if>
            <if test="data != null">data = #{data},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTDeviceById" parameterType="Long">
        delete from t_device where id = #{id}
    </delete>

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

</mapper>