<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.business.dao.BillPushDAO">
	<resultMap id="BillPushMap" type="com.jpsoft.shinestar.modules.business.entity.BillPush">
		<id property="id" column="id_" />
		<result property="name" column="name_" />
		<result property="bak" column="bak_" />
		<result property="collectionAccountId" column="collection_account_id" />
		<result property="payService" column="pay_service" />
		<result property="pushTime" column="push_time" />
		<result property="companyId" column="company_id" />
		<result property="payee" column="payee" />
		<result property="delFlag" column="del_flag" />
		<result property="createBy" column="create_by" />
		<result property="createTime" column="create_time" />
		<result property="updateBy" column="update_by" />
		<result property="updateTime" column="update_time" />
		<result property="personId" column="person_id" />
		<result property="orderId" column="order_id" />
		<result property="status" column="status_" />
		<result property="checkinInfoId" column="checkinInfo_id" />
		<result property="isOpenWechat" column="is_open_wechat" />
		<result property="isOpenAlipay" column="is_open_alipay" />
		<result property="invoiceType" column="invoice_type" />
		<result property="invoiced" column="invoiced_" />
	</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.BillPush">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into business_bill_push
	    (id_,name_,bak_,collection_account_id,pay_service,push_time,company_id,payee,
	    del_flag,create_by,create_time,update_by,update_time,person_id,order_id,status_,
	    checkinInfo_id,is_open_wechat,is_open_alipay,invoice_type,invoiced_)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{name,jdbcType=VARCHAR}
			,#{bak,jdbcType=VARCHAR}
			,#{collectionAccountId,jdbcType=VARCHAR}
			,#{payService,jdbcType=VARCHAR}
			,#{pushTime,jdbcType= TIMESTAMP }
			,#{companyId,jdbcType=VARCHAR}
			,#{payee,jdbcType=VARCHAR}
			,#{delFlag,jdbcType= NUMERIC }
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{personId,jdbcType= NUMERIC }
			,#{orderId,jdbcType=VARCHAR}
			,#{status,jdbcType=VARCHAR}
			,#{checkinInfoId,jdbcType=VARCHAR}
			,#{isOpenWechat,jdbcType= NUMERIC }
			,#{isOpenAlipay,jdbcType= NUMERIC }
			,#{invoiceType,jdbcType=VARCHAR}
			,#{invoiced,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from business_bill_push where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.BillPush">
		update business_bill_push
		<set>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="bak!=null">
		bak_=#{bak,jdbcType=VARCHAR},
		</if>
				<if test="collectionAccountId!=null">
		collection_account_id=#{collectionAccountId,jdbcType=VARCHAR},
		</if>
				<if test="payService!=null">
		pay_service=#{payService,jdbcType=VARCHAR},
		</if>
				<if test="pushTime!=null">
		push_time=#{pushTime,jdbcType= TIMESTAMP },
		</if>
				<if test="companyId!=null">
		company_id=#{companyId,jdbcType=VARCHAR},
		</if>
				<if test="payee!=null">
		payee=#{payee,jdbcType=VARCHAR},
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="personId!=null">
		person_id=#{personId,jdbcType= NUMERIC },
		</if>
				<if test="orderId!=null">
		order_id=#{orderId,jdbcType=VARCHAR},
		</if>
			<if test="status!=null">
				status_=#{status,jdbcType=VARCHAR},
			</if>
			<if test="checkinInfoId!=null">
				checkinInfo_id=#{checkinInfoId,jdbcType=VARCHAR},
			</if>
			<if test="isOpenWechat!=null">
				is_open_wechat=#{isOpenWechat,jdbcType= NUMERIC },
			</if>
			<if test="isOpenAlipay!=null">
				is_open_alipay=#{isOpenAlipay,jdbcType= NUMERIC },
			</if>
			<if test="invoiceType!=null">
				invoice_type=#{invoiceType,jdbcType= VARCHAR },
			</if>
			<if test="invoiced!=null">
				invoiced_=#{invoiced,jdbcType= NUMERIC },
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="BillPushMap">
		select * from business_bill_push where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from business_bill_push where id_=#{0}
	</select>
	<select id="list" resultMap="BillPushMap">
		select * from business_bill_push
	</select>
	<select id="search" parameterType="hashmap" resultMap="BillPushMap">
		<![CDATA[
			select a.* from business_bill_push a inner join
			base_order_info b on a.order_id = b.id_
		]]>
		<where>
			a.del_flag=false and b.del_flag=false
			<if test="searchParams.name != null">
				and a.name_ like #{searchParams.name}
			</if>
			<if test="searchParams.companyId != null">
				and a.company_id = #{searchParams.companyId}
			</if>
			<if test="searchParams.status != null">
				and a.status_ = #{searchParams.status}
			</if>
			<if test="searchParams.notStatus1 != null">
				and a.status_ != #{searchParams.notStatus1}
			</if>
			<if test="searchParams.notStatus2 != null">
				and a.status_ != #{searchParams.notStatus2}
			</if>
			<if test="searchParams.payStatus != null">
				and b.pay_status = #{searchParams.payStatus}
			</if>
			<if test="searchParams.invoiced != null">
				and a.invoiced_ = #{searchParams.invoiced}
			</if>
			<if test="searchParams.payName != null">
				and b.pay_name = #{searchParams.payName}
			</if>

			<if test="searchParams.collectionAccount != null">
				and a.collection_account_id = #{searchParams.collectionAccount}
			</if>
			<if test="searchParams.beginPushTime != null">
				<![CDATA[
                  and a.push_time >= #{searchParams.beginPushTime}
            ]]>
			</if>
			<if test="searchParams.endPushTime != null">
				<![CDATA[
                  and a.push_time <= #{searchParams.endPushTime}
            ]]>
			</if>
			<if test="searchParams.beginPayTime != null">
				<![CDATA[
                  and b.pay_time >= #{searchParams.beginPayTime}
            ]]>
			</if>
			<if test="searchParams.endPayTime != null">
				<![CDATA[
                  and b.pay_time <= #{searchParams.endPayTime}
            ]]>
			</if>
			<if test="searchParams.companyPaymentInfoList != null">
				<foreach collection="searchParams.companyPaymentInfoList" index="index" item="item" open="and a.collection_account_id in("
						 separator="," close=")">
					#{item.id}
				</foreach>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByOrderId" resultMap="BillPushMap">
		<![CDATA[
		select * from business_bill_push
		where del_flag = 0
		and order_id = #{orderId}
		]]>
	</select>
</mapper>