<?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.srs.comprehensive.mapper.SrsOrderMapper">
    
    <resultMap type="SrsOrder" id="SrsOrderResult">
        <result property="id"    column="id"    />
        <result property="paymentId"    column="payment_id"    />
        <result property="paymentName"    column="payment_name"    />
        <result property="paymentCode"    column="payment_code"    />
        <result property="amount"    column="amount"    />
        <result property="userName"    column="user_name"    />
        <result property="name"    column="nick_name"    />
        <result property="userId"    column="user_id"    />
        <result property="payStatus"    column="pay_status"    />
        <result property="transNo"    column="trans_no"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectSrsOrderVo">
        select o.id, payment_id, o.user_id,user_name,nick_name,p.payment_name,p.amount ,p.payment_code , pay_status, trans_no, o.create_time,o. create_by, o.update_time, o.update_by,o.del_flag
        from srs_order o
        left join srs_payment  p on p.id =o.payment_id
        left join sys_user su on o.user_id = su.user_id
    </sql>

    <select id="selectSrsOrderList" parameterType="SrsOrder" resultMap="SrsOrderResult">
        <include refid="selectSrsOrderVo"/>
        <where>  
            <if test="paymentId != null "> and o.payment_id = #{paymentId}</if>
            <if test="userId != null "> and o.user_id = #{userId}</if>
            <if test="payStatus != null  and payStatus != ''"> and o.pay_status = #{payStatus}</if>
            <if test="transNo != null  and transNo != ''"> and o.trans_no = #{transNo}</if>
        </where>
    </select>
    
    <select id="selectSrsOrderById" parameterType="Long" resultMap="SrsOrderResult">
        <include refid="selectSrsOrderVo"/>
        where o.id = #{id}
    </select>
        
    <insert id="insertSrsOrder" parameterType="SrsOrder" useGeneratedKeys="true" keyProperty="id">
        insert into srs_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">payment_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="payStatus != null">pay_status,</if>
            <if test="transNo != null">trans_no,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">#{paymentId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="payStatus != null">#{payStatus},</if>
            <if test="transNo != null">#{transNo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateSrsOrder" parameterType="SrsOrder">
        update srs_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="paymentId != null">payment_id = #{paymentId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="payStatus != null">pay_status = #{payStatus},</if>
            <if test="transNo != null">trans_no = #{transNo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSrsOrderById" parameterType="Long">
        delete from srs_order where id = #{id}
    </delete>

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