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

package com.yami.shop.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.shop.bean.dto.OrderRefundDto;
import com.yami.shop.bean.model.OrderRefund;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yami.shop.bean.param.OrderRefundCountParam;
import com.yami.shop.bean.param.OrderRefundStaisticsParam;
import com.yami.shop.bean.param.StatisticsRefundParam;
import com.yami.shop.bean.vo.OrderRefundVo;
import com.yami.shop.common.util.PageParam;
import org.apache.ibatis.annotations.Param;

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

public interface OrderRefundMapper extends BaseMapper<OrderRefund> {

    /**
     * 获取分页列表
     */
    IPage<OrderRefundDto> getPage(Page page, @Param("orderRefundDto") OrderRefundDto orderRefundDto, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    /**
     * 获取详情信息
     */
    OrderRefundDto getById(@Param("id") Long id, @Param("shopId") Long shopId);

    /**
     * 获取首页商家的退款信息
     */
    StatisticsRefundParam getRefundByShopId(@Param("shopId") Long shopId, @Param("startTime") Date beginTime, @Param("endTime") Date endTime);

    /**
     * 通过时间获取商家每天的退款信息
     */
    List<StatisticsRefundParam> getRefundByShopIdAndDay(@Param("shopId") Long shopId, @Param("startTime") Date beginTime, @Param("endTime") Date endTime);

    /**
     * 获取退款商品信息排行
     */
    List<StatisticsRefundParam> getRefundRankingByProd(@Param("shopId") Long shopId, @Param("startTime") Date beginTime, @Param("endTime") Date endTime);

    /**
     * 获取退款原因排行
     */
    List<StatisticsRefundParam> getRefundRankingByReason(@Param("shopId") Long shopId, @Param("startTime") Date beginTime, @Param("endTime") Date endTime);

    /**
     * 通过退款编号获取退款订单
     */
    OrderRefundDto getOrderRefundByRefundSn(@Param("refundSn") String refundSn);

    /**
     * 更新退款状态
     */
    void updateReturnMoneySts(@Param("refundList") List<OrderRefund> refundList, @Param("status") Integer status);

    double sumRefundSuccessAmountByOrderId(@Param("orderId") Long orderId);

    /**
     * 通过订单id获取正在处理中的退款订单
     */
    List<OrderRefund> getProcessingOrderRefundByOrderId(@Param("orderId") Long orderId);

    double sumRefundSuccessPlatformAmountByOrderId(@Param("orderId") Long orderId);

    Integer getOrderRefundCountByRefundSn(@Param("refundSn") String refundSn);

    Integer getRefundCount(@Param("userId") String userId);

    Integer countRefundByOrderItem(@Param("orderItemId") Long orderItemId, @Param("returnMoneySts0") Integer returnMoneySts0, @Param("returnMoneySts1") Integer returnMoneySts1);

    /**
     * 获取退款订单统计数量
     */
    OrderRefundCountParam orderRefundCount(@Param("orderRefund") OrderRefundStaisticsParam orderRefund);

    /**
     * 获取退款订单统计
     * @param page 分页参数
     * @param orderRefund 订单退款参数
     * @return 订单退款分页
     */
    IPage<OrderRefundVo> orderRefundPage(@Param("page") PageParam<OrderRefund> page, @Param("orderRefund") OrderRefundStaisticsParam orderRefund);

    /**
     * 获取退款订单详情
     * @param refundId 订单退款id
     * @return 订单退款详情
     */
    OrderRefundVo selectInfoById(Long refundId);

    List<OrderRefund> findByOrderNumber(@Param("orderNumber")String orderNumber, @Param("returnMoneySts")Integer returnMoneySts);



    List<OrderRefundVo> findOrderRefund( @Param("orderRefund") OrderRefundStaisticsParam orderRefund);

    Integer queryRemainGoodsNumber(String orderNumber);

    BigDecimal countRefundMoney(@Param("orderId")Long orderId, @Param("returnMoneySts")Integer returnMoneySts);
}
