/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.service;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yami.shop.bean.app.dto.OrderCountData;
import com.yami.shop.bean.app.dto.ShopCartOrderMergerDto;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.model.OrderRefund;
import com.yami.shop.bean.param.CancelOrderParam;
import com.yami.shop.bean.param.OrderParam;
import com.yami.shop.bean.param.OrderPayParam;
import com.yami.shop.bean.param.OrderRefundParam;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author lgh on 2018/09/15.
 */
public interface OrderService extends IService<Order> {


    Order getOrderByOrderNumber(String orderNumber);

    /**
     * 根据订单号和用户id获取订单
     * @param orderNumber
     * @param userId
     * @return
     */
    Order getOrderByOrderNumberAndUserId(String orderNumber,String userId, boolean valid);

    /**
     * 根据店铺id获取支付数据
     * @param shopId
     */
    OrderPayParam getPayUserCountByshopId(Long shopId, Date startTime, Date endTime);

    /**
     * 根据时间和店铺id获取分段时间数据
     */
    OrderPayParam getActualTotalByHour(Long shopId, Date startTime, Date endTime);

    /**
     * 根据天数和店铺id获取分段时间数据
     */
    List<OrderPayParam> getActualTotalByDay(Long shopId, Date startTime, Date endTime);

    /**
     * 根据店铺id和订单号获取订单
     * @param orderNumber
     * @param shopId
     * @return
     */
    Order getOrderByOrderNumberAndShopId(String orderNumber,Long shopId, boolean valid);


    ShopCartOrderMergerDto putConfirmOrderCache(String userId, ShopCartOrderMergerDto shopCartOrderMergerDto);

    ShopCartOrderMergerDto getConfirmOrderCache(String userId);

    void removeConfirmOrderCache(String userId);


    List<Order> submit(String userId, ShopCartOrderMergerDto mergerOrder);

    void delivery(Order order);

    List<Order> listUnRefundOrderAndOrderItems(Integer orderStatus, DateTime lessThanUpdateTime);

    void cancelOrders(List<Order> orders);

    void receiptOrder(List<Order> orders);

//    List<Order> listOrdersDetialByOrder(Order order, Date startTime, Date endTime);

    IPage<Order> pageOrdersDetialByOrderParam(Page<Order> page, OrderParam orderParam);

    void deleteOrders(List<Order> orders);

    OrderCountData getOrderCount(String userId);

    double sumTotalDistributionAmountByOrderItem(List<OrderItem> orderItems);

    void changeAmount(Order order);

    void soldExcel(OrderParam orderParam, HttpServletResponse response);

    List<Order> getOrderPayInfoByOrderNumber(List<String> orderNumberList);

    Order getOrderDetailByOrderNumberAndShopId(String orderNumber, Long shopId);

    /**
     * 获取退款的订单项的id和退款状态
     * @param orderId
     * @return
     */
    Map<Long, Integer> getOrderItemMap(Long orderId);

    String cancelOrder(CancelOrderParam cancelOrderParam);


    /**
     * 订单申请退款
     * @param orderRefundParam 订单申请退款参数
     * @param rReturnMoneySts 退款状态
     * @return 订单申请退款结果
     */
    OrderRefund applyAgain(OrderRefundParam orderRefundParam , Integer  rReturnMoneySts);

    /**
     * 订单申请退款
     * @param orderNumber 订单单号
     * @return 订单申请退款结果
     */
    void returnRefund(String orderNumber);
}
