package com.tofly.xrtygis.custom.controller.dma;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.xrtygis.custom.entity.dma.CostomWaterDiff;
import com.tofly.xrtygis.custom.util.DateTimeUtil;
import com.tofly.xrtygis.service.DmanightflowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @author FlashWJL
 * @date 2021/5/25 20:07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/night")
@Api(tags = "分区计量--夜间最小流量分析")
public class CustomNightController {

    private final DmanightflowService dmanightflowService;


    @GetMapping("/minFLow")
    @ApiOperation(value = "夜间最小流量数据汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableId",value = "仪表ID，逗号隔开",readOnly = true,dataType = "string"),
            @ApiImplicitParam(name = "startTime",value = "起始月份；如：2021-05-01",readOnly = true,dataType = "string"),
            @ApiImplicitParam(name = "endTime",value = "结束月份；如：2021-06-01",readOnly = true,dataType = "string"),
            @ApiImplicitParam(name = "flag",value = "查询标识；1：查询汇总正常数/异常；2：查询数据详情",readOnly = true,dataType = "string"),
    })
    public ResultRespone getMinFlow(HttpServletResponse response , CostomWaterDiff diff , Page page){
        String tableIds = diff.getTableId();
        String startTime = diff.getStartTime();
        String endTime = diff.getEndTime();
        String flag = diff.getFlag();
        String templateFlag = diff.getTemplateFlag();
        return ResultRespone.success(dmanightflowService.getMinFlow(response , tableIds , startTime , endTime , flag , templateFlag , page));
    }

    @GetMapping("/getTableTree")
    @ApiOperation(value = "获取区域观察表")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "isFlow",value = " 如果1就只查询夜间最小流量，如果2就只查询采集压力的 ",readOnly = true,dataType = "string")
    )
    public ResultRespone getTableTree(String isFlow){

        return ResultRespone.success(dmanightflowService.getTableTree(isFlow));
    }

    @ApiOperation(value = "当前 2:00-4:00 夜间最小流量分析")
    @PostMapping("/nightMinimumFlowAnalysis")
    public ResultRespone nightMinimumFlowAnalysis(String date) {
        Date time = DateTimeUtil.convertLDTToDate(DateTimeUtil.fromString2LocalDateTime(date, DateTimeUtil.FULL_FORMAT));
        return ResultRespone.success(dmanightflowService.nightMinimumFlowAnalysis(time));
    }



}
