<?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.TourProjectGroupPurchaseMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourProjectGroupPurchase">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="project_id" jdbcType="BIGINT" property="projectId"/>
        <result column="end_time" jdbcType="DATE" property="endTime"/>
        <result column="travel_start_time" jdbcType="DATE" property="travelStartTime"/>
        <result column="travel_end_time" jdbcType="DATE" property="travelEndTime"/>
        <result column="state" jdbcType="TINYINT" property="state"/>
        <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="max_count" jdbcType="INTEGER" property="maxCount"/>
        <result column="adult_price" jdbcType="DECIMAL" property="adultPrice"/>
        <result column="children_price" jdbcType="DECIMAL" property="childrenPrice"/>
        <result column="show_order" jdbcType="INTEGER" property="showOrder"/>
        <result column="code" jdbcType="BIGINT" property="code"/>
        <result column="now_count" jdbcType="INTEGER" property="nowCount"/>
        <result column="success" jdbcType="TINYINT" property="success"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="image" jdbcType="VARCHAR" property="image"/>
        <result column="price_unit" jdbcType="VARCHAR" property="priceUnit"/>
        <result column="original_price" jdbcType="DECIMAL" property="originalPrice"/>
        <result column="single_rebate" jdbcType="DECIMAL" property="singleRebate"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_project_group_purchase
            (id,
            project_id,
            end_time,
            travel_start_time,
            travel_end_time,
            state,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state,
            max_count,
            adult_price,
            children_price,
            show_order,
            code,
            now_count,
            success,
            title,
            image,
            price_unit,
            original_price,
            single_rebate)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.projectId},
            #{item.endTime},
            #{item.travelStartTime},
            #{item.travelEndTime},
            #{item.state},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.maxCount},
            #{item.adultPrice},
            #{item.childrenPrice},
            #{item.showOrder},
            #{item.code},
            #{item.nowCount},
            #{item.success},
            #{item.title},
            #{item.image},
            #{item.priceUnit},
            #{item.originalPrice},
            #{item.singleRebate})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourProjectGroupPurchaseFilter != null">
            <if test="tourProjectGroupPurchaseFilter.projectId != null">
                AND tour_project_group_purchase.project_id = #{tourProjectGroupPurchaseFilter.projectId}
            </if>
            <if test="tourProjectGroupPurchaseFilter.endTimeStart != null and tourProjectGroupPurchaseFilter.endTimeStart != ''">
                AND tour_project_group_purchase.end_time &gt;= #{tourProjectGroupPurchaseFilter.endTimeStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.endTimeEnd != null and tourProjectGroupPurchaseFilter.endTimeEnd != ''">
                AND tour_project_group_purchase.end_time &lt;= #{tourProjectGroupPurchaseFilter.endTimeEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.travelStartTimeStart != null and tourProjectGroupPurchaseFilter.travelStartTimeStart != ''">
                AND tour_project_group_purchase.travel_start_time &gt;= #{tourProjectGroupPurchaseFilter.travelStartTimeStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.travelStartTimeEnd != null and tourProjectGroupPurchaseFilter.travelStartTimeEnd != ''">
                AND tour_project_group_purchase.travel_start_time &lt;= #{tourProjectGroupPurchaseFilter.travelStartTimeEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.travelEndTimeStart != null and tourProjectGroupPurchaseFilter.travelEndTimeStart != ''">
                AND tour_project_group_purchase.travel_end_time &gt;= #{tourProjectGroupPurchaseFilter.travelEndTimeStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.travelEndTimeEnd != null and tourProjectGroupPurchaseFilter.travelEndTimeEnd != ''">
                AND tour_project_group_purchase.travel_end_time &lt;= #{tourProjectGroupPurchaseFilter.travelEndTimeEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.state != null">
                AND tour_project_group_purchase.state = #{tourProjectGroupPurchaseFilter.state}
            </if>
            <if test="tourProjectGroupPurchaseFilter.maxCountStart != null">
                AND tour_project_group_purchase.max_count &gt;= #{tourProjectGroupPurchaseFilter.maxCountStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.maxCountEnd != null">
                AND tour_project_group_purchase.max_count &lt;= #{tourProjectGroupPurchaseFilter.maxCountEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.adultPriceStart != null">
                AND tour_project_group_purchase.adult_price &gt;= #{tourProjectGroupPurchaseFilter.adultPriceStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.adultPriceEnd != null">
                AND tour_project_group_purchase.adult_price &lt;= #{tourProjectGroupPurchaseFilter.adultPriceEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.childrenPriceStart != null">
                AND tour_project_group_purchase.children_price &gt;= #{tourProjectGroupPurchaseFilter.childrenPriceStart}
            </if>
            <if test="tourProjectGroupPurchaseFilter.childrenPriceEnd != null">
                AND tour_project_group_purchase.children_price &lt;= #{tourProjectGroupPurchaseFilter.childrenPriceEnd}
            </if>
            <if test="tourProjectGroupPurchaseFilter.code != null">
                AND tour_project_group_purchase.code = #{tourProjectGroupPurchaseFilter.code}
            </if>
            <if test="tourProjectGroupPurchaseFilter.nowCount != null">
                AND tour_project_group_purchase.now_count >= #{tourProjectGroupPurchaseFilter.nowCount}
            </if>
        </if>
    </sql>

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