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.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.prepare.harmonic.pojo.param.OrgParam;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatEventService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatEventVoltageService;
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("/rStartEventVoltage")
@RequiredArgsConstructor
public class RStatEventVoltageController extends BaseController {

    private final RStatEventVoltageService rStatEventVoltageService;

    private final CommTerminalGeneralClient commTerminalGeneralClient;

    private final DeptFeignClient deptFeignClient;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/rStartEventVoltage")
    @ApiOperation("暂态指标统计（电压等级）")
    @ApiImplicitParam(name = "orgParam", value = "参数", required = true)
    public HttpResult<String> rStartEventVoltageHandler(@RequestBody @Validated OrgParam orgParam) {
        log.info(LocalDateTime.now() + "rStartEventVoltageHandler开始执行");
        String methodDescribe = getMethodDescribe("rStartEventVoltageHandler");
        /**
         * 支持补录
         */
        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<DeptGetChildrenMoreDTO> data = commTerminalGeneralClient.deptGetLine(deptGetLineParam).getData();

        rStatEventVoltageService.handler(data,orgParam.getDataDate(),orgParam.getType());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
