package com.huatek.busi.service.impl.arrester;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

import com.huatek.busi.common.DateUtils;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.dao.*;
import com.huatek.busi.dto.HomeSearchDto;
import com.huatek.busi.entity.*;
import com.huatek.busi.service.BusiEquipmentRelationshipService;
import com.huatek.busi.vo.*;
import com.huatek.torch.sql.beans.WherePrams;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import com.huatek.busi.common.BusiConstant.EqType;
import com.huatek.busi.common.BusiConstant.GzType;
import com.huatek.busi.common.SiteConstants.ArresterTreeEnum;
import com.huatek.busi.common.SiteConstants.ExternalTypeEnum;
import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.common.util.DecimalUtil;
import com.huatek.busi.common.util.FieldUtil;
import com.huatek.busi.common.util.TimeUtil;
import com.huatek.busi.common.util.Tools;
import com.huatek.busi.dto.EquipmentInfoDto;
import com.huatek.busi.dto.LightningrodImStatisticsDto;
import com.huatek.busi.dto.curve.BaseCurveQueryDto;
import com.huatek.busi.dto.curve.PointItemDto;
import com.huatek.busi.mapper.LightningrodImMapper;
import com.huatek.busi.mapper.RptAretMonitorMapper;
import com.huatek.busi.service.BusiSiteTreeService;
import com.huatek.busi.service.IecBydworkParamService;
import com.huatek.busi.service.arrester.LightningrodImService;
import com.huatek.busi.service.arrester.RptAretMonitorService;
import com.huatek.busi.service.impl.cac.AbstractCacEtlService;
import com.huatek.busi.service.threshold.ArresterInsulationMonitorThresholdService;
import com.huatek.busi.vo.curve.PointItemVo;
import com.huatek.busi.vo.monitor.BusiOnlineMonitorDataVo;
import com.huatek.busi.vo.stability.LightningrodImStabilityVo;
import com.huatek.busi.vo.warning.BusiArresterItemVo;
import com.huatek.busi.vo.warning.BusiArresterItemVo.BusiArresterItemVoBuilder;
import com.huatek.busi.vo.warning.BusiArresterVo;
import com.huatek.busi.vo.warning.BusiGisSf6Vo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 金属氧化物避雷器——绝缘监测：023001 ServiceImpl
 *
 * @author anker_cheng
 * @date Jun 26, 2019 1:11:48 PM
 */
@Slf4j
@Component
@Service(interfaceClass = LightningrodImService.class)
@Transactional(rollbackFor = Exception.class)
public class LightningrodImServiceImpl extends AbstractCacEtlService<LightningrodIm> implements LightningrodImService {

    @Autowired
    private LightningrodImMapper lightningrodImMapper;
    @Reference(check = false)
    private RptAretMonitorService rptAretMonitorService;
    @Reference(check = false)
    private IecBydworkParamService iecBydworkParamService;
    
    @Reference(check = false)
    private BusiSiteTreeService busiSiteTreeService;
    
    @Reference(check = false)
    private ArresterInsulationMonitorThresholdService arresterInsulationMonitorThresholdService;

    @Autowired
    private BusiArresterSensorDao busiArresterSensorDao;

    @Autowired
    private BusiArresterSubTreeDao busiArresterSubTreeDao;

    @Autowired
    private BusiOnlineMonitorDataDao busiOnlineMonitorDataDao;

    @Autowired
    private LightningrodImDao lightningrodImDao;

    @Autowired
    private BusiEquipmentRelationshipService busiEquipmentRelationshipService;

    @Autowired
    private ArresterInsulationMonitorThresholdDao arresterInsulationMonitorThresholdDao;

    @Override
    public void saveHistoryData(LightningrodIm cacEntity, EquipmentInfoDto equipmentInfo) {

        // 设备状态
        String state = iecBydworkParamService.getIecType(cacEntity.getMainTreeId(), cacEntity.getTimeStamp());
        if (StringUtils.isEmpty(state)) {
            log.info("无法获取设备状态");
        }
        cacEntity.setRunState(state);
        //设置rowkey，导入hbase使用
        cacEntity.setHbaseRowkey(Tools.strReverse(TimeUtil.getTimeStr(cacEntity.getTimeStamp())) + "_"
            + cacEntity.getSensorId() + "_" + TimeUtil.getTimeStr(cacEntity.getTimeStamp()) + "_"
            + cacEntity.getCacMonitorTypeCode() + "_" + cacEntity.getMainTreeId());
        super.saveHistoryData(cacEntity, equipmentInfo);
    }

