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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.entity.meterRead.ReadSearch;
import com.tofly.watermeter.custom.entity.meterRead.ReadStatisticsDetail;
import com.tofly.watermeter.custom.entity.meterRead.readstatic.AllocationSta;
import com.tofly.watermeter.custom.entity.meterRead.readstatic.ReadOverTime;
import com.tofly.watermeter.custom.entity.meterRead.readstatic.ReadOverTimeDetail;
import com.tofly.watermeter.custom.service.ReadStatisticService;
import com.tofly.watermeter.entity.Readmeterhis;
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.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author FlashWJL
 * @date 2021/6/12 16:49
 */
@RestController
@AllArgsConstructor
@RequestMapping("/statistics")
@Api(tags = "抄表--抄表统计")
public class ReadStatisticController {

    private final ReadStatisticService readStatisticService ;

    @GetMapping("/allocationClloect")
    @ApiOperation(value = "抄表分配统计--汇总数据")
    public ResultRespone<List<AllocationSta>> allocationClloect(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.allocationClloect(search , response));
    }

    @GetMapping("/allocationInfo")
    @ApiOperation(value = "抄表分配统计--详情数据")
    public ResultRespone allocationInfo( Page page , ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.allocationInfo(page , search , response));
    }

    @GetMapping("/readPercent")
    @ApiOperation(value = "抄表率统计--(月)抄表区域")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sspq", value = "片区(区域)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cwyf", value = "月份", required = true, dataType = "String")
    })
    public ResultRespone<List<Map>> getReadPercent(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadPercent(search , response));
    }

    @GetMapping("/readPercentByQy")
    @ApiOperation(value = "抄表率统计--(月)抄表区域段")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sspq", value = "区域", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cwyf", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbb", value = "抄表段", required = true, dataType = "String")
    })
    public ResultRespone<List<Map>> getReadPercentByQy(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadPercentByQy( search , response));
    }

    @GetMapping("/readPercentByCbry")
    @ApiOperation(value = "抄表率统计--(月)抄表人员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cwyf", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbryName", value = "抄表人员", required = true, dataType = "String")
    })
    public ResultRespone<List<Map>> getReadPercentByCbry(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadPercentByCbry(search , response));
    }


    @GetMapping("/getReadPercentDay")
    @ApiOperation(value = "抄表率统计--(日)抄表率汇总")
    public ResultRespone<List<Map>> getReadPercentDay(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadPercentDay(search , response));
    }

    @GetMapping("/getReadDayInfo")
    @ApiOperation(value = "抄表详情数据(抄表用户列表信息)")
    public ResultRespone<IPage<Readmeterhis>> getReadDayInfo(Page page, ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadDayInfo(page, search , response));
    }

    @GetMapping("/getClient")
    @ApiOperation(value = "客户抄表查询")
    public ResultRespone<IPage<Readmeterhis>> getClient(Page page, ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getClient(page, search , response));
    }


    @GetMapping("/readTimeDeatil")
    @ApiOperation(value = "抄表时间统计--抄表时间")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbb", value = "抄表本(区域段)(必传)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "开始时间", required = true, dataType = "String")
    })
    public ResultRespone<List<Map>> getReadTimeDeatil(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadTimeDeatil(search , response));
    }

    @GetMapping("/readQuery")
    @ApiOperation(value = "抄表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbb", value = "抄表本(区域段)(必传)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员", required = true, dataType = "String"),
            @ApiImplicitParam(name = "state", value = "抄表状态：'0','未抄表','1','已抄表'", required = true, dataType = "String"),
            @ApiImplicitParam(name = "auditState", value = "审核状态：0：未审核；1：已审核", required = true, dataType = "String")
    })
    public ResultRespone<IPage<ReadStatisticsDetail>> getReadQuery(Page page, ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getReadQuery(page , search , response));
    }

    @GetMapping("/getOvertimeCollect")
    @ApiOperation(value = "抄表超时统计--汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbb", value = "区域段", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbryName", value = "抄表人员，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "开始时间", required = true, dataType = "String")
    })
    public ResultRespone<List<ReadOverTime>> getOvertimeCollect(ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(readStatisticService.getOvertimeCollect(search , response));
    }

    @GetMapping("/getOvertimeCollectDeatil")
    @ApiOperation(value = "抄表超时统计--详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbry", value = "抄表人员", required = true, dataType = "Long")
    })
    public ResultRespone<List<ReadOverTimeDetail>> getOvertimeCollectDeatil(ReadSearch search , HttpServletResponse response , Float overTimeRatio) {
        return ResultRespone.success(readStatisticService.getOvertimeCollectDeatil(search , response , overTimeRatio));
    }

    @GetMapping("/getTimeAbnormalOne")
    @ApiOperation(value = "抄表超时异常统计--第一层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "overDiffTime", value = "间隔时长（分钟）", required = true, dataType = "int"),
            @ApiImplicitParam(name = "yearMonth", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员，多个逗号隔开", required = true, dataType = "String"),
    })
    public ResultRespone<List<ReadOverTime>> getTimeAbnormalOne(String cbry ,String yearMonth, Integer overDiffTime, HttpServletResponse response , String isGeneral) {
        return ResultRespone.success(readStatisticService.getTimeAbnormalCollect(cbry , yearMonth , overDiffTime, response,isGeneral));
    }
    @GetMapping("/getTimeAbnormalTwo")
    @ApiOperation(value = "抄表超时异常统计--第二层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "overDiffTime", value = "间隔时长（分钟）", required = true, dataType = "int"),
            @ApiImplicitParam(name = "yearMonth;", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员，多个逗号隔开", required = true, dataType = "String")
    })
    public ResultRespone<IPage<ReadOverTimeDetail>> getTimeAbnormalTwo(Page page , String cbry ,String yearMonth, Integer overDiffTime, HttpServletResponse response , String isGeneral) {
        return ResultRespone.success(readStatisticService.getTimeAbnormalTwo(page , cbry , yearMonth , overDiffTime, response,isGeneral));
    }


}
