package com.njcn.product.carrycapacity.controller;


import com.alibaba.excel.EasyExcel;
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.product.carrycapacity.pojo.excel.CarryCapcityDataEexcel;
import com.njcn.product.carrycapacity.pojo.param.CarryCapacityCalParam;
import com.njcn.product.carrycapacity.pojo.param.CarryCapacityEvaluateParam;
import com.njcn.product.carrycapacity.pojo.param.CarryCapacityQueryDataParam;
import com.njcn.product.carrycapacity.pojo.param.ExcelDataParam;
import com.njcn.product.carrycapacity.pojo.vo.CarryCapacityDResultVO;
import com.njcn.product.carrycapacity.pojo.vo.CarryCapacityDataIVO;
import com.njcn.product.carrycapacity.pojo.vo.CarryCapacityDataQVO;
import com.njcn.product.carrycapacity.pojo.vo.CarryCapacityDataVO;
import com.njcn.product.carrycapacity.service.CarryCapacityService;
import com.njcn.product.carrycapacity.util.EasyExcelUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年07月21日 10:06
 */
@RestController
@RequestMapping("carrycapacity")
@Api(tags = "承载能力评估")
@RequiredArgsConstructor
public class CarryCapacityController extends BaseController {


    private final CarryCapacityService carryCapcityService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryCarryCapacityData")
    @ApiOperation("承载能力评估数据查询-主页面")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<CarryCapacityDataVO> queryCarryCapacityData(@RequestBody @Validated CarryCapacityQueryDataParam queryParam) {
        String methodDescribe = getMethodDescribe("queryCarryCapacityData");
        CarryCapacityDataVO carryCapacityDataVO = carryCapcityService.queryCarryCapacityData(queryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, carryCapacityDataVO, methodDescribe);
    }



    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryCarryCapacityQData")
    @ApiOperation("承载能力评估数据查询-无功功率")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<CarryCapacityDataQVO> queryCarryCapacityQData(@RequestBody @Validated CarryCapacityQueryDataParam queryParam) {
        String methodDescribe = getMethodDescribe("queryCarryCapacityQData");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, carryCapcityService.queryCarryCapacityqData(queryParam), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryCarryCapacityIData")
    @ApiOperation("承载能力评估数据查询-谐波电流幅值")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<CarryCapacityDataIVO> queryCarryCapacityIData(@RequestBody @Validated CarryCapacityQueryDataParam queryParam) {
        String methodDescribe = getMethodDescribe("queryCarryCapacityIData");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, carryCapcityService.queryCarryCapacityiData(queryParam), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/carryCapacityCal")
    @ApiOperation("承载能力评估")
    @ApiImplicitParam(name = "calParam", value = "计算参数", required = true)
    public HttpResult<CarryCapacityDResultVO> carryCapacityCal(@RequestBody @Validated CarryCapacityCalParam calParam) {
        String methodDescribe = getMethodDescribe("carryCapacityCal");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, carryCapcityService.carryCapacityCal(calParam), methodDescribe);
    }

//    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
//    @GetMapping("/carryCapacityTree")
//    @ApiOperation("承载能力评估-台账树")
//    public HttpResult<List<TerminalTree>> carryCapacityTree() {
//        String methodDescribe = getMethodDescribe("carryCapacityTree");
//        List<TerminalTree> terminalTree = carryCapcityService.carryCapacityTree();
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, terminalTree, methodDescribe);
//    }

    @ResponseBody
    @ApiOperation("导出数据集模板")
    @GetMapping(value = "getExcelTemplate")
    public HttpResult<String> getExcelTemplate(HttpServletResponse response) throws IOException {
        String sheetName = "数据集模版";
        List<CarryCapcityDataEexcel> excels = new ArrayList<>();
        CarryCapcityDataEexcel exportHeadersExcel = new CarryCapcityDataEexcel();
        excels.add(exportHeadersExcel);
        EasyExcel.write(response.getOutputStream(), CarryCapcityDataEexcel.class)
                .sheet(sheetName)
                .doWrite(excels);
        EasyExcelUtil.writeWithSheetsWeb(response,  "数据集模版.xlsx");
        return null;
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/uploadExcel")
    @ApiOperation("上传数据集")
    public HttpResult<Boolean> uploadExcel(@Validated ExcelDataParam excelDataParam) throws Exception {
        String methodDescribe = getMethodDescribe("uploadExcel");
        boolean flag = carryCapcityService.uploadExcel(excelDataParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/carryCapacityEvaluate")
    @ApiOperation("承载能力评估_充电站、电加热负荷、电气化铁路承载能力评估")
    @ApiImplicitParam(name = "calParam", value = "计算参数", required = true)
    public HttpResult<CarryCapacityDResultVO> carryCapacityEvaluate(@RequestBody @Validated CarryCapacityEvaluateParam calParam) {
        String methodDescribe = getMethodDescribe("carryCapacityEvaluate");
        CarryCapacityDResultVO vo = carryCapcityService.carryCapacityEvaluate(calParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }


}
