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

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.pq.api.LineFeignClient;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.line.DistortionRateService;
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.CollectionUtils;
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.ArrayList;
import java.util.List;

/**
 * @author xiaoyao
 * @version 1.0.0
 * @createTime 2022/11/4 15:58
 */
@Slf4j
@Api(tags = "谐波畸变率")
@RestController
@RequestMapping("/distortion")
@RequiredArgsConstructor
public class DistortionRateController extends BaseController {

    private final DistortionRateService distortionRateService;
    private final LineFeignClient lineFeignClient;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/distortionRate")
    @ApiOperation("谐波畸变率排名_mysql")
    @ApiImplicitParam(name = "lineParam", value = "参数", required = true)
    @Deprecated
    public HttpResult<String> distortionRate(@RequestBody @Validated LineParam lineParam){
        String methodDescribe = getMethodDescribe("distortionRate");
        distortionRateService.distortionRate(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }








    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/distortionRateBySource")
    @ApiOperation("谐波畸变率排名")
    @ApiImplicitParam(name = "lineParam", value = "参数", required = true)
    @Deprecated
    public HttpResult<String> distortionRateBySource(@RequestBody @Validated LineParam lineParam){
        log.info(LocalDateTime.now()+"distortionRateBySource开始执行");
        String methodDescribe = getMethodDescribe("distortionRateBySource");
        List<String> indexLists = new ArrayList<> ();
        if(CollectionUtils.isEmpty (lineParam.getLineIds ())){
            indexLists = lineFeignClient.getLineList ( ).getData ( );
        }else{
            indexLists = lineParam.getLineIds ();
        }
        lineParam.setLineIds (indexLists);

        distortionRateService.distortionRateBySource (lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


}
