<?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.voyage.VoyageMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->
    <select id="selectVovageList" resultType="com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO">
         select  w.*,r.direction from product_voyage w inner join resource_route r on w.route_id = r.id
         where w.deleted = 0 and r.deleted = 0 and w.ship_id = #{shipId} and w.start_time > now() and w.shelf_status = 1 and w.channel like '%1%' order by w.create_time asc;
    </select>
    <select id="selectListCalendar2" resultType="com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO">
        select w.*,r.price basicPrice from product_voyage w inner join resource_route r on w.route_id = r.id
        where w.deleted = 0 and r.deleted = 0
        <if test="vo.shipIds != null and vo.shipIds.size() > 0">
            and w.ship_id in
            <foreach item="item" collection="vo.shipIds" separator="," open="(" close=")" index="">
                #{item}
            </foreach>
        </if>
        <if test="vo.startDate != null and vo.startDate != ''">
            and w.start_time >= #{vo.startDate}
        </if>
        <if test="vo.endDate != null and vo.endDate != ''">
            and w.start_time &lt;= #{vo.endDate}
        </if>
        <if test="vo.channel != null and vo.channel != ''">
            and w.channel like concat('%',#{vo.channel},'%')
        </if>
         and w.shelf_status = 1 order by w.start_time asc;
    </select>
    <select id="selectVoyageListByShipIdAndDate"
            resultType="com.yc.ship.module.product.controller.app.voyage.vo.AppVoyageDayRespVO">
        select w.id voyage_id, w.name as voyage_name,
               s.id ship_id, s.name as ship_name, s.short_name as ship_short_name,
               r.id route_id, r.name as route_name, r.short_name as route_short_name,
               r.duration, r.price as route_price, r.direction
        from product_voyage w
        inner join resource_ship s on w.ship_id = s.id
        inner join resource_route r on w.route_id = r.id
        INNER JOIN product_price_voyage t on w.id = t.voyage_id
        where w.deleted = 0 and r.deleted = 0 and s.deleted = 0 and t.deleted = 0
        and w.channel like '%2%'
        and w.start_time > now()
          <if test="shipId != null and shipId != ''">
              and w.ship_id = #{shipId}
          </if>
          <if test="date != null and date != ''">
              and w.start_time >= #{date}
              and w.start_time &lt;= CONCAT(#{date},' 23:59:59')
          </if>
         and w.shelf_status = 1
        order by w.start_time asc
    </select>
</mapper>