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

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.RmpPassRateService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
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 qijian
 * @date 2022/10/26
 * 数据是否异常
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/RmpPassRate")
@Api(tags = "监测点稳态指标合格率")
@AllArgsConstructor
@Deprecated
public class RmpPassRateController extends BaseController {

    private  final LineFeignClient lineFeignClient;
    private final RmpPassRateService rmpPassRateService;
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/RmpPassRateD")
    @ApiOperation("监测点稳态指标合格率-日计算")
    @ApiImplicitParam(name = "lineParam", value = "算法通用查询参数", required = true)
    public HttpResult<Boolean> rmpPassRateDHandler(@RequestBody @Validated LineParam lineParam) {
        log.info(LocalDateTime.now()+"rmpPassRateDHandler开始执行");
        String methodDescribe = getMethodDescribe("rmpPassRateDHandler");
        Boolean result = true;
        List<String> indexLists = new ArrayList<> ();
        if(CollectionUtils.isEmpty (lineParam.getLineIds ())){
            indexLists = lineFeignClient.getLineList ( ).getData ( );
        }else{
            indexLists = lineParam.getLineIds ();
        }
        rmpPassRateService.rmpPassRateDHandler (lineParam);
        if (result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }
}
