<?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.iformall.mapper.WxPrepaymentHistoryMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxPrepaymentHistory">
		<id column="id" property="id"/>
		<result column="tenant_id" property="tenantId"/>
		<result column="merchant_id" property="merchantId"/>
		<result column="pay_type" property="payType"/>
		<result column="pay_way" property="payWay"/>
		<result column="amount_detail" property="amountDetail"/>
		<result column="remain_amount" property="remainAmount"/>
		<result column="operation_type" property="operationType"/>
		<result column="operator" property="operator"/>
		<result column="create_time" property="createTime"/>
		<result column="merchant_name" property="merchantName"/>
	</resultMap>
	
	<sql id="allColumns">
		  p.`id,p.`tenant_id`,p.`merchant_id`,p.`pay_way`,p.`pay_type`,p.`amount_detail`,p.`remain_amount`,p.`operation_type`,p.`operator`,p.`create_time`,m.`name` merchant_name
	</sql>
	
	
	<sql id="dynamicWhereConditions">
		where 1 = 1
		<if test=" null != tenantId ">
			and p.`tenant_id` = #{tenantId}
		</if>
		<if test=" null != id ">
			and p.`id` = #{id}
		</if>
		<if test=" null != merchantId ">
			and p.`merchant_id` = #{merchantId}
		</if>
		<if test=" null != payType ">
			and p.`pay_type` = #{payType}
		</if>
		<if test=" null != payWay ">
			and p.`pay_way` = #{payWay}
		</if>
		<if test=" null != operationType ">
			and p.`operation_type` = #{operationType}
		</if>
		<if test=" null != merchantName and '' != merchantName">
			and m.`name` like concat('%',#{merchantName},'%')
		</if>
		<if test=" null != ids ">
			and p.id in
			<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
				#{idItem}
			</foreach>
		</if>
		<if test=" null != sortColumns">order by ${sortColumns}</if>
	</sql>
	
	<select id="findList" parameterType="com.iformall.domain.po.WxPrepayment" resultMap="BaseResultMap">
		select
		<include refid="allColumns"/>
		from wx_prepayment_history p inner join wx_merchant m on p.merchant_id=m.id
		<include refid="dynamicWhereConditions"/>
	</select>


</mapper>
