<?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.fuzamei.mapperInterface.PromptLetterMapper"> 
	<!--提示函  管理人接收列表  -->
	<select id="queryPromptLetterByAdmin" resultType="com.fuzamei.entity.PromptLetter">
	   	select   
	   		t.prompt_letter_id,
	        f.attachment_name, 
			f.url,
			t.receive_time 
		from   
			prompt_letter t 
		left join 
			attachment f 
		on 
			t.prompt_letter_id=f.attachment_id  
		 <where>
		 	receive_person=#{receiverId}
		 	<if test="startTime!=null and endTime != null">
		    	and receive_time between #{startTime} and #{endTime}
		 	</if>
		 </where>
		 order by 
		     receive_time desc  
		 limit #{startPage},#{rowNum}	
	</select>
	
	<!-- 根据条件查出符合条件的所有信息条数 -->
	<select id="findAllInformation" resultType="int">
		select 
			count(*)
		from 
			prompt_letter
		<where>
			<if test="receiverId!=null">
				receive_person=#{receiverId}
			</if>
		 	<if test="startTime!=null and endTime != null">
		    	and receive_time between #{startTime} and #{endTime}
		 	</if>
		 </where>
	</select>
	
	<!--提示函上传 插入数据到提示函表  -->
	<insert id="insertIntoPromptLetterTable" parameterType="java.util.Map">
		insert into 
		prompt_letter(prompt_letter_id,
						   prompt_letter_name,
				    	   send_person,
						   receive_person,
						   send_time,
						   receive_time,
						   hash) 
			values(
					#{prompt_letter_id},
					#{prompt_letter_name},
					#{send_person},
					#{receive_person},  
					#{send_time},
					#{receive_time},
					#{hash}
					)
	</insert>
	<!-- 提示函上传  往附件表也插入数据信息 -->
	<insert id="insertIntoAttachmentTable">
		insert into 
				attachment(attachment_id,
					   attachment_name,
						 url,
					   upload_person_id,
					   create_time) 
			values(#{attachmentId},
				   #{attachmentName},
				   #{url},
				   #{upload_person_id},
				   #{create_time})
	</insert> 
	<!-- 提示函上传  往操作记录表也插入数据信息 -->
	<insert id="insertOperationHistory">
		insert into 
			operation_history(operator_type_id,
							  operator_account,
							  operator_role,
							  operator_person,
							  operator_time,
							  hash)
		values(#{operatorTypeId},
			   #{operatorAccount},
			   #{operatorRole},
			   #{operatorPerson},
			   #{operatorTime},
			   #{hash})
	</insert>
    <!--发送记录查询风险提示函 ，省分行托管中心风管岗   发送时间列biao-->
	<select id="queryPromptLetterByVenture" resultType="com.fuzamei.entity.PromptLetter">
	   	select 
	   		t.prompt_letter_id, 
	        y.person_name, 
	        f.attachment_name,
	        f.url,
	        t.send_time    
	   	from   
			prompt_letter t 
		left  join  
			attachment f  
		on 
			t.prompt_letter_id=f.attachment_id 
		left  join 
			t_user y 
		on  
			t.receive_person=y.user_id   
		<where>
		    <if test="startTime!=null and endTime != null">
		    	t.send_time between #{startTime} and #{endTime}
		   </if>
		</where>
		order by 
			send_time desc
	    limit #{startPage},#{rowNum}
	</select>
</mapper>