<?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.yc.ship.module.product.dal.mysql.pricevoyage.PriceVoyageMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="selectListCalendarPrice"
            resultType="com.yc.ship.module.product.controller.app.voyage.vo.AppVoyageCalendarPriceRespVO">
        SELECT
            DATE_FORMAT( t1.start_time, '%Y-%m-%d' ) date,
	t1.id voyage_id,
	t1.name voyage_name,
	min( t3.price ) price
        FROM
            product_voyage t1
            LEFT JOIN product_price_voyage t2 ON t1.id = t2.voyage_id
            LEFT JOIN product_price_room_model t3 ON t2.id = t3.object_id
        LEFT JOIN resource_room_model t4 on t3.room_model_id = t4.id
        WHERE
            t1.deleted = 0
          AND t2.deleted = 0
          AND t3.deleted = 0
        and t1.shelf_status = 1
        <if test="reqVO.shipId != null and reqVO.shipId != ''">
          and t1.ship_id = #{reqVO.shipId}
        </if>
        <if test="reqVO.routeId != null and reqVO.routeId != ''">
          AND t1.route_id = #{reqVO.routeId}
        </if>
        and t1.boarding_time > now()
        and t1.channel like '%2%'
        and t4.can_sale = 1
        <if test="reqVO.startDate != null and reqVO.startDate != ''">
            AND t1.boarding_time >= #{reqVO.startDate}
        </if>
        <if test="reqVO.endDate != null and reqVO.endDate != ''">
            AND t1.boarding_time &lt;= CONCAT(#{reqVO.endDate},' 23:59:59')
        </if>
        GROUP BY
        t1.id
        order by
        t1.boarding_time ASC

    </select>
    <select id="selectRoomModelListByVoyageId"
            resultType="com.yc.ship.module.product.controller.app.voyage.vo.AppRoomModelPriceRespVO">
        SELECT
            t1.price,
            t1.room_model_id,
            t2.`name` room_model_name
        FROM
            product_price_room_model t1
                LEFT JOIN resource_room_model t2 ON t1.room_model_id = t2.id
        WHERE
            EXISTS (SELECT id FROM product_price_voyage WHERE voyage_id = #{voyageId} and t1.object_id= id AND deleted = 0 )
          AND t1.deleted = 0
          AND t2.deleted = 0
        and t2.can_sale = 1
        ORDER BY
            t1.price ASC
    </select>
</mapper>