package com.yami.shop.platform.controller;


import cn.hutool.core.date.DateUtil;
import com.yami.shop.bean.param.OrderPayParam;
import com.yami.shop.bean.param.StatisticsRefundParam;
import com.yami.shop.service.OrderRefundService;
import com.yami.shop.service.OrderService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.yami.shop.common.util.R;
/**
 * 订单统计信息管理实现
 *
 * @author lhd
 * @version 1.0.0
 * @since 2019-10-19
 */
@RestController
@RequestMapping("/platform/statisticsOrder")
@AllArgsConstructor
public class StatisticsOrderController {

    private final OrderService orderService;
    private final OrderRefundService orderRefundService;


    @GetMapping("/orderPayByShopId")
    @ApiOperation(value = "通过时间获取支付信息")
    public R<OrderPayParam> orderPayByShopId() {
        OrderPayParam actualTotal = orderService.getPayUserCountByshopId(null,DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(actualTotal);
    }

    @GetMapping("/getActualTotalByHour")
    @ApiOperation(value = "通过24小时分段获取支付金额")
    public R<OrderPayParam> getActualTotalByHour() {
        OrderPayParam payList = orderService.getActualTotalByHour(
                null,DateUtil.beginOfDay(DateUtil.date()),DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(payList);
    }

    @GetMapping("/getActualTotalByDay")
    @ApiOperation(value = "通过天数分段获取支付金额")
    public R<List<OrderPayParam>> getActualTotalByDay() {
        List<OrderPayParam> payList = orderService.getActualTotalByDay(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(payList);
    }

    @GetMapping("/getOrderRefundByTime")
    @ApiOperation(value = "通过时间获取比率信息")
    public R<StatisticsRefundParam> getOrderRefundByTime() {
        StatisticsRefundParam refundParam = orderRefundService.getOrderRefundByShopId(
                null,DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(refundParam);
    }

    @GetMapping("/getOrderRefundDayByTime")
    @ApiOperation(value = "通过时间获取分段比率信息及退款金额信息")
    public R<List<StatisticsRefundParam>> getOrderRefundById() {
        List<StatisticsRefundParam> refundList = orderRefundService.getOrderRefundByShopIdAndDay(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(refundList);
    }

    @GetMapping("/getRefundRankingByProd")
    @ApiOperation(value = "根据商品名生成退款排行")
    public R<List<StatisticsRefundParam>> getRefundRankingByProd() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByProd(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(refundList);
    }

  @GetMapping("/getRefundRankingByReason")
    @ApiOperation(value = "根据退款原因生成退款排行")
    public R<List<StatisticsRefundParam>> getRefundRankingByReason() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByReason(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return R.SUCCESS(refundList);
    }

}
