package com.ylx.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.massage.domain.vo.HomeBlock;
import com.ylx.order.domain.TOrder;
import com.ylx.order.domain.dto.OrderDateQueryDTO;
import com.ylx.order.domain.dto.RecentOrderQueryDTO;
import com.ylx.order.domain.vo.RecentMerchantVO;
import com.ylx.order.domain.vo.merchant.OrderPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author YJR
 * @since 2023-11-24
 */
@Mapper
public interface TOrderMapper extends BaseMapper<TOrder> {

    Page<TOrder> getAll(Page<TOrder> page, @Param("param") TOrder param);

    Integer getOrderNum(@Param("jsid") String jsid, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    Integer getAddNum(@Param("jsid") String jsid, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    Integer getUpgradeNum(@Param("jsid") String jsid, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    BigDecimal getTurnover(@Param("jsid") String jsid, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<HomeBlock> getBlock(@Param("start") Date start, @Param("end") Date end, @Param("deptId") String deptId);

    //执行存储过程 大于48小时 订单状态更新为 已结算  自动分账  订单总金额*佣金比例划入用户余额
    void callAutoAccount(@Param("hCount") int hCount, @Param("percent") BigDecimal percent);

    List<TOrder> getAll(@Param("param") TOrder param);

    List<TOrder> selectValidOrdersByMerchantAndDate(
            @Param("merchantId") Long merchantId,
            @Param("projectId") Long projectId,
            @Param("dayStart") LocalDateTime dayStart,
            @Param("dayEnd") LocalDateTime dayEnd
    );

    Page<OrderPageVO> queryMerchantOrderList(Page<OrderPageVO> page, @Param("dto") OrderDateQueryDTO dto);

    LocalDateTime getLastOrderDateBeforeCurrent(@Param("userId") Long userId,
                                                @Param("merchantId") Long merchantId,
                                                @Param("categoryId") Long categoryId,
                                                @Param("currentTime") LocalDateTime currentTime);

    Page<RecentMerchantVO> getRecentMerchants(Page<RecentMerchantVO> page, @Param("dto") RecentOrderQueryDTO dto);
}
