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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.api.CodeClient;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.pojo.CustomCode;
import com.tofly.pojo.Syschildcode;
import com.tofly.watermeter.custom.entity.KhSearch;
import com.tofly.watermeter.custom.entity.quality.QualityKhInfo;
import com.tofly.watermeter.custom.entity.quality.QualityStatis;
import com.tofly.watermeter.custom.entity.webserverbean.KhInfo;
import com.tofly.watermeter.custom.service.websb.WebSBservice;
import com.tofly.watermeter.entity.*;
import com.tofly.watermeter.mapper.YhbingqyMapper;
import com.tofly.watermeter.service.*;
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.checkerframework.checker.units.qual.K;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author FlashWJL
 * @date 2021/6/15 17:08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/quality")
@Api(tags = "质检--客户查询")
public class QualityController {

    private final QfmidysxzbmEService qfmidysxzbmEService;

    private final QfkhjbxxService qfkhjbxxService;

    private final FileService fileService;
    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/nature")
    @ApiOperation(value = "用水性质")
    public ResultRespone getQfmidysxzbmEPage() {
        return ResultRespone.success(qfmidysxzbmEService.list(Wrappers.<QfmidysxzbmE>lambdaQuery()
                .eq(QfmidysxzbmE::getYxbz, "1").select(QfmidysxzbmE::getYsxzBm, QfmidysxzbmE::getYsxzMc)));
    }


    @GetMapping("/allotInfo")
    @ApiOperation(value = "质检--归集--客户分配查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collectionNumber", value = "归集编号", required = true , dataType = "String"),
            @ApiImplicitParam(name = "isWatchType", value = "分配查看类型；0：查看未分配的，1：查看已分配的", required = true , dataType = "String")
    })
    public ResultRespone<IPage<Qfkhjbxx>> allotInfo(Page<Qfkhjbxx> page, KhSearch khSearch, String collectionNumber, String isWatchType) {
        return ResultRespone.success(qfkhjbxxService.allotInfo(page , khSearch , collectionNumber , isWatchType));
    }
    @GetMapping("/collectAnalyzeOne")
    @ApiOperation(value = "质检--归集分析--第一层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "inputcontent", value = "输入框内容", required = true , dataType = "String"),
            @ApiImplicitParam(name = "collectionType", value = "归集类型", required = true , dataType = "String")
    })
    public ResultRespone<IPage<Map>> collectAnalyzeOne(Page<Gjgl> page, QualityStatis qualityStatis, HttpServletResponse response) {
        return ResultRespone.success(qfkhjbxxService.collectAnalyzeOne(page , qualityStatis , response));
    }
    @GetMapping("/collectAnalyzeTwo")
    @ApiOperation(value = "质检--归集分析--第二层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "collectionNumber", value = "归集编号", required = true , dataType = "String")
    })
    public ResultRespone<List<Map>> collectAnalyzeTwo(String startDate , String endDate , String collectionNumber , HttpServletResponse response) {
        return ResultRespone.success(qfkhjbxxService.collectAnalyzeTwo(startDate , endDate , collectionNumber , response));
    }
    @GetMapping("/collectAnalyzeThree")
    @ApiOperation(value = "质检--归集分析--第三层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束月份（202201）", required = true , dataType = "String"),
            @ApiImplicitParam(name = "collectionNumber", value = "归集编号", required = true , dataType = "String")
    })
    public ResultRespone<IPage<Map>> collectAnalyzeThree(Page<Gjglxq> page,String startDate , String endDate , String collectionNumber , HttpServletResponse response) {
        return ResultRespone.success(qfkhjbxxService.collectAnalyzeThree(page , startDate , endDate , collectionNumber , response));
    }

    @GetMapping("/test111")
    @ApiOperation(value = "测试111")
    public ResultRespone test111(String strTime,String eTime) {
        fileService.s(strTime,eTime);
        return ResultRespone.success();
    }
}
