package com.huatek.busi.service.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.service.MeteorologicalService;
import com.huatek.busi.service.arrester.ArresterMeteorologicalCacheService;
import com.huatek.busi.service.gis.SubstationMicGisNowService;
import com.huatek.busi.service.substation.SubstationMicCacheService;
import com.huatek.busi.service.transformer.TransformerMeteorologicalCacheService;
import com.huatek.busi.vo.MeteorologicalVo;

@Component
@Service(interfaceClass = MeteorologicalService.class)
@Transactional(rollbackFor = Exception.class)
public class MeteorologicalServiceImpl implements MeteorologicalService {

    @Autowired
    private TransformerMeteorologicalCacheService transformerMeteorologicalCacheService;
    @Autowired
    private ArresterMeteorologicalCacheService arresterMeteorologicalCacheService;
    @Autowired
    private SubstationMicGisNowService substationMicGisNowService;
    @Autowired
    private SubstationMicCacheService substationMicCacheService;

    @Override
    public MeteorologicalVo queryMeteorologicalInfo(String sensorCode, String equipmentType) {
        MeteorologicalVo meteorologicalVo = new MeteorologicalVo();
        //首页默认加载避雷器气象
        if ((sensorCode == null || "".equals(sensorCode)) && (equipmentType == null || "".equals(equipmentType))) {
            meteorologicalVo = arresterMeteorologicalCacheService.defaultMeteorologicalInfo();
        }
        if (SiteConstants.ExternalTypeEnum.BYQ.getValue().equals(equipmentType)) {
            //如果没取到值显示变电站信息
            meteorologicalVo = transformerMeteorologicalCacheService.queryMeteorologicalInfo(sensorCode);
            if (meteorologicalVo == null) {
                meteorologicalVo = substationMicCacheService.queryMeteorologicalInfo();
            }
            String loadRate = meteorologicalVo.getLoadRate();
            if (meteorologicalVo.getLoadRate() == null || "".equals(meteorologicalVo.getLoadRate())) {
                loadRate = "0.00";
            }
            DecimalFormat df = new DecimalFormat("0.00%");
            meteorologicalVo.setLoadRate(df.format(new BigDecimal(loadRate)));
        } else if (SiteConstants.ExternalTypeEnum.GIS.getValue().equals(equipmentType)) {
            meteorologicalVo = substationMicGisNowService.queryMeteorologicalInfo(sensorCode);
        } else if (SiteConstants.ExternalTypeEnum.BLQ.getValue().equals(equipmentType)) {
            meteorologicalVo = arresterMeteorologicalCacheService.queryMeteorologicalInfo(sensorCode);
        }
//        else if(SiteConstants.ExternalTypeEnum.BLQ.getValue().equals(equipmentType)){
//        {     // 综合——变电站微气象
//            meteorologicalVo = substationMicCacheService.queryMeteorologicalInfo();
//        }
        return meteorologicalVo;
    }

    public static void main(String[] args) {
        DecimalFormat df = new DecimalFormat("0.00%");
        String s = df.format(0.01832);

        System.out.println(s);

    }

}
