<?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.tourism.webadmin.back.dao.TourProjectGroupPurchaseRebateMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourProjectGroupPurchaseRebate">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="group_purchase_progress_id" jdbcType="BIGINT" property="groupPurchaseProgressId"/>
        <result column="order_id" jdbcType="BIGINT" property="orderId"/>
        <result column="price" jdbcType="DECIMAL" property="price"/>
        <result column="reason" jdbcType="TINYINT" property="reason"/>
        <result column="reason_relation_userId" jdbcType="BIGINT" property="reasonRelationUserid"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="price_unit" jdbcType="VARCHAR" property="priceUnit"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_project_group_purchase_rebate
            (id,
            user_id,
            group_purchase_progress_id,
            order_id,
            price,
            reason,
            reason_relation_userId,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state,
            price_unit)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.userId},
            #{item.groupPurchaseProgressId},
            #{item.orderId},
            #{item.price},
            #{item.reason},
            #{item.reasonRelationUserid},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.priceUnit})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.TourProjectGroupPurchaseRebateMapper.inputFilterRef"/>
        AND tour_project_group_purchase_rebate.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourProjectGroupPurchaseRebateFilter != null">
            <if test="tourProjectGroupPurchaseRebateFilter.userId != null">
                AND tour_project_group_purchase_rebate.user_id = #{tourProjectGroupPurchaseRebateFilter.userId}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.groupPurchaseProgressId != null">
                AND tour_project_group_purchase_rebate.group_purchase_progress_id = #{tourProjectGroupPurchaseRebateFilter.groupPurchaseProgressId}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.orderId != null">
                AND tour_project_group_purchase_rebate.order_id = #{tourProjectGroupPurchaseRebateFilter.orderId}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.priceStart != null">
                AND tour_project_group_purchase_rebate.price &gt;= #{tourProjectGroupPurchaseRebateFilter.priceStart}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.priceEnd != null">
                AND tour_project_group_purchase_rebate.price &lt;= #{tourProjectGroupPurchaseRebateFilter.priceEnd}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.reason != null">
                AND tour_project_group_purchase_rebate.reason = #{tourProjectGroupPurchaseRebateFilter.reason}
            </if>
            <if test="tourProjectGroupPurchaseRebateFilter.reasonRelationUserid != null">
                AND tour_project_group_purchase_rebate.reason_relation_userId = #{tourProjectGroupPurchaseRebateFilter.reasonRelationUserid}
            </if>
        </if>
    </sql>

    <select id="getTourProjectGroupPurchaseRebateList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourProjectGroupPurchaseRebate">
        SELECT * FROM tour_project_group_purchase_rebate
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
