<?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.nantian.sc.cloud.admin.mapper.SysLogMapper">

	<resultMap id="sysLogMap" type="com.nantian.sc.cloud.admin.api.entity.SysLog">
		<id property="id" column="id"/>
		<result property="type" column="type"/>
		<result property="title" column="title"/>
		<result property="serviceId" column="service_id"/>
		<result property="createBy" column="create_by"/>
		<result property="createTime" column="create_time"/>
		<result property="updateTime" column="update_time"/>
		<result property="remoteAddr" column="remote_addr"/>
		<result property="userAgent" column="user_agent"/>
		<result property="requestUri" column="request_uri"/>
		<result property="method" column="method"/>
		<result property="params" column="params"/>
		<result property="time" column="time"/>
		<result property="delFlag" column="del_flag"/>
		<result property="exception" column="exception"/>
		<result column="tenant_id" property="tenantId"/>
		<result column="login_type" property="loginType"/>
	</resultMap>

	<sql id="sysLog_List">
		id, type, title, service_id, create_by, create_time, update_time, remote_addr, user_agent, request_uri, method, params, del_flag, exception, tenant_id, login_type
	</sql>

	<select id="getSysLog" resultType="com.nantian.sc.cloud.admin.api.entity.SysLog">
		select <include refid="sysLog_List"></include> from sys_log
		where 1 =1
		<if test="mold != null and mold !=''">
			<choose>
				<when test="mold==1">
					and title not like concat('%',"用户登录",'%')
				</when>
				<when test="mold==2">
					and title like concat('%',"用户登录",'%')
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="log.title != null and log.title !=''">
			and title like concat('%',#{log.title},'%')
		</if>
		<if test="log.createBy != null and log.createBy !=''">
			and create_by LIKE CONCAT ('%',#{log.createBy},'%')
		</if>
		<if test="log.method != null and log.method !=''">
			and method LIKE CONCAT ('%',#{log.method},'%')
		</if>
		<if test="log.remoteAddr != null and log.remoteAddr !=''">
			and remote_addr LIKE CONCAT ('%',#{log.remoteAddr},'%')
		</if>
		<if test="log.requestUri != null and log.requestUri !=''">
			and request_uri LIKE CONCAT ('%',#{log.requestUri},'%')
		</if>
		<if test="beginDate != null and beginDate !=''">
			and left( create_time, 10) <![CDATA[>=]]> DATE_FORMAT(#{beginDate},'%Y-%m-%d')
		</if>
		<if test="endDate != null and endDate != ''">
			AND left( create_time, 10) <![CDATA[<=]]> DATE_FORMAT(#{endDate},'%Y-%m-%d')
		</if>
		ORDER BY create_time DESC
	</select>

</mapper>
