package cn.cecep.talroad.controller.analysis;
import cn.cecep.talroad.common.core.domain.R;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.security.utils.SecurityUtils;
import cn.cecep.talroad.domain.analysis.SRaEmissionsStatistics;
import cn.cecep.talroad.domain.leader.vo.ProblemGroupCountVO;
import cn.cecep.talroad.feign.BaseRegionService;
import cn.cecep.talroad.vo.analysis.FactoryTop10ProblemCountVO;
import cn.cecep.talroad.vo.query.analysis.SREStatisticsQuery;
import cn.cecep.talroad.service.analysis.SRaEmissionsStatisticsService;
import cn.cecep.talroad.vo.EChartsVO;
import io.swagger.annotations.Api;
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.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* (s_ra_emissions_statistics)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/sRaEmissionsStatistics")
@Api(tags = "异常行为统计分析",value = "异常行为统计分析")
public class SRaEmissionsStatisticsController extends BasesController {
    /**
    * 服务对象
    */
    @Resource
    private SRaEmissionsStatisticsService sRaEmissionsStatisticsService;

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

    /**
    * 企业异常行为发生趋势
    *
    * @param query 查询条件
    * @return 单条数据
    */
    @ApiOperation("企业异常行为发生趋势")
    @GetMapping("selectChartDataTrend")
    public AjaxResults<EChartsVO> selectChartDataTrend(SREStatisticsQuery query) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        R<List<String>> r = baseRegionService.getRegionCodeListChild(regionCode);
        if(r.getCode()==200){
            query.setRegionCodes(r.getData());
        }
        return sRaEmissionsStatisticsService.selectChartData(query);
    }

    /**
     * 企业异常行为TOP10
     *
     * @param query 查询条件
     * @return 单条数据
     */
    @ApiOperation("企业异常行为TOP10")
    @GetMapping("selectChartDataTop")
    public AjaxResults<List<FactoryTop10ProblemCountVO>> selectChartDataTop(SREStatisticsQuery query) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        R<List<String>> r = baseRegionService.getRegionCodeListChild(regionCode);
        if(r.getCode()==200){
            query.setRegionCodes(r.getData());
        }
        return AjaxResults.success(sRaEmissionsStatisticsService.selectChartDataTop(query));
    }
    /**
     * 企业异常行为TOP10
     *
     * @param query 查询条件
     * @return 单条数据
     */
    @ApiOperation("行业异常行为排名" )
    @GetMapping("selectChartDataIndustry")
    public AjaxResults<EChartsVO> selectChartDataIndustry(SREStatisticsQuery query) {
        String regionCode = SecurityUtils.getLoginUser().getSysUser().getRegionCode();
        R<List<String>> r = baseRegionService.getRegionCodeListChild(regionCode);
        if(r.getCode()==200){
            query.setRegionCodes(r.getData());
        }
        return AjaxResults.success(sRaEmissionsStatisticsService.selectChartDataIndustry(query));
    }

}
