<?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.SearchDao">

	<select id="get" resultType="com.bootdo.system.domain.SearchDO">
		select `ID`,`DEVICE_NAME`,`DEVICE_MAC`,`DEVICE_SN`,`REGTIME`,`RESULT`,`LOAD_UNIQE`,`NEW_UNIQE` from device_search where ID = #{value}
	</select>

	<select id="list" resultType="com.bootdo.system.domain.SearchDO">
		select `ID`,`DEVICE_NAME`,`DEVICE_MAC`,`DEVICE_SN`,`REGTIME`,`RESULT`,`LOAD_UNIQE`,`NEW_UNIQE` from device_search
        <where>  
		  		  <if test="id != null and id != ''"> and ID = #{id} </if>
		  		  <if test="deviceName != null and deviceName != ''"> and DEVICE_NAME = #{deviceName} </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="regtime != null and regtime != ''"> and REGTIME = #{regtime} </if>
		  		  <if test="result != null and result != ''"> and RESULT = #{result} </if>
		  		  <if test="loadUniqe != null and loadUniqe != ''"> and LOAD_UNIQE = #{loadUniqe} </if>
		  		  <if test="newUniqe != null and newUniqe != ''"> and NEW_UNIQE = #{newUniqe} </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_search
		 <where>  
		  		  <if test="id != null and id != ''"> and ID = #{id} </if>
		  		  <if test="deviceName != null and deviceName != ''"> and DEVICE_NAME = #{deviceName} </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="regtime != null and regtime != ''"> and REGTIME = #{regtime} </if>
		  		  <if test="result != null and result != ''"> and RESULT = #{result} </if>
		  		  <if test="loadUniqe != null and loadUniqe != ''"> and LOAD_UNIQE = #{loadUniqe} </if>
		  		  <if test="newUniqe != null and newUniqe != ''"> and NEW_UNIQE = #{newUniqe} </if>
		  		</where>
	</select>
	 
	<insert id="save" parameterType="com.bootdo.system.domain.SearchDO" useGeneratedKeys="true" keyProperty="id">
		insert into device_search
		(
			`DEVICE_NAME`, 
			`DEVICE_MAC`, 
			`DEVICE_SN`, 
			`REGTIME`, 
			`RESULT`, 
			`LOAD_UNIQE`, 
			`NEW_UNIQE`
		)
		values
		(
			#{deviceName}, 
			#{deviceMac}, 
			#{deviceSn}, 
			now(),
			#{result}, 
			#{loadUniqe}, 
			#{newUniqe}
		)
	</insert>
	 
	<update id="update" parameterType="com.bootdo.system.domain.SearchDO">
		update device_search 
		<set>
			<if test="deviceName != null">`DEVICE_NAME` = #{deviceName}, </if>
			<if test="deviceMac != null">`DEVICE_MAC` = #{deviceMac}, </if>
			<if test="deviceSn != null">`DEVICE_SN` = #{deviceSn}, </if>
			<if test="regtime != null">`REGTIME` = #{regtime}, </if>
			<if test="result != null">`RESULT` = #{result}, </if>
			<if test="loadUniqe != null">`LOAD_UNIQE` = #{loadUniqe}, </if>
			<if test="newUniqe != null">`NEW_UNIQE` = #{newUniqe}</if>
		</set>
		where ID = #{id}
	</update>
	
	<delete id="remove">
		delete from device_search where ID = #{value}
	</delete>
	
	<delete id="batchRemove">
		delete from device_search where ID in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>