<?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.base.dao.OrderInfoDAO">
    <resultMap id="OrderInfoMap" type="com.jpsoft.shinestar.modules.base.entity.OrderInfo">
        <id property="id" column="id_" />
        <result property="totalFee" column="total_fee" />
        <result property="body" column="body_" />
        <result property="payStatus" column="pay_status" />
        <result property="payName" column="pay_name" />
        <result property="payFee" column="pay_fee" />
        <result property="payTime" column="pay_time" />
        <result property="outOrderNo" column="out_order_no" />
        <result property="transactionId" column="transaction_id" />
        <result property="openId" column="open_id" />
        <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="type" column="type_"/>
        <result property="status" column="status_"/>
        <result property="personId" column="person_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="companyId" column="company_id"/>
        <result property="payPopedomId" column="pay_popedom_id"/>
        <result property="popularizePersonId" column="popularize_person_id"/>
        <result property="belongPopedomId" column="belong_popedom_id"/>
        <result property="detail" column="detail_"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.OrderInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_order_info
	    (id_,total_fee,body_,pay_status,pay_name,pay_fee,pay_time,out_order_no,transaction_id,open_id,del_flag,create_by,create_time,update_by,update_time,type_,status_,person_id,goods_id,company_id,pay_popedom_id,popularize_person_id,belong_popedom_id,detail_)
		values
		(
#{id,jdbcType=VARCHAR}
,#{totalFee,jdbcType=DECIMAL}
,#{body,jdbcType=VARCHAR}
,#{payStatus,jdbcType=INTEGER,jdbcType=VARCHAR}
,#{payName,jdbcType=VARCHAR}
,#{payFee,jdbcType=DECIMAL }
,#{payTime,jdbcType=TIMESTAMP }
,#{outOrderNo,jdbcType=VARCHAR }
,#{transactionId,jdbcType=VARCHAR }
,#{openId,jdbcType=VARCHAR}
,#{delFlag,jdbcType= NUMERIC }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{type,jdbcType=VARCHAR}
,#{status,jdbcType=VARCHAR}
,#{personId,jdbcType=BIGINT }
,#{goodsId,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{payPopedomId,jdbcType=VARCHAR}
,#{popularizePersonId,jdbcType=BIGINT}
,#{belongPopedomId,jdbcType=VARCHAR}
,#{detail,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_order_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.OrderInfo">
        update base_order_info
        <set>
            <if test="totalFee!=null">
                total_fee=#{totalFee,jdbcType=DECIMAL},
            </if>
            <if test="body!=null">
                body_=#{body,jdbcType=VARCHAR},
            </if>
            <if test="payStatus!=null">
                pay_status=#{payStatus,jdbcType=INTEGER},
            </if>
            <if test="payName!=null">
                pay_name=#{payName,jdbcType=VARCHAR},
            </if>
            <if test="payFee!=null">
                pay_fee=#{payFee,jdbcType=DECIMAL },
            </if>
            <if test="payTime!=null">
                pay_time=#{payTime,jdbcType=TIMESTAMP },
            </if>
            <if test="outOrderNo!=null">
                out_order_no=#{outOrderNo,jdbcType=VARCHAR },
            </if>
            <if test="transactionId!=null">
                transaction_id=#{transactionId,jdbcType=VARCHAR },
            </if>
            <if test="openId!=null">
                open_id=#{openId,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="type!=null">
                type_=#{type,jdbcType= VARCHAR },
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType= VARCHAR },
            </if>
            <if test="personId!=null">
                person_id=#{personId,jdbcType=BIGINT },
            </if>
            <if test="goodsId!=null">
                goods_id=#{goodsId,jdbcType= VARCHAR },
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType= VARCHAR },
            </if>
            <if test="payPopedomId!=null">
                pay_popedom_id=#{payPopedomId,jdbcType=VARCHAR },
            </if>
            <if test="popularizePersonId!=null">
                popularize_person_id=#{popularizePersonId,jdbcType=BIGINT},
            </if>
            <if test="belongPopedomId!=null">
                belong_popedom_id=#{belongPopedomId,jdbcType=VARCHAR},
            </if>
            <if test="detail!=null">
                detail_ = #{detail,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="OrderInfoMap">
        select * from base_order_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_order_info where id_=#{0}
    </select>
    <select id="list" resultMap="OrderInfoMap">
		select * from base_order_info where del_flag = 0
	</select>
    <select id="search" parameterType="hashmap" resultMap="OrderInfoMap">
        <![CDATA[
			select * from base_order_info
		]]>
        <where>
            del_flag = false
            <if test="searchParams.outOrderNo != null">
                and out_order_no like #{searchParams.outOrderNo}
            </if>
            <if test="searchParams.payStatus != null">
                and pay_status = #{searchParams.payStatus}
            </if>
            <if test="searchParams.name != null">
                and name_ like #{searchParams.name}
            </if>
            <if test="searchParams.type != null">
                and type_ = #{searchParams.type}
            </if>
            <if test="searchParams.personId != null">
                and person_id = #{searchParams.personId}
            </if>
            <if test="searchParams.status != null">
                and status_ = #{searchParams.status}
            </if>
            <if test="searchParams.transactionId != null">
                and transaction_id like #{searchParams.transactionId}
            </if>
            <if test="searchParams.companyId != null">
                and company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.beginTime != null">
                <![CDATA[
                  and create_time >= #{searchParams.beginTime}
            ]]>
            </if>
            <if test="searchParams.endTime != null">
                <![CDATA[
                  and create_time <= #{searchParams.endTime}
            ]]>
            </if>
            <if test="searchParams.payBeginTime != null">
                <![CDATA[
                  and pay_time >= #{searchParams.payBeginTime}
            ]]>
            </if>
            <if test="searchParams.payEndTime != null">
                <![CDATA[
                  and pay_time <= #{searchParams.payEndTime}
            ]]>
            </if>
            <if test="searchParams.goodsIdList != null">
                <foreach collection="searchParams.goodsIdList" index="index" item="item" open="and goods_id in("
                         separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="searchParams.personIdList != null">
                <foreach collection="searchParams.personIdList" index="index" item="item" open="and person_id in("
                         separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByOutOrderNo" resultMap="OrderInfoMap">
        <![CDATA[
        select * from base_order_info
        where del_flag = 0
        and out_order_no = #{outTradeNo}
        ]]>
    </select>


</mapper>