<?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="cn.pluss.platform.mapper.MerchantBankCardMapper">

	   	<insert id="saveMerchantBankCard" parameterType="cn.pluss.platform.entity.MerchantBankCard">
        	insert into tb_pluss_merchant_bank_card(merchantCode,storeId,bankCardNo,bankCertName,branchName,accountType,contactLine,branchProvince,branchCity,certType,certNo,cardHolderAddress,orderNo,merchantId,registerStatus,failReason,accountNo,wechatChannelList,phone,createDt,updateDt,userId,aisleSwitch,bankName,bankCardFrontPic,certStartTime,certEndTime,bankAddressNo,branchArea)VALUES(#{merchantCode},#{storeId},#{bankCardNo},#{bankCertName},#{branchName},#{accountType},#{contactLine},#{branchProvince},#{branchCity},#{certType},#{certNo},#{cardHolderAddress},#{orderNo},#{merchantId},#{registerStatus},#{failReason},#{accountNo},#{wechatChannelList},#{phone},now(),#{updateDt},#{userId},#{aisleSwitch},#{bankName},#{bankCardFrontPic},#{certStartTime},#{certEndTime},#{bankAddressNo},#{branchArea})
    	</insert>

	   	<insert id="saveMerchantBankCardBatch">
        	insert into tb_pluss_merchant_bank_card(merchantCode,storeId,bankCardNo,bankCertName,branchName,accountType,contactLine,branchProvince,branchCity,certType,certNo,cardHolderAddress,orderNo,merchantId,registerStatus,failReason,accountNo,wechatChannelList,phone,createDt,updateDt) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{merchantCode},#{storeId},#{bankCardNo},#{bankCertName},#{branchName},#{accountType},#{contactLine},#{branchProvince},#{branchCity},#{certType},#{certNo},#{cardHolderAddress},#{orderNo},#{merchantId},#{registerStatus},#{failReason},#{accountNo},#{wechatChannelList},#{phone},#{createDt},#{updateDt}		)
				</foreach>
    	</insert>

		<select id="queryMerchantBankCard" parameterType="cn.pluss.platform.entity.MerchantBankCard" resultType="cn.pluss.platform.entity.MerchantBankCard">
			SELECT * from tb_pluss_merchant_bank_card 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					 	and merchantCode = #{merchantCode}
					 </if> 
					<if test="storeId!= null"> 
					 	and storeId = #{storeId}
					 </if> 
					<if test="bankCardNo!= null"> 
					 	and bankCardNo = #{bankCardNo}
					 </if> 
					<if test="bankCertName!= null"> 
					 	and bankCertName = #{bankCertName}
					 </if> 
					<if test="branchName!= null"> 
					 	and branchName = #{branchName}
					 </if> 
					<if test="accountType!= null"> 
					 	and accountType = #{accountType}
					 </if> 
					<if test="contactLine!= null"> 
					 	and contactLine = #{contactLine}
					 </if> 
					<if test="branchProvince!= null"> 
					 	and branchProvince = #{branchProvince}
					 </if> 
					<if test="branchCity!= null"> 
					 	and branchCity = #{branchCity}
					 </if> 
					<if test="certType!= null"> 
					 	and certType = #{certType}
					 </if> 
					<if test="certNo!= null"> 
					 	and certNo = #{certNo}
					 </if> 
					<if test="cardHolderAddress!= null"> 
					 	and cardHolderAddress = #{cardHolderAddress}
					 </if> 
					<if test="orderNo!= null"> 
					 	and orderNo = #{orderNo}
					 </if> 
					<if test="merchantId!= null"> 
					 	and merchantId = #{merchantId}
					 </if> 
					<if test="registerStatus!= null"> 
					 	and registerStatus = #{registerStatus}
					 </if> 
					<if test="failReason!= null"> 
					 	and failReason = #{failReason}
					 </if> 
					<if test="accountNo!= null"> 
					 	and accountNo = #{accountNo}
					 </if> 
					<if test="wechatChannelList!= null"> 
					 	and wechatChannelList = #{wechatChannelList}
					 </if> 
					<if test="phone!= null"> 
					 	and phone = #{phone}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
					<if test="updateDt!= null"> 
					 	and updateDt = #{updateDt}
					 </if> 
					<if test="userId!= null"> 
					 	and userId = #{userId}
					 </if> 
					<if test="aisleSwitch!= null"> 
					 	and aisleSwitch = #{aisleSwitch}
					 </if> 
					<if test="bankName!= null"> 
					 	and bankName = #{bankName}
					 </if> 
					<if test="bankCardFrontPic!= null"> 
					 	and bankCardFrontPic = #{bankCardFrontPic}
					 </if> 
					<if test="certStartTime!= null"> 
					 	and certStartTime = #{certStartTime}
					 </if> 
					<if test="certEndTime!= null"> 
					 	and certEndTime = #{certEndTime}
					 </if> 
					<if test="bankAddressNo!= null"> 
					 	and bankAddressNo = #{bankAddressNo}
					 </if> 
					<if test="branchArea!= null"> 
					 	and branchArea = #{branchArea}
					 </if> 
				 </where> 
		</select>

		<select id="queryMerchantBankCardList" parameterType="cn.pluss.platform.entity.MerchantBankCard" resultType="cn.pluss.platform.entity.MerchantBankCard">
			SELECT * from tb_pluss_merchant_bank_card 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					 and 	merchantCode = #{merchantCode}
					 </if> 
					<if test="storeId!= null"> 
					 and 	storeId = #{storeId}
					 </if> 
					<if test="bankCardNo!= null"> 
					 and 	bankCardNo = #{bankCardNo}
					 </if> 
					<if test="bankCertName!= null"> 
					 and 	bankCertName = #{bankCertName}
					 </if> 
					<if test="branchName!= null"> 
					 and 	branchName = #{branchName}
					 </if> 
					<if test="accountType!= null"> 
					 and 	accountType = #{accountType}
					 </if> 
					<if test="contactLine!= null"> 
					 and 	contactLine = #{contactLine}
					 </if> 
					<if test="branchProvince!= null"> 
					 and 	branchProvince = #{branchProvince}
					 </if> 
					<if test="branchCity!= null"> 
					 and 	branchCity = #{branchCity}
					 </if> 
					<if test="certType!= null"> 
					 and 	certType = #{certType}
					 </if> 
					<if test="certNo!= null"> 
					 and 	certNo = #{certNo}
					 </if> 
					<if test="cardHolderAddress!= null"> 
					 and 	cardHolderAddress = #{cardHolderAddress}
					 </if> 
					<if test="orderNo!= null"> 
					 and 	orderNo = #{orderNo}
					 </if> 
					<if test="merchantId!= null"> 
					 and 	merchantId = #{merchantId}
					 </if> 
					<if test="registerStatus!= null"> 
					 and 	registerStatus = #{registerStatus}
					 </if> 
					<if test="failReason!= null"> 
					 and 	failReason = #{failReason}
					 </if> 
					<if test="accountNo!= null"> 
					 and 	accountNo = #{accountNo}
					 </if> 
					<if test="wechatChannelList!= null"> 
					 and 	wechatChannelList = #{wechatChannelList}
					 </if> 
					<if test="phone!= null"> 
					 and 	phone = #{phone}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
					<if test="updateDt!= null"> 
					 and 	updateDt = #{updateDt}
					 </if> 
					 <if test="userId!= null"> 
                        and userId = #{userId}
                     </if> 
                    <if test="aisleSwitch!= null"> 
                        and aisleSwitch = #{aisleSwitch}
                     </if> 
                     <if test="bankName!= null"> 
                        and bankName = #{bankName}
                     </if> 
                     <if test="bankCardFrontPic!= null"> 
                        and bankCardFrontPic = #{bankCardFrontPic}
                     </if> 
                     <if test="certStartTime!= null"> 
                        and certStartTime = #{certStartTime}
                     </if> 
                    <if test="certEndTime!= null"> 
                        and certEndTime = #{certEndTime}
                     </if> 
                     <if test="bankAddressNo!= null"> 
                        and bankAddressNo = #{bankAddressNo}
                     </if> 
                     <if test="branchArea!= null"> 
                        and branchArea = #{branchArea}
                     </if>
				 </where> 
		</select>

		<update id="updateMerchantBankCard" parameterType="cn.pluss.platform.entity.MerchantBankCard" >
			update tb_pluss_merchant_bank_card 
				  <set> 
					<if test="merchantCode!= null"> 
					 	merchantCode = #{merchantCode},
					 </if> 
					<if test="storeId!= null"> 
					 	storeId = #{storeId},
					 </if> 
					<if test="bankCardNo!= null"> 
					 	bankCardNo = #{bankCardNo},
					 </if> 
					<if test="bankCertName!= null"> 
					 	bankCertName = #{bankCertName},
					 </if> 
					<if test="branchName!= null"> 
					 	branchName = #{branchName},
					 </if> 
					<if test="accountType!= null"> 
					 	accountType = #{accountType},
					 </if> 
					<if test="contactLine!= null"> 
					 	contactLine = #{contactLine},
					 </if> 
					<if test="branchProvince!= null"> 
					 	branchProvince = #{branchProvince},
					 </if> 
					<if test="branchCity!= null"> 
					 	branchCity = #{branchCity},
					 </if> 
					<if test="certType!= null"> 
					 	certType = #{certType},
					 </if> 
					<if test="certNo!= null"> 
					 	certNo = #{certNo},
					 </if> 
					<if test="cardHolderAddress!= null"> 
					 	cardHolderAddress = #{cardHolderAddress},
					 </if> 
					<if test="orderNo!= null"> 
					 	orderNo = #{orderNo},
					 </if> 
					<if test="merchantId!= null"> 
					 	merchantId = #{merchantId},
					 </if> 
					<if test="registerStatus!= null"> 
					 	registerStatus = #{registerStatus},
					 </if> 
					<if test="failReason!= null"> 
					 	failReason = #{failReason},
					 </if> 
					<if test="accountNo!= null"> 
					 	accountNo = #{accountNo},
					 </if> 
					<if test="wechatChannelList!= null"> 
					 	wechatChannelList = #{wechatChannelList},
					 </if> 
					<if test="phone!= null"> 
					 	phone = #{phone},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt},
					 </if> 
					<if test="updateDt!= null"> 
					 	updateDt = #{updateDt},
					 </if> 
					 <if test="userId!= null"> 
                         userId = #{userId},
                     </if> 
                    <if test="aisleSwitch!= null"> 
                         aisleSwitch = #{aisleSwitch},
                     </if> 
                     <if test="bankName!= null"> 
                         bankName = #{bankName},
                     </if> 
                     <if test="bankCardFrontPic!= null"> 
                         bankCardFrontPic = #{bankCardFrontPic},
                     </if> 
                     <if test="certStartTime!= null"> 
                         certStartTime = #{certStartTime},
                     </if> 
                    <if test="certEndTime!= null"> 
                         certEndTime = #{certEndTime},
                     </if> 
                     <if test="bankAddressNo!= null"> 
                         bankAddressNo = #{bankAddressNo},
                     </if> 
                     <if test="branchArea!= null"> 
                         branchArea = #{branchArea}
                     </if>
				</set>
			where id=#{id} 
		</update>

	<update id="updateMerchantBankCardUserId" parameterType="cn.pluss.platform.entity.MerchantBankCard" >
		update tb_pluss_merchant_bank_card
		<set>
			<if test="merchantCode!= null">
				merchantCode = #{merchantCode},
			</if>
			<if test="storeId!= null">
				storeId = #{storeId},
			</if>
			<if test="bankCardNo!= null">
				bankCardNo = #{bankCardNo},
			</if>
			<if test="bankCertName!= null">
				bankCertName = #{bankCertName},
			</if>
			<if test="branchName!= null">
				branchName = #{branchName},
			</if>
			<if test="accountType!= null">
				accountType = #{accountType},
			</if>
			<if test="contactLine!= null">
				contactLine = #{contactLine},
			</if>
			<if test="branchProvince!= null">
				branchProvince = #{branchProvince},
			</if>
			<if test="branchCity!= null">
				branchCity = #{branchCity},
			</if>
			<if test="certType!= null">
				certType = #{certType},
			</if>
			<if test="certNo!= null">
				certNo = #{certNo},
			</if>
			<if test="cardHolderAddress!= null">
				cardHolderAddress = #{cardHolderAddress},
			</if>
			<if test="orderNo!= null">
				orderNo = #{orderNo},
			</if>
			<if test="merchantId!= null">
				merchantId = #{merchantId},
			</if>
			<if test="registerStatus!= null">
				registerStatus = #{registerStatus},
			</if>
			<if test="failReason!= null">
				failReason = #{failReason},
			</if>
			<if test="accountNo!= null">
				accountNo = #{accountNo},
			</if>
			<if test="wechatChannelList!= null">
				wechatChannelList = #{wechatChannelList},
			</if>
			<if test="phone!= null">
				phone = #{phone},
			</if>
			<if test="createDt!= null">
				createDt = #{createDt},
			</if>
			<if test="updateDt!= null">
				updateDt = #{updateDt},
			</if>
			<if test="aisleSwitch!= null">
				aisleSwitch = #{aisleSwitch},
			</if>
			<if test="bankName!= null">
				bankName = #{bankName},
			</if>
			<if test="bankCardFrontPic!= null">
				bankCardFrontPic = #{bankCardFrontPic},
			</if>
			<if test="certStartTime!= null">
				certStartTime = #{certStartTime},
			</if>
			<if test="certEndTime!= null">
				certEndTime = #{certEndTime},
			</if>
			<if test="bankAddressNo!= null">
				bankAddressNo = #{bankAddressNo},
			</if>
			<if test="branchArea!= null">
				branchArea = #{branchArea}
			</if>
		</set>
		where userId=#{userId}
	</update>

		<delete id="deleteMerchantBankCard" parameterType="cn.pluss.platform.entity.MerchantBankCard" >
			DELETE FROM tb_pluss_merchant_bank_card where id=#{id}
		</delete>

		<select id="queryMerchantBankCardPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.MerchantBankCard">
			SELECT * from tb_pluss_merchant_bank_card 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					and merchantCode = #{merchantCode}
					 </if> 
					<if test="storeId!= null"> 
					and storeId = #{storeId}
					 </if> 
					<if test="bankCardNo!= null"> 
					and bankCardNo = #{bankCardNo}
					 </if> 
					<if test="bankCertName!= null"> 
					and bankCertName like CONCAT("%",#{bankCertName},"%")
					 </if> 
					<if test="branchName!= null"> 
					and branchName = #{branchName}
					 </if> 
					<if test="accountType!= null"> 
					and accountType = #{accountType}
					 </if> 
					<if test="contactLine!= null"> 
					and contactLine = #{contactLine}
					 </if> 
					<if test="branchProvince!= null"> 
					and branchProvince = #{branchProvince}
					 </if> 
					<if test="branchCity!= null"> 
					and branchCity = #{branchCity}
					 </if> 
					<if test="certType!= null"> 
					and certType = #{certType}
					 </if> 
					<if test="certNo!= null"> 
					and certNo = #{certNo}
					 </if> 
					<if test="cardHolderAddress!= null"> 
					and cardHolderAddress = #{cardHolderAddress}
					 </if> 
					<if test="orderNo!= null"> 
					and orderNo = #{orderNo}
					 </if> 
					<if test="merchantId!= null"> 
					and merchantId = #{merchantId}
					 </if> 
					<if test="registerStatus!= null"> 
					and registerStatus = #{registerStatus}
					 </if> 
					<if test="failReason!= null"> 
					and failReason = #{failReason}
					 </if> 
					<if test="accountNo!= null"> 
					and accountNo = #{accountNo}
					 </if> 
					<if test="wechatChannelList!= null"> 
					and wechatChannelList = #{wechatChannelList}
					 </if> 
					<if test="phone!= null"> 
					and phone = #{phone}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					<if test="updateDt!= null"> 
					and updateDt = #{updateDt}
					 </if> 
					 <if test="userId!= null"> 
                        and userId = #{userId}
                     </if> 
                    <if test="aisleSwitch!= null"> 
                        and aisleSwitch = #{aisleSwitch}
                     </if> 
                     <if test="bankName!= null"> 
                        and bankName = #{bankName}
                     </if> 
                     <if test="bankCardFrontPic!= null"> 
                        and bankCardFrontPic = #{bankCardFrontPic}
                     </if> 
                     <if test="certStartTime!= null"> 
                        and certStartTime = #{certStartTime}
                     </if> 
                    <if test="certEndTime!= null"> 
                        and certEndTime = #{certEndTime}
                     </if> 
                     <if test="bankAddressNo!= null"> 
                        and bankAddressNo = #{bankAddressNo}
                     </if> 
                     <if test="branchArea!= null"> 
                        and branchArea = #{branchArea}
                     </if>
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryMerchantBankCardPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_merchant_bank_card 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					 and merchantCode = #{merchantCode}
					 </if> 
					<if test="storeId!= null"> 
					 and storeId = #{storeId}
					 </if> 
					<if test="bankCardNo!= null"> 
					 and bankCardNo = #{bankCardNo}
					 </if> 
					<if test="bankCertName!= null"> 
					 and bankCertName like  CONCAT("%",#{bankCertName},"%")
					 </if> 
					<if test="branchName!= null"> 
					 and branchName = #{branchName}
					 </if> 
					<if test="accountType!= null"> 
					 and accountType = #{accountType}
					 </if> 
					<if test="contactLine!= null"> 
					 and contactLine = #{contactLine}
					 </if> 
					<if test="branchProvince!= null"> 
					 and branchProvince = #{branchProvince}
					 </if> 
					<if test="branchCity!= null"> 
					 and branchCity = #{branchCity}
					 </if> 
					<if test="certType!= null"> 
					 and certType = #{certType}
					 </if> 
					<if test="certNo!= null"> 
					 and certNo = #{certNo}
					 </if> 
					<if test="cardHolderAddress!= null"> 
					 and cardHolderAddress = #{cardHolderAddress}
					 </if> 
					<if test="orderNo!= null"> 
					 and orderNo = #{orderNo}
					 </if> 
					<if test="merchantId!= null"> 
					 and merchantId = #{merchantId}
					 </if> 
					<if test="registerStatus!= null"> 
					 and registerStatus = #{registerStatus}
					 </if> 
					<if test="failReason!= null"> 
					 and failReason = #{failReason}
					 </if> 
					<if test="accountNo!= null"> 
					 and accountNo = #{accountNo}
					 </if> 
					<if test="wechatChannelList!= null"> 
					 and wechatChannelList = #{wechatChannelList}
					 </if> 
					<if test="phone!= null"> 
					 and phone = #{phone}
					 </if> 
					<if test="createDt!= null"> 
					 and createDt = #{createDt}
					 </if> 
					<if test="updateDt!= null"> 
					 and updateDt = #{updateDt}
					 </if> 
					 <if test="userId!= null"> 
                        and userId = #{userId}
                     </if> 
                    <if test="aisleSwitch!= null"> 
                        and aisleSwitch = #{aisleSwitch}
                     </if> 
                      <if test="bankName!= null"> 
                        and bankName = #{bankName}
                     </if> 
                     <if test="bankCardFrontPic!= null"> 
                        and bankCardFrontPic = #{bankCardFrontPic}
                     </if> 
                     <if test="certStartTime!= null"> 
                        and certStartTime = #{certStartTime}
                     </if> 
                    <if test="certEndTime!= null"> 
                        and certEndTime = #{certEndTime}
                     </if> 
                     <if test="bankAddressNo!= null"> 
                        and bankAddressNo = #{bankAddressNo}
                     </if> 
                     <if test="branchArea!= null"> 
                        and branchArea = #{branchArea}
                     </if>
				</where>
		</select>
		
		<select id="queryMerchantBankCardInfoPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.MerchantBankCard">
		      select mbc.id,mbc.bankCardNo,mbc.bankCertName,mbc.branchName,mbc.contactLine,mbc.branchProvince,mbc.branchCity,mbc.certNo,(select picUrl from tb_pluss_merchant_image mi where mi.merchantCode=mbc.merchantCode and mi.photoType='01') as image01,(select picUrl from tb_pluss_merchant_image mi where mi.merchantCode=mbc.merchantCode and mi.photoType='02') as image02,(select picUrl from tb_pluss_merchant_image mi where mi.merchantCode=mbc.merchantCode and mi.photoType='98') as image03,mbc.phone,mbc.createDt,mbc.updateDt from tb_pluss_merchant_bank_card mbc
		      <where>
		          <if test="bankCertName!=null and bankCertName!=''">
		             and mbc.bankCertName=#{bankCertName}
		          </if>
		      </where>
		      order by mbc.id DESC  limit #{pageSize}  offset  #{offset}  
		</select>
		
		<select id="queryMerchantBankCardInfoPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
              select count(mbc.id) from tb_pluss_merchant_bank_card mbc
              <where>
                  <if test="bankCertName!=null and bankCertName!=''">
                     and mbc.bankCertName=#{bankCertName}
                  </if>
              </where>
        </select>
		

</mapper>
