<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.base.system.oper.dao.ibatis.OperLogDaoImpl">
    
	<!-- 字段和属性映射 -->
	<resultMap type="OperLogEntity" id="OperLogEntity-Map">
		<result property="id" column="id" />
		<result property="platformMark" column="platformMark" />
		<result property="userId" column="userId" />
		<result property="userName" column="userName" />
		<result property="loginName" column="loginName" />
		<result property="requestUrl" column="requestUrl" />
		<result property="content" column="content" />
		<result property="ip" column="ip" />
		<result property="logDate" column="logDate" />
		<result property="operType" column="operType" />
	</resultMap>
	
	
	
	<!-- 表所有列 -->
	<sql id="_columns">
		<trim suffixOverrides="," suffix="">
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('id') or colPickMode == 1 and data.containsKey('id')))">
				a.id as id,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('platformMark') or colPickMode == 1 and data.containsKey('platformMark')))">
				a.platformMark as platformMark,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('userId') or colPickMode == 1 and data.containsKey('userId')))">
				a.userId as userId,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('userName') or colPickMode == 1 and data.containsKey('userName')))">
				a.userName as userName,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('loginName') or colPickMode == 1 and data.containsKey('loginName')))">
				a.loginName as loginName,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('requestUrl') or colPickMode == 1 and data.containsKey('requestUrl')))">
				a.requestUrl as requestUrl,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('content') or colPickMode == 1 and data.containsKey('content')))">
				a.content as content,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('ip') or colPickMode == 1 and data.containsKey('ip')))">
				a.ip as ip,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('logDate') or colPickMode == 1 and data.containsKey('logDate')))">
				a.logDate as logDate,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('operType') or colPickMode == 1 and data.containsKey('operType')))">
				a.operType as operType,
			</if>
		</trim>
	</sql>
	<!-- 新增 -->
	<insert id="insert" parameterType="OperLogEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mortals_xhx_oper_log 
		(platformMark,userId,userName,loginName,requestUrl,
			content,ip,logDate,operType
		)VALUES(#{platformMark},#{userId},#{userName},#{loginName},#{requestUrl},
			#{content},#{ip},#{logDate},#{operType})
	</insert>
	<!-- 批量新增 -->
	<insert id="insertBatch" parameterType="paramDto">
		insert into mortals_xhx_oper_log 
		(platformMark,userId,userName,loginName,requestUrl,
			content,ip,logDate,operType
		)
		VALUES
		<foreach collection="data.dataList" item="item" index="index" separator="," >  
		(#{item.platformMark},#{item.userId},#{item.userName},#{item.loginName},#{item.requestUrl},
			#{item.content},#{item.ip},#{item.logDate},#{item.operType})
		</foreach>
	</insert>
	<!-- 根据ParamDto更新 -->
	<update id="update" parameterType="paramDto">
		update mortals_xhx_oper_log as a
		   set
		   <trim suffixOverrides="," suffix="">
				<if test="(colPickMode==0 and data.containsKey('platformMark')) or (colPickMode==1 and !data.containsKey('platformMark'))">
					a.platformMark=#{data.platformMark},
				</if>
				<if test="(colPickMode==0 and data.containsKey('userId')) or (colPickMode==1 and !data.containsKey('userId'))">
					a.userId=#{data.userId},
				</if>
				<if test="(colPickMode==0 and data.containsKey('userIdIncrement')) or (colPickMode==1 and !data.containsKey('userIdIncrement'))">
					a.userId=ifnull(a.userId,0) + #{data.userIdIncrement},
				</if>
				<if test="(colPickMode==0 and data.containsKey('userName')) or (colPickMode==1 and !data.containsKey('userName'))">
					a.userName=#{data.userName},
				</if>
				<if test="(colPickMode==0 and data.containsKey('loginName')) or (colPickMode==1 and !data.containsKey('loginName'))">
					a.loginName=#{data.loginName},
				</if>
				<if test="(colPickMode==0 and data.containsKey('requestUrl')) or (colPickMode==1 and !data.containsKey('requestUrl'))">
					a.requestUrl=#{data.requestUrl},
				</if>
				<if test="(colPickMode==0 and data.containsKey('content')) or (colPickMode==1 and !data.containsKey('content'))">
					a.content=#{data.content},
				</if>
				<if test="(colPickMode==0 and data.containsKey('ip')) or (colPickMode==1 and !data.containsKey('ip'))">
					a.ip=#{data.ip},
				</if>
				<if test="(colPickMode==0 and data.containsKey('logDate')) or (colPickMode==1 and !data.containsKey('logDate'))">
					a.logDate=#{data.logDate},
				</if>
				<if test="(colPickMode==0 and data.containsKey('operType')) or (colPickMode==1 and !data.containsKey('operType'))">
					a.operType=#{data.operType},
				</if>
				<if test="(colPickMode==0 and data.containsKey('operTypeIncrement')) or (colPickMode==1 and !data.containsKey('operTypeIncrement'))">
					a.operType=ifnull(a.operType,0) + #{data.operTypeIncrement},
				</if>
		    </trim>
		   <trim suffixOverrides="where" suffix="">
			    where
			    <trim prefixOverrides="and" prefix="">
					<include refid="_condition_"/>
			   	</trim>
			</trim>
	</update>

	<!-- 根据主健查询 -->
	<select id="getByKey" parameterType="paramDto" resultMap="OperLogEntity-Map">
		select <include refid="_columns"/>
		from mortals_xhx_oper_log as a
	   where a.id=#{condition.id}
	</select>
	<!-- 根据主健删除 -->
	<delete id="deleteByKey" parameterType="paramDto">
		delete a.* from mortals_xhx_oper_log as a where a.id=#{condition.id}
	</delete>
	<!-- 根据主健删除一批，针对单一主健有效 -->
	<delete id="deleteByKeys">
		delete from mortals_xhx_oper_log where id in
		<foreach collection="array" item="item" index="index" open="(" separator="," close=")">
			#{item}
		</foreach>
	</delete>
	<!-- 根据paramDto删除一批 -->
	<delete id="deleteByMap" parameterType="paramDto">
		delete a.* from mortals_xhx_oper_log as a
		<trim suffixOverrides="where" suffix="">
			 where 
			<trim prefixOverrides="and" prefix="">
				<include refid="_condition_"/>
			</trim>
		</trim>
	</delete>
	<!-- 获取列表 -->
	<select id="getList" parameterType="paramDto" resultMap="OperLogEntity-Map">
		select <include refid="_columns"/>
		  from mortals_xhx_oper_log as a
		 <trim suffixOverrides="where" suffix="">
			 where 
			 <trim prefixOverrides="and" prefix="">
			 	<include refid="_condition_"/>
			 </trim>
		 </trim>
		 <include refid="_orderCols_"/>
	</select>
	<!-- 获取 -->
	<select id="getListCount" parameterType="paramDto" resultType="int">
		select count(1)
		  from mortals_xhx_oper_log as a
		 <trim suffixOverrides="where" suffix="">
			 where 
			 <trim prefixOverrides="and" prefix="">
				<include refid="_condition_"/>
			</trim>
		</trim>
	</select>
	
	<!-- 条件映射 -->
	<sql id="_condition_">
		<if test="condition != null and !condition.isEmpty()">
				<if test="condition.containsKey('id')">
					<if test="condition.id != null">
						and a.id=#{condition.id}
					</if>
				</if>
				<if test="condition.containsKey('id')">
					<if test="condition.id != null ">
						and a.id = #{condition.id}
					</if>
					<if test="condition.id == null">
						and a.id is null
					</if>
				</if>
				<if test="condition.containsKey('idList')">
					 and a.id in 
					<foreach collection="condition.idList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('idStart') and condition.idStart != null">
					<![CDATA[ and a.id >= #{condition.idStart} ]]>
				</if>
				<if test="condition.containsKey('idEnd') and condition.idEnd != null">
					<![CDATA[ and a.id <= #{condition.idEnd} ]]>
				</if>
				<if test="condition.containsKey('platformMark')">
					<if test="condition.platformMark != null and condition.platformMark != ''">
						and a.platformMark like #{condition.platformMark}
					</if>
					<if test="condition.platformMark == null">
						and a.platformMark is null
					</if>
				</if>
				<if test="condition.containsKey('platformMarkList')">
					 and a.platformMark in 
					<foreach collection="condition.platformMarkList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('userId')">
					<if test="condition.userId != null ">
						and a.userId = #{condition.userId}
					</if>
					<if test="condition.userId == null">
						and a.userId is null
					</if>
				</if>
				<if test="condition.containsKey('userIdList')">
					 and a.userId in 
					<foreach collection="condition.userIdList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('userIdStart') and condition.userIdStart != null">
					<![CDATA[ and a.userId >= #{condition.userIdStart} ]]>
				</if>
				<if test="condition.containsKey('userIdEnd') and condition.userIdEnd != null">
					<![CDATA[ and a.userId <= #{condition.userIdEnd} ]]>
				</if>
				<if test="condition.containsKey('userName')">
					<if test="condition.userName != null and condition.userName != ''">
						and a.userName like #{condition.userName}
					</if>
					<if test="condition.userName == null">
						and a.userName is null
					</if>
				</if>
				<if test="condition.containsKey('userNameList')">
					 and a.userName in 
					<foreach collection="condition.userNameList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('loginName')">
					<if test="condition.loginName != null and condition.loginName != ''">
						and a.loginName like #{condition.loginName}
					</if>
					<if test="condition.loginName == null">
						and a.loginName is null
					</if>
				</if>
				<if test="condition.containsKey('loginNameList')">
					 and a.loginName in 
					<foreach collection="condition.loginNameList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('requestUrl')">
					<if test="condition.requestUrl != null and condition.requestUrl != ''">
						and a.requestUrl like #{condition.requestUrl}
					</if>
					<if test="condition.requestUrl == null">
						and a.requestUrl is null
					</if>
				</if>
				<if test="condition.containsKey('requestUrlList')">
					 and a.requestUrl in 
					<foreach collection="condition.requestUrlList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('content')">
					<if test="condition.content != null and condition.content != ''">
						and a.content like #{condition.content}
					</if>
					<if test="condition.content == null">
						and a.content is null
					</if>
				</if>
				<if test="condition.containsKey('contentList')">
					 and a.content in 
					<foreach collection="condition.contentList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('ip')">
					<if test="condition.ip != null and condition.ip != ''">
						and a.ip like #{condition.ip}
					</if>
					<if test="condition.ip == null">
						and a.ip is null
					</if>
				</if>
				<if test="condition.containsKey('ipList')">
					 and a.ip in 
					<foreach collection="condition.ipList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('logDate')">
					<if test="condition.logDate != null ">
						and a.logDate = #{condition.logDate}
					</if>
					<if test="condition.logDate == null">
						and a.logDate is null
					</if>
				</if>
				<if test="condition.containsKey('logDateStart') and condition.logDateStart != null and condition.logDateStart!=''">
					<![CDATA[ and a.logDate >= STR_TO_DATE(left(concat(#{condition.logDateStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') ]]>
				</if>
				<if test="condition.containsKey('logDateEnd') and condition.logDateEnd != null and condition.logDateEnd!=''">
					<![CDATA[ and a.logDate <= STR_TO_DATE(left(concat(#{condition.logDateEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') ]]>
				</if>
				<if test="condition.containsKey('operType')">
					<if test="condition.operType != null ">
						and a.operType = #{condition.operType}
					</if>
					<if test="condition.operType == null">
						and a.operType is null
					</if>
				</if>
				<if test="condition.containsKey('operTypeList')">
					 and a.operType in 
					<foreach collection="condition.operTypeList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('operTypeStart') and condition.operTypeStart != null">
					<![CDATA[ and a.operType >= #{condition.operTypeStart} ]]>
				</if>
				<if test="condition.containsKey('operTypeEnd') and condition.operTypeEnd != null">
					<![CDATA[ and a.operType <= #{condition.operTypeEnd} ]]>
				</if>
		</if>
	</sql>
	<sql id="_orderCols_">
		<if test="orderColList != null and !orderColList.isEmpty()">
	        order by
	        <trim suffixOverrides=","  suffix="">
				<foreach collection="orderColList" open="" close="" index="index" item="item" separator=",">
						${item.colName} ${item.sortKind}
				</foreach>
			</trim>
		</if>
		<if test="(orderColList == null or orderColList.isEmpty()) and orderCol != null and !orderCol.isEmpty()">
			order by
			<trim suffixOverrides=","  suffix="">
				<if test="orderCol.containsKey('id')">
					a.id
					<if test="orderCol.id!= null">
						${orderCol.id}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('platformMark')">
					a.platformMark
					<if test="orderCol.platformMark!= null">
						${orderCol.platformMark}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('userId')">
					a.userId
					<if test="orderCol.userId!= null">
						${orderCol.userId}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('userName')">
					a.userName
					<if test="orderCol.userName!= null">
						${orderCol.userName}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('loginName')">
					a.loginName
					<if test="orderCol.loginName!= null">
						${orderCol.loginName}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('requestUrl')">
					a.requestUrl
					<if test="orderCol.requestUrl!= null">
						${orderCol.requestUrl}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('content')">
					a.content
					<if test="orderCol.content!= null">
						${orderCol.content}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('ip')">
					a.ip
					<if test="orderCol.ip!= null">
						${orderCol.ip}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('logDate')">
					a.logDate
					<if test="orderCol.logDate!= null">
						${orderCol.logDate}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('operType')">
					a.operType
					<if test="orderCol.operType!= null">
						${orderCol.operType}
					</if>
					,
				</if>
			</trim>
		</if>
	</sql>
	<sql id="_group_by_">
		<if test="groupList != null and !groupList.isEmpty()">
			GROUP BY
			<trim suffixOverrides=","  suffix="">
				<foreach collection="groupList" open="" close="" index="index" item="item" separator=",">
						${item}
				</foreach>
			</trim>
		</if>
	</sql>
</mapper>