<?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.diaoyun.zion.chinafrica.dao.TbCfPlatformOrderDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfPlatformOrderEntity" id="tbCfPlatformOrderMap">
        <result property="relativeId" column="relative_id"/>
        <result property="orderId" column="order_id"/>
        <result property="pOrderId" column="p_order_id"/>
        <result property="platformName" column="platform_name"/>
        <result property="platformCode" column="platform_code"/>
        <result property="pDeliveryAddress" column="p_delivery_address"/>
        <result property="agentName" column="agent_name"/>
        <result property="agentId" column="agent_id"/>
        <result property="createTime" column="create_time"/>
        <result property="realPay" column="real_pay"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformOrderEntity">
		select
			`relative_id`,
			`order_id`,
			`p_order_id`,
			`platform_name`,
			`platform_code`,
			`p_delivery_address`,
			`agent_name`,
			`agent_id`,
			`create_time`,
			`real_pay`
		from tb_cf_platform_order
		where relative_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformOrderEntity">
		select
    		`relative_id`,
    		`order_id`,
    		`p_order_id`,
    		`platform_name`,
    		`platform_code`,
    		`p_delivery_address`,
    		`agent_name`,
    		`agent_id`,
    		`create_time`,
    		`real_pay`
		from tb_cf_platform_order
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by relative_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_platform_order
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformOrderEntity">
		insert into tb_cf_platform_order(
			`relative_id`,
			`order_id`,
			`p_order_id`,
			`platform_name`,
			`platform_code`,
			`p_delivery_address`,
			`agent_name`,
			`agent_id`,
			`create_time`,
			`real_pay`)
		values(
			#{relativeId},
			#{orderId},
			#{pOrderId},
			#{platformName},
			#{platformCode},
			#{pDeliveryAddress},
			#{agentName},
			#{agentId},
			#{createTime},
			#{realPay})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfPlatformOrderEntity">
		update tb_cf_platform_order 
		<set>
			<if test="orderId != null">`order_id` = #{orderId}, </if>
			<if test="pOrderId != null">`p_order_id` = #{pOrderId}, </if>
			<if test="platformName != null">`platform_name` = #{platformName}, </if>
			<if test="platformCode != null">`platform_code` = #{platformCode}, </if>
			<if test="pDeliveryAddress != null">`p_delivery_address` = #{pDeliveryAddress}, </if>
			<if test="agentName != null">`agent_name` = #{agentName}, </if>
			<if test="agentId != null">`agent_id` = #{agentId}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="realPay != null">`real_pay` = #{realPay}</if>
		</set>
		where relative_id = #{relativeId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_platform_order where relative_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_platform_order where relative_id in 
		<foreach item="relativeId" collection="array" open="(" separator="," close=")">
			#{relativeId}
		</foreach>
	</delete>

</mapper>