package com.njcn.harmonic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.common.utils.LogUtil;
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.vo.*;
import com.njcn.harmonic.service.IAnalyzeService;
import com.njcn.harmonic.service.IHarmonicService;
import com.njcn.poi.util.PoiUtil;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/4/29 14:35
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/detailAnalysis")
@Api(tags = "详细分析")
@AllArgsConstructor
public class AnalyzeController extends BaseController {

    private final IAnalyzeService IAnalyzeService;

    private final IHarmonicService harmonicService;


  /*  @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineRank")
    @ApiOperation("污区图-获取前十监测点排名")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<PollutionLineDTO>> getLineRank(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getLineRank");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<PollutionLineDTO> list = pollutionService.getLineRank(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }*/

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deptSubRelations")
    @ApiOperation("谐波统计-部门变电站关系")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<PollutionVO>> deptSubRelations(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("deptSubRelations");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<PollutionVO> list = harmonicService.getDeptSubstationRelations(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deptInfo")
    @ApiOperation("谐波统计-部门列表")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<HarmonicDeptVO>> deptInfo(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("deptInfo");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<HarmonicDeptVO> list = harmonicService.getDeptInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSubInfoById")
    @ApiOperation("谐波统计-根据部门获取变电站详情")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<HarmonicSubstationVO>> getSubInfoById(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getSubInfoById");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<HarmonicSubstationVO> list = harmonicService.getSubstationInfoById(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getXbLineInfoById")
    @ApiOperation("谐波统计-根据变电站获取监测点详情")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<HarmonicLineVO>> getXbLineInfoById(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getXbLineInfoById");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<HarmonicLineVO> list = harmonicService.getLineInfoById(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getXbLineRank")
    @ApiOperation("谐波统计-获取前十监测点排名")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<List<HarmonicLineVO>> getXbLineRank(@RequestBody HarmonicPublicParam param) {
        String methodDescribe = getMethodDescribe("getXbLineRank");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        List<HarmonicLineVO> list = harmonicService.getLineRank(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/overAreaStatistics")
    @ApiOperation("区域稳态超标统计")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<Page<OverAreaLimitVO>> overAreaStatistics(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("overAreaStatistics");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        Page<OverAreaLimitVO> list = IAnalyzeService.getAreaData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/warnSubstationDetail")
    @ApiOperation("告警变电站明细")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<Page<WarningSubstationVO>> warnSubstationDetail(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("warnSubstationDetail");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        Page<WarningSubstationVO> list = IAnalyzeService.getWarningSubstation(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/lineOverLimit")
    @ApiOperation("监测点超标统计")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<Page<MonitorOverLimitVO>> lineOverLimit(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("lineOverLimit");
        LogUtil.njcnDebug(log, "{}，实体参数：{}", methodDescribe, param);
        Page<MonitorOverLimitVO> list = IAnalyzeService.monitorOverLimitVO(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/exportHarmonicArea")
    @ApiOperation("区域稳态超标统计导出")
    @ApiImplicitParam(name = "param", value = "查询参数", required = true)
    public HttpResult<String> exportHarmonicArea(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("exportHarmonicArea");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, IAnalyzeService.exportArea(param,methodDescribe), methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/exportHarmonicSubstation")
    @ApiOperation("告警变电站明细导出")
    @ApiImplicitParam(name = "param", value = "查询参数", required = true)
    public HttpResult<String> exportHarmonicSubstation(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("exportHarmonicSubstation");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, IAnalyzeService.exportSubstation(param,methodDescribe), methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/exportHarmonicMonitor")
    @ApiOperation("监测点超标统计导出")
    @ApiImplicitParam(name = "param", value = "查询参数", required = true)
    public HttpResult<String> exportHarmonicMonitor(@Validated @RequestBody OverAreaVO param) {
        String methodDescribe = getMethodDescribe("exportHarmonicMonitor");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, IAnalyzeService.exportMonitor(param,methodDescribe), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @GetMapping("/exportDataExcel")
    @ApiOperation("导出数据报表")
    @ApiImplicitParam(name = "filePath", value = "报表路径", required = true)
    public void exportDataExcel(String filePath, HttpServletResponse response) {
        PoiUtil.exportFileByAbsolutePath(filePath,response);
    }

}
