package com.tofly.watermeter.custom.controller.statisticanalysis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.service.statisticanalysis.IWaterStatisticsService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 水量统计控制器
 */
@RestController
@AllArgsConstructor
@RequestMapping("/water")
@Api(value = "水量统计",tags = "水量统计")
public class WaterStatisticsController {

    private final IWaterStatisticsService service;

    /**
     * 水量分析
     */
    @GetMapping("/analysis" )
    @ApiOperation(value = "水量分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbpq",value = "抄表片区 多个片区','隔开 ",type = "String",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询时间，年-月（2020年-03月）",type = "String",required = true)
    })
    public ResultRespone getWaterAnalysis(@RequestParam("cbpq") String cbpq,
                                          @RequestParam("queryDate") String queryDate) {
        return ResultRespone.success(service.getWaterAnalysis(cbpq,queryDate));
    }

    /**
     * 水量分析-点击详情
     */
    @GetMapping("/analysis-detail" )
    @ApiOperation(value = "水量分析-点击详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbpq",value = "抄表片区 多个片区','隔开 ",type = "String",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询时间，年-月（2020年-03月）",type = "String",required = true),
            @ApiImplicitParam(name = "queryType",value = "正常户数-zc，异常户数-yc",type = "String",required = true)
    })
    public ResultRespone getWaterAnalysisDetail(Page page,
                                                @RequestParam("cbpq") String cbpq,
                                                @RequestParam("queryDate") String queryDate,
                                                @RequestParam("queryType") String queryType) {
        return ResultRespone.success(service.getWaterAnalysisDetail(page,cbpq,queryDate,queryType));
    }

    @GetMapping("/getQuantityHandler" )
    @ApiOperation(value = "执行同步数据，同步用户用水数据普表、远传表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "endDate",value = "结束时间yyyyMMdd",type = "String",required = false),
            @ApiImplicitParam(name = "begDate",value = "开始时间yyyyMMdd",type = "String",required = false)
    })
    public ResultRespone getQuantityHandler(String begDate,String endDate){
        service.synchroWaterQuantityData(begDate,endDate);
        return ResultRespone.success();
    }

    /**
     * 水量分析-用户详情-同、环比水量查询
     */
    @GetMapping("/analysis-detail-getYOM" )
    @ApiOperation(value = "水量分析-用户详情-同、环比水量查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "khbh",value = "客户编号 ",type = "String",required = true),
            @ApiImplicitParam(name = "startDate",value = "查询开始时间，年-月（2020年-03月）",type = "String",required = true),
            @ApiImplicitParam(name = "endDate",value = "查询结束时间，年-月（2021年-03月）,这里默认传的是水量分析选择的年月",type = "String",required = true),
            @ApiImplicitParam(name = "queryType",value = "同比-tbcx，环比-hbcx",type = "String",required = true)
    })
    public ResultRespone getWaterAnalysisDetailAndYOM(@RequestParam("khbh") String khbh,
                                                      @RequestParam("startDate") String startDate,
                                                      @RequestParam("endDate") String endDate,
                                                      @RequestParam("queryType") String queryType) {
        return ResultRespone.success(service.getWaterAnalysisDetailAndYOM(khbh,startDate,endDate,queryType));
    }

    /**
     * 水量趋势
     * @param cbpq 抄表片区 多个片区','隔开
     * @param startDate 查询开始时间
     * @param endDate 查询结束时间
     * @return
     */
    @GetMapping("/trend" )
    @ApiOperation(value = "水量趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbpq",value = "抄表片区 多个片区','隔开",type = "String",required = true),
            @ApiImplicitParam(name = "startDate",value = "查询开始时间，年-月（2020年-03月）",type = "String",required = true),
            @ApiImplicitParam(name = "endDate",value = "查询结束时间，年-月（2020年-03月）",type = "String",required = true)
    })
    public ResultRespone getWaterTrend(@RequestParam("cbpq") String cbpq,
                                       @RequestParam("startDate") String startDate,
                                       @RequestParam("endDate") String endDate) {
        return ResultRespone.success(service.getWaterTrend(cbpq,startDate,endDate));
    }

    /**
     * 水量趋势-点击区域展示区域段用水
     * @param cbpq 抄表片区
     * @param queryDate 查询时间
     * @return
     */
    @GetMapping("/trend-Detail" )
    @ApiOperation(value = "水量趋势-点击区域展示区域段用水")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbpq",value = "抄表片区",type = "String",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询时间，年-月（2020年-03月）",type = "String",required = true)
    })
    public ResultRespone getWaterTrendDetail(@RequestParam("cbpq") String cbpq,
                                             @RequestParam("queryDate") String queryDate) {
        return ResultRespone.success(service.getWaterTrendDetail(cbpq,queryDate));
    }

    /**
     * 水量趋势-用水详情
     * @param cbqyd 抄表区域段
     * @param queryDate 查询时间
     * @return
     */
    @GetMapping("/trend-water-Detail" )
    @ApiOperation(value = "水量趋势-用水详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbpq",value = "抄表片区",type = "String",required = true),
            @ApiImplicitParam(name = "cbqyd",value = "抄表区域段",type = "String",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询时间，年-月（2020年-03月）",type = "String",required = true)
    })
    public ResultRespone getWaterTrendWaterDetail(Page page,
                                                  @RequestParam("cbpq") String cbpq,
                                                  @RequestParam("cbqyd") String cbqyd,
                                                  @RequestParam("queryDate") String queryDate) {
        return ResultRespone.success(service.getWaterTrendWaterDetail(page,cbpq,cbqyd,queryDate));
    }

    /**
     * 水量波动
     */
    @GetMapping("/fluctuation" )
    @ApiOperation(value = "水量波动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryType",value = "查询类型，抄表片区-cbpq，口径-sbkj，用水性质-ysxz",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询年月",required = true),
            @ApiImplicitParam(name = "numberParam",value = "查询个数参数",required = false)
    })
    public ResultRespone getWaterFluctuation(@RequestParam("queryType") String queryType,
                                             @RequestParam("queryDate") String queryDate,
                                             @RequestParam(value = "numberParam",required = false) String numberParam) {
        return ResultRespone.success(service.getWaterFluctuation(queryType,queryDate,numberParam));
    }

    /**
     * 水量波动-点击详情
     */
    @GetMapping("/fluctuation-detail" )
    @ApiOperation(value = "水量波动-点击详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "khbh",value = "客户编号,多个以','分隔 ",required = true),
            @ApiImplicitParam(name = "queryDate",value = "查询年月",required = true),
    })
    public ResultRespone getWaterFluctuation(@RequestParam("khbh") String khbh,
                                             @RequestParam("queryDate") String queryDate) {
        return ResultRespone.success(service.getWaterFluctuationDetail(khbh,queryDate));
    }

    /**
     * 水量查询
     * @param yhbh 用户编号
     * @param queryYear 查询年份，多年以','隔开
     * @return
     */
    @GetMapping("/inquire" )
    @ApiOperation(value = "水量查询")
    public ResultRespone getWaterInquire(Page page,
                                         @RequestParam("yhbh") String yhbh,
                                         @RequestParam("queryYear") String queryYear) {
        return ResultRespone.success(service.getWaterInquire(page,yhbh,queryYear));
    }

}
