
package com.wzj.soopin.statistics.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wzj.soopin.order.domain.entity.Aftersale;
import com.wzj.soopin.order.domain.vo.PageVO;
import com.wzj.soopin.statistics.entity.dto.StatisticsQueryParam;
import com.wzj.soopin.statistics.entity.vo.OrderOverviewVO;
import com.wzj.soopin.statistics.entity.vo.OrderSimpleVO;
import com.wzj.soopin.statistics.entity.vo.OrderStatisticsDataVO;
import com.wzj.soopin.statistics.service.AfterSaleStatisticsService;
import com.wzj.soopin.statistics.service.OrderStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
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.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 管理端,订单统计接口
 *
 * @author Bulbasaur
 * @since 2020/12/9 19:04
 */
@Slf4j
@Tag(name = "管理端,订单统计接口")
@RestController
@RequestMapping("/manager/statistics/order")
public class OrderStatisticsManagerController {
    @Autowired
    private OrderStatisticsService orderStatisticsService;
    @Autowired
    private AfterSaleStatisticsService afterSaleStatisticsService;

    @Operation(summary = "订单概览统计")
    @GetMapping("/overview")
    public R<OrderOverviewVO> overview(StatisticsQueryParam statisticsQueryParam) {
        try {
            return R.ok(orderStatisticsService.overview(statisticsQueryParam));
        } catch (Exception e) {
            log.error("订单概览统计错误",e);
        }
        return null;
    }

    @Operation(summary = "订单图表统计")
    @GetMapping
    public R<List<OrderStatisticsDataVO>> statisticsChart(StatisticsQueryParam statisticsQueryParam) {
        try {
            return R.ok(orderStatisticsService.statisticsChart(statisticsQueryParam));
        } catch (Exception e) {
            log.error("订单图表统计",e);
        }
        return null;
    }


    @Operation(summary = "订单统计")
    @GetMapping("/order")
    public R<IPage<OrderSimpleVO>> order(StatisticsQueryParam statisticsQueryParam, PageVO pageVO) {
        try {
            return R.ok(orderStatisticsService.getStatistics(statisticsQueryParam, pageVO));
        } catch (Exception e) {
            log.error("订单统计",e);
        }
        return null;
    }


    @Operation(summary = "退单统计")
    @GetMapping("/refund")
    public R<IPage<Aftersale>> refund(StatisticsQueryParam statisticsQueryParam, PageVO pageVO) {
        return R.ok(afterSaleStatisticsService.getStatistics(statisticsQueryParam, pageVO));
    }

    @Operation(summary = "退单统计导出")
    @GetMapping("/refund/export")
    public void exportRefund(StatisticsQueryParam statisticsQueryParam, HttpServletResponse response) throws IOException {
        afterSaleStatisticsService.exportRefund(statisticsQueryParam, response);
    }

}
