package com.cf.imes.module.executor.controller.admin.order;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
import com.cf.imes.module.executor.service.order.OrderStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import java.util.Map;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

/**
 * @author Gqr
 * @since 2024/8/5 17:00
 */
@Tag(name = "管理后台 - 订单统计管理")
@RestController
@RequestMapping("/executor/order/statistics")
public class OrderStatisticsController {
    @Resource
    private OrderStatisticsService orderStatisticsService;

    @GetMapping("/total")
    @Operation(summary = "订单总数")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-statistic')")
    public CommonResult<Integer> getOrderCount() {
        return success(orderStatisticsService.orderCount());
    }

    @GetMapping("/today/increase")
    @Operation(summary = "今日新增订单总数")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-statistic')")
    public CommonResult<Integer> getOrderCountToday() {
        return success(orderStatisticsService.orderCountToday());
    }

    @GetMapping("/today/finish")
    @Operation(summary = "今日订单完成总数")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-statistic')")
    public CommonResult<Integer> getOrderCountTodayFinish() {
        return success(orderStatisticsService.orderCountTodayFinish());
    }

    @GetMapping("/producing/total")
    @Operation(summary = "生产中订单总数")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-statistic')")
    public CommonResult<Integer> getOrderCountProduce() {
        return success(orderStatisticsService.orderCountProduce());
    }

    @GetMapping("/producing/square")
    @Operation(summary = "生产中生产平方数")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-statistic')")
    public CommonResult<Double> getOrderSquareProduce() {
        return success(orderStatisticsService.orderSquareProduce());
    }

    @GetMapping("/orderStatus/group")
    @Operation(summary = "订单状态分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:order-status')")
    public CommonResult<Map<String, Object>> getOrderStatusCount(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getOrderStatusCount(reqVO));
    }

    @GetMapping("/orderAndPlanCount/group")
    @Operation(summary = "订单、排单单量分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:orderAndPlan-count')")
    public CommonResult<Map<String, Object>> getOrderAndPlanCountGroup(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getOrderAndPlanCountGroup(reqVO));
    }

    @GetMapping("/orderAndPlanArea/group")
    @Operation(summary = "订单、排单平方数分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:orderAndPlan-square-num')")
    public CommonResult<Map<String, Object>> getOrderAndPlanAreaGroup(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getOrderAndPlanAreaSumGroup(reqVO));
    }

    @GetMapping("/plateCount/group")
    @Operation(summary = "小板数量分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:plate-count')")
    public CommonResult<Map<String,Object>> getPlateCount(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getOrderPlateCountGroup(reqVO));
    }

    @GetMapping("/plateArea/group")
    @Operation(summary = "小板面积分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:plate-area')")
    public CommonResult<Map<String,Object>> getPlateArea(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getOrderPlateAreaGroup(reqVO));
    }

    @GetMapping("/bigPlateCount/group")
    @Operation(summary = "大板数量分组统计")
    @PreAuthorize("@ss.hasPermission('homePage:analysis:goods-count')")
    public CommonResult<Map<String, Object>> getBigPlateCount(@Valid OrderStatisticsReqVO reqVO) {
        return success(orderStatisticsService.getBigPlateCountGroup(reqVO));
    }

}
