<?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.AccountOpenMapper"> 
	<!--查询账户开立  返回总页数-->
	<select id="serchCountPage" resultType="int">
	  select count(*)  from account_opening_record  
	</select>
	<!--查询提示函  返回总页数  -->
	<select id="serchCountPage2" resultType="int">
	  select count(*)  from prompt_letter
	</select>
   <!-- 账户开立带分页，没用左链接-->
	<!-- <select id="queryAllAccountOpening"  resultType="com.fuzamei.entity.AccountOpeningRecord">
		select 
			customer_id,
			customer_name,
			bank_account,
			attachment_name as basic_data_id,
			attachment_name as letter_of_commitment_id,
			attachment_name as application_id,
			update_time,s.status_name 
		from  
			account_opening_record a, attachment f,status s  
	 
	 <where>
	  		a.basic_data_id=f.attachment_id 
	  	and 
	  		a.letter_of_commitment_id = f.attachment_id 
	  	and 
	  		a.application_id= f.attachment_id 
	  	and  
	  		s.status_id=a.status_id 
		<if test="customer_name!='' and customer_name!=null ">
		 and  customer_name=#{customer_name}
		</if>
		<if test="bank_account!='' and bank_account!=null">
		  and bank_account=#{bank_account}
		</if>
	   	<if test="startTime!='' and endTime != ''">
		  and a.update_time  between #{startTime} and #{endTime}
		</if>
	 </where>
	   order by update_time desc
	   limit #{startPage},#{rowNum}
	</select> -->
	<!-- ************************************************************************************************** -->
	<!--提示函  管理人接收的 列表  -->
	<!-- select   t.prompt_letter_id,f.attachment_name,  t.receive_time ,f.url from  prompt_letter t left join attachment f on t.prompt_letter_id=f.attachment_id    order by receive_time desc -->
	<select id="selectPromptLetter" parameterType="java.util.Map" 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_time between #{startTime} and #{endTime}
		 </where>
		     order by receive_time desc  limit #{startPage},#{rowNum}	
		 
	</select>
	<!--*********************************************************************************************  -->

	<!-- <insert id="insertTiShiHanOrUserOrOtherTable" parameterType="java.util.Map">
	     </insert> -->
	<!--提示函上传 插入数据到提示函表  -->
	<!-- *********************************************************************************************** -->
	<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="selectTishihan" parameterType="java.util.Map" resultType="com.fuzamei.entity.PromptLetter">
	select  t.prompt_letter_id , y.person_name , f.attachment_name, 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.send_person=f.attachment_id	     
		<where>
		    <if test="startTime!='' and endTime != ''">
		    		t.send_time  between #{startTime} and #{endTime}
		   </if>
		</where>
		      order by send_time desc
	          limit #{startPage},#{rowNum}
	</select>
	
	<!--***********************************************************************************************  -->
	<!-- 真伪查询   上传服务器  往 附件表记录插入-->
	<insert id="insertTrueFalseSelect" parameterType="java.util.Map">
		   insert into attachment (
	                attachment_id,
	                attachment_name,
	                url,
	                upload_person_id,
	                create_time) 
	          values(
	               #{attachment_id},
	               #{attachment_name},
	               #{url},
	               #{upload_person_id},
	               #{create_time} );
	</insert>
	<!--**************************************************************************************************************  -->
	<!-- 上传客户资料，承诺书，开户申请书    经办支行创建添加账号和客户名称   useGeneratedKeys="true" 返回主键  闲着没有用  -->
	<insert id="insertAccountUploadFile"   parameterType="java.util.Map">
	<!-- 插入到开户记录表 -->
	   insert into account_opening_record(
	              customer_id,
	              customer_name,
	              bank_account,
	              basic_data_id,
	              letter_of_commitment_id,
	              application_id,
	              update_time,
	              status_id,
	              hash)
	       values(
	            #{customer_id},
	            #{customer_name},
	            #{bank_account},
	            #{basicAttachment_id},
	            #{letterAttachment_id},
	            #{applicationAttachment_id},
	            #{update_time},
	            #{status_id},
	            #{hash}
	            )
	</insert>
	 <!-- 上传客户资料，承诺书，开户申请书    经办支行添加创建账号和客户名称  上传到附件表--> 
	<insert id="insertAccountUploadFileFuJianBiao" parameterType="java.util.Map">
	     	   <!--  插入到附件表-->
		   insert into attachment (
		                attachment_id,
		                attachment_name,
		                url,
		                upload_person_id,
		                create_time) 
		          values(
		               #{attachment_id},
		               #{attachment_name},
		               #{url},
		               #{upload_person_id},
		               #{create_time} )
	</insert>
<!-- *******************代替上面的账户开立,用左链接************************************************* -->
 <select id="queryAllAccountOpening" resultType="com.fuzamei.entity.AccountOpeningRecord">
	select 
			customer_id,
			customer_name,
			bank_account,
			f.attachment_name as basic_data_id,
			f1.attachment_name as letter_of_commitment_id,
			f2.attachment_name as application_id,
			update_time,s.status_name 
		from  
			      account_opening_record a
		LEFT JOIN  attachment f
		
			on a.basic_data_id=f.attachment_id 
	  	LEFT JOIN	attachment f1
	  	on	a.letter_of_commitment_id = f1.attachment_id 
	  	LEFT JOIN attachment f2
	  	on	a.application_id= f2.attachment_id 
	  	LEFT JOIN status s
	  	on a.status_id = s.status_id
	 <where>
		    <if test="customer_name!='' and customer_name!=null ">
			  customer_name=#{customer_name}
			</if>
			<if test="bank_account!='' and bank_account!=null">
			  and bank_account=#{bank_account}
			</if>
		   	<if test="startTime!='' and endTime != ''">
			  and a.update_time  between #{startTime} and #{endTime}
			</if>
	 </where>
	             order by update_time desc
	            limit #{startPage},#{rowNum}
</select>
<!--账户开立 通过点击查看  供应下载页面  -->	
<select id="selectAccountopenNoPage" parameterType="java.util.Map" resultType="com.fuzamei.entity.AccountOpeningRecord">
	select 
			customer_id,
			customer_name,
			bank_account,
			f.attachment_name as basic_data_id,
			f1.attachment_name as letter_of_commitment_id,
			f2.attachment_name as application_id,
			update_time,
			f.url
		from  
			account_opening_record a
			left  join  attachment f
			on a.basic_data_id=f.attachment_id 
	  	left  join	attachment f1
	  	on	a.letter_of_commitment_id = f1.attachment_id 
	  	left  join attachment f2
	  	on	a.application_id= f2.attachment_id 

		 where  customer_id=#{customer_id}
</select>
	
	
	
	
	

	
</mapper>
