<?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.TourProjectGroupPurchaseDetailMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="group_purchase_code" jdbcType="BIGINT" property="groupPurchaseCode"/>
        <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="adult_price" jdbcType="DECIMAL" property="adultPrice"/>
        <result column="children_price" jdbcType="DECIMAL" property="childrenPrice"/>
        <result column="min_count" jdbcType="INTEGER" property="minCount"/>
        <result column="max_count" jdbcType="INTEGER" property="maxCount"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_project_group_purchase_detail
        (id,
        group_purchase_code,
        create_user_id,
        create_time,
        update_user_id,
        update_time,
        data_state,
        adult_price,
        children_price,
        min_count,
        max_count)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.groupPurchaseCode},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.adultPrice},
            #{item.childrenPrice},
            #{item.minCount},
            #{item.maxCount})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourProjectGroupPurchaseDetailFilter != null">
            <if test="tourProjectGroupPurchaseDetailFilter.groupPurchaseCode != null">
                AND tour_project_group_purchase_detail.group_purchase_code = #{tourProjectGroupPurchaseDetailFilter.groupPurchaseCode}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.adultPriceStart != null">
                AND tour_project_group_purchase_detail.adult_price &gt;= #{tourProjectGroupPurchaseDetailFilter.adultPriceStart}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.adultPriceEnd != null">
                AND tour_project_group_purchase_detail.adult_price &lt;= #{tourProjectGroupPurchaseDetailFilter.adultPriceEnd}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.childrenPriceStart != null">
                AND tour_project_group_purchase_detail.children_price &gt;= #{tourProjectGroupPurchaseDetailFilter.childrenPriceStart}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.childrenPriceEnd != null">
                AND tour_project_group_purchase_detail.children_price &lt;= #{tourProjectGroupPurchaseDetailFilter.childrenPriceEnd}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.minCountStart != null">
                AND tour_project_group_purchase_detail.min_count &gt;= #{tourProjectGroupPurchaseDetailFilter.minCountStart}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.minCountEnd != null">
                AND tour_project_group_purchase_detail.min_count &lt;= #{tourProjectGroupPurchaseDetailFilter.minCountEnd}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.maxCountStart != null">
                AND tour_project_group_purchase_detail.max_count &gt;= #{tourProjectGroupPurchaseDetailFilter.maxCountStart}
            </if>
            <if test="tourProjectGroupPurchaseDetailFilter.maxCountEnd != null">
                AND tour_project_group_purchase_detail.max_count &lt;= #{tourProjectGroupPurchaseDetailFilter.maxCountEnd}
            </if>
        </if>
    </sql>

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

    <!-- 支持基于一对一或者一对多从表字段过滤的SQL_ID -->
    <select id="getTourProjectGroupPurchaseDetailListEx" resultMap="BaseResultMap" >
        SELECT
        tour_project_group_purchase_detail.*
        FROM
        tour_project_group_purchase_detail
        <where>
            <include refid="filterRef"/>
            <if test="tourProjectGroupPurchaseFilter != null">
                AND EXISTS (SELECT * FROM tour_project_group_purchase
                <where>
                    tour_project_group_purchase_detail.group_purchase_code = tour_project_group_purchase.code
                    <include refid="com.tourism.webadmin.back.dao.TourProjectGroupPurchaseMapper.filterRef"/>
                </where>)
            </if>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
