package com.njcn.csreport.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csreport.pojo.vo.ReportEventVO;
import com.njcn.csreport.pojo.vo.ReportHarmonicVO;
import com.njcn.csreport.service.ICsAppReportService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xy
 * @since 2026-03-19
 */
@RestController
@Slf4j
@RequestMapping("/csAppReport")
@Api(tags = "App报告")
@AllArgsConstructor
public class CsAppReportController extends BaseController {

    private final ICsAppReportService csAppReportService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/reportList")
    @ApiOperation("获取稳态报表首页")
    @ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
    public HttpResult<List<ReportHarmonicVO>> reportList(@RequestBody LineParamDTO param) {
        String methodDescribe = getMethodDescribe("reportList");
        List<ReportHarmonicVO> result = csAppReportService.getReportList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/downloadHarmonicReport")
    @ApiOperation("下载稳态报告")
    @ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
    public HttpResult<String> downloadHarmonicReport(@RequestBody LineParamDTO param) {
        String methodDescribe = getMethodDescribe("downloadHarmonicReport");
        String filePath = csAppReportService.downloadHarmonicReport(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, filePath, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/applicationReport")
    @ApiOperation("申请暂态报告")
    @ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
    public HttpResult<List<ReportHarmonicVO>> applicationReport(@RequestBody LineParamDTO param) {
        String methodDescribe = getMethodDescribe("applicationReport");
        csAppReportService.applicationReport(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getApplicationReport")
    @ApiOperation("查询暂态报告申请记录")
    @ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
    public HttpResult<Page<ReportEventVO>> getApplicationReportList(@RequestBody LineParamDTO param) {
        String methodDescribe = getMethodDescribe("getApplicationReportList");
        Page<ReportEventVO> result = csAppReportService.getApplicationReportList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/createEventReport")
    @ApiOperation("生成暂态报告")
    @ApiImplicitParam(name = "id", value = "报告id", required = true)
    public HttpResult<Boolean> createEventReport(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("createEventReport");
        Boolean result = csAppReportService.createEventReport(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/downloadEventReport")
    @ApiOperation("下载暂态报告")
    @ApiImplicitParam(name = "id", value = "报告id", required = true)
    public HttpResult<String> downloadEventReport(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("downloadEventReport");
        String filePath = csAppReportService.downloadEventReport(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, filePath, methodDescribe);
    }

}

