package com.njcn.cloud.controller.statistics;


import com.njcn.cloud.pojo.vo.StatisticsData;
import com.njcn.cloud.pojo.vo.StatisticsDetail;
import com.njcn.cloud.service.IAppStatisticsService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 统计消息 前端控制器
 * </p>
 *
 * @author wr
 * @since 2024-01-03
 */
@RestController
@RequestMapping("/appStatistics")
@Api(tags = "统计数据")
@RequiredArgsConstructor
public class StatisticsController extends BaseController {

    private final IAppStatisticsService appStatisticsService;

    /**
     * @param lineIndex 监测点ID
     * @param page      当前页数
     * @param num       每页数量
     * @description: 统计数据
     * @author wr
     */
    @PostMapping("/statistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineIndex", value = "监测点ID", required = true, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "查询的开始时间", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "查询的结束时间", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "num", value = "每页数量", required = true, paramType = "query")
    })
    @ApiOperation(value = "统计数据", notes = "统计数据")
    public HttpResult<List<StatisticsData>> statistics(String lineIndex, String startTime, String endTime, int page, int num, HttpServletRequest request) {
        String methodDescribe = getMethodDescribe("statistics");
        List<StatisticsData> statisticsData = appStatisticsService.queryData(lineIndex, startTime, endTime, page, num);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, statisticsData, methodDescribe);
    }

    /**
     * @param lineIndex 监测点ID
     * @param timeID    统计时间
     * @description: 统计数据详情
     * @author wr
     */
    @PostMapping("/statisticsDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineIndex", value = "监测点ID", required = true, paramType = "query"),
            @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query")
    })
    @ApiOperation(value = "统计数据详情", notes = "统计数据详情")
    public HttpResult<StatisticsDetail> statisticsDetail(String lineIndex, String timeID) {
        String methodDescribe = getMethodDescribe("statistics");
        StatisticsDetail statisticsDetail = appStatisticsService.queryDetail(lineIndex, timeID);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, statisticsDetail, methodDescribe);
    }
}