    @Override
    public void saveBusiWarning(LightningrodIm cacEntity, String cacMonitorTypeCode, String sensorId,
        EquipmentInfoDto equipmentInfo) {
        // 阈值
        ArresterInsulationMonitorThreshold arresterThreshold =
            arresterInsulationMonitorThresholdService.getArresterInsulationMonitorThreshold(cacEntity.getMainTreeId(),
                cacEntity.getRunState(), cacEntity.getSensorId());
        if (arresterThreshold == null) {
            log.warn("ArresterInsulationMonitorThreshold not exists! mainTreeId: {}, runState: {}, sensorCode: {}",
                cacEntity.getMainTreeId(), cacEntity.getRunState(), cacEntity.getSensorId());
            return;
        }
        final StringBuilder warningMsg = new StringBuilder();

        // 全电流、阻性电流的预警值、阈值
        String fullCurrentWarning = getWarningVal(arresterThreshold, cacEntity.getPhase(), "FullCurrent");
        String fullCurrentThreshold = getThresholdVal(arresterThreshold, cacEntity.getPhase(), "FullCurrent");
        String resistiveCurrentWarning = getWarningVal(arresterThreshold, cacEntity.getPhase(), "ResistiveCurrent");
        String resistiveCurrentThreshold = getThresholdVal(arresterThreshold, cacEntity.getPhase(), "ResistiveCurrent");

        Map<String, Object> stabilityMap= busiStabilityService.getStabilityBySensorCodeAndStatus(sensorId, cacEntity.getRunState());

        // 全电流
        BusiArresterItemVoBuilder builder1 = BusiArresterItemVo.builder().phase(cacEntity.getPhase()).name("全电流（mA）")
            .collectValue(cacEntity.getTotalCurrent()).thresholdValue(fullCurrentThreshold)
            .equipmentStatus(cacEntity.getRunState()).warningValue(fullCurrentWarning);
        //数据稳定性
         builder1.stabilityIndex(getString(stabilityMap, "totalCurrent", "--"));
        if(isWarning(cacEntity.getTotalCurrent(),arresterThreshold.getAFullCurrentWarning()))
		{
        	append(warningMsg, format("{}全电流超标为：{}", cacEntity.getPhase(), cacEntity.getTotalCurrent()));
            builder1.alarmValue(cacEntity.getTotalCurrent());
		}

        BusiArresterItemVoBuilder builder2 = BusiArresterItemVo.builder().phase(cacEntity.getPhase()).name("阻性电流（mA）")
                .collectValue(cacEntity.getResistiveCurrent()).thresholdValue(resistiveCurrentThreshold)
                .equipmentStatus(cacEntity.getRunState()).warningValue(resistiveCurrentWarning);
        if(isWarning(cacEntity.getResistiveCurrent(),arresterThreshold.getAResistiveCurrentWarning()))
		{
        	append(warningMsg, format("{}阻性电流超标为：{}", cacEntity.getPhase(), cacEntity.getResistiveCurrent()));
            builder2.alarmValue(cacEntity.getResistiveCurrent());
		}
        //告警则保存告警
        if(warningMsg.length() > 0)
        {
        	// 保存告警
            BusiEqmWarning busiEqmWarning = newEw(EqType.EQ_TYPE3, GzType.GZ_TYPE6, warningMsg.toString(), cacMonitorTypeCode,"1");
            busiEqmWarning.setWarningTime(cacEntity.getTimeStamp());
            busiEqmWarning.setRunState(cacEntity.getRunState());
            busiEqmWarning.setWarningFlag("1");
            busiEqmWarning = this.buildWarning(busiEqmWarning, equipmentInfo);
            // 保存告警详情
            BusiArresterVo busiArresterVo = new BusiArresterVo();
            busiArresterVo.setEquipmentName(equipmentInfo.getSubEquipmentName());
            busiArresterVo.setList(Arrays.asList(builder1.build(),builder2.build()));
            busiArresterVo.setCollectDate(cacEntity.getTimeStamp());
            this.buildWarningInfo(busiEqmWarning, JSON.toJSONString(busiArresterVo));
            return;
        }
        
        if(isThreshold(cacEntity.getResistiveCurrent(), arresterThreshold.getAResistiveCurrentThreshold(),arresterThreshold.getAResistiveCurrentWarning()))
		{
        	append(warningMsg, format("{}全电流超标为：{}", cacEntity.getPhase(), cacEntity.getTotalCurrent()));
            builder1.alarmValue(cacEntity.getTotalCurrent());
		}
        
        if(isThreshold(cacEntity.getResistiveCurrent(), arresterThreshold.getAResistiveCurrentThreshold(),arresterThreshold.getAResistiveCurrentWarning()))
		{
        	append(warningMsg, format("{}阻性电流超标为：{}", cacEntity.getPhase(), cacEntity.getResistiveCurrent()));
            builder2.alarmValue(cacEntity.getResistiveCurrent());
		}
        if(warningMsg.length() > 0)
        {
        	// 保存告警
            BusiEqmWarning busiEqmWarning = newEw(EqType.EQ_TYPE3, GzType.GZ_TYPE6, warningMsg.toString(), cacMonitorTypeCode,"2");
            busiEqmWarning.setWarningTime(cacEntity.getTimeStamp());
            busiEqmWarning.setRunState(cacEntity.getRunState());
            busiEqmWarning.setWarningFlag("2");
            busiEqmWarning = this.buildWarning(busiEqmWarning, equipmentInfo);
            // 保存告警详情
            BusiArresterVo busiArresterVo = new BusiArresterVo();
            busiArresterVo.setEquipmentName(equipmentInfo.getSubEquipmentName());
            busiArresterVo.setList(Arrays.asList(builder1.build(),builder2.build()));
            busiArresterVo.setCollectDate(cacEntity.getTimeStamp());
            this.buildWarningInfo(busiEqmWarning, JSON.toJSONString(busiArresterVo));
            return;
        }
        if (warningMsg.length() == 0) {
            return;
        }
    }

