package com.tofly.xrtygis.custom.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.xrtygis.custom.entity.dto.RelationshipCostDto;
import com.tofly.xrtygis.custom.entity.dto.WisdomDisplayDto;
import com.tofly.xrtygis.custom.entity.vo.WaterCruxIndexVo;
import com.tofly.xrtygis.custom.service.CustomDisplayService;
import com.tofly.xrtygis.entity.Densityconfig;
import com.tofly.xrtygis.entity.Layerfield;
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.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 陈浩
 * @date 2021-3-25
 */
@RestController
@RequestMapping("/customDisplay")
@AllArgsConstructor
@Api(tags = "自定义智慧综合展示")
public class CustomDisplayController {

    private final CustomDisplayService customDisplayService;

    /**
     * 添加动态标注
     */
    @PostMapping("/insertDynamicLogo")
    @ApiOperation("添加动态标注")
    public ResultRespone insertDynamicLogo(@RequestBody Layerfield layerfield) {
        return ResultRespone.success(customDisplayService.insertDynamicLogo(layerfield));
    }

    /**
     * 删除动态标注
     */
    @DeleteMapping("/deleteDynamicLogo")
    @ApiOperation("删除动态标注")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "动态标注id", required = true, dataType = "long")
    )
    public ResultRespone deleteDynamicLogo(Long id) {
        return ResultRespone.success(customDisplayService.deleteDynamicLogo(id));
    }

    /**
     * 查看动态标注
     */
    @GetMapping("/viewDynamicLog")
    @ApiOperation("查看动态标注")
    public ResultRespone viewDynamicLog(Page page) {
        return ResultRespone.success(customDisplayService.viewDynamicLogo(page));
    }


    /**
     * 获取多个测站指标实时指标
     */
    @PostMapping("/getSiteInfos")
    @ApiOperation("获取多个测站指标实时指标")
    public ResultRespone getSiteInfos(String stids) {
        return ResultRespone.success(customDisplayService.getSiteInfos(stids));
    }

    /**
     * 取供水趋势
     */
    @GetMapping("/waterVolumeTrend")
    @ApiOperation("综合应用-取供水趋势")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scid", value = "厂id", dataType = "long"),
            @ApiImplicitParam(name = "code", value = "0：按小时查看,1：按天查看，2：按月查看，3：同期对比", required = true, dataType = "string"),
    })
    public ResultRespone waterVolumeTrend(Page page, Long scid, String code, String startTime, String endTime) {
        return ResultRespone.success(customDisplayService.waterVolumeTrend(page, scid, code, startTime, endTime));
    }


    /**
     * 查询视频监控的分组名
     */
    @GetMapping("/getGroupName")
    @ApiOperation("查询视频监控的分组名")
    public ResultRespone getGroupName() {
        return ResultRespone.success(customDisplayService.getGroupName());
    }

    /**
     * 获取监控视频信息
     */
    @GetMapping("/getAllVideo")
    @ApiOperation("获取监控视频信息")
    public ResultRespone getAllVideo() {
        return ResultRespone.success(customDisplayService.getAllVideo());
    }

    /**
     * 模糊查询视频地址
     */
    @GetMapping("/likeVideo")
    @ApiOperation("模糊查询视频地址")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "add", value = "视频地址信息", required = true, dataType = "string")
    )
    public ResultRespone likeVideo(String add) {
        return ResultRespone.success(customDisplayService.likeVideo(add));
    }

    /**
     * 修改视频在大屏中显示
     */
    @PutMapping("/updateVideo")
    @ApiOperation("修改视频在大屏中显示")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "videoId", value = "视频监控id多个“,”分割")
    )
    public ResultRespone updateVideo(String videoId) {
        return ResultRespone.success(customDisplayService.updateVideo(videoId));
    }

    @GetMapping("/stopArea")
    @ApiOperation("营销信息-停水区域查询")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "valves", value = "阀门编号，多个，分隔", required = true, dataType = "string")
    )
    public ResultRespone waterStopArea(Page page, String valves) {
        return ResultRespone.success(customDisplayService.waterStopArea(page, valves));
    }

    /**
     * 获取客户用水量
     */
    @GetMapping("/getUseWater")
    @ApiOperation("营销信息-获取客户用水量")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "khbh", value = "客户编号", required = true, dataType = "string")
    )
    public ResultRespone getUseWater(Page page, String khbh) {
        return ResultRespone.success(customDisplayService.getUseWater(page, khbh));
    }

    @GetMapping("/getUserHistory")
    @ApiOperation("营销信息-查询客户历史用水量")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "khbh", value = "客户编号", required = true, dataType = "string")
    )
    public ResultRespone getUserHistory(Page page, String khbh, String strTime, String endTime) {
        return ResultRespone.success(customDisplayService.getUserHistroy(page, khbh, strTime, endTime));
    }

    @GetMapping("/waterMonitoring")
    @ApiOperation("营销信息-客户水量查询")
    public ResultRespone waterMonitoring(Page page) {
        return ResultRespone.success(customDisplayService.waterMonitoring(page));
    }

    /**
     * 区域查询用水量
     */
    @GetMapping("/getTableInArea")
    @ApiOperation("营销信息-区域查询用水量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lon", value = "区域各顶点的横坐标数组", required = true, dataType = "Double[]"),
            @ApiImplicitParam(name = "lat", value = "区域各顶点的纵坐标数组", required = true, dataType = "Double[]"),
            @ApiImplicitParam(name = "code", value = "0:查看全部 1：同期对比", required = true, dataType = "string"),
            @ApiImplicitParam(name = "strTime", value = "开始时间yyyyMM", dataType = "string"),
            @ApiImplicitParam(name = "endTime", value = "结束时间yyyyMM", dataType = "string"),
    })
    public ResultRespone getTableInArea(Page page, Double[] lon, Double[] lat, String strTime, String endTime, String code) {
        return ResultRespone.success(customDisplayService.getTableInArea(page, lon, lat, strTime, endTime, code));
    }

    @GetMapping("/pipeToCustomers")
    @ApiOperation("根据管线查询用户信息")
    public ResultRespone pipeToCustomers(Page page, String pipes) {
        return ResultRespone.success(customDisplayService.pipeToCustomers(page, pipes));
    }

    @GetMapping("/relationChart")
    @ApiOperation("多因子成本关系图")
    public ResultRespone relationshipCost(RelationshipCostDto dto) {
        return ResultRespone.success(customDisplayService.relationshipCost(dto));
    }

    @PostMapping("/config")
    @ApiOperation("多因子--浓度配置")
    public ResultRespone concentrationConfig(@RequestBody Densityconfig config) {
        return ResultRespone.success(customDisplayService.concentrationConfig(config));
    }

    @GetMapping("/viewConfig")
    @ApiOperation("多因子--查看浓度配置")
    public ResultRespone viewConfig() {
        return ResultRespone.success(customDisplayService.viewConfig());
    }

    @GetMapping("/viewTable")
    @ApiOperation("查询客户关联水表信息")
    public ResultRespone viewTable(Page page, String khbh, String khxm, String khdz) {
        return ResultRespone.success(customDisplayService.viewTable(page, khbh, khxm, khdz));
    }

    @GetMapping("/getCodeInfo")
    @ApiOperation("获取编码表消息")
    @ApiImplicitParam(name = "pcid", value = "pcid", required = true, dataType = "string")
    public ResultRespone getCodeInfo(String pcid) {
        return ResultRespone.success(customDisplayService.getCodeInfo(pcid));
    }

    @GetMapping("/viewWaterCruxIndex")
    @ApiOperation(value = "供水关键指标展示")
    public ResultRespone<WaterCruxIndexVo> viewWaterCruxIndex(WisdomDisplayDto wisdomDisplayDto){
        try {
//            List<String> codesWater= Arrays.asList(waterSupply.split(","));
//            List<String> codes=new ArrayList<>();
//            codesWater.forEach(a->{
//                if(!a.equals("SCADA_CHENGJIAO_JIN_TFT2") && !a.equals("SCADA_CHENGJIAO_CHU_TFT"))
//
//                    codes.add(a);
//
//            });
            return ResultRespone.success(customDisplayService.viewWaterCruxIndex(wisdomDisplayDto, null));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }
    }

    @GetMapping("/reportFormCensus")
    @ApiOperation(value = "报表统计（censusDateType:1年;2月;3日）")
    public ResultRespone reportFormCensus(Page page, WisdomDisplayDto wisdomDisplayDto){
        try {
            return ResultRespone.success(customDisplayService.reportFormCensus(page, wisdomDisplayDto));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }
    }

    @GetMapping("/getDmaStatisticalList")
    @ApiOperation(value = "获取DMA分区统计列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始时间", required = true, dataType = "string"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", required = true, dataType = "string"),
            @ApiImplicitParam(name = "dmaIds", value = "DMA分区ID（多个用,分隔）", required = true, dataType = "string"),
            @ApiImplicitParam(name = "statisticsType", value = "统计类型（0小时统计;1天统计;2月统计;3年统计）", required = true, dataType = "Integer"),
    })
    public ResultRespone getDmaStatisticalList(String startDate, String endDate, String dmaIds, Integer statisticsType){
        try {
            List<Long> dmaIdList = Arrays.stream(dmaIds.split(",")).map(Long::parseLong).collect(Collectors.toList());
            return ResultRespone.success(customDisplayService.getDmaStatisticalList(startDate, endDate, dmaIdList, statisticsType));
        }catch (Exception e){
            e.printStackTrace();
            return ResultRespone.failed(e.getMessage());
        }
    }

}
