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

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.RStatAbnormalDService;
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.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;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/4/19  15:45【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/rmstatabnormal")
@Api(tags = "监测点异常_日统计")
@AllArgsConstructor
public class RMStatAbnormalDController extends BaseController {
    private final LineFeignClient lineFeignClient;
    private final RStatAbnormalDService rStatAbnormalDService;


    @ApiOperation("监测点异常_日统计(MySQL库)")
    @ApiImplicitParam(value = "jobParam",name = "jobParam",required = true)
    @PostMapping("handlerMonitorAbnormal")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    public HttpResult<Boolean> handlerMonitorAbnormal(@RequestBody LineParam jobParam ){

        log.info(LocalDateTime.now()+"handlerMonitorAbnormal开始执行");
        String methodDescribe = getMethodDescribe("handlerMonitorAbnormal");
        List<String> indexLists = new ArrayList<> ();
        if(CollectionUtils.isEmpty (jobParam.getLineIds ())){
            indexLists = lineFeignClient.getLineList ( ).getData ( );
        }else{
            indexLists = jobParam.getLineIds ();
        }

        rStatAbnormalDService.handlerMonitorAbnormal (indexLists,jobParam.getDataDate ());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }
}
