<?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.trade.dal.mysql.smsSendconfig.MessageSendMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->
    <select id="querySendList1" resultType="com.yc.ship.module.trade.controller.admin.smsSendconfig.vo.SmsSendconfigQueryRespVO">
        SELECT
        t1.group_no groupNo,
        t2.product_id,
        t2.product_name,
        t66.NAME voyageName,
        t66.start_time,
        t66.leave_time,
        t77.NAME shipName,
        t67.NAME routeName,
        t1.order_no,
        t1.seller_id,
        t2.use_date,
        count( DISTINCT t2.id ) num,
        t1.source_name,
        t1.link_man contact_name,
        t1.link_mobile mobile,
        t1.group_no
        FROM
        trade_order t1
        INNER JOIN trade_detail t2 ON t1.id = t2.order_id
        left JOIN trade_order_user t3 ON t3.order_id = t1.id
        left JOIN product_voyage t66 ON t66.id = t1.voyage_id
        left JOIN resource_route t67 ON t66.route_id = t67.id
        left JOIN resource_ship t77 ON t77.id = t1.ship_id
        WHERE 1=1
        and DATE_FORMAT(t2.use_date, '%Y-%m-%d') = DATE_SUB(CURDATE(), INTERVAL( -#{day} ) DAY )
        AND t1.order_status =14
        AND t1.deleted = 0
        AND t2.deleted = 0
        and t2.use_date>now()
        GROUP BY
        t1.id
    </select>
    <select id="querySendList2" resultType="com.yc.ship.module.trade.controller.admin.smsSendconfig.vo.SmsSendconfigQueryRespVO">
        SELECT
        t1.group_no groupNo,
        t2.product_id,
        t2.product_name,
        t66.NAME voyageName,
        t66.start_time,
        t66.leave_time,
        t77.NAME shipName,
        t67.NAME routeName,
        t1.order_no,
        t1.seller_id,
        t2.use_date,
        count( DISTINCT t2.id ) num,
        t1.source_name,
        t1.link_man contact_name,
        t1.link_mobile mobile,
        t1.group_no
        FROM
        trade_order t1
        INNER JOIN trade_detail t2 ON t1.id = t2.order_id
        left JOIN trade_order_user t3 ON t3.order_id = t1.id
        left JOIN product_voyage t66 ON t66.id = t1.voyage_id
        left JOIN resource_route t67 ON t66.route_id = t67.id
        left JOIN resource_ship t77 ON t77.id = t1.ship_id
        WHERE 1=1
        and DATE_FORMAT(t2.use_date, '%Y-%m-%d') = DATE_SUB(CURDATE(), INTERVAL( -#{day} ) DAY )
        AND t1.order_status =1
        AND t1.deleted = 0
        AND t2.deleted = 0
        and t2.use_date>now()
        GROUP BY
        t1.id
    </select>

    <select id="querySendList3" resultType="com.yc.ship.module.trade.controller.admin.smsSendconfig.vo.SmsSendconfigQueryRespVO">
        SELECT
        t1.group_no groupNo,
        t2.product_id,
        t2.product_name,
        t66.NAME voyageName,
        t66.start_time,
        t66.leave_time,
        t77.NAME shipName,
        t67.NAME routeName,
        t1.order_no,
        t1.seller_id,
        t2.use_date,
        count( DISTINCT t2.id ) num,
        t1.source_name,
        t1.link_man contact_name,
        t1.link_mobile mobile,
        t1.group_no
        FROM
        trade_order t1
        INNER JOIN trade_detail t2 ON t1.id = t2.order_id
        left JOIN trade_order_user t3 ON t3.order_id = t1.id
        left JOIN product_voyage t66 ON t66.id = t1.voyage_id
        left JOIN resource_route t67 ON t66.route_id = t67.id
        left JOIN resource_ship t77 ON t77.id = t1.ship_id
        WHERE 1=1
        and DATE_FORMAT(t2.use_date, '%Y-%m-%d') = DATE_SUB(CURDATE(), INTERVAL( -#{day} ) DAY )
        AND t1.order_status =6
        AND t1.deleted = 0
        AND t2.deleted = 0
        and t2.use_date>now()
        GROUP BY
        t1.id
    </select>

</mapper>