<?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.ylcm.sys.mapper.LogMapper">
	<resultMap id="BaseResultMap" type="com.ylcm.sys.domain.Log">
		<id column="id" property="id" jdbcType="INTEGER" />
		<result column="type" property="type" jdbcType="VARCHAR" />
		<result column="login" property="login" jdbcType="VARCHAR" />
		<result column="ip" property="ip" jdbcType="VARCHAR" />
		<result column="content" property="content" jdbcType="VARCHAR" />
		<result column="name" property="name" jdbcType="VARCHAR" />
		<result column="crt_time" property="crtTime" jdbcType="TIMESTAMP" />
	</resultMap>
	<sql id="Base_Column_List">
		id, type, login, name, crt_time, ip, content
	</sql>
	<!-- 根据条件查询日志 -->
	<select id="selectByCondition" resultMap="BaseResultMap"
		parameterType="java.util.Map">
		select
		<include refid="Base_Column_List" />
		from log
		<where>
			<if test="startDate != null and startDate != ''">
				AND crt_time  <![CDATA[>=]]>
				str_to_date(#{startDate},'%Y-%m-%d %H:%i:%s')
			</if>
			<if test="endDate != null and endDate != ''">
				AND crt_time  <![CDATA[<=]]>
				str_to_date(#{endDate},'%Y-%m-%d %H:%i:%s')
			</if>
			<if test="name != null and name != ''">
				and name = #{name}
			</if>
		</where>
		ORDER BY crt_time desc
		<if test="offSet !=null and pageSize !=null"> LIMIT #{pageSize} OFFSET #{offSet}</if>
	</select>
	<!-- 根据条件查询日志 -->
	<select id="getCount" resultType="Integer" parameterType="java.util.Map">
		select
		count(1)
		from log
		<where>
			<if test="startDate != null and startDate != ''">
				crt_time  <![CDATA[>=]]>
				str_to_date(#{startDate},'%Y-%m-%d %H:%i:%s')
			</if>
			<if test="endDate != null and endDate != ''">
				AND crt_time  <![CDATA[<=]]>
				str_to_date(#{endDate},'%Y-%m-%d %H:%i:%s')
			</if>
			<if test="name != null and name != ''">
				AND name = #{name}
			</if>
		</where>
	</select>
	<insert id="insert" parameterType="com.ylcm.sys.domain.Log">
		insert into log (id, type,
		login,
		name, crt_time,ip,content
		)
		values (#{id,jdbcType=INTEGER},
		#{type,jdbcType=VARCHAR},
		#{login,jdbcType=VARCHAR},
		#{name,jdbcType=VARCHAR}, #{crtTime,jdbcType=TIMESTAMP},#{ip}, #{content}
		)
	</insert>
</mapper>