package com.njcn.device.pq.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.common.utils.LogUtil;
import com.njcn.device.line.service.LineService;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.param.PqsParam;
import com.njcn.device.pq.pojo.po.TopMsgPO;
import com.njcn.device.pq.pojo.vo.*;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.RequestUtil;
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 denghuajun
 * @version 1.0.0
 * @date 2022年05月11日 15:24
 */
@Slf4j
@Api(tags = "运维中心")
@RestController
@RequestMapping("/operation")
@RequiredArgsConstructor
public class OperationContrController extends BaseController {

    private final LineService lineService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineDistribution")
    @ApiOperation("获取监测点分布")
    @ApiImplicitParam(name = "deviceInfoParam", value = "实体", required = true)
    public HttpResult<List<LineDistributionVO>> getLineDistribution(@RequestBody DeviceInfoParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getLineDistribution");
        DeviceInfoParam param = new DeviceInfoParam(RequestUtil.getDeptIndex(),null);
        deviceInfoParam.setDeptIndex(param.getDeptIndex());
        LogUtil.njcnDebug(log, "{}，参数集合：{}", methodDescribe, deviceInfoParam);
        List<LineDistributionVO> result = lineService.getLineDistribution(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineStatisticsDetail")
    @ApiOperation("获取监测点统计")
    @ApiImplicitParam(name = "deviceInfoParam", value = "实体", required = true)
    public HttpResult<List<LineStatisticsDetailVO>> getLineStatisticsDetail(@RequestBody DeviceInfoParam.BusinessParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getLineStatisticsDetail");
        LogUtil.njcnDebug(log, "{}，参数集合：{}", methodDescribe, deviceInfoParam);
        List<LineStatisticsDetailVO> result = lineService.getLineStatisticsDetail(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineStatisticsTable")
    @ApiOperation("获取监测点表格统计")
    @ApiImplicitParam(name = "deviceInfoParam", value = "实体", required = true)
    public HttpResult<List<LineStatisticsTableVO>> getLineStatisticsTable(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getLineStatisticsTable");
        LogUtil.njcnDebug(log, "{}，参数集合：{}", methodDescribe, deviceInfoParam);
        List<LineStatisticsTableVO> result = lineService.getLineStatisticsTable(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getNewDeviceRunStatistics")
    @ApiOperation("获取终端运行统计_新")
    @ApiImplicitParam(name = "deviceInfoParam", value = "实体", required = true)
    public HttpResult<Page<LineFlowMealDetailVO>> getNewDeviceRunStatistics(@RequestBody PqsParam deviceInfoParam)  {
        String methodDescribe = getMethodDescribe("getDeviceRunStatistics");
        if (deviceInfoParam.getDeptIndex() == null) {
            DeviceInfoParam param = new DeviceInfoParam(RequestUtil.getDeptIndex(),null);
            deviceInfoParam.setDeptIndex(param.getDeptIndex());
        }
        LogUtil.njcnDebug(log, "{}，参数集合：{}", methodDescribe, deviceInfoParam);
        Page<LineFlowMealDetailVO> result = lineService.getNewDeviceRunStatistics(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDailyDeviceAbnormalStatistics")
    @ApiOperation("获取终端异常统计")
    @ApiImplicitParam(name = "param", value = "实体", required = true)
    public HttpResult<Page<TopMsgPO>> dailyDeviceAbnormalStatistics(@RequestBody PqsParam param) {
        String methodDescribe = getMethodDescribe("dailyDeviceAbnormalStatistics");
        Page<TopMsgPO> result = lineService.dailyDeviceAbnormalStatistics(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDailyDeviceAbnormal")
    @ApiOperation("获取终端异常详情列表")
    @ApiImplicitParam(name = "conditionBusinessParam", value = "实体", required = true)
    public HttpResult<List<TopMsgPO>> dailyDeviceAbnormal(@RequestBody DeviceInfoParam.BusinessParam conditionBusinessParam) {
        String methodDescribe = getMethodDescribe("dailyDeviceAbnormal");
        List<TopMsgPO> result = lineService.dailyDeviceAbnormal(conditionBusinessParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}
