<?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.xinelu.manage.mapper.paymentinfo.PaymentInfoMapper">

    <resultMap type="PaymentInfo" id="PaymentInfoResult">
        <result property="id" column="id"/>
        <result property="patientId" column="patient_id"/>
        <result property="nurseStationPersonId" column="nurse_station_person_id"/>
        <result property="orderNo" column="order_no"/>
        <result property="paymentTitle" column="payment_title"/>
        <result property="transactionNo" column="transaction_no"/>
        <result property="payPrice" column="pay_price"/>
        <result property="payType" column="pay_type"/>
        <result property="payChannel" column="pay_channel"/>
        <result property="wechatTradeState" column="wechat_trade_state"/>
        <result property="alipayTradeState" column="alipay_trade_state"/>
        <result property="payNotifyContent" column="pay_notify_content"/>
        <result property="payTime" column="pay_time"/>
        <result property="paymentMerchantType" column="payment_merchant_type"/>
        <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="selectPaymentInfoVo">
        select id,
               patient_id,
               nurse_station_person_id,
               order_no,
               payment_title,
               transaction_no,
               pay_price,
               pay_type,
               pay_channel,
               wechat_trade_state,
               alipay_trade_state,
               pay_notify_content,
               pay_time,
               payment_merchant_type,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from payment_info
    </sql>

    <select id="selectPaymentInfoList" parameterType="PaymentInfo" resultMap="PaymentInfoResult">
        <include refid="selectPaymentInfoVo"/>
        <where>
            <if test="patientId != null ">
                and patient_id = #{patientId}
            </if>
            <if test="nurseStationPersonId != null ">
                and nurse_station_person_id = #{nurseStationPersonId}
            </if>
            <if test="orderNo != null  and orderNo != ''">
                and order_no = #{orderNo}
            </if>
            <if test="paymentTitle != null  and paymentTitle != ''">
                and payment_title = #{paymentTitle}
            </if>
            <if test="transactionNo != null  and transactionNo != ''">
                and transaction_no = #{transactionNo}
            </if>
            <if test="payPrice != null ">
                and pay_price = #{payPrice}
            </if>
            <if test="payType != null  and payType != ''">
                and pay_type = #{payType}
            </if>
            <if test="payChannel != null  and payChannel != ''">
                and pay_channel = #{payChannel}
            </if>
            <if test="wechatTradeState != null  and wechatTradeState != ''">
                and wechat_trade_state = #{wechatTradeState}
            </if>
            <if test="alipayTradeState != null  and alipayTradeState != ''">
                and alipay_trade_state = #{alipayTradeState}
            </if>
            <if test="payNotifyContent != null  and payNotifyContent != ''">
                and pay_notify_content = #{payNotifyContent}
            </if>
            <if test="payTime != null ">
                and pay_time = #{payTime}
            </if>
            <if test="paymentMerchantType != null  and paymentMerchantType != ''">
                and payment_merchant_type = #{paymentMerchantType}
            </if>
        </where>
    </select>

    <select id="selectPaymentInfoById" parameterType="Long"
            resultMap="PaymentInfoResult">
        <include refid="selectPaymentInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPaymentInfo" parameterType="PaymentInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into payment_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patientId != null">patient_id,
            </if>
            <if test="nurseStationPersonId != null">nurse_station_person_id,
            </if>
            <if test="orderNo != null">order_no,
            </if>
            <if test="paymentTitle != null">payment_title,
            </if>
            <if test="transactionNo != null">transaction_no,
            </if>
            <if test="payPrice != null">pay_price,
            </if>
            <if test="payType != null">pay_type,
            </if>
            <if test="payChannel != null">pay_channel,
            </if>
            <if test="wechatTradeState != null">wechat_trade_state,
            </if>
            <if test="alipayTradeState != null">alipay_trade_state,
            </if>
            <if test="payNotifyContent != null">pay_notify_content,
            </if>
            <if test="payTime != null">pay_time,
            </if>
            <if test="paymentMerchantType != null">payment_merchant_type,
            </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="patientId != null">#{patientId},
            </if>
            <if test="nurseStationPersonId != null">#{nurseStationPersonId},
            </if>
            <if test="orderNo != null">#{orderNo},
            </if>
            <if test="paymentTitle != null">#{paymentTitle},
            </if>
            <if test="transactionNo != null">#{transactionNo},
            </if>
            <if test="payPrice != null">#{payPrice},
            </if>
            <if test="payType != null">#{payType},
            </if>
            <if test="payChannel != null">#{payChannel},
            </if>
            <if test="wechatTradeState != null">#{wechatTradeState},
            </if>
            <if test="alipayTradeState != null">#{alipayTradeState},
            </if>
            <if test="payNotifyContent != null">#{payNotifyContent},
            </if>
            <if test="payTime != null">#{payTime},
            </if>
            <if test="paymentMerchantType != null">#{paymentMerchantType},
            </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="updatePaymentInfo" parameterType="PaymentInfo">
        update payment_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
            <if test="nurseStationPersonId != null">nurse_station_person_id =
                #{nurseStationPersonId},
            </if>
            <if test="orderNo != null">order_no =
                #{orderNo},
            </if>
            <if test="paymentTitle != null">payment_title =
                #{paymentTitle},
            </if>
            <if test="transactionNo != null">transaction_no =
                #{transactionNo},
            </if>
            <if test="payPrice != null">pay_price =
                #{payPrice},
            </if>
            <if test="payType != null">pay_type =
                #{payType},
            </if>
            <if test="payChannel != null">pay_channel =
                #{payChannel},
            </if>
            <if test="wechatTradeState != null">wechat_trade_state =
                #{wechatTradeState},
            </if>
            <if test="alipayTradeState != null">alipay_trade_state =
                #{alipayTradeState},
            </if>
            <if test="payNotifyContent != null">pay_notify_content =
                #{payNotifyContent},
            </if>
            <if test="payTime != null">pay_time =
                #{payTime},
            </if>
            <if test="paymentMerchantType != null">payment_merchant_type =
                #{paymentMerchantType},
            </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="deletePaymentInfoById" parameterType="Long">
        delete
        from payment_info
        where id = #{id}
    </delete>

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

    <select id="getPaymentInfoByOrderNo" parameterType="string" resultType="int">
        select count(1) paymentCount
        from payment_info
        where order_no = #{orderNo}
    </select>
</mapper>
