
package com.tmerclub.cloud.order.controller.platform;

import cn.hutool.core.date.DateUtil;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.order.service.OrderStatisticsService;
import com.tmerclub.cloud.order.vo.OrderOverviewVO;
import com.tmerclub.cloud.order.vo.OrderRefundStatisticsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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.List;

/**
 * @Author lth
 * @Date 2021/4/30 14:01
 */
@RestController("platformOrderStatisticsController")
@RequestMapping("/p/order_statistics")
@Tag(name = "platform-订单数据统计接口")
public class OrderStatisticsController {

    @Autowired
    private OrderStatisticsService orderStatisticsService;

    @GetMapping("/get_detail_by_hour")
    @Operation(summary = "获取当天与昨天订单实时统计数据", description = "获取当天与昨天订单实时统计数据")
    public ServerResponseEntity<OrderOverviewVO> getDetailInfoByHour() {
        OrderOverviewVO orderOverviewVO = orderStatisticsService.getDetailInfoByHour(null);
        return ServerResponseEntity.success(orderOverviewVO);
    }

    @GetMapping("/get_order_info_by_day_count")
    @Operation(summary = "获取近多少天内的订单统计数据", description = "获取近多少天内订单内的订单统计数据")
    @Parameters(@Parameter(name = "dayCount", description = "天数（几天内的统计数据）"))
    public ServerResponseEntity<OrderOverviewVO> getCurrentMonthInfoByDay(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount) {
        OrderOverviewVO orderOverviewVO = orderStatisticsService.getOrderInfoByDayCountAndShopId(null, dayCount);
        return ServerResponseEntity.success(orderOverviewVO);
    }

    @GetMapping("/list_spu_ranking_by_order_count")
    @Operation(summary = "获取商品订单数量排行榜", description = "获取商品订单数量排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderOverviewVO>> listSpuRankingByPayActual(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                 @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderOverviewVO> orderOverviewVOList = orderStatisticsService.listSpuRankingByOrderCount(null, DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }

    @GetMapping("/list_shop_ranking_by_pay_actual")
    @Operation(summary = "获取店铺销售排行榜", description = "获取店铺销售排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderOverviewVO>> listShopRankingByPayActual(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                  @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderOverviewVO> orderOverviewVOList = orderStatisticsService.listShopRankingByPayActual(DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }

    @GetMapping("/list_shop_ranking_by_refund_count")
    @Operation(summary = "获取店铺退款订单数量排行榜", description = "获取店铺退款订单数量排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<OrderRefundStatisticsVO>> listRefundRankingByProd(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                                       @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        List<OrderRefundStatisticsVO> orderRefundStatisticsVOList = orderStatisticsService.listShopRankingByRefundCount(DateUtil.endOfDay(DateUtil.date()), dayCount, limit);
        return ServerResponseEntity.success(orderRefundStatisticsVOList);
    }

}
