<?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.fs.live.mapper.LiveOrderPaymentMapper">

    <resultMap type="LiveOrderPayment" id="LiveOrderPaymentResult">
        <result property="paymentId"    column="payment_id"    />
        <result property="payCode"    column="pay_code"    />
        <result property="payTypeCode"    column="pay_type_code"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="payTime"    column="pay_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="tradeNo"    column="trade_no"    />
        <result property="userId"    column="user_id"    />
        <result property="openId"    column="open_id"    />
        <result property="businessType"    column="business_type"    />
        <result property="businessId"    column="business_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="bankTransactionId"    column="bank_transaction_id"    />
        <result property="bankSerialNo"    column="bank_serial_no"    />
        <result property="refundMoney"    column="refund_money"    />
        <result property="refundTime"    column="refund_time"    />
        <result property="storeId"    column="store_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="businessCode"    column="business_code"    />
        <result property="payMode"    column="pay_mode"    />
        <result property="shareStatus"    column="share_status"    />
        <result property="shareCode"    column="share_code"    />
        <result property="shareMoney"    column="share_money"    />
        <result property="isShare"    column="is_share"    />
    </resultMap>

    <sql id="selectLiveOrderPaymentVo">
        select payment_id, pay_code, pay_type_code, pay_money, pay_time, create_time, trade_no, user_id, open_id, business_type, business_id, status, remark, bank_transaction_id, bank_serial_no, refund_money, refund_time, store_id, company_id, company_user_id, business_code, pay_mode, share_status, share_code, share_money, is_share from live_order_payment
    </sql>

    <select id="selectLiveOrderPaymentList" parameterType="LiveOrderPayment" resultMap="LiveOrderPaymentResult">
        <include refid="selectLiveOrderPaymentVo"/>
        <where>
            <if test="payCode != null  and payCode != ''"> and pay_code = #{payCode}</if>
            <if test="payTypeCode != null  and payTypeCode != ''"> and pay_type_code = #{payTypeCode}</if>
            <if test="payMoney != null "> and pay_money = #{payMoney}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="tradeNo != null  and tradeNo != ''"> and trade_no = #{tradeNo}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="businessType != null "> and business_type = #{businessType}</if>
            <if test="businessId != null  and businessId != ''"> and business_id = #{businessId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="bankTransactionId != null  and bankTransactionId != ''"> and bank_transaction_id = #{bankTransactionId}</if>
            <if test="bankSerialNo != null  and bankSerialNo != ''"> and bank_serial_no = #{bankSerialNo}</if>
            <if test="refundMoney != null "> and refund_money = #{refundMoney}</if>
            <if test="refundTime != null "> and refund_time = #{refundTime}</if>
            <if test="storeId != null "> and store_id = #{storeId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="payMode != null  and payMode != ''"> and pay_mode = #{payMode}</if>
            <if test="shareStatus != null "> and share_status = #{shareStatus}</if>
            <if test="shareCode != null  and shareCode != ''"> and share_code = #{shareCode}</if>
            <if test="shareMoney != null "> and share_money = #{shareMoney}</if>
            <if test="isShare != null "> and is_share = #{isShare}</if>
        </where>
    </select>
    <select id="selectLiveOrderPaymentVoList" parameterType="com.fs.live.vo.LiveOrderPaymentVo" resultType="com.fs.live.vo.LiveOrderPaymentVo">
        select lop.payment_id, lop.pay_code, lop.pay_type_code, lop.pay_money, lop.pay_time, lop.create_time, lop.trade_no, lop.user_id, lop.open_id, lop.business_type, lop.business_id as order_code,
        lop.status, lop.remark, lop.bank_transaction_id, lop.bank_serial_no, lop.refund_money, lop.refund_time, lop.store_id, lo.company_id, lo.company_user_id, lop.business_code,
        lop.pay_mode, lop.share_status, lop.share_code, lop.share_money, lop.is_share, lo.user_phone,c.company_name as company_name, cde.dept_name as dept_name,cu.nick_name as company_user_nick_name
        from live_order_payment lop
        left join live_order lo on lop.business_id = lo.order_id
        left join company_user cu on lo.company_user_id = cu.user_id
        left join company c on lo.company_id = c.company_id
        left join company_dept cde  on cde.dept_id = cu.dept_id

        <where>
            <if test="payCode != null  and payCode != ''"> and lop.pay_code = #{payCode}</if>
            <if test="payTypeCode != null  and payTypeCode != ''"> and lop.pay_type_code = #{payTypeCode}</if>
            <if test="payMoney != null "> and lop.pay_money = #{payMoney}</if>
            <if test="payTime != null "> and lop.pay_time = #{payTime}</if>
            <if test="tradeNo != null  and tradeNo != ''"> and lop.trade_no = #{tradeNo}</if>
            <if test="userId != null "> and lop.user_id = #{userId}</if>
            <if test="openId != null  and openId != ''"> and lop.open_id = #{openId}</if>
            <if test="businessType != null "> and lop.business_type = #{businessType}</if>
            <if test="businessId != null  and businessId != ''"> and lop.business_id = #{businessId}</if>
            <if test="status != null "> and lop.status = #{status}</if>
            <if test="bankTransactionId != null  and bankTransactionId != ''"> and lop.bank_transaction_id = #{bankTransactionId}</if>
            <if test="bankSerialNo != null  and bankSerialNo != ''"> and lop.bank_serial_no = #{bankSerialNo}</if>
            <if test="refundMoney != null "> and lop.refund_money = #{refundMoney}</if>
            <if test="refundTime != null "> and lop.refund_time = #{refundTime}</if>
            <if test="storeId != null "> and lop.store_id = #{storeId}</if>
            <if test="companyId != null "> and lop.company_id = #{companyId}</if>
            <if test="companyUserId != null "> and lop.company_user_id = #{companyUserId}</if>
            <if test="businessCode != null  and businessCode != ''"> and lop.business_code = #{businessCode}</if>
            <if test="payMode != null  and payMode != ''"> and lop.pay_mode = #{payMode}</if>
            <if test="shareStatus != null "> and lop.share_status = #{shareStatus}</if>
            <if test="shareCode != null  and shareCode != ''"> and lop.share_code = #{shareCode}</if>
            <if test="shareMoney != null "> and lop.share_money = #{shareMoney}</if>
            <if test="isShare != null "> and lop.is_share = #{isShare}</if>
        </where>
    </select>
    <select id="selectLiveOrderPaymentByPaymentIdNew"  resultType="com.fs.live.vo.LiveOrderPaymentVo">
        select lop.payment_id, lop.pay_code, lop.pay_type_code, lop.pay_money, lop.pay_time, lop.create_time, lop.trade_no, lop.user_id, lop.open_id, lop.business_type, lop.business_id as order_code,
        lop.status, lop.remark, lop.bank_transaction_id, lop.bank_serial_no, lop.refund_money, lop.refund_time, lop.store_id, lo.company_id, lo.company_user_id, lop.business_code,
        lop.pay_mode, lop.share_status, lop.share_code, lop.share_money, lop.is_share, lo.user_phone,c.company_name as company_name, cde.dept_name as dept_name,cu.nick_name as company_user_nick_name
        from live_order_payment lop
        left join live_order lo on lop.business_id = lo.order_id
        left join company_user cu on lo.company_user_id = cu.user_id
        left join company c on lo.company_id = c.company_id
        left join company_dept cde  on cde.dept_id = cu.dept_id
        where lop.payment_id = #{paymentId}
    </select>

    <select id="selectLiveOrderPaymentByPaymentId" parameterType="Long" resultMap="LiveOrderPaymentResult">
        <include refid="selectLiveOrderPaymentVo"/>
        where payment_id = #{paymentId}
    </select>

    <insert id="insertLiveOrderPayment" parameterType="LiveOrderPayment" useGeneratedKeys="true" keyProperty="paymentId">
        insert into live_order_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="payCode != null">pay_code,</if>
            <if test="payTypeCode != null">pay_type_code,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="tradeNo != null">trade_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="openId != null">open_id,</if>
            <if test="businessType != null">business_type,</if>
            <if test="businessId != null">business_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="bankTransactionId != null">bank_transaction_id,</if>
            <if test="bankSerialNo != null">bank_serial_no,</if>
            <if test="refundMoney != null">refund_money,</if>
            <if test="refundTime != null">refund_time,</if>
            <if test="storeId != null">store_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="businessCode != null">business_code,</if>
            <if test="payMode != null">pay_mode,</if>
            <if test="shareStatus != null">share_status,</if>
            <if test="shareCode != null">share_code,</if>
            <if test="shareMoney != null">share_money,</if>
            <if test="isShare != null">is_share,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="payCode != null">#{payCode},</if>
            <if test="payTypeCode != null">#{payTypeCode},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="tradeNo != null">#{tradeNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="openId != null">#{openId},</if>
            <if test="businessType != null">#{businessType},</if>
            <if test="businessId != null">#{businessId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="bankTransactionId != null">#{bankTransactionId},</if>
            <if test="bankSerialNo != null">#{bankSerialNo},</if>
            <if test="refundMoney != null">#{refundMoney},</if>
            <if test="refundTime != null">#{refundTime},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="businessCode != null">#{businessCode},</if>
            <if test="payMode != null">#{payMode},</if>
            <if test="shareStatus != null">#{shareStatus},</if>
            <if test="shareCode != null">#{shareCode},</if>
            <if test="shareMoney != null">#{shareMoney},</if>
            <if test="isShare != null">#{isShare},</if>
         </trim>
    </insert>

    <update id="updateLiveOrderPayment" parameterType="LiveOrderPayment">
        update live_order_payment
        <trim prefix="SET" suffixOverrides=",">
            <if test="payCode != null">pay_code = #{payCode},</if>
            <if test="payTypeCode != null">pay_type_code = #{payTypeCode},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="tradeNo != null">trade_no = #{tradeNo},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="businessType != null">business_type = #{businessType},</if>
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="bankTransactionId != null">bank_transaction_id = #{bankTransactionId},</if>
            <if test="bankSerialNo != null">bank_serial_no = #{bankSerialNo},</if>
            <if test="refundMoney != null">refund_money = #{refundMoney},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
            <if test="payMode != null">pay_mode = #{payMode},</if>
            <if test="shareStatus != null">share_status = #{shareStatus},</if>
            <if test="shareCode != null">share_code = #{shareCode},</if>
            <if test="shareMoney != null">share_money = #{shareMoney},</if>
            <if test="isShare != null">is_share = #{isShare},</if>
        </trim>
        where payment_id = #{paymentId}
    </update>

    <delete id="deleteLiveOrderPaymentByPaymentId" parameterType="Long">
        delete from live_order_payment where payment_id = #{paymentId}
    </delete>

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