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.pojo.param.PulicTimeParam;
import com.njcn.device.pq.pojo.param.PulicTimeStatisParam;
import com.njcn.device.pq.pojo.vo.CommunicateStatisticsVO;
import com.njcn.device.pq.pojo.vo.CommunicateVO;
import com.njcn.device.pq.pojo.vo.DeviceOnlineDataVO;
import com.njcn.device.pq.service.CommunicateService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author denghuajun
 * @date 2022/2/28
 *
 */
@Validated
@Slf4j
@Api(tags = "运行状态管理")
@RestController
@RequestMapping("/communicate")
@RequiredArgsConstructor
public class CommunicateController extends BaseController {

    private final CommunicateService communicateService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getComFlagInfoData")
    @ApiOperation("终端通讯信息")
    @ApiImplicitParam(name = "pulicTimeParam", value = "终端通讯信息", required = true)
    public HttpResult<CommunicateVO> getComFlagInfoData(@RequestBody @Validated PulicTimeParam pulicTimeParam) {
        String methodDescribe = getMethodDescribe("getComFlagInfoData");
        CommunicateVO list = communicateService.getComFlagInfoData(pulicTimeParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRunInfoData")
    @ApiOperation("终端运行状态统计")
    @ApiImplicitParam(name = "pulicTimeStatisParam", value = "终端运行状态统计", required = true)
    public HttpResult<CommunicateStatisticsVO> getRunInfoData(@RequestBody @Validated PulicTimeStatisParam pulicTimeStatisParam) {
        String methodDescribe = getMethodDescribe("getRunInfoData");
        CommunicateStatisticsVO list = communicateService.getRunInfoData(pulicTimeStatisParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRunOnlineRateData")
    @ApiOperation("终端在线率统计")
    @ApiImplicitParam(name = "pulicTimeParam", value = "终端在线率统计", required = true)
    public HttpResult<List<DeviceOnlineDataVO>> getRunOnlineRateData(@RequestBody @Validated PulicTimeParam pulicTimeParam) {
        String methodDescribe = getMethodDescribe("getRunOnlineRateData");
        List<DeviceOnlineDataVO> list = communicateService.getRunOnlineRateData(pulicTimeParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
