package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.domain.R;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.security.utils.SecurityUtils;
import cn.cecep.talroad.feign.BaseRegionService;
import cn.cecep.talroad.service.IAmProblemFiService;
import cn.cecep.talroad.service.KeyEmittingIndustryService;
import cn.cecep.talroad.vo.*;
import cn.cecep.talroad.vo.homepage.HpmEnvironmentOverviewVo;
import cn.cecep.talroad.vo.homepage.HpmMeriRatingOverviewVo;
import cn.cecep.talroad.vo.query.AmProblemFiQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "固定源分析-重点排放行业分析")
@RestController
@RequestMapping("/KeyEmittingIndustry")
public class KeyEmittingIndustryController {

    @Autowired
    private KeyEmittingIndustryService keyEmittingIndustryService;

    @Autowired
    private IAmProblemFiService amProblemFiService;

    @Autowired
    @Qualifier("baseRegionService")
    private BaseRegionService baseRegionService;

    @ApiOperation(value = "行业企业总览")
    @GetMapping("/industryCompanyOverview")
    @ApiImplicitParam(name = "industry", value = "行业", dataType = "String")
    public AjaxResults<IndustryCompanyOverviewVo> industryCompanyOverview(String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectIndustryCompanyOverview(industry,regionCode));
    }


    @ApiOperation(value = "绩效评级总览")
    @GetMapping("/meritRatingOverview")
    @ApiImplicitParam(name = "industry", value = "行业", dataType = "String")
    public AjaxResults<HpmMeriRatingOverviewVo> meritRatingOverview(String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        HpmMeriRatingOverviewVo hrov = keyEmittingIndustryService.selectMeritRatingOverview(industry,regionCode);
        return AjaxResults.success(hrov);
    }

    @ApiOperation(value = "生产环境信用总览")
    @GetMapping("/environmentOverview")
    @ApiImplicitParam(name = "industry", value = "行业", dataType = "String")
    public AjaxResults<HpmEnvironmentOverviewVo> environmentOverview(String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectOnvironmentOverview(industry,regionCode));
    }

    @ApiOperation(value = "行业污染物排放跟踪 (实际排放/许可排放)及行业排名")
    @GetMapping("/emissionTrackingOverview")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "emissionType", value = "系统: 0;执行报告:1;", dataType = "String"),
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<List<IndustryEmissionTrackingOverviewVo>> industryEmissionTrackingOverview(String emissionType, String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectIndustryEmissionTrackingOverviewVo(emissionType, industry,regionCode));
    }

    @ApiOperation(value = "行业危废产生及处置利用")
    @GetMapping("/industrialHazardousWaste")
    @ApiImplicitParam(name = "industry", value = "行业", dataType = "String")
    public AjaxResults<List<IndustrialHazardousWasteVo>> productionAndDisposalOfIndustrialHazardousWaste(String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectProductionAndDisposalOfIndustrialHazardousWaste(industry,regionCode));
    }

    @ApiOperation(value = "行业污染物排放趋势")
    @GetMapping("/industryPollutantDischargeTrends")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pollutantCategory", value = "污染物种类 0 废气 1 废水 2固废", dataType = "String"),
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<EChartsVO> industryPollutantDischargeTrends(String pollutantCategory, String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectIndustryPollutantDischargeTrends(pollutantCategory, industry,regionCode));
    }

    @ApiOperation(value = "行业产品产量趋势")
    @GetMapping("/industryProductOutputTrends")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<EChartsVO> industryProductOutputTrends(String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectIndustryProductOutputTrends(industry,regionCode));
    }

    @ApiOperation(value = "行业污染物排放TOP10企业")
    @GetMapping("/top10CompaniesWithPollutantEmissionsInTheIndustry")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pollutantType", value = "污染物类型", dataType = "String", required = true),
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<List<IndustryPollutantEmissionsTop10Vo>> top10CompaniesWithPollutantEmissionsInTheIndustry(@RequestParam String pollutantType, @RequestParam String industry) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(keyEmittingIndustryService.selectTop10CompaniesWithPollutantEmissionsInTheIndustry(pollutantType, industry,regionCode));
    }

    @ApiOperation(value = "执法情况统计")
    @GetMapping("/selectLawEnforcementStatistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<EChartsVO> lawEnforcementStatistics(String industry) {
        return AjaxResults.success(keyEmittingIndustryService.selectLawEnforcementStatistics(industry));
    }

    @ApiOperation(value = "行业污染物治理工艺")
    @GetMapping("/industryPollutantTreatmentProcess")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<EChartsVO> industryPollutantTreatmentProcess(String industry) {
        return AjaxResults.success(keyEmittingIndustryService.selectIndustryPollutantTreatmentProcess(industry));
    }

    @ApiOperation(value = "行业问题统计")
    @GetMapping("/industryIssuesStatistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "industry", value = "行业", dataType = "String"),
    })
    public AjaxResults<List<EChartsVO.Sunburst>> industryIssuesStatistics(String industry) {
        AmProblemFiQuery.ChartDataParam param = new AmProblemFiQuery.ChartDataParam();
        param.setIndustry(industry);
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        return AjaxResults.success(amProblemFiService.getChartData(param,regionCode));
    }

    @ApiOperation(value = "执法情况饼图统计")
    @GetMapping("/selectLawEnforcementPieStatistics")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "factoryId", value = "企业id", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String"),
    })
    public AjaxResults<List<LawEnforcementPieStatisticsVo>> selectLawEnforcementPieStatistics(@RequestParam(value = "factoryId",required = false) String factoryId,
                                                                                              @RequestParam(value = "startTime",required = false) String startTime,
                                                                                              @RequestParam(value = "endTime",required = false) String endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("factoryId", factoryId);
        return AjaxResults.success(keyEmittingIndustryService.selectLawEnforcementPieStatistics(params));
    }

}
