package com.younike.system.mapper;

import com.younike.hlpay.dto.OrderParam;
import com.younike.system.domain.GoodsServerDimension;
import com.younike.system.domain.Order;
import com.younike.system.domain.OrderStat;
import com.younike.system.domain.vo.*;
import com.younike.system.param.OrderQueryParam;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * 订单主Mapper接口
 *
 * @author elev
 * @date 2022-01-07
 */
public interface OrderMapper {

    /**
     * 订单列表
     * @param param
     * @return
     */
    List<OrderVo> orderList(OrderQueryParam param);
    /**
     * 查询订单主
     *
     * @param orderId 订单主主键
     * @return 订单主
     */
    Order selectOrderByOrderId(Long orderId);

    Order selectOrderByOrderIndex(String orderIndex);

    Order selectOrderId(Long orderId);

    /**
     * 查询订单主列表
     *
     * @param order 订单主
     * @return 订单主集合
     */
    List<Order> selectOrderList(Order order);

    /**
     * 新增订单主
     *
     * @param order 订单主
     * @return 结果
     */
    int insertOrder(Order order);

    /**
     * 修改订单主
     *
     * @param order 订单主
     * @return 结果
     */
    int updateOrder(Order order);

    /**
     * 删除订单主
     *
     * @param orderId 订单主主键
     * @return 结果
     */
    int deleteOrderByOrderId(Long orderId);

    /**
     * 批量删除订单主
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    int deleteOrderByOrderIds(Long[] orderIds);

    int updateOrderCustom(Order order);

    List<OrderStat> listLastOrders(@Param("days") int days, @Param("orderStates") String orderStates);

    List<GoodsServerDimension> statisticGoodsServerDimension(@Param("days") int days, @Param("orderStates") String orderStates);


    //添加订单，返回订单id
    int  addOrder(Order order);

    /**
     * 查询会员端订单分页列表
     *
     * @param order
     * @param orderStates
     * @return
     */
    List<MemberOrderVo> listMemberOrderByOrderState(@Param("order") Order order, @Param("orderStates") List<String> orderStates);

    /**
     * 查询会员订单详情
     *
     * @param orderId
     * @return
     */
    MemberOrderDetailVo getMemberOrderByOrderId(Long orderId);

    /**
     * @param serverId 服务人员ID
     * @return 服务人员已预约（orderState：000，001）的订单
     */
    List<Order> listOrderedOrderByServerId(Long serverId);

    void selectOrderList();

    /**
     * 查询是否已经被预约
     * @param order
     * @return
     */
    List<Order> getOrderList(@Param("order") OrderParam order);

    List<Order> selectPreSettleOrders(Date settleDate);

    List<OrderPaymentVO> selectPreProfitSharingOrders(Date settleDate);

    boolean updateBatchById(List<Order> updated);

    MerchantDashboardVO statisticsToday(Long merchantId);

    List<OrderStatisticsVO> statisticsByMonth(Long merchantId);

    List<ServerUserVo> getTopServerUser(Long merchantId);

    /**
     * 查询未支付订单列表
     *
     * @param orderState
     * @return
     */
    List<Order> listMemberOrderOfPendingPayment(@Param("orderState") String orderState);

    /**
     * 更新超时未支付订单状态
     *
     * @param orderList
     */
    void updateOrderState(@Param("orderList") List<Order> orderList);

    /**
     * 查询今日订单数据
     *
     * @return
     */
    TodayOrderVO getTodayOrderData();

    /**
     * 查询本周Top5商家订单数据
     *
     * @return
     */
    List<MerchantOrderOfWeekVO> getTopFiveMerchantOrderData();

    OrderVo selectPublishInfo(Long orderId);
    /**
     * 查询近30天订单数据
     *
     * @return
     */
    List<OrderStatisticsVO> getOrderDataByMonth();

    List<Order> selectServerBookedOrder(Long serverId);

    /**
     * 取消收取维修配件费数据变更
     * @param order
     * @return
     */
    int cancelMaintenanceServer(Order order);

    /**
     * 查询个体户结算订单信息
     *
     * @param settleStartDate
     * @param settleEndDate
     * @return
     */
    List<Order> listPersonalMerchantSettleOrder(@Param("settleStartDate") LocalDate settleStartDate, @Param("settleEndDate") LocalDate settleEndDate);

    /**
     * 根据服务id查询是否有订单非已取消与已退款状态
     *
     * @param goodsId
     * @return
     */
    List<Order> adminDeleteGoods(@Param("goodsId") Long goodsId);

    /**
     * 根据服务人员id查询服务人员是否有未完成的订单
     *
     * @param serverIds
     * @return
     */
    List<Order> merchanServerUserId(Long[] serverIds);
}
