<?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.cftech.sys.dao.MobileLogMapper">

	<resultMap id="resultMap" type="com.cftech.sys.model.MobileLog">
		<id column="id" property="id"/>
		<result column="type" property="type"/>
		<result column="create_date" property="createDate"/>
		<result column="remote_addr" property="remoteAddr"/>
		<result column="user_agent" property="userAgent"/>
		<result column="request_uri" property="requestUri"/>
		<result column="method" property="method"/>
		<result column="params" property="params"/>
		<result column="exception" property="exception"/>
		<result column="appid" property="appid"/>
	</resultMap>

	<sql id="sqlWhere">
		<if test="conds!=null">
			<trim prefix="WHERE" prefixOverrides="AND|OR">
				<foreach collection="conds.conds" index="index" item="cond">
					${cond.linkType}
					<if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
					<if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
					<if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
					<if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
					<if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
					<if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
					<if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND #{cond.endValue}</if>
					<if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
					<if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
					<if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
					<if test="cond.condType == 'IN'">${cond.param} IN
						<foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
							#{item}
						</foreach>
					</if>
				</foreach>
			</trim>
		</if>
	</sql>

	<sql id="sqlColumns">
		id, type, create_date, remote_addr, user_agent, request_uri, method, params, exception, appid
	</sql>

	<insert id="save" parameterType="com.cftech.sys.model.MobileLog" keyProperty="id">
		insert into mobile_log
		(
		id, type, create_date, remote_addr, user_agent, request_uri, method, params, exception, appid
		)
		values
		(
		#{id, jdbcType=BIGINT},  #{type, jdbcType=CHAR},  now(),  #{remoteAddr, jdbcType=VARCHAR},  
		#{userAgent, jdbcType=VARCHAR},  #{requestUri, jdbcType=VARCHAR},  #{method, jdbcType=VARCHAR},  #{params, jdbcType=VARCHAR},  
		#{exception, jdbcType=VARCHAR},#{appid, jdbcType=VARCHAR}
		)
	</insert>

	<select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> FROM mobile_log t
		WHERE t.id=#{id}
	</select>

	<select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT COUNT(1)  FROM mobile_log t<include refid="sqlWhere" />
	</select>

	<select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> 
		FROM mobile_log t
		<include refid="sqlWhere" />
		<if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
		<if test="limit>0">limit #{offset},#{limit}</if>
	</select>
	
	<update id="update" parameterType="com.cftech.sys.model.MobileLog">
		update mobile_log
		<set>
			<if test="id != null">
				id = #{id, jdbcType=BIGINT},
			</if>
			<if test="type != null">
				type = #{type, jdbcType=CHAR},
			</if>
			<if test="createDate != null">
				create_date = #{createDate, jdbcType=TIMESTAMP},
			</if>
			<if test="remoteAddr != null">
				remote_addr = #{remoteAddr, jdbcType=VARCHAR},
			</if>
			<if test="userAgent != null">
				user_agent = #{userAgent, jdbcType=VARCHAR},
			</if>
			<if test="requestUri != null">
				request_uri = #{requestUri, jdbcType=VARCHAR},
			</if>
			<if test="method != null">
				method = #{method, jdbcType=VARCHAR},
			</if>
			<if test="params != null">
				params = #{params, jdbcType=VARCHAR},
			</if>
			<if test="exception != null">
				exception = #{exception, jdbcType=VARCHAR},
			</if>
			<if test="appid != null">
				appid = #{appid, jdbcType=VARCHAR},
			</if>
		</set>
		where id=#{id,jdbcType=BIGINT}
	</update>

	<update id="delete" parameterType="java.lang.Long">
		update mobile_log set delflag=1 where id=#{id,jdbcType=BIGINT}
	</update>
	<delete id="deleteAllMobileLog">
		delete  from mobile_log
	</delete>
</mapper>