    @Override
    public void updateCurrentData(LightningrodIm cacEntity, EquipmentInfoDto equipmentInfo) {
        rptAretMonitorService.saveRptAretMonitor(cacEntity);
    }

    /**
     * 判断告警
     * 返回 aVal.compareTo(bVal)>0的结果，判断aVal是否大于bVal
     * 
     * @param aVal  报文数据
     * @param bVal  阈值
     */
    private static boolean isWarning(String aVal, String bVal) {
    
    	if (StringUtils.isEmpty(bVal)) {
    		return false;
    	}
    	return DecimalUtil.getVal(aVal).compareTo(DecimalUtil.getVal(bVal)) > 0;
    }

    public static void main(String[] args) {
        boolean warning = isWarning("20", "10");
        System.out.println(warning);
    }

    /**
     * 判断预警
     * 返回 aVal.compareTo(bVal)>0的结果，判断aVal是否大于bVal
     * 
     * @param aVal  报文数据
     * @param bVal  阈值
     * @param cVal  预警值
     * @return  0,正常；1预警；2告警
     */
    private static boolean isThreshold(String aVal, String bVal,String cVal) {
    	boolean flag = false;
    	if (StringUtils.isEmpty(bVal)) {
    		flag = false;
    	}
    	//预警
    	if(DecimalUtil.getVal(aVal).compareTo(DecimalUtil.getVal(bVal)) > 0 && DecimalUtil.getVal(aVal).compareTo(DecimalUtil.getVal(cVal)) < 0)
    	{
    		flag = true;
    	}
    	return flag;
    }
    

    private String getWarningVal(ArresterInsulationMonitorThreshold threshold, String phase, String name) {
        return (String)FieldUtil.getFieldValue(threshold, phase(phase) + name + "Warning");
    }

    private String getThresholdVal(ArresterInsulationMonitorThreshold threshold, String phase, String name) {
        return (String)FieldUtil.getFieldValue(threshold, phase(phase) + name + "Threshold");
    }

