package com.njcn.harmonic.controller.powerstatistics;

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.harmonic.pojo.param.PowerStatisticsParam;
import com.njcn.harmonic.pojo.vo.PowerStatisticsTargetVO;
import com.njcn.harmonic.pojo.vo.PowerStatisticsVO;
import com.njcn.harmonic.pojo.vo.ThdDataVO;
import com.njcn.harmonic.service.activepowerrange.PowerStatisticsService;
import io.swagger.annotations.Api;
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 com.njcn.web.controller.BaseController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 有功功率趋势统计 前端控制器
 * @author guofeihu
 * @since 2024-08-20
 */
@Slf4j
@RestController
@RequestMapping("/powerStatistics")
@Api(tags = "有功功率趋势")
@AllArgsConstructor
public class PowerStatisticsController extends BaseController {

    private final PowerStatisticsService powerStatisticsService;

    /**
     * 根据监测点ID及时间获取有功功率趋势
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDataByLineId")
    @ApiOperation("根据监测点ID及时间获取有功功率趋势")
    public HttpResult<PowerStatisticsVO> getDataByLineId(@RequestBody @Validated PowerStatisticsParam powerStatisticsParam) {
        String methodDescribe = getMethodDescribe("getDataByLineId");
        PowerStatisticsVO dataByLineId = powerStatisticsService.getDataByLineId(powerStatisticsParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,dataByLineId , methodDescribe);
    }

    /**
     * 根据监测点ID、有功功率趋势区间字段、时间获取该有功功率趋势下指标越限列表
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTargetLimitById")
    @ApiOperation("根据监测点ID、有功功率趋势区间字段、时间获取该有功功率趋势下指标越限列表")
    public HttpResult<List<PowerStatisticsTargetVO>> getTargetLimitById(@RequestBody @Validated PowerStatisticsParam powerStatisticsParam) {
        String methodDescribe = getMethodDescribe("getTargetLimitById");
        List<PowerStatisticsTargetVO> targetLimitById = powerStatisticsService.getTargetLimitById(powerStatisticsParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,targetLimitById , methodDescribe);
    }

    /**
     * 点击越限列表时间查询指标的详细数据
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTargetByTime")
    @ApiOperation("点击越限列表时间查询指标的详细数据")
    public HttpResult<List<ThdDataVO>> getTargetByTime(@RequestBody @Validated PowerStatisticsParam powerStatisticsParam) {
        String methodDescribe = getMethodDescribe("getTargetByTime");
        List<ThdDataVO> targetByTime = powerStatisticsService.getTargetByTimeDetail(powerStatisticsParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, targetByTime, methodDescribe);
    }

    @ResponseBody
    @ApiOperation("导出区间数据")
    @PostMapping(value = "exportExcelRangTemplate")
    public void exportExcelRangTemplate(@RequestBody @Validated PowerStatisticsParam powerStatisticsParam,HttpServletResponse response) {
        powerStatisticsService.exportExcelRangTemplate(powerStatisticsParam,response);
    }

    @ResponseBody
    @ApiOperation("导出指标越限列表数据")
    @PostMapping(value = "exportExcelListTemplate")
    public void exportExcelListTemplate(@RequestBody @Validated PowerStatisticsParam powerStatisticsParam,HttpServletResponse response) {
        powerStatisticsService.exportExcelListTemplate(powerStatisticsParam,response);
    }

}

