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

import cn.hutool.core.date.DateUtil;
import com.tmerclub.cloud.common.order.vo.OrderCountVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.order.service.SupplierOrderStatisticsService;
import com.tmerclub.cloud.order.vo.HotProductVO;
import com.tmerclub.cloud.order.vo.SupplierOrderOverviewVO;
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
 */
@RestController("supplierOrderStatisticsController")
@RequestMapping("/s/order_statistics")
@Tag(name = "supplier-供应商订单数据统计接口")
public class OrderStatisticsController {

    @Autowired
    private SupplierOrderStatisticsService supplierOrderStatisticsService;

    @GetMapping("/order_count")
    @Operation(summary = "查询店铺各种状态下的订单数量", description = "根据订单状态统计订单数量")
    public ServerResponseEntity<OrderCountVO> getOrderCount() {
        OrderCountVO orderCountVO = supplierOrderStatisticsService.getOrderCountOfStatusBySupplierId(AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success(orderCountVO);
    }

    @GetMapping("/get_today_info_by_hour")
    @Operation(summary = "获取当天订单实时统计数据", description = "获取当天订单实时统计数据")
    public ServerResponseEntity<SupplierOrderOverviewVO> getTodayInfoByHour() {
        SupplierOrderOverviewVO supplierOrderOverviewVO = supplierOrderStatisticsService.getTodayInfoByHour(AuthUserContext.get().getTenantId(),
                DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ServerResponseEntity.success(supplierOrderOverviewVO);
    }

    @GetMapping("/list_prod_ranking_by_payActual")
    @Operation(summary = "根据支付金额获取近30天的商品销售数据排行榜", description = "获取近30天的商品销售数据排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）"),
            @Parameter(name = "limit", description = "排行榜条数")
    })
    public ServerResponseEntity<List<HotProductVO>> listProdRankingByPayActual(@RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                               @RequestParam(value = "limit", defaultValue = "5") Integer limit) {
        List<HotProductVO> orderOverviewVOList = supplierOrderStatisticsService.listProdRankingByPayActual(AuthUserContext.get().getTenantId(), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }


}
