package com.njcn.prepare.harmonic.controller.dim;

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.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenDTO;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
import com.njcn.prepare.harmonic.service.mysql.dim.*;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * pqs
 *
 * @author cdf
 * @date 2023/11/20
 */

@Slf4j
@Api(tags = "母线变电站每日运行情况统计")
@RestController
@RequestMapping("/dimGlobal")
@RequiredArgsConstructor
public class IRDimBusGlobalDController extends BaseController {

    private final IRDimBusGlobalDService irDimBusGlobalDService;

    private final IRDimMonitorRateDService irDimMonitorRateDService;

    private final IRDimMonitorRateMService irDimMonitorRateMService;

    private final IRDimObjRateDService irDimObjRateDService;

    private final IRDimObjRateMService irDimObjRateMService;

    private final IRDimObjRateYService irDimObjRateYService;

    private final IRDimMonitorRateYService irDimMonitorRateYService;

    private final CommTerminalGeneralClient commTerminalGeneralClient;

    private final DeptFeignClient deptFeignClient;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/dayDimGlobal")
    @ApiOperation("母线变电站每日运行情况统计")
    @ApiImplicitParam(name = "calculatedParam", value = "参数", required = true)
    public HttpResult<Boolean> dayDimGlobal(@RequestBody CalculatedParam calculatedParam) {
        String methodDescribe = getMethodDescribe("dayDimGlobal");
        irDimBusGlobalDService.globalCalBusBarDay(calculatedParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }



    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/monitorRate")
    @ApiOperation("母线变电站监测率统计")
    @ApiImplicitParam(name = "calculatedParam", value = "参数", required = true)
    public HttpResult<Boolean> monitorRate(@RequestBody CalculatedParam calculatedParam) {
        String methodDescribe = getMethodDescribe("monitorRate");

        Dept data = deptFeignClient.getRootDept().getData();
        DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
        deptGetLineParam.setDeptId(data.getId());
        deptGetLineParam.setSystemType(0);
        List<DeptGetChildrenDTO> dept = commTerminalGeneralClient.deptGetLineList(deptGetLineParam).getData();
        calculatedParam.setIdList(dept);
        calculatedParam.setDataDate("2023-11-22");

        irDimMonitorRateDService.monitorRateDay(calculatedParam);


        irDimMonitorRateMService.monitorRateMonth(calculatedParam);


        irDimMonitorRateYService.monitorRateYear(calculatedParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/objMonitorRate")
    @ApiOperation("源荷类型监测率统计")
    @ApiImplicitParam(name = "calculatedParam", value = "参数", required = true)
    public HttpResult<Boolean> objMonitorRate(@RequestBody CalculatedParam calculatedParam) {
        String methodDescribe = getMethodDescribe("objMonitorRate");

        Dept data = deptFeignClient.getRootDept().getData();
        DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
        deptGetLineParam.setDeptId(data.getId());
        deptGetLineParam.setSystemType(0);
        List<DeptGetChildrenDTO> dept = commTerminalGeneralClient.deptGetLineList(deptGetLineParam).getData();
        calculatedParam.setIdList(dept);


        irDimObjRateDService.objMonitorRateDay(calculatedParam);


        irDimObjRateMService.objMonitorRateMonth(calculatedParam);


        irDimObjRateYService.objMonitorRateYear(calculatedParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


}
