package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant;
import com.huatek.busi.entity.*;
import com.huatek.busi.service.*;

import com.huatek.busi.vo.SensiorIdExportVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 各个设备相关信息查询
 * author:mitchell
 */
@Api(tags = {ApiConstant.Tags.BUSI_Transformer_Number})
@RestController
@RequestMapping("/api/equipmentNumber")
public class EquipmentNumberController {

    @Reference(check = false)
    TransformerNumberService transformerNumberService;

    @Reference(check = false)
    CableNumberService cableNumberService;

    @Reference(check = false)
    GisNumberService gisNumberService;

    @Reference(check = false)
    ArresterNumberService arresterNumberService;

    @Reference(check = false)
    CubicleNumberService cubicleNumberService;

    @Reference(check = false)
    GeneratorNumberService generatorNumberService;

    @Reference(check = false)
    SumEquipmentNumberService sumEquipmentNumberService;

    @Reference(check = false)
    LoadStatusService loadStatusService;

    /**
     * 查询所有外挂设备并插入cache表中
     */
    @ApiOperation(value = "查询所有设备的外挂设备并插入cache表中")
    @GetMapping(value="/selectAllEquipment")
    public Map<String, Object> selectAllEquipment (){
        List<SensiorIdExportVo> list = transformerNumberService.findAllEquipment();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 查询系统中外挂删除设备，并更新cache表
     */
    @ApiOperation(value = "查询系统中外挂删除设备，并更新cache表")
    @GetMapping(value="/selectEquipmentAndDelete")
    public Map<String, Object> selectEquipmentAndDelete (){
        List<EquipmentTemperatureCache> list = transformerNumberService.findEquipmentAndDelete();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }


    /**
     * 变压器外挂装置查询并将计算值加入Cache表
     *
     */
    @ApiOperation(value = "变压器外挂装置查询并将计算值加入Cache表")
    @GetMapping(value="/selectTransformerNumber")
    public Map<String, Object> selectTransformerNumber () throws  Exception{
        int addTransformer = transformerNumberService.findTransformerNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", addTransformer);
    }


    /**
     * 变压器状态
     *
     */
    @ApiOperation(value = "变压器状态查询")
    @GetMapping(value="/selectTransformerStatus")
    public Map<String, Object> selectTransformerStatus () {
        List<TransformerStatus> list = transformerNumberService.findTransformerStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 变压器电流电压查询
     *
     */
    @ApiOperation(value = "变压器电流电压查询")
    @GetMapping(value="/selectTransformerUI")
    public Map<String, Object> selectTransformerUI (@RequestParam String transformerId) {
        TransformerIU transformerIU = transformerNumberService.findTransformerUI(transformerId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", transformerIU);
    }

    /**
     * 所有变压器最近15天负荷率查询
     *
     */
    @ApiOperation(value = "所有变压器最近15天负荷率查询")
    @GetMapping(value="/findTransformerLoadRate")
    public Map<String, Object> findTransformerLoadRate () {
        List<TransformerLoadRate> transformerLoadRate = transformerNumberService.findTransformerLoadRate();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", transformerLoadRate);
    }




    /**
     * 变压器故障,在线,总数查询
     *
     */
    @ApiOperation(value = "变压器装置总数统计")
    @GetMapping(value="/selectSumTransformerNumber")
    public Map<String, Object> selectSumTransformerNumber () throws Exception {
        EquipmentSumNumber equipmentSumNumber = transformerNumberService.findSumTransformerNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }



    /**
     * 电缆外挂装置查询并将计算值加入Cache表
     *
     */
    @ApiOperation(value = "电缆外挂装置查询并将计算值加入Cache表")
    @GetMapping(value="/selectCableNumber")
    public Map<String, Object> selectCableNumber () throws  Exception{
        int addCable = cableNumberService.findCableNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", addCable);
    }

    /**
     * 电缆状态
     *
     */
    @ApiOperation(value = "电缆状态查询")
    @GetMapping(value="/selectCableStatus")
    public Map<String, Object> selectCableStatus () {
        List<CableStatus> list = cableNumberService.findCableStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 发电机状态
     *
     */
    @ApiOperation(value = "发电机状态查询")
    @GetMapping(value="/selectGeneratorStatus")
    public Map<String, Object> selectGeneratorStatus () {
        List<GeneratorStatus> list = generatorNumberService.findGeneratorStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 电缆故障,在线,总数查询
     *
     */
    @ApiOperation(value = "电缆装置总数统计")
    @GetMapping(value="/selectSumCableNumber")
    public Map<String, Object> selectSumCableNumber () throws Exception{
        EquipmentSumNumber equipmentSumNumber = cableNumberService.findSumCableNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }

    /**
     * GIS外挂装置查询并将计算值加入Cache表
     *
     */
    @ApiOperation(value = "GIS外挂装置查询并将计算值加入Cache表")
    @GetMapping(value="/selectGisNumber")
    public Map<String, Object> selectGisNumber () throws  Exception{
        int addGis = gisNumberService.findGisNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", addGis);
    }

    /**
     * GIS断路器状态
     *
     */

    @ApiOperation(value = "GIS断路器状态查询")
    @GetMapping(value="/selectGisStatus")
    public Map<String, Object> selectGisStatus () {
        List<GisStatus> list = gisNumberService.findGisStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    @ApiOperation(value = "所有GIS设备")
    @GetMapping(value="/selectTotalGisList")
    public Map<String, Object> selectTotalGisList () {
        List<GisStatus> list = gisNumberService.selectTotalGisList();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * GIS断路器电流电压查询
     */
    @ApiOperation(value = "GIS断路器电流电压查询")
    @GetMapping(value = "/selectGisUI")
    public Map<String,Object> selectGisUI(@RequestParam String gisId){
        GisIU gisIU =gisNumberService.findGisUI(gisId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", gisIU);
    }



    /**
     * GIS所有状态
     *
     */

    @ApiOperation(value = "GIS所有状态查询")
    @GetMapping(value="/selectAllGisStatus")
    public Map<String, Object> selectAllGisStatus () {
        List<GisStatus> list = gisNumberService.findAllGisStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * GIS故障,在线,总数查询
     *
     */
    @ApiOperation(value = "GIS装置总数统计")
    @GetMapping(value="/selectSumGisNumber")
    public Map<String, Object> selectSumGisNumber () throws Exception{
        EquipmentSumNumber equipmentSumNumber = gisNumberService.findSumGisNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }



    /**
     *避雷器状态
     *
     */
    @ApiOperation(value = "避雷器状态查询")
    @GetMapping(value="/selectArresterStatus")
    public Map<String, Object> selectArresterStatus () {
        List<ArresterStatus> list = arresterNumberService.findArresterStatus();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 避雷器外挂装置查询并将计算值加入Cache表
     *
     */
    @ApiOperation(value = "避雷器外挂装置查询并将计算值加入Cache表")
    @GetMapping(value="/selectArresterNumber")
    public Map<String, Object> selectArresterNumber () throws  Exception{
        int addArrester = arresterNumberService.findArresterNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", addArrester);
    }

    /**
     * 避雷器故障,在线,总数查询
     *
     */
    @ApiOperation(value = "避雷器装置总数统计")
    @GetMapping(value="/selectSumArresterNumber")
    public Map<String, Object> selectSumArresterNumber () throws Exception {
        EquipmentSumNumber equipmentSumNumber = arresterNumberService.findSumArresterNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }

    /**
     * 避雷器温度超标率查询
     *
     */
    @ApiOperation(value = "避雷器温度超标率查询")
    @GetMapping(value="/selectHwChaobiao")
    public Map<String, Object> selectHwChaobiao (@RequestParam("siteId") String siteId,
                                                 @RequestParam("mainEquipmentId") String mainEquipmentId,
                                                 @RequestParam("dTime") String rtpTime){
        ArresterHwChaobiaoLv arresterHwChaobiaoLv = arresterNumberService.findHwChaobiao(siteId,mainEquipmentId,rtpTime);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", arresterHwChaobiaoLv);
    }




    /**
     *开关柜状态查询
     *
     */
    @ApiOperation(value = "开关柜状态查询")
    @GetMapping(value = "selectCubicleStatus")
    public Map<String,Object> selectCubicleStatus(){
        List<CubicleStatus> list =cubicleNumberService.findCubicleStart();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }

    /**
     * 开关柜外挂装置查询并将计算值加入Cache表
     *
     */
    @ApiOperation(value = "开关柜外挂装置查询并将计算值加入Cache表")
    @GetMapping(value="/selectCubicleNumber")
    public Map<String, Object> selectCubicleNumber () throws  Exception{
        int addCubicle = cubicleNumberService.findCubicleNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", addCubicle);
    }

    /**
     * 开关柜故障,在线,总数查询
     *
     */
    @ApiOperation(value = "开关柜总数统计")
    @GetMapping(value="/selectSumCubicleNumber")
    public Map<String, Object> selectSumCubicleNumber () throws Exception{
        EquipmentSumNumber equipmentSumNumber = cubicleNumberService.findSumCubicleNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }

    /**
     * 开关柜测温点查询
     *
     */
    @ApiOperation(value = "开关柜测温点查询")
    @GetMapping(value="/selectCubiclePoint")
    public Map<String, Object> selectCubiclePoint (@RequestParam("siteId") String siteId,
                                                   @RequestParam("eqmId") String eqmId){
        List<RptTermperRecord> rptTermperRecord = cubicleNumberService.findCubiclePoint(siteId,eqmId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", rptTermperRecord);
    }

    /**
     * 开关柜故障率查询
     *
     */
    @ApiOperation(value = "开关柜故障率查询")
    @GetMapping(value="/selectTemperRate")
    public Map<String, Object> selectTemperRate (@RequestParam("siteId") String siteId,
                                                   @RequestParam("eqmId") String eqmId){
        List<RptTemperRate> rptTemperRate = cubicleNumberService.findTemperRate(siteId,eqmId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", rptTemperRate);
    }


    /**
     * 开关柜ABC相出入温度查询
     *
     */
    @ApiOperation(value = "开关柜ABC相出入温度查询")
    @GetMapping(value="/selectTemper")
    public Map<String, Object> selectTemper (@RequestParam("siteId") String siteId,
                                                 @RequestParam("eqmId") String eqmId){
        List<RptTemper> rptTemper = cubicleNumberService.findTemper(siteId,eqmId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", rptTemper);
    }



    /**
     * 发电机故障,在线,总数查询
     *
     */
    @ApiOperation(value = "发电机总数统计")
    @GetMapping(value="/selectSumGeneratorNumber")
    public Map<String, Object> selectSumGeneratorNumber () throws Exception {
        EquipmentSumNumber equipmentSumNumber = generatorNumberService.findSumGeneratorNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }


    /**
     * 所有外挂故障,在线,总数查询
     *
     */
    @ApiOperation(value = "所有外挂总数统计")
    @GetMapping(value="/selectSumEquipmentNumber")
    public Map<String, Object> selectSumEquipmentNumber (){
        EquipmentSumNumber equipmentSumNumber = sumEquipmentNumberService.findSumEquipmentNumber();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", equipmentSumNumber);
    }


    /**
     * 查询变压器设备负载状态
     *
     */
    @ApiOperation(value = "查询变压器设备负载状态")
    @GetMapping(value="/selectTransformerLoadStatus")
    public Map<String, Object> selectTransformerLoadStatus (@RequestParam("eqmCode") String eqmCode){
        LoadStatus loadStatus = loadStatusService.findTransformerLoadStatus(eqmCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", loadStatus);
    }

    /**
     * 查询其他设备负载状态
     *
     */
    @ApiOperation(value = "查询其他设备负载状态")
    @GetMapping(value="/selectOtherLoadStatus")
    public Map<String, Object> selectOtherLoadStatus (@RequestParam("equipmentId") String equipmentId){
        LoadStatus loadStatus = loadStatusService.findOtherLoadStatus(equipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", loadStatus);
    }


    @ApiOperation(value = "获取每个主设备对应的数量以相关信息")
    @GetMapping(value = "/getAllEquipmentNumber")
    public Map<String, Object> getAllEquipmentNumber() {
        List<TransformerStatus> byq = transformerNumberService.findTransformerStatus();
        List<GisStatus> gis = gisNumberService.findGisStatus();
        List<CableStatus> dl = cableNumberService.findCableStatus();
        List<CubicleStatus> kgg =cubicleNumberService.findCubicleStart();
        List<ArresterStatus> blq = arresterNumberService.findArresterStatus();
        List<GeneratorStatus> fdj = generatorNumberService.findGeneratorStatus();
        int otherNumber =generatorNumberService.findOtherEquNumber();

        Map<String, Integer> map = new HashMap<>();
        map.put("byq", byq.size());
        map.put("gis", gis.size());
        map.put("dl", dl.size());
        map.put("kgg", kgg.size());
        map.put("blq", blq.size());
        map.put("fdj",fdj.size());
        map.put("other", otherNumber);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", map);
    }
}
