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.IQueryStatisticsService;
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.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询统计控制器
 */
@RestController
@AllArgsConstructor
@RequestMapping("/query")
@Api(value = "查询统计",tags = "查询统计")
public class QueryStatisticsController {

    private final IQueryStatisticsService service;

    /**
     * 事件查询
     * @param startDate 查询k开始时间 ‘年-月’
     * @param endDate 查询截止时间 ‘年-月’
     * @return
     */
    @GetMapping("/event" )
    @ApiOperation(value = "事件查询")
    public ResultRespone getEventQuery(Page page,
                                       @RequestParam("startDate") String startDate,
                                       @RequestParam("endDate") String endDate,
                                       @RequestParam(value = "yhbh",required = false) String yhbh,
                                       @RequestParam(value = "yhxm",required = false) String yhxm) {
        return ResultRespone.success(service.getEventQuery(page,startDate,endDate,yhbh,yhxm));
    }

    /**
     * 事件查询-点击详情
     * @param quertType 查询类型
     * @param startDate 查询k开始时间 ‘年-月’
     * @param endDate 查询截止时间 ‘年-月’
     * @param khbh 客户编号
     * @return
     */
    @GetMapping("/event-detail" )
    @ApiOperation(value = "事件查询-点击详情")
    public ResultRespone getEventQueryDetail(Page page,
                                             @RequestParam("quertType")String quertType,
                                             @RequestParam("startDate") String startDate,
                                             @RequestParam("endDate") String endDate,
                                             @RequestParam("khbh") String khbh) {
        return ResultRespone.success(service.getEventQueryDetail(page,quertType,startDate,endDate,khbh));
    }

    /**
     * 户数查询
     * @param map 查询条件对象
     * @return
     */
    @PostMapping("/households" )
    @ApiOperation(value = "户数查询")
    @ApiImplicitParam(name = "map",value = "查询条件:qybm-抄表区域编码;qydbm-抄表区域段编码;" +
            "sbkj-水表口径，编码;ysxz-用水性质，编码;sbcj-水表厂家，编码;",type = "Map",required = true)
    public ResultRespone getHouseholdsQuery(@RequestBody Map<String,List<HashMap<String,String>>> map) {
        if (map.get("queryData") != null) {
            List<HashMap<String,String>> queryData = map.get("queryData");
            return ResultRespone.success(service.getHouseholdsQuery(queryData));
        }
        return ResultRespone.failed();
    }

    /**
     * 户数查询-点击详情
     * @param page 分页条件
     * @param query 查询条件
     * @return
     */
    @GetMapping("/households-detail" )
    @ApiOperation(value = "户数查询-点击详情")
    public ResultRespone getHouseholdsDetail(Page page,
                                             @RequestParam("query") String query) {
        return ResultRespone.success(service.getHouseholdsDetail(page,query));
    }

}
