package com.njcn.device.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.common.utils.LogUtil;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.*;
import com.njcn.device.service.LineService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
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
 * @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 @Validated DeviceInfoParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getLineDistribution");
        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 @Validated 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("/getLineRunStatistics")
    @ApiOperation("获取监测点运行统计")
    @ApiImplicitParam(name = "deviceInfoParam", value = "实体", required = true)
    public HttpResult<List<LineFlowMealDetailVO>> getLineRunStatistics(@RequestBody @Validated DeviceInfoParam.BusinessParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getLineRunStatistics");
        LogUtil.njcnDebug(log, "{}，参数集合：{}", methodDescribe, deviceInfoParam);
        List<LineFlowMealDetailVO> result = lineService.getLineRunStatistics(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineStaticsView")
    @ApiOperation("获取详细的监测点统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "起始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(name = "lineId", value = "监测点id", required = true)
    })
    public HttpResult<LineStaticsViewVO> getLineStaticsView(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("lineId") String lineId) {
        String methodDescribe = getMethodDescribe("getLineStaticsView");
        LineStaticsViewVO result = lineService.getLineStaticsView(startTime, endTime, lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}
