package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.vo.TbOrderSaleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Timestamp;
import java.util.List;

public interface TbOrderInfoMapper extends BaseMapper<TbOrderInfo> {
    @Select("<script>" +
            " SELECT   \n" +
            "            oi.order_no,   \n" +
            "            od.num,   \n" +
            "            od.price,   \n" +
            "            od.status, od.product_sku_id skuId  \n" +
            "        FROM   \n" +
            "            tb_order_info oi  \n" +
            "        LEFT JOIN   \n" +
            "            tb_order_detail od ON oi.id = od.order_id   \n" +
            "        WHERE   \n" +
            "            od.shop_id = #{shopId}   \n" +
            "            AND (od.status = 'closed' OR od.status = 'refund')   \n" +
            "            AND od.create_time > #{startTime}   \n" +
            "            AND od.create_time &lt; #{endTime}   \n" +
            "            AND (od.product_sku_id IN   \n" +
            "                <foreach item=\"productSkuId\" collection=\"productSkuIds\" open=\"(\" separator=\",\" close=\")\">  \n" +
            "                    #{productSkuId}  \n" +
            "                </foreach>  \n" +
            "            )  " +
            "</script>")
    List<TbOrderSaleVO> selectAllSaleInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime,  @Param("productSkuIds") List<Integer> productSkuIds, @Param("shopId") Integer shopId);
}
