package com.ktg.iscs.controller;

import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.iscs.domain.vo.homePage.HomePageVO;
import com.ktg.iscs.domain.vo.statistics.*;
import com.ktg.iscs.service.StatisticsApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 硬件调用接口
 *
 * @author cgj
 * @date 2024-10-16
 */
@Api(tags = "统计接口")
@RestController
@RequestMapping("/iscs/statistics-api")
public class StatisticsApiController extends BaseController {
    @Autowired
    private StatisticsApiService statisticsApiService;

    @ApiOperation("物资柜使⽤情况统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getCabinetStatistics")
    public CommonResult<List<CabinetStatisticsVO>> getCabinetStatistics(String startTime, String endTime) {
        List<CabinetStatisticsVO> list = statisticsApiService.getCabinetStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("物资当前状态统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getMaterialsStatusStatistics")
    public CommonResult<List<MaterialsStatusStatisticsVO>> getMaterialsStatusStatistics(String startTime, String endTime) {
        List<MaterialsStatusStatisticsVO> list = statisticsApiService.getMaterialsStatusStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("物资使⽤情况统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getMaterialsLoanStatistics")
    public CommonResult<List<MaterialsLoanStatisticsVO>> getMaterialsLoanStatistics(String startTime, String endTime) {
        List<MaterialsLoanStatisticsVO> list = statisticsApiService.getMaterialsLoanStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("物资更换情况统计⽤情况统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getMaterialsChangeStatistics")
    public CommonResult<List<MaterialsChangeStatisticsVO>> getMaterialsChangeStatistics(String startTime, String endTime) {
        List<MaterialsChangeStatisticsVO> list = statisticsApiService.getMaterialsChangeStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("⼈员借⽤情况统计⽤情况统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getUserLoanStatistics")
    public CommonResult<List<UserLoanStatisticsVO>> getUserLoanStatistics(String startTime, String endTime) {
        List<UserLoanStatisticsVO> list = statisticsApiService.getUserLoanStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("每⽇领取归还统计")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getDayLoanStatistics")
    public CommonResult<List<DayLoanStatisticsVO>> getDayLoanStatistics(String startTime, String endTime) {
        List<DayLoanStatisticsVO> list = statisticsApiService.getDayLoanStatistics(startTime, endTime);
        return CommonResult.success(list);
    }

    @ApiOperation("首页")
    @Parameters({
            @Parameter(name = "startTime", description = "开始时间"),
            @Parameter(name = "endTime", description = "结束时间")
    })
    @GetMapping("/getHomePage")
    public CommonResult<HomePageVO> getHomePage(String startTime, String endTime) {
        HomePageVO vo = statisticsApiService.getHomePage(startTime, endTime);
        return CommonResult.success(vo);
    }

    @ApiOperation("物资盘点")
    @Parameter(name = "type", description = "查询类型(0-总览 1-柜中 2-借出 3-正常 4-过期 5-损坏)")
    @GetMapping("/getMaterialInventory")
    public CommonResult<List<InventoryVO>> getMaterialInventory(Integer type) {
        List<InventoryVO> vo = statisticsApiService.getMaterialInventory(type);
        return CommonResult.success(vo);
    }

    @ApiOperation("物资盘点-上方统计")
    @GetMapping("/getInventorySum")
    public CommonResult<List<InventoryTypeVO>> getInventorySum() {
        List<InventoryTypeVO> vo = statisticsApiService.getInventorySum();
        return CommonResult.success(vo);
    }

    @ApiOperation("导出物资盘点")
    @Log(title = "导出物资盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/exportMaterialInventory")
    public void exportMaterialInventory(HttpServletResponse response, HttpServletRequest request) {
        statisticsApiService.exportMaterialInventory(response, request);
    }

    @ApiOperation("导出基础数据统计")
    @Log(title = "导出基础数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportBaseData")
    public void exportBaseData(HttpServletResponse response, HttpServletRequest request, String startTime, String endTime) {
        statisticsApiService.exportBaseData(response, request, startTime, endTime);
    }

    @ApiOperation("导出领取归还统计")
    @Log(title = "导出领取归还统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportClaimAndReturn")
    public void exportClaimAndReturn(HttpServletResponse response, HttpServletRequest request, String startTime, String endTime) {
        statisticsApiService.exportClaimAndReturn(response, request, startTime, endTime);
    }

}
