<?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.ghy.payment.mapper.FinancialMasterMapper">

    <resultMap id="FinancialMasterResult" type="com.ghy.payment.domain.FinancialMaster">
        <id property="id"                    column="id"/>
        <result property="orderMasterId"     column="order_master_id"/>
        <result property="orderMasterCode"   column="order_master_code"/>
        <result property="totalMoney"        column="total_money"/>
        <result property="discountMoney"     column="discount_money"/>
        <result property="payMoney"          column="pay_money"/>
        <result property="payType"           column="pay_type"/>
        <result property="payStatus"         column="pay_status"/>
        <result property="payTime"           column="pay_time"/>
        <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="remark"            column="remark"/>
    </resultMap>

    <sql id="selectFinancialMaster">
        SELECT  id,
                order_master_id,
                order_master_code,
                total_money,
                discount_money,
                pay_money,
                pay_type,
                pay_status,
                pay_time,
                create_by,
                create_time,
                remark
        FROM financial_master
    </sql>

    <select id="selectFinancialMasterList" parameterType="com.ghy.payment.domain.FinancialMaster" resultMap="FinancialMasterResult">
        <include refid="selectFinancialMaster"/>
        <where>
            <if test="orderMasterId != null and orderMasterId != 0">
                AND order_master_id = #{orderMasterId}
            </if>
            <if test="orderMasterCode != null and orderMasterCode != ''">
                AND order_master_code LIKE concat('%', #{orderMasterCode}, '%')
            </if>
            <if test="payType != null and payType != 0">
                AND pay_type = #{payType}
            </if>
            <if test="payStatus != null and payStatus != 0">
                AND pay_status = #{payStatus}
            </if>
        </where>
    </select>

    <select id="selectById" parameterType="long" resultMap="FinancialMasterResult">
        <include refid="selectFinancialMaster"/>
        <where>
            <if test="financialMasterId != null and financialMasterId != 0">
                AND id = #{financialMasterId}
            </if>
        </where>
    </select>

    <delete id="deleteFinancialMasterByIds" parameterType="Long">
        DELETE FROM financial_master WHERE id IN
        <foreach collection="array" item="financialMasterId" open="(" separator="," close=")">
            #{financialMasterId}
        </foreach>
    </delete>

    <update id="updateFinancialMaster" parameterType="com.ghy.payment.domain.FinancialMaster">
        UPDATE financial_master
        <set>
            <if test="orderMasterId != null and orderMasterId != ''">order_master_id = #{orderMasterId},</if>
            <if test="orderMasterCode != null and orderMasterCode != ''">order_master_code = #{orderMasterCode},</if>
            <if test="totalMoney != null and totalMoney != ''">total_money = #{totalMoney},</if>
            <if test="discountMoney != null and discountMoney != ''">discount_money = #{discountMoney},</if>
            <if test="payType != null and payType != ''">pay_type = #{payType},</if>
            <if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
            <if test="payTime != null and payTime != ''">pay_time = #{payTime},</if>
            <if test="payMoney != null and payMoney != ''">pay_money = #{payMoney},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = SYSDATE()
        </set>
        WHERE id = #{id}
    </update>

    <insert id="insertFinancialMaster" parameterType="com.ghy.payment.domain.FinancialMaster" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO financial_master(
        <if test="orderMasterId != null and orderMasterId != 0">order_master_id,</if>
        <if test="orderMasterCode != null and orderMasterCode != ''">order_master_code,</if>
        <if test="totalMoney != null and totalMoney != ''">total_money,</if>
        <if test="discountMoney != null and discountMoney != ''">discount_money,</if>
        <if test="payType != null and payType != ''">pay_type,</if>
        <if test="payStatus != null and payStatus != ''">pay_status,</if>
        <if test="payTime != null and payTime != ''">pay_time,</if>
        <if test="payMoney != null and payMoney != ''">pay_money,</if>
        <if test="createBy != null and createBy != ''">create_by,</if>
        create_time
        )VALUES(
        <if test="orderMasterId != null and orderMasterId != 0">#{orderMasterId},</if>
        <if test="orderMasterCode != null and orderMasterCode != ''">#{orderMasterCode},</if>
        <if test="totalMoney != null and totalMoney != ''">#{totalMoney},</if>
        <if test="discountMoney != null and discountMoney != ''">#{discountMoney},</if>
        <if test="payType != null and payType != ''">#{payType},</if>
        <if test="payStatus != null and payStatus != ''">#{payStatus},</if>
        <if test="payTime != null and payTime != ''">#{payTime},</if>
        <if test="payMoney != null and payMoney != ''">#{payMoney},</if>
        <if test="createBy != null and createBy != ''">#{createBy},</if>
        SYSDATE()
        )
    </insert>

</mapper>