<?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.kmall.api.dao.ApiPayerChildOrderRealMapper">

    <resultMap type="com.kmall.api.entity.PayerChildOrderRealEntity" id="payerChildOrderRealMap">
        <result property="id" column="id"/>
        <result property="orderSn" column="order_sn"/>
        <result property="userId" column="user_id"/>
        <result property="payNo" column="pay_no"/>
        <result property="merchSn" column="merch_sn"/>
		<result property="merchOrderSn" column="merch_order_sn"/>
        <result property="payPrice" column="pay_price"/>
        <result property="goodsBizType" column="goods_biz_type"/>
        <result property="createrSn" column="creater_sn"/>
        <result property="createTime" column="create_time"/>
        <result property="moderSn" column="moder_sn"/>
        <result property="modTime" column="mod_time"/>
        <result property="tstm" column="tstm"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.api.entity.PayerChildOrderRealEntity">
		select
			`id`,
			`order_sn`,
			`user_id`,
			`merch_order_sn`,
			`pay_no`,
			`merch_sn`,
			`pay_price`,
			`goods_biz_type`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from mall_payer_child_order_real
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.api.entity.PayerChildOrderRealEntity">
		select
    		`id`,
    		`order_sn`,
    		`user_id`,
			`merch_order_sn`,
    		`pay_no`,
    		`merch_sn`,
    		`pay_price`,
    		`goods_biz_type`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`
		from mall_payer_child_order_real
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<if test="merchOrderSn != null and merchOrderSn.trim() != ''">
			AND merch_order_sn = #{merchOrderSn}
		</if>
		<if test="orderSn != null and orderSn.trim() != ''">
			AND order_sn = #{orderSn}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from mall_payer_child_order_real
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.api.entity.PayerChildOrderRealEntity">
		insert into mall_payer_child_order_real(
			`order_sn`,
			`user_id`,
			`merch_order_sn`,
			`pay_no`,
			`merch_sn`,
			`pay_price`,
			`goods_biz_type`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{orderSn},
			#{userId},
			#{merchOrderSn},
			#{payNo},
			#{merchSn},
			#{payPrice},
			#{goodsBizType},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>
	 
	<update id="update" parameterType="com.kmall.api.entity.PayerChildOrderRealEntity">
		update mall_payer_child_order_real 
		<set>
			<if test="orderSn != null">`order_sn` = #{orderSn}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="merchOrderSn != null">`merch_order_sn` = #{merchOrderSn}, </if>
			<if test="payNo != null">`pay_no` = #{payNo}, </if>
			<if test="merchSn != null">`merch_sn` = #{merchSn}, </if>
			<if test="payPrice != null">`pay_price` = #{payPrice}, </if>
			<if test="goodsBizType != null">`goods_biz_type` = #{goodsBizType}, </if>
			<if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
			<if test="modTime != null">`mod_time` = #{modTime}, </if>
			<if test="tstm != null">`tstm` = #{tstm}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from mall_payer_child_order_real where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mall_payer_child_order_real where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>