    private static String phase(String phase) {
        if (phase == null) {
            return "";
        }
        return phase.replace("相", "").toLowerCase();
    }
	/**
	 * 数据输入-绝缘监测原始数据查询
	 */
    @Override
    public Map<String, Object> findCACPageData(Map<String, Object> params) {
    	if (params.get("page") != null && params.get("limit") != null) {
    		PageHelper.startPage(page(params), limit(params));
        }
        Page<Map<String, Object>> page = lightningrodImMapper.findCACPageData(params);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, page.getTotal(), "", page.getResult());
    }

	@Override
	public Map<String, Object> exportCacMonitorData(Map<String, Object> mapParams) {
		Map<String, Object> returnMap = new HashMap<>();
		if (mapParams.containsKey("mainTreeId") && StringUtils.isNotEmpty(mapParams.get("mainTreeId")+"")) {
			BusiSiteTree busiSiteTree = busiSiteTreeService.findByPK(mapParams.get("mainTreeId")+"");
			List<LightningrodImVo> lightningrodImList = lightningrodImMapper.exportCacMonitorData(mapParams);
			String replaceRegex = "[\\\\n`~!@#$%^&*()+=|{}':;',\\\\\\\\[\\\\\\\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。， 、？]";
            String treeName = busiSiteTree.getName().replaceAll(replaceRegex, "-");
			returnMap.put("fileName", String.format("%s%s", treeName,"落雷监测数据"));
			returnMap.put("title", String.format("%s%s", treeName,"落雷监测数据"));
			if (lightningrodImList.isEmpty()) {
				lightningrodImList = new ArrayList<>();
				lightningrodImList.add(new LightningrodImVo());
			}
			returnMap.put("data", lightningrodImList);
		} else {
			throw new RuntimeException("主设备编码不正确");
		}
		return returnMap;
	}

	@Override
	public List<LightningrodImStabilityVo> getByStatus(String sensorCode, String status, LocalDateTime begin, LocalDateTime end) {
		return lightningrodImMapper.selectByStatus( sensorCode,  status,  begin,  end);
	}

	@Override
    protected List<Map<String, Object>> queryMonitorDataList(LocalDateTime startTime, LocalDateTime endTime) {
        return lightningrodImMapper.queryMonitorDataList(startTime, endTime);
    }

    @Override
    protected void saveBusiOnlineMonitorData(BusiOnlineMonitorData busiOnlineMonitorData, Map<String, Object> item) {
        busiOnlineMonitorData.setSubEquipmentType(ArresterTreeEnum.JY_EQM.getValue());
        busiOnlineMonitorData.setExtType(ExternalTypeEnum.BLQ.getValue());
        busiOnlineMonitorData.setEquipmentType(SiteTreeEnum.BLQ_HL_EQM.getValue());
        // 这里将保存的任务交给父类方法完成，子类只需要修改指定几个字段就可以了
        super.saveBusiOnlineMonitorData(busiOnlineMonitorData, item);
    }

    @Override
    protected Map<String, Object> thresholdDataMap(BusiOnlineMonitorDataVo vo) {
        Map<String, Object> tMap = Maps.newLinkedHashMapWithExpectedSize(10);
        ArresterInsulationMonitorThreshold thresholdVo = arresterInsulationMonitorThresholdService
            .getArresterInsulationMonitorThreshold(vo.getMainTreeId(), vo.getRunState(), vo.getSensorCode());
        if(thresholdVo == null) {
            return tMap;
        }
        String phase = phase(vo.getPhase());
        if("A".equalsIgnoreCase(phase)) {
            tMap.put("totalCurrentWarning", thresholdVo.getAFullCurrentWarning());
            tMap.put("totalCurrentThreshold", thresholdVo.getAFullCurrentThreshold());
            tMap.put("resistiveCurrentWarning", thresholdVo.getAResistiveCurrentWarning());
            tMap.put("resistiveCurrentThreshold", thresholdVo.getAResistiveCurrentThreshold());
            tMap.put("capacitanceCurrentWarning", thresholdVo.getACapacitanceCurrentWarning());
            tMap.put("capacitanceCurrentThreshold", thresholdVo.getACapacitanceCurrentThreshold());
        }else if("B".equalsIgnoreCase(phase)) {
            tMap.put("totalCurrentWarning", thresholdVo.getBFullCurrentWarning());
            tMap.put("totalCurrentThreshold", thresholdVo.getBFullCurrentThreshold());
            tMap.put("resistiveCurrentWarning", thresholdVo.getBResistiveCurrentWarning());
            tMap.put("resistiveCurrentThreshold", thresholdVo.getBResistiveCurrentThreshold());
            tMap.put("capacitanceCurrentWarning", thresholdVo.getBCapacitanceCurrentWarning());
            tMap.put("capacitanceCurrentThreshold", thresholdVo.getBCapacitanceCurrentThreshold());
        }else if("C".equalsIgnoreCase(phase)) {
            tMap.put("totalCurrentWarning", thresholdVo.getCFullCurrentWarning());
            tMap.put("totalCurrentThreshold", thresholdVo.getCFullCurrentThreshold());
            tMap.put("resistiveCurrentWarning", thresholdVo.getCResistiveCurrentWarning());
            tMap.put("resistiveCurrentThreshold", thresholdVo.getCResistiveCurrentThreshold());
            tMap.put("capacitanceCurrentWarning", thresholdVo.getCCapacitanceCurrentWarning());
            tMap.put("capacitanceCurrentThreshold", thresholdVo.getCCapacitanceCurrentThreshold());
        }
        return tMap;
    }

    @Override
    public LightningrodImStatisticsVo getListEquInfo(String cacMonitorTypeCode, LocalDate day, String sensorCode) {
        LightningrodImStatisticsDto param = new LightningrodImStatisticsDto();
        param.setCacMonitorTypeCode(cacMonitorTypeCode);
        param.setStartTime(day.atStartOfDay());
        param.setEndTime(day.plusDays(1).atStartOfDay());
        param.setSensorCode(sensorCode);
        List<LightningrodImStatisticsVo> list = lightningrodImMapper.getListEquInfo(param);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }

    // *****************************趋势图部分********************************\\
    @Override
    public List<BaseCurveQueryDto> findSensorCodeList(LocalDate day) {
        return lightningrodImMapper.findSensorCodeList(day.atStartOfDay(), day.plusDays(1).atStartOfDay());
    }

    @Override
    public List<PointItemVo> findDaylyPointList(BaseCurveQueryDto sensorCode, LocalDate day, String subType) {
        return lightningrodImMapper.findDaylyPointList(sensorCode, subType, day.atStartOfDay(),
            day.plusDays(1).atStartOfDay());
    }

    @Override
    public PointItemDto getDaylyPointStatistics(BaseCurveQueryDto param) {
        return lightningrodImMapper.getDaylyPointStatistics(param);
    }
    
    /**
     * 获取避雷器最近半年类落雷监测次数
     */
	@Override
	public String getSensorActionCount(String sensorCode, LocalDateTime startTime, LocalDateTime endTime) {
		// TODO Auto-generated method stub
		Map<String, Object> param = Maps.newLinkedHashMapWithExpectedSize(3);
        param.put("sensorCode", sensorCode);
        param.put("startTime", startTime);
        param.put("endTime", endTime);
        String actionCount = lightningrodImMapper.getActionCount(param);
        return actionCount;
	}

    @Override
    public HomeActualVo queryActual(HomeSearchDto param) {
        HomeActualVo homeActualVo=new HomeActualVo();
        List<BusiArresterSensor> busiArresterSensors = busiArresterSensorDao.list(new WherePrams()
                .where("sensor_code", param.getSensorCode()).and("status", SiteConstants.Status.NORMAL.getValue()));
        if(ObjectUtils.isEmpty(busiArresterSensors)){
            return homeActualVo;
        }
        HomeActualInfoVo homeActualInfoVo =new HomeActualInfoVo();
        BusiArresterSensor busiArresterSensor = busiArresterSensors.get(0);
        String mainTreeId=busiArresterSubTreeDao.get(busiArresterSensor.getEquipmentId()).getEquipmentId();
        homeActualInfoVo = build(homeActualInfoVo, busiArresterSensor,mainTreeId);
        String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -1));
        List<BusiOnlineMonitorData> busiOnlineMonitorDatas = busiOnlineMonitorDataDao.list(new WherePrams()
                .where("sensor_code", param.getSensorCode())
                .orderBy("day desc limit 1"));
        //组装各种率
        if(!ObjectUtils.isEmpty(busiOnlineMonitorDatas)){
            BusiOnlineMonitorData busiOnlineMonitorData = busiOnlineMonitorDatas.get(0);
            String runState = busiOnlineMonitorData.getRunState();
            if ("3".equals(runState)){
                homeActualInfoVo.setRunState("空载");
            } else if ("2".equals(runState)) {
                homeActualInfoVo.setRunState("抽水");
            } else if ("1".equals(runState)) {
                homeActualInfoVo.setRunState("发电");
            }
            homeActualInfoVo.setFalseAlarmRate(busiOnlineMonitorData.getFalseAlarmRate());
            homeActualInfoVo.setLossRate(busiOnlineMonitorData.getLossRate());
            homeActualInfoVo.setRepairCount(busiOnlineMonitorData.getRepairCount());
            homeActualInfoVo.setDTime(busiOnlineMonitorData.getCreatedTime());
        }
        homeActualInfoVo.setUseDate(busiArresterSensor.getUseDate());

        homeActualVo.setHomeActualInfoVo(homeActualInfoVo);
        LightningrodIm lightningrodIm = lightningrodImDao.get(new WherePrams()
                .where("sensor_id", param.getSensorCode())
                .orderBy("time_stamp desc  limit 1"));

        List<HomeActualDataVo> homeActualDataVos=new ArrayList<>();
        if(ObjectUtils.isEmpty(lightningrodIm)){
            return homeActualVo;
        }
        HomeActualDataVo homeActualDataVo=new HomeActualDataVo();
        HomeActualDataVo homeActualDataVo1=new HomeActualDataVo();
        HomeActualDataVo homeActualDataVo2=new HomeActualDataVo();
        HomeActualDataVo homeActualDataVo3=new HomeActualDataVo();
        homeActualDataVo.setName("系统电压(V)");
        homeActualDataVo1.setName("全电流(mA)");
        homeActualDataVo2.setName("阻性电流(mA)");
        homeActualDataVo3.setName("计数器动作次数");
        homeActualDataVo.setDTime(lightningrodIm.getTimeStamp());
        homeActualDataVo1.setDTime(lightningrodIm.getTimeStamp());
        homeActualDataVo2.setDTime(lightningrodIm.getTimeStamp());
        homeActualDataVo3.setDTime(lightningrodIm.getTimeStamp());
        homeActualDataVo.setValue(lightningrodIm.getSystemVoltage());
        homeActualDataVo1.setValue(lightningrodIm.getTotalCurrent());
        homeActualDataVo2.setValue(lightningrodIm.getResistiveCurrent());
        homeActualDataVo3.setValue(lightningrodIm.getActionCount());
        ArresterInsulationMonitorThreshold arresterInsulationMonitorThreshold = arresterInsulationMonitorThresholdDao.get(new WherePrams()
                .where("sensor_code", param.getSensorCode())
                .and("run_state", lightningrodIm.getRunState()));

        if(!ObjectUtils.isEmpty(arresterInsulationMonitorThreshold)){
            // B相
            if ("2".equals(busiArresterSensor.getPosition())) {
                homeActualDataVo1.setThresholdValue(arresterInsulationMonitorThreshold.getBFullCurrentThreshold());
                homeActualDataVo2.setThresholdValue(arresterInsulationMonitorThreshold.getBResistiveCurrentThreshold());
            }
            // C相
            else if ("3".equals(busiArresterSensor.getPosition())) {
                homeActualDataVo1.setThresholdValue(arresterInsulationMonitorThreshold.getCFullCurrentThreshold());
                homeActualDataVo2.setThresholdValue(arresterInsulationMonitorThreshold.getCResistiveCurrentThreshold());
            }
            // 如果不是B、C相则默认A相
            else {
                homeActualDataVo1.setThresholdValue(arresterInsulationMonitorThreshold.getAFullCurrentThreshold());
                homeActualDataVo2.setThresholdValue(arresterInsulationMonitorThreshold.getAResistiveCurrentThreshold());
            }
            homeActualDataVo.setThresholdValue("");
            homeActualDataVo3.setThresholdValue("");
        }
        homeActualDataVos.add(homeActualDataVo);
        homeActualDataVos.add(homeActualDataVo1);
        homeActualDataVos.add(homeActualDataVo2);
        homeActualDataVos.add(homeActualDataVo3);
        homeActualVo.setHomeActualDataVos(homeActualDataVos);
        return homeActualVo;
    }

    public  HomeActualInfoVo build(HomeActualInfoVo homeActualInfoVo,BusiArresterSensor busiTemperPoint,String mainTreeId){
        homeActualInfoVo.setEquipmentBrand(busiTemperPoint.getSensorBrand());
        homeActualInfoVo.setEquipmentName(busiTemperPoint.getSensorName());
        homeActualInfoVo.setInstallLocation(busiTemperPoint.getPositionDes());
        homeActualInfoVo.setEqmId(busiTemperPoint.getEquipmentId());
        homeActualInfoVo.setPhase(busiTemperPoint.getPosition());
        homeActualInfoVo.setManufactor(busiTemperPoint.getManufactor());
        homeActualInfoVo.setSensorBrand(busiTemperPoint.getSensorBrand());
        homeActualInfoVo.setUseDate(busiTemperPoint.getUseDate());
        homeActualInfoVo.setSensorId(busiTemperPoint.getSensorCode());
        homeActualInfoVo.setSensorName(busiTemperPoint.getSensorName());
        homeActualInfoVo.setMainTreeId(mainTreeId);
        return homeActualInfoVo;
    }
}