<?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，namespace的值习惯上设置成包名+sql映射文件名，这样就能够保证namespace的值是唯一的,例如namespace="me.gacl.mapping.userMapper"就是me.gacl.mapping(包名)+userMapper(userMapper.xml文件去除后缀)
-->               
<mapper namespace="com.fuzamei.mapperInterface.OperationHistoryMapper"> 
	<!-- 根据操作记录给的条件查询分页数据 -->
	<select id="queryOperationHistoryInformation" resultType="com.fuzamei.entity.OperationHistory">
		select 
			oh.id,
			oh.operator_type_id,
			ot.operator_name,
			oh.operator_account,
			oh.operator_role,
			oh.operator_person,
			oh.operator_time,
			oh.hash
		from 
			operation_history oh 
		left join 
			operation_type ot 
		on 
			oh.operator_type_id=ot.operator_type_id 
		<where>
			<if test="account!='' and account!=null">
				oh.operator_account=#{account} 
			</if>
			<if test="role!='' and role!=null">
				and oh.operator_role=#{role} 
			</if>
			<if test="type!='' and type!=null">
				and ot.operator_name=#{type}
			</if>
			<if test="startTime!=null and endTime!=null">
				and oh.operator_time between #{startTime} and #{endTime}
			</if>
		</where>
		order by oh.id asc  
		limit #{startPage},#{rowNum}
	</select>
	
	<!-- 返回总页数 -->
	<select id="findAllInformation" resultType="int">
		select
			count(*)
		from
			(select 
				oh.id,
				oh.operator_type_id,
				ot.operator_name,
				oh.operator_account,
				oh.operator_role,
				oh.operator_person,
				oh.operator_time,
				oh.hash
			from 
				operation_history oh 
			left join 
				operation_type ot 
			on 
				oh.operator_type_id=ot.operator_type_id 
			<where>
				<if test="account!='' and account!=null">
					oh.operator_account=#{account} 
				</if>
				<if test="role!='' and role!=null">
					and oh.operator_role=#{role} 
				</if>
				<if test="type!='' and type!=null">
					and ot.operator_name=#{type}
				</if>
				<if test="startTime!=null and endTime!=null">
					and oh.operator_time between #{startTime} and #{endTime}
				</if>
			</where>) temp
		<where>
				<if test="Account!='' and Account!=null">
					temp.operator_account=#{Account} 
				</if>
		</where>
	</select>
	
	<!-- 根据操作记录给的条件查询分页数据,但是还要根据用户的账号名来查询 -->
	<select id="queryOperationHistoryInformationByUser" resultType="com.fuzamei.entity.OperationHistory">
		select
			temp.id,
			temp.operator_type_id,
			temp.operator_name,
			temp.operator_account,
			temp.operator_role,
			temp.operator_person,
			temp.operator_time,
			temp.hash
		from
			(select 
				oh.id,
				oh.operator_type_id,
				ot.operator_name,
				oh.operator_account,
				oh.operator_role,
				oh.operator_person,
				oh.operator_time,
				oh.hash
			from 
				operation_history oh 
			left join 
				operation_type ot 
			on 
				oh.operator_type_id=ot.operator_type_id 
			<where>
				<if test="account!='' and account!=null">
					oh.operator_account=#{account} 
				</if>
				<if test="role!='' and role!=null">
					and oh.operator_role=#{role} 
				</if>
				<if test="type!='' and type!=null">
					and ot.operator_name=#{type}
				</if>
				<if test="startTime!=null and endTime!=null">
					and oh.operator_time between #{startTime} and #{endTime}
				</if>
			</where>) temp
		where 
			temp.operator_account=#{Account}
		order by 
			temp.id asc  
		limit #{startPage},#{rowNum}
	</select>
	
</mapper>
