<?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="logSqlMapper">
	
	<sql id="base_column">
		id,
		table_name as tableName,
		record_id as recordId,
		account_id as accountId,
		account_name as accountName,
		module,
		action_type as actionType,
		action,
		action_time as actionTime,
		user_ip as userIp,
		oper_time as operTime
	</sql>
	
	<insert id="addLog" parameterType="com.cloudcross.ssp.model.Log">
		insert into t_log(table_name,record_id,account_id,account_name,module,action_type,action,action_time,user_ip,oper_time)
		values(#{tableName},#{recordId},#{accountId},#{accountName},#{module},#{actionType},#{action},#{actionTime},#{userIp},#{operTime})
	</insert>
	
	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.Log">
		select 
		<include refid="base_column" />
		from t_log where 1 = 1
		and table_name=#{tableName}
		and record_id=#{recordId}
		order by id   desc
		limit #{pager.offset}, #{pager.limit}
	</select>
	<select id="selectByParams1"  parameterType="map" resultType="com.cloudcross.ssp.model.Log">
		select 
		oper_time as operTime,
		account_name as accountName,
		user_ip as userIp,
		action_type as actionType,
		action
		from t_log where 
		table_name=#{tableName}
	 	and record_id=#{recordId}
	</select>
	
	<select id="countByParams" parameterType="map" resultType="int">
		select count(id)
		from t_log where 1 = 1
		and table_name=#{tableName}
		and record_id=#{recordId}
	</select>
	
	<select id="selectByModule"  parameterType="String" resultType="com.cloudcross.ssp.model.Log">
		select 
		<include refid="base_column" />
		from t_log where
		module = #{module} 
		order by id   desc
		limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="findByModule" parameterType="String" resultType="com.cloudcross.ssp.model.Log">
		select 
		<include refid="base_column" />
		from t_log where
		module = #{module}
	</select>
	
	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.Log">
		select 
		<include refid="base_column" />
		from t_log
		<where>
			id = #{id}
		</where>
	</select>
	
	<update id="editLog" parameterType="com.cloudcross.ssp.model.Log">
		update t_log set account_id=#{accountId},account_name=#{accountName},
		action_type=#{actionType},user_ip=#{userIp},
		<if test="module !=null">
			module=#{module},
		</if>
			oper_time=#{operTime} 
		 	where id=#{id}
	</update>	
	<!-- 导出Excel用 -->
	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.Log">
		select 
		<include refid="base_column" />
		from t_log 	where 
		 table_name=#{tableName}
		and record_id=#{recordId}
		order by id   desc
	</select>
	
	<select id="countByParamsBack" parameterType="map" resultType="int">
		select count(id) from t_log where table_name = #{tableName} and record_id = #{recordId}
	</select>
	
	<select id="findByParamsBack" parameterType="map" resultType="Log">
		select 
		<include refid="base_column" />
		from t_log where 
		table_name=#{tableName}
		and record_id=#{recordId}
		order by id  desc
		limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="findByParams1Back" parameterType="map" resultType="Log">
		select 
		<include refid="base_column" />
		from t_log where 
		table_name=#{tableName}
		and record_id=#{recordId}
		order by id  desc
	</select>
</mapper>
	
