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

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.readstatic.AccuracyCollect;
import com.tofly.watermeter.custom.entity.meterRead.readstatic.AuditMap;
import com.tofly.watermeter.custom.entity.quality.*;
import com.tofly.watermeter.custom.service.QualityStatisService;
import com.tofly.watermeter.entity.Cbqydwater;
import com.tofly.watermeter.entity.Qfkhjbxx;
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.PostMapping;
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/12/9 9:39
 */
@RestController
@AllArgsConstructor
@RequestMapping("/qualitysta")
@Api(tags = "抄表--质检统计分析")
public class QualityStatisController {

    private final QualityStatisService qualityStatisService;

    @GetMapping("/inspectRatio")
    @ApiOperation(value = "抄表抽查--修改抽查比例")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "ratio", value = "比例", required = true, dataType = "String")
    })
    public ResultRespone<Boolean> inspectRatio(String ratio) {
        return ResultRespone.success(qualityStatisService.inspectRatio(ratio));
    }

    @GetMapping("/inspect")
    @ApiOperation(value = "抄表抽查--当天核查情况汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期 格式：yyyy-MM-dd 00:00:00", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 格式：yyyy-MM-dd 23:59:59", required = true, dataType = "Date")
    })
    public ResultRespone<List<Map<String, Object>>> inspectCollect(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.inspectCollect(qualityStatis , response));
    }

    @GetMapping("/inspectDetail")
    @ApiOperation(value = "抄表抽查--详情数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbqyd", value = "区域段编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期 格式：yyyy-MM-dd HH:mm:ss", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 格式：yyyy-MM-dd HH:mm:ss", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "queryType", value = "详情数据查询类型；0：异常客户数；1：应抄表总数；2：待核客户数；3：已核客户数；4：转质检户数；", required = true, dataType = "String"),
            @ApiImplicitParam(name = "queryCount", value = "数目", required = true, dataType = "Integer")
    })
    public ResultRespone<IPage<Readmeterhis>> inspectCollectDeatils(Page page , QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.inspectCollectDeatils(page ,qualityStatis , response));
    }

    @GetMapping("/analyze")
    @ApiOperation(value = "水量分析--抄表区域汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期 格式：yyyy-MM-dd 00:00:00", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 格式：yyyy-MM-dd 23:59:59", required = true, dataType = "Date")
    })
    public ResultRespone<List<QualityResult>> analyzeCollect(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.analyzeCollect(qualityStatis , response));
    }

    @GetMapping("/analyzeAbnromal")
    @ApiOperation(value = "水量分析--异常类型页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期 格式：yyyy-MM-dd 00:00:00", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 格式：yyyy-MM-dd 23:59:59", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "queryType", value = "0：异常客户数 1：应抄表总数；2：待核客户数；3：已核客户数；4：转质检户数", required = true, dataType = "String"),
    })
    public ResultRespone<List<QualityResult>> analyzeAbnromal(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.analyzeAbnromal(qualityStatis , response));
    }

    @GetMapping("/analyzeDeatils")
    @ApiOperation(value = "水量分析--详情数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "cbqyd", value = "区域段编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "abnormal", value = "异常类型原因，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期 格式：yyyy-MM-dd HH:mm:ss", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 格式：yyyy-MM-dd HH:mm:ss", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "queryType", value = "详情数据查询类型；0：异常客户数；1：应抄表总数；2：待核客户数；3：已核客户数；4：转质检户数；", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "queryCount", value = "数目", required = true, dataType = "Integer")
    })
    public ResultRespone<IPage<Readmeterhis>> analyzeCollectDetails(Page page , QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.analyzeCollectDetails(page , qualityStatis , response));
    }

    @GetMapping("/trendOne")
    @ApiOperation(value = "水量趋势--第一个页面")
    public ResultRespone<List<Cbqydwater>> trendCollectOne(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.trendCollectOne(qualityStatis , response));
    }
    @GetMapping("/trendTwo")
    @ApiOperation(value = "水量趋势--第二个页面")
    public ResultRespone<List<Cbqydwater>> trendCollectTwo(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.trendCollectTwo(qualityStatis , response));
    }
    @GetMapping("/trendThree")
    @ApiOperation(value = "水量趋势--第三个页面")
    public ResultRespone trendCollectThree(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.trendCollectThree(qualityStatis , response));
    }
    @GetMapping("/trendFour")
    @ApiOperation(value = "水量趋势--第四个页面")
    public ResultRespone<IPage<Object>> trendCollectFour(Page page, QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.trendCollectFour(page , qualityStatis , response));
    }

    @GetMapping("/queryCollect")
    @ApiOperation(value = "水量查询--用户累计水量汇总")
    public ResultRespone<IPage<Map>> queryCollect(Page page, QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.queryCollect(page , qualityStatis , response));
    }

    @GetMapping("/queryCollectDeatil")
    @ApiOperation(value = "水量查询--用户累计水量详情表")
    public ResultRespone queryCollectDeatil(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.queryCollectDeatil(qualityStatis , response));
    }

    @GetMapping("/fluctuateCollect")
    @ApiOperation(value = "水量波动--汇总表")
    public ResultRespone<Map<String , List<QualityFluctuate>>> fluctuateCollect(QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.fluctuateCollect(qualityStatis , response));
    }

    @GetMapping("/fluctuateCollectDeatil")
    @ApiOperation(value = "水量波动--详情列表")
    public ResultRespone<IPage<Readmeterhis>> fluctuateCollectDeatil(Page page , QualityStatis qualityStatis , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.fluctuateCollectDeatil(page , qualityStatis , response));
    }

    @GetMapping("/accuracyCollect")
    @ApiOperation(value = "抄表准确率--汇总数据")
    public ResultRespone<List<AccuracyCollect>> accuracyCollect(QualityStatis qualityStatis , HttpServletResponse response) {
        return qualityStatisService.accuracyCollect(qualityStatis , response);
    }

    @GetMapping("/accuracyCollectDeatil")
    @ApiOperation(value = "抄表准确率--详情列表")
    public ResultRespone<IPage<AuditMap>> accuracyCollectDeatil(Page page, ReadSearch search , HttpServletResponse response) {
        return qualityStatisService.accuracyCollectDeatil(page , search , response);
    }

    @GetMapping("/eventCollect")
    @ApiOperation(value = "事件查询--汇总数据")
    public ResultRespone<IPage<QualityEvent>> eventCollect(Page page , ReadSearch search , HttpServletResponse response) {
        return qualityStatisService.eventCollect(page , search , response);
    }

    @GetMapping("/eventCollectInfo")
    @ApiOperation(value = "事件查询--用户所有事件信息")
    public ResultRespone<List<QualityEventInfo>> eventCollectInfo(ReadSearch search , HttpServletResponse response) {
        return qualityStatisService.eventCollectInfo(search , response);
    }

    @GetMapping("/eventById")
    @ApiOperation(value = "事件查询--点击事件查看详情展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventid", value = "事件唯一标识", required = true, dataType = "String"),
            @ApiImplicitParam(name = "eventtype", value = "事件类型；1：抄表事件，2：业务工单事件，3：质检事件，4：表务事件", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "qwxid", value = "抢维修工单ID，有转抢维修才展示", required = true, dataType = "Date")
    })
    public ResultRespone<Object> eventById(String eventid , String  eventtype , String qwxid , HttpServletResponse response) {
        return qualityStatisService.eventById(eventid , eventtype , qwxid , response);
    }

    @PostMapping("/householdsCollect")
    @ApiOperation(value = "户数查询--数量查询汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbqyd", value = "抄表区域段编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbkj", value = "水表口径编码，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "ysxz", value = "用水性质，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbcj", value = "水表厂家，多个逗号隔开", required = true, dataType = "String")
    })
    public ResultRespone<List<QualityHouse>> householdsCollect(String jsonString) {
        return ResultRespone.success(qualityStatisService.householdsCollect(jsonString));
    }

    @GetMapping("/householdsCollectDeatil")
    @ApiOperation(value = "户数查询--客户详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cbqy", value = "抄表区域编码，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbqyd", value = "抄表区域段编码v", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbkj", value = "水表口径编码，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "ysxz", value = "用水性质，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbcj", value = "水表厂家，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "inputcontent", value = "水表厂家，多个逗号隔开", required = true, dataType = "String")
    })
    public ResultRespone<IPage<Qfkhjbxx>> householdsCollectDeatil(Page<Qfkhjbxx> page,String cbqy , String cbqyd , String sbkj , String ysxz , String sbcj , String inputcontent) {
        return ResultRespone.success(qualityStatisService.householdsCollectDeatil(page , cbqy , cbqyd , sbkj , ysxz , sbcj , inputcontent));
    }

    @GetMapping("/cardDataAnalyeCollect")
    @ApiOperation(value = "卡表数据分析--汇总数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始时间", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", required = true, dataType = "Date")
    })
    public ResultRespone cardDataAnalyeCollect(ReadSearch search) {
        return ResultRespone.success(qualityStatisService.cardDataAnalyeCollect(search));
    }


    @GetMapping("/cardUpdateCollect")
    @ApiOperation(value = "卡表修改统计--汇总数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yearMonth", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "isGeneral", value = "卡表、机械表", required = true, dataType = "String")
    })
    public ResultRespone<List<AccuracyCollect>> cardUpdateCollect(String isGeneral , String yearMonth , String cbry) {
        return ResultRespone.success(qualityStatisService.cardUpdateCollect(isGeneral , yearMonth , cbry));
    }

    @GetMapping("/cardUpdateTwo")
    @ApiOperation(value = "卡表修改统计--第二层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yearMonth", value = "月份", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员，多个逗号隔开", required = true, dataType = "String"),
            @ApiImplicitParam(name = "isGeneral", value = "卡表、机械表", required = true, dataType = "String")
    })
    public ResultRespone<IPage<AuditMap>> cardUpdateTwo(Page<Readmeterhis> page ,  ReadSearch search , HttpServletResponse response) {
        return ResultRespone.success(qualityStatisService.cardUpdateTwo(page , search , response));
    }


}
