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

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo;
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.DeptGetSubStationDTO;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.prepare.harmonic.pojo.param.OrgParam;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatSubstationService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatSubstationVoltageMPOService;
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.util.StringUtils;
import org.springframework.validation.annotation.Validated;
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.LocalDateTime;
import java.util.List;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2022/12/28  13:47【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@Api(tags = "变电站指标统计")
@RestController
@RequestMapping("/rStartSubstationVoltage")
@RequiredArgsConstructor
public class RStatSubstationVoltageController extends BaseController {

    private final RStatSubstationVoltageMPOService service;

    private final CommTerminalGeneralClient commTerminalGeneralClient;

    private final DeptFeignClient deptFeignClient;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/rStartSubstationHandler")
    @ApiOperation("变电站指标统计")
    @ApiImplicitParam(name = "orgParam", value = "参数", required = true)
    public HttpResult<String> rStartSubstationHandler(@RequestBody @Validated OrgParam orgParam) {
        log.info(LocalDateTime.now() + "rStartSubstationHandler开始执行");
        String methodDescribe = getMethodDescribe("rStartSubstationHandler");
        /**
         * 支持补录
         */
        DeptGetLineParam deptGetLineParam = new DeptGetLineParam();

        if (StringUtils.isEmpty(orgParam.getOrgId())) {
            Dept data = deptFeignClient.getRootDept().getData();
            deptGetLineParam.setDeptId(data.getId());
        } else {
            deptGetLineParam.setDeptId(orgParam.getOrgId());
        }
        deptGetLineParam.setServerName(ServerInfo.PREPARE_BOOT);
        List<DeptGetSubStationDTO> data = commTerminalGeneralClient.deptSubStation(deptGetLineParam).getData();

        long start = System.currentTimeMillis();
//        service.handler(data,orgParam.getDataDate(),orgParam.getType());
        long end = System.currentTimeMillis();
        System.out.println("该方法总耗时为 ---> "+(end-start));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
