<?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.bootdo.system.dao.RegistrationDao">

    <select id="get" resultType="com.bootdo.system.domain.RegistrationDO">
		select `ID`,`DEVICE_NAME`,`DEVICE_CODE`,`DEVICE_UNIQE`,`DEVICE_TYPE`,`DEVICE_MAC`,`DEVICE_SN`,`DEVICE_PB`,`DEVICE_PORT`,`DEVICE_ORDER`,`DEVICE_ASSET_NUM`,`DEVICE_NET_FLAG`,`DEVICE_UPLOAD`,`DEVICE_RESULT`,`DEVICE_REGTIME`,`DEVICE_UPDTIME` from device_registration where ID = #{value}
	</select>

    <select id="list" resultType="com.bootdo.system.domain.RegistrationDO">
        select
        `ID`,`DEVICE_NAME`,`DEVICE_CODE`,`DEVICE_UNIQE`,`DEVICE_TYPE`,`DEVICE_MAC`,`DEVICE_SN`,`DEVICE_PB`,`DEVICE_PORT`,`DEVICE_ORDER`,`DEVICE_ASSET_NUM`,`DEVICE_NET_FLAG`,`DEVICE_UPLOAD`,`DEVICE_RESULT`,`DEVICE_REGTIME`,`DEVICE_UPDTIME`
        from device_registration
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="deviceName != null and deviceName != ''">and DEVICE_NAME = #{deviceName}</if>
            <if test="deviceCode != null and deviceCode != ''">and DEVICE_CODE = #{deviceCode}</if>
            <if test="deviceUniqe != null and deviceUniqe != ''">and DEVICE_UNIQE = #{deviceUniqe}</if>
            <if test="deviceType != null and deviceType != ''">and DEVICE_TYPE = #{deviceType}</if>
            <if test="deviceMac != null and deviceMac != ''">and DEVICE_MAC = #{deviceMac}</if>
            <if test="deviceSn != null and deviceSn != ''">and DEVICE_SN = #{deviceSn}</if>
            <if test="devicePb != null and devicePb != ''">and DEVICE_PB = #{devicePb}</if>
            <if test="devicePort != null and devicePort != ''">and DEVICE_PORT = #{devicePort}</if>
            <if test="deviceOrder != null and deviceOrder != ''">and DEVICE_ORDER = #{deviceOrder}</if>
            <if test="deviceAssetNum != null and deviceAssetNum != ''">and DEVICE_ASSET_NUM = #{deviceAssetNum}</if>
            <if test="deviceNetFlag != null and deviceNetFlag != ''">and DEVICE_NET_FLAG = #{deviceNetFlag}</if>
            <if test="deviceUpload != null and deviceUpload != ''">and DEVICE_UPLOAD = #{deviceUpload}</if>
            <if test="deviceResult != null and deviceResult != ''">and DEVICE_RESULT = #{deviceResult}</if>
            <if test="deviceRegtime != null and deviceRegtime != ''">and DEVICE_REGTIME = #{deviceRegtime}</if>
            <if test="deviceUpdtime != null and deviceUpdtime != ''">and DEVICE_UPDTIME = #{deviceUpdtime}</if>
        </where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
            <otherwise>
                order by ID desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="count" resultType="int">
        select count(*) from device_registration
        <where>
            <if test="id != null and id != ''">and ID = #{id}</if>
            <if test="deviceName != null and deviceName != ''">and DEVICE_NAME = #{deviceName}</if>
            <if test="deviceUniqe != null and deviceUniqe != ''">and DEVICE_UNIQE = #{deviceUniqe}</if>
            <if test="deviceType != null and deviceType != ''">and DEVICE_TYPE = #{deviceType}</if>
            <if test="deviceMac != null and deviceMac != ''">and DEVICE_MAC = #{deviceMac}</if>
            <if test="deviceSn != null and deviceSn != ''">and DEVICE_SN = #{deviceSn}</if>
            <if test="devicePb != null and devicePb != ''">and DEVICE_PB = #{devicePb}</if>
            <if test="devicePort != null and devicePort != ''">and DEVICE_PORT = #{devicePort}</if>
            <if test="deviceOrder != null and deviceOrder != ''">and DEVICE_ORDER = #{deviceOrder}</if>
            <if test="deviceAssetNum != null and deviceAssetNum != ''">and DEVICE_ASSET_NUM = #{deviceAssetNum}</if>
            <if test="deviceNetFlag != null and deviceNetFlag != ''">and DEVICE_NET_FLAG = #{deviceNetFlag}</if>
            <if test="deviceUpload != null and deviceUpload != ''">and DEVICE_UPLOAD = #{deviceUpload}</if>
            <if test="deviceRegtime != null and deviceRegtime != ''">and DEVICE_REGTIME = #{deviceRegtime}</if>
            <if test="deviceUpdtime != null and deviceUpdtime != ''">and DEVICE_UPDTIME = #{deviceUpdtime}</if>
        </where>
    </select>

    <insert id="save" parameterType="com.bootdo.system.domain.RegistrationDO" useGeneratedKeys="true" keyProperty="id">
		insert into device_registration
		(
			`DEVICE_NAME`,
			`DEVICE_CODE`,
			`DEVICE_UNIQE`, 
			`DEVICE_TYPE`, 
			`DEVICE_MAC`, 
			`DEVICE_SN`, 
			`DEVICE_PB`, 
			`DEVICE_PORT`, 
			`DEVICE_ORDER`, 
			`DEVICE_ASSET_NUM`, 
			`DEVICE_NET_FLAG`,
			`DEVICE_RESULT`,
			`DEVICE_UPLOAD`,
			`DEVICE_REGTIME`
		)
		values
		(
			#{deviceName},
			#{deviceCode},
			#{deviceUniqe}, 
			#{deviceType}, 
			#{deviceMac}, 
			#{deviceSn}, 
			#{devicePb}, 
			#{devicePort}, 
			#{deviceOrder}, 
			#{deviceAssetNum}, 
			#{deviceNetFlag},
			#{deviceResult},
			#{deviceUpload}, 
			now()
		)
	</insert>

    <update id="update" parameterType="com.bootdo.system.domain.RegistrationDO">
        update device_registration
        <set>
            <if test="deviceName != null">`DEVICE_NAME` = #{deviceName},</if>
            <if test="deviceUniqe != null">`DEVICE_UNIQE` = #{deviceUniqe},</if>
            <if test="deviceType != null">`DEVICE_TYPE` = #{deviceType},</if>
            <if test="deviceMac != null">`DEVICE_MAC` = #{deviceMac},</if>
            <if test="deviceSn != null">`DEVICE_SN` = #{deviceSn},</if>
            <if test="devicePb != null">`DEVICE_PB` = #{devicePb},</if>
            <if test="devicePort != null">`DEVICE_PORT` = #{devicePort},</if>
            <if test="deviceOrder != null">`DEVICE_ORDER` = #{deviceOrder},</if>
            <if test="deviceAssetNum != null">`DEVICE_ASSET_NUM` = #{deviceAssetNum},</if>
            <if test="deviceNetFlag != null">`DEVICE_NET_FLAG` = #{deviceNetFlag},</if>
            <if test="deviceUpload != null">`DEVICE_UPLOAD` = #{deviceUpload},</if>
            <if test="deviceRegtime != null">`DEVICE_REGTIME` = #{deviceRegtime},</if>
            <if test="deviceUpdtime != null">`DEVICE_UPDTIME` = #{deviceUpdtime}</if>
        </set>
        where ID = #{id}
    </update>

    <delete id="remove">
		delete from device_registration where ID = #{value}
	</delete>

    <delete id="batchRemove">
        delete from device_registration where ID in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>