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

	<select id="get" resultType="com.bootdo.system.domain.QueryDO">
		select `ID`,`HANDLE`,`HANDLE_TYPE`,`IP`,`REGTIME`,`cost`,`RESULT`,`RESPONSE` from handle_query where ID = #{value}
	</select>

	<select id="list" resultType="com.bootdo.system.domain.QueryDO">
		select `ID`,`HANDLE`,`HANDLE_TYPE`,`IP`,`REGTIME`,`cost`,`RESULT`,`RESPONSE` from handle_query
        <where>  
		  		  <if test="id != null and id != ''"> and ID = #{id} </if>
		  		  <if test="handle != null and handle != ''"> and HANDLE = #{handle} </if>
		  		  <if test="handleType != null and handleType != ''"> and HANDLE_TYPE = #{handleType} </if>
		  		  <if test="ip != null and ip != ''"> and IP = #{ip} </if>
		  		  <if test="regtime != null and regtime != ''"> and REGTIME = #{regtime} </if>
		  		  <if test="cost != null and cost != ''"> and cost = #{cost} </if>
		  		  <if test="result != null and result != ''"> and RESULT = #{result} </if>
		  		  <if test="response != null and response != ''"> and RESPONSE = #{response} </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 handle_query
		 <where>  
		  		  <if test="id != null and id != ''"> and ID = #{id} </if>
		  		  <if test="handle != null and handle != ''"> and HANDLE = #{handle} </if>
		  		  <if test="handleType != null and handleType != ''"> and HANDLE_TYPE = #{handleType} </if>
		  		  <if test="ip != null and ip != ''"> and IP = #{ip} </if>
		  		  <if test="regtime != null and regtime != ''"> and REGTIME = #{regtime} </if>
		  		  <if test="cost != null and cost != ''"> and cost = #{cost} </if>
		  		  <if test="result != null and result != ''"> and RESULT = #{result} </if>
		  		  <if test="response != null and response != ''"> and RESPONSE = #{response} </if>
		  		</where>
	</select>
	 
	<insert id="save" parameterType="com.bootdo.system.domain.QueryDO" useGeneratedKeys="true" keyProperty="id">
		insert into handle_query
		(
			`HANDLE`, 
			`HANDLE_TYPE`, 
			`IP`, 
			`REGTIME`, 
			`cost`, 
			`RESULT`, 
			`RESPONSE`
		)
		values
		(
			#{handle}, 
			#{handleType}, 
			#{ip}, 
			#{regtime}, 
			#{cost}, 
			#{result}, 
			#{response}
		)
	</insert>
	 
	<update id="update" parameterType="com.bootdo.system.domain.QueryDO">
		update handle_query 
		<set>
			<if test="handle != null">`HANDLE` = #{handle}, </if>
			<if test="handleType != null">`HANDLE_TYPE` = #{handleType}, </if>
			<if test="ip != null">`IP` = #{ip}, </if>
			<if test="regtime != null">`REGTIME` = #{regtime}, </if>
			<if test="cost != null">`cost` = #{cost}, </if>
			<if test="result != null">`RESULT` = #{result}, </if>
			<if test="response != null">`RESPONSE` = #{response}</if>
		</set>
		where ID = #{id}
	</update>
	
	<delete id="remove">
		delete from handle_query where ID = #{value}
	</delete>
	
	<delete id="batchRemove">
		delete from handle_query where ID in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>