<?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.BillPushGoodsDAO">
    <resultMap id="BillPushGoodsMap" type="com.jpsoft.shinestar.modules.business.entity.BillPushGoods">
        <id property="id" column="id_"/>
        <result property="billPushId" column="bill_push_id"/>
        <result property="beginEndTime" column="begin_end_time"/>
        <result property="goodsId" column="goods_id"/>
        <result property="numStr" column="num_str"/>
        <result property="details" column="details_"/>
        <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="sortNo" column="sort_no"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.BillPushGoods">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into business_bill_push_goods
	    (id_,bill_push_id,begin_end_time,goods_id,num_str,details_,del_flag,create_by,create_time,update_by,update_time,sort_no)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{billPushId,jdbcType=VARCHAR}
            ,#{beginEndTime,jdbcType=VARCHAR}
            ,#{goodsId,jdbcType=VARCHAR}
            ,#{numStr,jdbcType=VARCHAR}
            ,#{details,jdbcType=VARCHAR}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{sortNo,jdbcType= NUMERIC }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from business_bill_push_goods where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.BillPushGoods">
        update business_bill_push_goods
        <set>
            <if test="billPushId!=null">
                bill_push_id=#{billPushId,jdbcType=VARCHAR},
            </if>
            <if test="beginEndTime!=null">
                begin_end_time=#{beginEndTime,jdbcType=VARCHAR},
            </if>
            <if test="goodsId!=null">
                goods_id=#{goodsId,jdbcType=VARCHAR},
            </if>
            <if test="numStr!=null">
                num_str=#{numStr,jdbcType=VARCHAR},
            </if>
            <if test="details!=null">
                details_=#{details,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="sortNo!=null">
                sort_no=#{sortNo,jdbcType= NUMERIC },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="BillPushGoodsMap">
        select * from business_bill_push_goods where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from business_bill_push_goods where id_=#{0}
    </select>
    <select id="list" resultMap="BillPushGoodsMap">
        select * from business_bill_push_goods
    </select>
    <select id="search" parameterType="hashmap" resultMap="BillPushGoodsMap">
        <![CDATA[
			select * from business_bill_push_goods
		]]>
        <where>
            del_flag = false
            <if test="searchParams.billPushId != null">
                and bill_push_id like #{searchParams.billPushId}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="searchStatistics" parameterType="hashmap" resultMap="BillPushGoodsMap">
        <![CDATA[
			select b.* from business_bill_push a left join business_bill_push_goods b on a.id_ = b.bill_push_id
			inner join
			base_order_info c on a.order_id = c.id_
		]]>
        <where>
            a.del_flag = false and b.del_flag = false and c.del_flag=false
            <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.invoiced != null">
                and a.invoiced_ = #{searchParams.invoiced}
            </if>
            <if test="searchParams.invoiceType != null">
                and a.invoice_type = #{searchParams.invoiceType}
            </if>
            <if test="searchParams.payName != null">
                and c.pay_name = #{searchParams.payName}
            </if>
            <if test="searchParams.payStatus != null">
                and c.pay_status = #{searchParams.payStatus}
            </if>
            <if test="searchParams.notPayStatus != null">
                and c.pay_status != #{searchParams.notPayStatus}
            </if>
            <if test="searchParams.beginPayTime != null">
                <![CDATA[
                  and c.pay_time >= #{searchParams.beginPayTime}
                ]]>
            </if>
            <if test="searchParams.endPayTime != null">
                <![CDATA[
                      and c.pay_time <= #{searchParams.endPayTime}
                ]]>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByBillPushId" resultMap="BillPushGoodsMap">
        <![CDATA[
		select * from business_bill_push_goods
		where del_flag = 0
		and bill_push_id = #{billPushId}
		order by sort_no asc
		]]>
    </select>
    <select id="findLastByCheckinInfoIdAndGoodsId" resultMap="BillPushGoodsMap">
        select a.* from business_bill_push_goods a
        inner join business_bill_push b on a.bill_push_id = b.id_
        where a.del_flag = 0
        and b.del_flag = 0
        and a.goods_id = #{goodsId}
        and b.checkinInfo_id = #{checkinInfoId}
        order by a.create_time desc
        limit 1
    </select>
</mapper>