package com.njcn.device.pq.controller;

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.mapper.RStatOnlinerateDMapper;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.param.TerminalOnlineRateDataParam;
import com.njcn.device.pq.pojo.vo.OnlineRateCensusVO;
import com.njcn.device.pq.pojo.vo.RStatOnlineRateVO;
import com.njcn.device.pq.pojo.vo.TerminalOnlineRateDataVO;
import com.njcn.device.pq.service.TerminalOnlineRateDataService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 终端在线率列表
 *
 * @author yzh
 * @date 2022/9/19
 */
@Slf4j
@Api(tags = "终端在线率列表")
@RestController
@RequestMapping("/terminalOnlineRateData")
@RequiredArgsConstructor
public class TerminalOnlineRateDataController extends BaseController {

    private final TerminalOnlineRateDataService terminalOnlineRateDataService;

    private final RStatOnlinerateDMapper onlineRateMapper;

    /**
     * 终端在线率列表
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOnlineRateData")
    @ApiOperation("终端在线率列表")
    @ApiImplicitParam(name = "terminalOnlineRateDataParam", value = "参数实体", required = true)
    public HttpResult<List<TerminalOnlineRateDataVO>> getOnlineRateData(@RequestBody TerminalOnlineRateDataParam terminalOnlineRateDataParam) {
        String methodDescribe = getMethodDescribe("getOnlineRateData");
        List<TerminalOnlineRateDataVO> onlineRateData = terminalOnlineRateDataService.getOnlineRateData(terminalOnlineRateDataParam,0);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onlineRateData,methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getNodeOnlineRateData")
    @ApiOperation("终端在线率节点图")
    @ApiImplicitParam(name = "terminalOnlineRateDataParam", value = "参数实体", required = true)
    public HttpResult<List<TerminalOnlineRateDataVO>> getNodeOnlineRateData(@RequestBody TerminalOnlineRateDataParam terminalOnlineRateDataParam) {
        String methodDescribe = getMethodDescribe("getOnlineRateData");
        List<TerminalOnlineRateDataVO> onlineRateData = terminalOnlineRateDataService.getOnlineRateData(terminalOnlineRateDataParam,1);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onlineRateData,methodDescribe);
    }

    @OperateInfo
    @PostMapping("/getOnlineRateDataCensus")
    @ApiOperation("终端在线率图表")
    @ApiImplicitParam(name = "onlineRateCensusParam", value = "终端在线率参数", required = true)
    public HttpResult<OnlineRateCensusVO> getOnlineRateDataCensus(@RequestBody @Validated DeviceInfoParam.CompareBusinessParam onlineRateCensusParam){
        String methodDescribe = getMethodDescribe("getOnlineRateDataCensus");
        OnlineRateCensusVO onlineRateCensusVO = terminalOnlineRateDataService.getOnlineRateDataCensus(onlineRateCensusParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onlineRateCensusVO,methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOnlineRateByDevIds")
    @ApiOperation("终端在线率（谐波专用）")
    @ApiImplicitParam(name = "param", value = "参数实体", required = true)
    public HttpResult<List<RStatOnlineRateVO>> getOnlineRateByDevIds(@RequestBody OnlineRateParam param) {
        String methodDescribe = getMethodDescribe("getOnlineRateByDevIds");
        List<RStatOnlineRateVO> onlineRateByDevIds = onlineRateMapper.getOnlineRateByDevIds(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onlineRateByDevIds,methodDescribe);
    }







}
