package cn.iocoder.lyzsys.module.tjt.controller.admin.report;

import cn.iocoder.lyzsys.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.lyzsys.framework.common.pojo.CommonResult;
import cn.iocoder.lyzsys.module.tjt.controller.admin.report.vo.*;
import cn.iocoder.lyzsys.module.tjt.service.report.ProjectOutputReportService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

import static cn.iocoder.lyzsys.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.lyzsys.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 产值报表导出")
@RestController
@RequestMapping("/tjt/report")
@Validated
public class ProjectOutputReportController {

    @Resource
    private ProjectOutputReportService projectOutputReportService;

    @GetMapping("/project-budget/export-excel")
    @Operation(summary = "导出项目考核产值预算表")
    @PreAuthorize("@ss.hasPermission('tjt:report-budget:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportProjectBudgetExcel(HttpServletResponse response,
                                         @Valid ProjectBudgetExportReqVO reqVO) throws IOException {
        projectOutputReportService.exportProjectBudgetExcel(response, reqVO);
    }

    @GetMapping("/project-quarter-output/export-excel")
    @Operation(summary = "导出项目级年度季度计取表")
    @PreAuthorize("@ss.hasPermission('tjt:report-project-quarter:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportProjectQuarterOutputExcel(HttpServletResponse response,
                                                @Valid ProjectQuarterOutputExportReqVO reqVO) throws IOException {
        projectOutputReportService.exportProjectQuarterOutputExcel(response, reqVO);
    }

    @GetMapping("/project-lead-quarter-output/export-excel")
    @Operation(summary = "导出工程负责人年度季度计取表")
    @PreAuthorize("@ss.hasPermission('tjt:report-project-quarter:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportProjectLeadQuarterOutputExcel(HttpServletResponse response,
                                                    @Valid ProjectLeadQuarterOutputExportReqVO reqVO)
            throws IOException {
        projectOutputReportService.exportProjectLeadQuarterOutputExcel(response, reqVO);
    }

    @GetMapping("/specialty-person-output/export-excel")
    @Operation(summary = "导出专业内人员年度季度计取表")
    @PreAuthorize("@ss.hasPermission('tjt:report-specialty-person:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportSpecialtyPersonOutputExcel(HttpServletResponse response,
                                                 @Valid SpecialtyPersonOutputExportReqVO reqVO) throws IOException {
        projectOutputReportService.exportSpecialtyPersonOutputExcel(response, reqVO);
    }

    @GetMapping("/specialty-person-output/preview")
    @Operation(summary = "预览专业内人员年度季度计取表")
    @PreAuthorize("@ss.hasAnyPermissions('tjt:report-specialty-person:query', 'tjt:report-specialty-person:export')")
    public CommonResult<SpecialtyPersonOutputPreviewRespVO> getSpecialtyPersonOutputPreview(
            @Valid SpecialtyPersonOutputPreviewReqVO reqVO) {
        return success(projectOutputReportService.getSpecialtyPersonOutputPreview(reqVO));
    }

    @GetMapping("/project-overview/preview")
    @Operation(summary = "预览项目总览表")
    @PreAuthorize("@ss.hasAnyPermissions('tjt:report-summary:query', 'tjt:report-summary:export')")
    public CommonResult<ProjectOverviewPreviewRespVO> getProjectOverviewPreview(
            @Valid ProjectOverviewExportReqVO reqVO) {
        return success(projectOutputReportService.getProjectOverviewPreview(reqVO));
    }

    @GetMapping("/project-overview/export-excel")
    @Operation(summary = "导出项目总览表")
    @PreAuthorize("@ss.hasPermission('tjt:report-summary:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportProjectOverviewExcel(HttpServletResponse response,
                                           @Valid ProjectOverviewExportReqVO reqVO) throws IOException {
        projectOutputReportService.exportProjectOverviewExcel(response, reqVO);
    }

    @GetMapping("/employee-output-summary/preview")
    @Operation(summary = "预览员工个人考核产值汇总表")
    @PreAuthorize("@ss.hasAnyPermissions('tjt:report-summary:query', 'tjt:report-summary:export')")
    public CommonResult<EmployeeOutputSummaryPreviewRespVO> getEmployeeOutputSummaryPreview(
            @Valid EmployeeOutputSummaryExportReqVO reqVO) {
        return success(projectOutputReportService.getEmployeeOutputSummaryPreview(reqVO));
    }

    @GetMapping("/employee-output-summary/export-excel")
    @Operation(summary = "导出员工个人考核产值汇总表")
    @PreAuthorize("@ss.hasPermission('tjt:report-summary:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportEmployeeOutputSummaryExcel(HttpServletResponse response,
                                                 @Valid EmployeeOutputSummaryExportReqVO reqVO)
            throws IOException {
        projectOutputReportService.exportEmployeeOutputSummaryExcel(response, reqVO);
    }

}
