package com.casic.missiles.controller.cockpit;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.casic.missiles.core.base.controller.ExportController;
import com.casic.missiles.core.page.PageFactory;
import com.casic.missiles.core.page.PageInfoBT;
import com.casic.missiles.dto.ReturnDTO;
import com.casic.missiles.dto.ReturnUtil;
import com.casic.missiles.dto.business.order.*;
import com.casic.missiles.dto.cockpit.AnnualDataResponse;
import com.casic.missiles.dto.cockpit.MeasureWorkResponse;
import com.casic.missiles.dto.cockpit.TrafficStatisticsResponse;
import com.casic.missiles.dto.customer.CustomerExcellentResponse;
import com.casic.missiles.service.business.IBusinessOrderService;
import com.casic.missiles.service.cockpit.IHomepageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @Description: 计量管理驾驶舱首页
 * @Author: wangpeng
 * @Date: 2023/6/5 11:35
 */
@Api(tags = "计量管理驾驶舱-首页")
@Slf4j
@RestController
@RequestMapping("/cockpit/homepage")
@AllArgsConstructor
public class HomepageController extends ExportController {

    private final IBusinessOrderService businessOrderService;

    private final IHomepageService homepageService;

    /**
     * 使用签订的收入合同和业务结算的金额
     */
    @ApiOperation("年度经营数据-年度产值、月度产值")
    @GetMapping("/annualData")
    public ReturnDTO<AnnualDataResponse> annualData() {
        AnnualDataResponse response = homepageService.annualData();
        return ReturnUtil.success(response);
    }

    @ApiOperation("计量作业-年度订单、月度订单、今日订单数、本月业务量、上月业务量")
    @GetMapping("/measureWork")
    public ReturnDTO<MeasureWorkResponse> measureWork() {
        MeasureWorkResponse response = homepageService.measureWork();
        return ReturnUtil.success(response);
    }

    @ApiOperation("业务量统计-近n个月每月业务量")
    @GetMapping("/trafficStatistics/{months}")
    public ReturnDTO<List<TrafficStatisticsResponse>> trafficStatistics(@PathVariable(name = "months") Integer months) {
        List<TrafficStatisticsResponse> responseList = homepageService.trafficStatistics(months);
        return ReturnUtil.success(responseList);
    }

    @ApiOperation("实时订单数据")
    @GetMapping("/orderList")
    public ReturnDTO<PageInfoBT<OrderListResponse>> orderList() throws Exception {
        Page<OrderListResponse> page = PageFactory.defaultPage();
        OrderListRequest request = new OrderListRequest();
        return ReturnUtil.success(super.packForBT(businessOrderService.orderListPage(page, request)));
    }

    /**
     * 计量能力，目前无该功能，需后续评审开发
     */

    @ApiOperation("各实验室收入(年：year，季：quarter，月：month)")
    @GetMapping("/labIncome/{dimension}")
    public ReturnDTO<List<labIncomeResponse>> labIncome(@PathVariable(name = "dimension") String dimension) {
        return ReturnUtil.success(homepageService.labIncomeList(dimension));
    }

    @ApiOperation("各实验室总收入(年：year，季：quarter，月：month)")
    @GetMapping("/labIncomeTotal/{dimension}")
    public ReturnDTO<labIncomeTotalResponse> labIncomeTotal(@PathVariable(name = "dimension") String dimension) {
        return ReturnUtil.success(homepageService.labIncomeTotal(dimension));
    }

    @ApiOperation("样品超期情况")
    @GetMapping("/sampleOverdue")
    public ReturnDTO<SampleOverdueResponse> sampleOverdue() {
        return ReturnUtil.success(homepageService.sampleOverdue());
    }

    @ApiOperation("样品超期总数")
    @GetMapping("/sampleOverdueTotal")
    public ReturnDTO<SampleOverdueTotalResponse> sampleOverdueTotal() {
        return ReturnUtil.success(homepageService.sampleOverdueTotal());
    }

    @ApiOperation("优质客户")
    @GetMapping("/excellentList")
    public ReturnDTO<CustomerExcellentResponse> customerExcellentList() {
        return ReturnUtil.success(homepageService.customerExcellentList());
    }
}
