<?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.younike.system.mapper.ProfitSharingRecordMapper">
    
    <resultMap type="ProfitSharingRecord" id="ProfitSharingRecordResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="outOrderNo"    column="out_order_no"    />
        <result property="subMchid"    column="sub_mchid"    />
        <result property="transactionId"    column="transaction_id"    />
        <result property="platformAccount"    column="platform_account"    />
        <result property="platformAmount"    column="platform_amount"    />
        <result property="agentAccount"    column="agent_account"    />
        <result property="agentAmount"    column="agent_amount"    />
        <result property="status"    column="status"    />
        <result property="result"    column="result"    />
        <result property="queryResult"    column="query_result"    />
        <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"    />
    </resultMap>

    <sql id="selectProfitSharingRecordVo">
        select id, order_id, out_order_no, sub_mchid, transaction_id, platform_account, platform_amount, agent_account, agent_amount, status, result, query_result, del_flag, create_by, create_time, update_by, update_time from profit_sharing_record
    </sql>

    <select id="selectProfitSharingRecordList" parameterType="ProfitSharingRecord" resultMap="ProfitSharingRecordResult">
        <include refid="selectProfitSharingRecordVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="outOrderNo != null  and outOrderNo != ''"> and out_order_no = #{outOrderNo}</if>
            <if test="subMchid != null  and subMchid != ''"> and sub_mchid = #{subMchid}</if>
            <if test="transactionId != null  and transactionId != ''"> and transaction_id = #{transactionId}</if>
            <if test="platformAccount != null  and platformAccount != ''"> and platform_account = #{platformAccount}</if>
            <if test="platformAmount != null "> and platform_amount = #{platformAmount}</if>
            <if test="agentAccount != null "> and agent_account = #{agentAccount}</if>
            <if test="agentAmount != null "> and agent_amount = #{agentAmount}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectProfitSharingRecordById" parameterType="Long" resultMap="ProfitSharingRecordResult">
        <include refid="selectProfitSharingRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProfitSharingRecord" parameterType="ProfitSharingRecord" useGeneratedKeys="true" keyProperty="id">
        insert into profit_sharing_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="outOrderNo != null">out_order_no,</if>
            <if test="subMchid != null">sub_mchid,</if>
            <if test="transactionId != null">transaction_id,</if>
            <if test="platformAccount != null">platform_account,</if>
            <if test="platformAmount != null">platform_amount,</if>
            <if test="agentAccount != null">agent_account,</if>
            <if test="agentAmount != null">agent_amount,</if>
            <if test="status != null">status,</if>
            <if test="result != null">result,</if>
            <if test="queryResult != null">query_result,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="outOrderNo != null">#{outOrderNo},</if>
            <if test="subMchid != null">#{subMchid},</if>
            <if test="transactionId != null">#{transactionId},</if>
            <if test="platformAccount != null">#{platformAccount},</if>
            <if test="platformAmount != null">#{platformAmount},</if>
            <if test="agentAccount != null">#{agentAccount},</if>
            <if test="agentAmount != null">#{agentAmount},</if>
            <if test="status != null">#{status},</if>
            <if test="result != null">#{result},</if>
            <if test="queryResult != null">#{queryResult},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateProfitSharingRecord" parameterType="ProfitSharingRecord">
        update profit_sharing_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="outOrderNo != null">out_order_no = #{outOrderNo},</if>
            <if test="subMchid != null">sub_mchid = #{subMchid},</if>
            <if test="transactionId != null">transaction_id = #{transactionId},</if>
            <if test="platformAccount != null">platform_account = #{platformAccount},</if>
            <if test="platformAmount != null">platform_amount = #{platformAmount},</if>
            <if test="agentAccount != null">agent_account = #{agentAccount},</if>
            <if test="agentAmount != null">agent_amount = #{agentAmount},</if>
            <if test="status != null">status = #{status},</if>
            <if test="result != null">result = #{result},</if>
            <if test="queryResult != null">query_result = #{queryResult},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProfitSharingRecordById" parameterType="Long">
        delete from profit_sharing_record where id = #{id}
    </delete>

    <delete id="deleteProfitSharingRecordByIds" parameterType="String">
        delete from profit_sharing_record where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>