package com.sqx.modules.order.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.datasource.annotation.DataSource;
import com.sqx.modules.datacentre.query.DataCenterQuery;
import com.sqx.modules.order.controller.query.GoodsSkuQuery;
import com.sqx.modules.order.controller.vo.GoodsSkuSalesCountVO;
import com.sqx.modules.order.dto.OrderQueryDto;
import com.sqx.modules.order.entity.TbOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AppOrderDao extends BaseMapper<TbOrder> {

   // IPage<TbOrder> selectOrderList(Page<TbOrder> pages, @Param("userId") Long userId,@Param("status") Integer status,@Param("orderType") Integer orderType, @Param("shopId")Long shopIs);

    IPage<TbOrder> selectOrderList(Page<TbOrder> pages, @Param("userId") Long userId, @Param("status") Integer status, @Param("orderType") Integer orderType, @Param("shopId")Long shopIs);

    int insertOrder(TbOrder order);

    IPage<TbOrder> selectOrder(Page<TbOrder> pages,
                               @Param("status") Integer status, @Param("phone") String phone, @Param("shopId") Long shopId,
                               @Param("userName") String userName, @Param("orderNumber") String orderNumber,@Param("orderType") Integer orderType,
                               @Param("shopName") String shopName, @Param("transactionId") String transactionId);

    @DataSource("dynamic")
    IPage<TbOrder> selectAllOrderAdmin(Page<TbOrder> pages,@Param("query") OrderQueryDto queryDto);

    @DataSource("dynamic")
    List<TbOrder> excelAllOrderAdmin(@Param("query") OrderQueryDto queryDto);

    @DataSource("dynamic")
    Integer excelAllOrderAdminCount(@Param("query") OrderQueryDto queryDto);


    IPage<TbOrder> selectOrderByAdmin(Page<TbOrder> pages,@Param("status") Integer status,@Param("phone") String phone,
                                      @Param("shopId") Long shopId, @Param("userName") String userName,
                                      @Param("userId") Long userId,@Param("orderNumber") String orderNumber,@Param("orderType") Integer orderType);

    int selectCountOrderByUserId(Long userId, String date, String dateType);

    BigDecimal selectSunMoneyByUserId(Long userId, String date, String dateType);

    IPage<TbOrder> selectOrderDetails(Page<TbOrder> pages, Long userId);

    IPage<TbOrder> waitTakeFood(Page<TbOrder> pages, Long userId, Integer orderType, Integer status);

    int selectCountOrderByTime(@Param("payTime") String payTime, @Param("shopId") Long shopId);

    int deleteCouponByOrderId(@Param("orderId") Long orderId);

    @DataSource("dynamic")
    BigDecimal selectSumMoney(@Param("query") DataCenterQuery query);

    @DataSource("dynamic")
    int selectCountOrder(@Param("query") DataCenterQuery query);

    int updateorderStatus(String date);

    List<TbOrder> selectOrderByTimeList(String date);

    List<TbOrder> selectShoppingTrolley(Long userId);

    TbOrder selectShoppingTrolleyByShopId(Long userId, Long shopId);

    TbOrder selectByOrderId(Long orderId);

    TbOrder selectBuyGoods(Long orderId, Long userId);

    List<TbOrder> selectOverTimeOrder(String overTime);

    List<TbOrder> selectMakeOrdersList(LocalDateTime minusMinutes);

    List<Long> selectCurrentOrderSequenceByShopId(@Param("shopId") Long shopId, @Param("payTime") String payTime);

    /**
     * 统计用户当天在当前店铺参与某次活动的次数
     * @param shopId 店铺id
     * @param activityId 活动id
     * @param userId 用户id
     * @param orderId 当前订单id
     * @return
     */
    int countByShopIdAndActivityIdAndUserIdAndCurDate(@Param("shopId") Long shopId, @Param("activityId") Long activityId, @Param("userId") Long userId, @Param("orderId") Long orderId);

    /**
     * 获取小于（当前时间+30分钟）还没有被接单的预约订单id
     * @return 订单id集合
     */
    List<Long> selectCurWaitReceivingOrderIds();

    /**
     * 统计当前订单未完成店铺数量
     * @param shopId 店铺id
     * @return 未完成订单数
     */
    int countUnFinishByShopId(@Param("shopId") Long shopId);

    int countCurDayPayByShopId(@Param("shopId") Long shopId, @Param("payTime") String payTime);

    IPage<TbOrder> selectOrderPage(Page<TbOrder> pages,@Param("userId") Long userId,@Param("orderId") Integer orderId);

    BigDecimal selectAllOrderTotalPrice(@Param("query") OrderQueryDto queryDto);

    List<TbOrder> changeTimeOutOrder(@Param("time") long time);

    IPage<GoodsSkuSalesCountVO> getGoodsSkuSalesCount(Page<GoodsSkuSalesCountVO> pages, GoodsSkuQuery query);
}
