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

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.huatek.busi.common.BusiConstant;
import com.huatek.busi.common.DateUtils;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.dao.CapacitanceEquipmentImDao;
import com.huatek.busi.dao.SubstationMicStatisticsDao;
import com.huatek.busi.dao.TransformerInfraredMonitoringStatisticsDao;
import com.huatek.busi.dao.TransformerRunStatusStatisticsDao;
import com.huatek.busi.dto.AppendixCalDto;
import com.huatek.busi.entity.*;
import com.huatek.busi.mapper.BusiParamAppendixMapper;
import com.huatek.busi.mapper.TransformerRunStatusMapper;
import com.huatek.busi.service.*;
import com.huatek.busi.service.param.BusiParamAppendixService;
import com.huatek.busi.service.transformer.BusiOfflineTransformerBrandService;
import com.huatek.busi.task.transformer.TransformerDateOnlineService;
import com.huatek.busi.util.AppendixCal;
import com.huatek.busi.util.EvaluationNameUtil;
import com.huatek.busi.util.GisAssessUtilsNew;
import com.huatek.busi.vo.BusiOfflineTransformerBrandVo;
import com.huatek.busi.vo.BusiParamAppendixVo;
import com.huatek.busi.vo.TransformerEvaluateDataVo;
import com.huatek.busi.vo.epa.*;
import com.huatek.frame.base.util.Constants;
import com.huatek.torch.frame.exception.OwlException;
import com.huatek.torch.util.uuid.Uuid;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
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 java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
@Service(interfaceClass = AppendixAssessService.class)
@Transactional(rollbackFor = Exception.class)
public class AppendixAssessServiceImpl implements AppendixAssessService {

    @Reference(check = false)
    ICalculateStepService calculateStepService;

    @Autowired
    private BusiOfflineTransformerBrandService busiOfflineTransformerBrandService;

    @Autowired
    private TransformerDateOnlineService transformerDateOnlineService;
    @Autowired
    private BusiParamAppendixService busiParamAppendixService;

    @Autowired
    private BusiParamAppendixMapper busiParamAppendixMapper;

    @Autowired
    private TransformerInfraredMonitoringStatisticsDao transformerInfraredMonitoringStatisticsDao;

    @Autowired
    private CapacitanceEquipmentImDao capacitanceEquipmentImDao;

    @Autowired
    private AppendixAssessmentResultService appendixAssessmentResultService;

    @Autowired
    private TransformerRunStatusStatisticsDao transformerRunStatusStatisticsDao;

    @Autowired
    private SubstationMicStatisticsDao substationMicStatisticsDao;

    @Autowired
    private TransformerRunStatusMapper transformerRunStatusMapper;

    @Autowired
    private BusiEqmWarningService busiEqmWarningService;

    @Autowired
    private ITransformerEvaluateDataService iTransformerEvaluateDataService;


    int step = 0;
    int step1 = 0;
    int step2 = 0;
    int step3 = 0;
    int step4 = 0;
    int step5 = 0;
    JSONArray jsonArray = new net.sf.json.JSONArray();
    JSONArray jsonArraytaoguan = new net.sf.json.JSONArray();
    JSONArray jsonArrayqishen = new net.sf.json.JSONArray();
    JSONArray jsonArraylengque = new net.sf.json.JSONArray();
    JSONArray jsonArrayfeijiekaiguan = new net.sf.json.JSONArray();
    JSONArray jsonArraybaohuzhuangzhi = new net.sf.json.JSONArray();
    JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();

    JSONObject jsonObjecttaoguan = new com.alibaba.fastjson.JSONObject();
    JSONObject jsonObjectqishen = new com.alibaba.fastjson.JSONObject();
    JSONObject jsonObjectlengque = new com.alibaba.fastjson.JSONObject();
    JSONObject jsonObjectfeijiekaiguan = new com.alibaba.fastjson.JSONObject();
    JSONObject jsonObjectbaohuzhuangzhi = new com.alibaba.fastjson.JSONObject();
    /**
     * 附件算法
     * @param appendixCalDto
     * @param type
     * @return
     */
    @Override
    public AppendixAssessmentResult assessmentForAppendix(AppendixCalDto appendixCalDto, String type,String sensorName,TransformerEvaluateDataVo transformerEvaluateDataVo) {

        String siteId = appendixCalDto.getSiteId();
        String mainTreeId = appendixCalDto.getMainTreeId();
        BigDecimal β = appendixCalDto.getΒ();
        step = 0;
        step1 = 0;
        step2 = 0;
        step3 = 0;
        step4 = 0;
        step5 = 0;
        jsonArray = new net.sf.json.JSONArray();
        jsonArraytaoguan = new net.sf.json.JSONArray();
        jsonArrayqishen = new net.sf.json.JSONArray();
        jsonArraylengque = new net.sf.json.JSONArray();
        jsonArrayfeijiekaiguan = new net.sf.json.JSONArray();
        jsonArraybaohuzhuangzhi = new net.sf.json.JSONArray();
        BigDecimal x11 = BigDecimal.ZERO;
        BigDecimal x21 = BigDecimal.ZERO;
        BigDecimal x31 = BigDecimal.ZERO;
        BigDecimal x41 = BigDecimal.ZERO;
        BigDecimal x51 = BigDecimal.ZERO;

        CalculateStep calculateStep = new CalculateStep();
        calculateStep.setId(Uuid.getUUID());
        calculateStep.setSiteId(siteId);
        calculateStep.setEquipmentType(SiteConstants.FJ);
        calculateStep.setMainEquipmentId(mainTreeId);
        calculateStep.setExecuteMode(Integer.valueOf(Constants.DEFAULT_YES));
        calculateStep.setCreateTime(LocalDateTime.now());
        BusiParamAppendixVo numberPojo = busiParamAppendixMapper.findFirstLevelNumber(siteId, mainTreeId);
        if(ObjectUtils.isEmpty(numberPojo)){
            busiParamAppendixService.initBusiParams("",siteId, mainTreeId);
            numberPojo = busiParamAppendixMapper.findFirstLevelNumber(siteId, mainTreeId);
        }
        //x计算
        List<BusiParamAppendixVo> busiParamAppendixVos = busiParamAppendixService.findBusiParamAppendixWeights(siteId, mainTreeId, numberPojo.getNumber(), "fujian");

        // 附件评估结果
        AppendixAssessmentResult appendixAssessmentResult = new AppendixAssessmentResult();


        if(CollectionUtils.isEmpty(busiParamAppendixVos)){
            transformerDateOnlineService.warringEvaluating(SiteConstants.FJ, BusiConstant.GzType.GZ_TYPE25,"附件评测-没有初始化建模数据",mainTreeId,sensorName);
            log.info("没有初始化数据！");
            return appendixAssessmentResult;
        }
        BigDecimal temp;
        for (BusiParamAppendixVo busiParamAppendixVo : busiParamAppendixVos) {
            switch (busiParamAppendixVo.getName()) {
                case "taoguan":

                    BigDecimal x1 = calThree("taoguan", busiParamAppendixVo,appendixCalDto,transformerEvaluateDataVo,type);
                    x11 = x1.multiply(busiParamAppendixVo.getValue());
                    step += 1;
                    jsonObject.clear();
                    jsonObject.put("检测值", x1.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                    jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVo.getCalculatedValue()));
                    jsonObject.put("权重", busiParamAppendixVo.getValue());
                    GisAssessUtilsNew.setStep(jsonArray, step, busiParamAppendixVo.getDescription(), jsonObject.toJSONString(), String.valueOf(x11.setScale(4, BigDecimal.ROUND_HALF_UP)));
                    calStep(x1,appendixCalDto,jsonObjecttaoguan,jsonArraytaoguan,step1,type,numberPojo.getNumber().toString(),"1");
                    break;
                case "qishen":
                    BigDecimal x2 = calThree("qishen", busiParamAppendixVo,appendixCalDto,transformerEvaluateDataVo,type);
                    step += 1;
                    x21 = x2.multiply(busiParamAppendixVo.getValue());
                    jsonObject.clear();
                    jsonObject.put("检测值", x2.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                    jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVo.getCalculatedValue()));
                    jsonObject.put("权重", busiParamAppendixVo.getValue());
                    GisAssessUtilsNew.setStep(jsonArray, step, busiParamAppendixVo.getDescription(), jsonObject.toJSONString(), String.valueOf(x21.setScale(4, BigDecimal.ROUND_HALF_UP)));
                    calStep(x2,appendixCalDto,jsonObjectqishen,jsonArrayqishen,step2,type,numberPojo.getNumber().toString(),"2");
                    break;
                case "lengque":

                    BigDecimal x3 = calThree("lengque", busiParamAppendixVo,appendixCalDto,transformerEvaluateDataVo,type);
                    step += 1;

                    x31 = x3.multiply(busiParamAppendixVo.getValue());
                    jsonObject.clear();
                    jsonObject.put("检测值", x3.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                    jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVo.getCalculatedValue()));
                    jsonObject.put("权重", busiParamAppendixVo.getValue());
                    GisAssessUtilsNew.setStep(jsonArray, step, busiParamAppendixVo.getDescription(), jsonObject.toJSONString(), String.valueOf(x31.setScale(4, BigDecimal.ROUND_HALF_UP)));
                    calStep(x3,appendixCalDto,jsonObjectlengque,jsonArraylengque,step3,type,numberPojo.getNumber().toString(),"3");
                    break;
                case "feijiekaiguan":


                    BigDecimal x4 = calThree("feijiekaiguan", busiParamAppendixVo,appendixCalDto,transformerEvaluateDataVo,type);
                    step += 1;
                    x41 = x4.multiply(busiParamAppendixVo.getValue());
                    jsonObject.clear();
                    jsonObject.put("检测值", x4.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                    jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVo.getCalculatedValue()));
                    jsonObject.put("权重", busiParamAppendixVo.getValue());
                    GisAssessUtilsNew.setStep(jsonArray, step, busiParamAppendixVo.getDescription(), jsonObject.toJSONString(), String.valueOf(x41.setScale(4, BigDecimal.ROUND_HALF_UP)));
                    calStep(x4,appendixCalDto,jsonObjectfeijiekaiguan,jsonArrayfeijiekaiguan,step4,type,numberPojo.getNumber().toString(),"4");
                    break;
                case "baohuzhuangzhi":

                    BigDecimal x5 = calThree("baohuzhuangzhi", busiParamAppendixVo,appendixCalDto,transformerEvaluateDataVo,type);
                    step += 1;
                    x51 = x5.multiply(busiParamAppendixVo.getValue());
                    jsonObject.clear();
                    jsonObject.put("检测值", x5.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
                    jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVo.getCalculatedValue()));
                    jsonObject.put("权重", busiParamAppendixVo.getValue());
                    GisAssessUtilsNew.setStep(jsonArray, step, busiParamAppendixVo.getDescription(), jsonObject.toJSONString(), String.valueOf(x51.setScale(4, BigDecimal.ROUND_HALF_UP)));
                    calStep(x5,appendixCalDto,jsonObjectbaohuzhuangzhi,jsonArraybaohuzhuangzhi,step5,type,numberPojo.getNumber().toString(),"5");
                    break;
                default:
                    break;
            }
        }
        BigDecimal x = x11.add(x21).add(x31).add(x41).add(x51);
        step += 1;
        jsonObject.clear();
        GisAssessUtilsNew.setStep(jsonArray, step, "计算安全系数 计算", jsonObject.toJSONString(), String.valueOf(x.setScale(4, BigDecimal.ROUND_HALF_UP)));
        BigDecimal w = appendixCalDto.getΩ();
        step += 1;
        jsonObject.clear();
        GisAssessUtilsNew.setStep(jsonArray, step, "投运时间(H) 计算", jsonObject.toJSONString(), String.valueOf(w.setScale(4, BigDecimal.ROUND_HALF_UP)));

        step += 1;
        jsonObject.clear();
        GisAssessUtilsNew.setStep(jsonArray, step, "计算健康指数 计算", jsonObject.toJSONString(), String.valueOf(β.setScale(4, BigDecimal.ROUND_HALF_UP)));


        //故障率
        //故障率
        BigDecimal futureFailureRate = BigDecimal.ZERO;
        if(!x.equals(BigDecimal.ZERO)){
            futureFailureRate= AppendixCal.calFutureFailureRate(x, β, w).setScale(6, BigDecimal.ROUND_HALF_UP);
        }
        step += 1;
        jsonObject.clear();
        GisAssessUtilsNew.setStep(jsonArray, step, "设备未来故障概率 计算", jsonObject.toJSONString(), String.valueOf(futureFailureRate.setScale(4, BigDecimal.ROUND_HALF_UP)));
        appendixAssessmentResult.setSafetyFactor(x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
        appendixAssessmentResult.setId(Uuid.getUUID());
        appendixAssessmentResult.setSiteId(siteId);
        appendixAssessmentResult.setMainTreeId(mainTreeId);
        appendixAssessmentResult.setFutureFailureRate(futureFailureRate.toString());
        appendixAssessmentResult.setOperationTime(w.toString());
        appendixAssessmentResult.setHealthLevel(β.toString());
        appendixAssessmentResult.setAssessTime(LocalDateTime.now());
        appendixAssessmentResult.setType(type);
        appendixAssessmentResult.setSoureType("0");
        appendixAssessmentResultService.saveAppendixAssessmentResult(appendixAssessmentResult);
        calculateStep.setNumber(numberPojo.getNumber().toString());
        calculateStep.setPId(appendixAssessmentResult.getId());
        calculateStep.setStepJson(jsonArray.toString());
        calculateStepService.insert(calculateStep);
        return appendixAssessmentResult;
    }

    @Override
    public AppendixAssessmentResult assessmentForAppendixHandMovement(AppendixCalDto appendixCalDto, String type) {

        BusiOfflineTransformerBrandVo busiOfflineTransformerBrandVo = busiOfflineTransformerBrandService.getBusiOfflineTransformerBrandVo(appendixCalDto.getSiteId(), appendixCalDto.getMainTreeId());
        TransformerEvaluateDataVo transformerEvaluateDataVo = iTransformerEvaluateDataService.getLastByMainTreeId(appendixCalDto.getMainTreeId());
        if(null == transformerEvaluateDataVo){
            log.error("附件评测出错【站点：{};设备Code：{}】,错误信息如下:{}", appendixCalDto.getSiteId(), appendixCalDto.getMainTreeId(), "没有设置运行时间");
            throw new OwlException("缺少试验数据！");
        }
        if(null == busiOfflineTransformerBrandVo.getEquipmentDeliveryTime()){
            log.error("附件评测出错【站点：{};设备Code：{}】,错误信息如下:{}", appendixCalDto.getSiteId(), appendixCalDto.getMainTreeId(), "没有设置运行时间");
            throw new OwlException("没有设置运行时间！");
        }
        BigDecimal w = AppendixCal.calW(busiOfflineTransformerBrandVo.getEquipmentDeliveryTime());
        BigDecimal β = AppendixCal.calHi1(busiOfflineTransformerBrandVo.getEquipmentDeliveryTime());
        appendixCalDto.setΒ(β);
        appendixCalDto.setΩ(w);
        BigDecimal β1 = AppendixCal.calHi11(busiOfflineTransformerBrandVo.getEquipmentDeliveryTime(),busiOfflineTransformerBrandVo.getDesignLife());
        appendixCalDto.setΒ1(β1);
        return this.assessmentForAppendix(appendixCalDto,type,busiOfflineTransformerBrandVo.getTransformerName(),transformerEvaluateDataVo);
    }

    public  void calStep(BigDecimal x,AppendixCalDto appendixCalDto,com.alibaba.fastjson.JSONObject jsonObjectNew, net.sf.json.JSONArray jsonArrayNew ,int stepNew,String type, String number,String soureType ){
        String siteId = appendixCalDto.getSiteId();
        String mainTreeId = appendixCalDto.getMainTreeId();
        BigDecimal β =BigDecimal.ZERO;
        if("2".equals(soureType)){
            β = appendixCalDto.getΒ1();
        }else{
            β = appendixCalDto.getΒ();
        }
        AppendixAssessmentResult appendixAssessmentResult = new AppendixAssessmentResult();
        CalculateStep calculateStep = new CalculateStep();
        calculateStep.setId(Uuid.getUUID());
        calculateStep.setSiteId(siteId);
        calculateStep.setEquipmentType(SiteConstants.FJ);
        calculateStep.setMainEquipmentId(mainTreeId);
        calculateStep.setExecuteMode(Integer.valueOf(Constants.DEFAULT_YES));
        calculateStep.setCreateTime(LocalDateTime.now());
        stepNew += 1;
        jsonObjectNew.clear();
        GisAssessUtilsNew.setStep(jsonArrayNew, stepNew, "计算安全系数 计算", jsonObjectNew.toJSONString(), String.valueOf(x.setScale(4, BigDecimal.ROUND_HALF_UP)));
        BigDecimal w = appendixCalDto.getΩ();
        stepNew += 1;
        jsonObjectNew.clear();
        GisAssessUtilsNew.setStep(jsonArrayNew, stepNew, "投运时间(H) 计算", jsonObjectNew.toJSONString(), String.valueOf(w.setScale(4, BigDecimal.ROUND_HALF_UP)));

        stepNew += 1;
        jsonObjectNew.clear();
        GisAssessUtilsNew.setStep(jsonArrayNew, stepNew, "计算健康指数 计算", jsonObjectNew.toJSONString(), String.valueOf(β.setScale(4, BigDecimal.ROUND_HALF_UP)));

        //故障率
        BigDecimal futureFailureRate = BigDecimal.ZERO;
        if(!x.equals(BigDecimal.ZERO)){
            futureFailureRate= AppendixCal.calFutureFailureRate(x, β, w).setScale(6, BigDecimal.ROUND_HALF_UP);
        }
        stepNew += 1;
        jsonObjectNew.clear();
        GisAssessUtilsNew.setStep(jsonArrayNew, stepNew, "设备未来故障概率 计算", jsonObjectNew.toJSONString(), String.valueOf(futureFailureRate.setScale(4, BigDecimal.ROUND_HALF_UP)));
        appendixAssessmentResult.setSafetyFactor(x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
        appendixAssessmentResult.setId(Uuid.getUUID());
        appendixAssessmentResult.setSiteId(siteId);
        appendixAssessmentResult.setMainTreeId(mainTreeId);
        appendixAssessmentResult.setFutureFailureRate(futureFailureRate.toString());
        appendixAssessmentResult.setOperationTime(w.toString());
        appendixAssessmentResult.setHealthLevel(β.toString());
        appendixAssessmentResult.setAssessTime(LocalDateTime.now());
        appendixAssessmentResult.setType(type);
        appendixAssessmentResult.setSoureType(soureType);
        appendixAssessmentResultService.saveAppendixAssessmentResult(appendixAssessmentResult);
        calculateStep.setNumber(number);
        calculateStep.setPId(appendixAssessmentResult.getId());
        calculateStep.setStepJson(jsonArrayNew.toString());
        calculateStepService.insert(calculateStep);
    }

    /**
     * 计算X
     * @param
     * @param busiParamAppendixVo
     * @param appendixCalDto
     * @return
     */
    public BigDecimal calThree(String  type, BusiParamAppendixVo busiParamAppendixVo,AppendixCalDto appendixCalDto,TransformerEvaluateDataVo transformerEvaluateDataVo,String typeZi) {
        List<BusiParamAppendixVo> busiParamAppendixVos = busiParamAppendixService.findBusiParamAppendixWeights(busiParamAppendixVo.getSiteId(), busiParamAppendixVo.getMainEquipmentId(), busiParamAppendixVo.getNumber(), busiParamAppendixVo.getName());
        if (CollectionUtils.isEmpty(busiParamAppendixVos)) {
            return BigDecimal.ZERO;
        }
        //查询实验数据
        BigDecimal x = BigDecimal.ZERO;
        BigDecimal temp = BigDecimal.ZERO;
        double count = 0;
        for (BusiParamAppendixVo busiParamAppendixVothree : busiParamAppendixVos) {
            step += 1;
            if("taoguan".equals(type)){
                step1 += 1;
            }
            if("qishen".equals(type)){
                step2 += 1;
            }
            if("lengque".equals(type)){
                step3 += 1;
            }
            if("feijiekaiguan".equals(type)){
                step4 += 1;
            }
            if("baohuzhuangzhi".equals(type)){
                step5 += 1;
            }
            x = calX(busiParamAppendixVothree, appendixCalDto,transformerEvaluateDataVo,typeZi);
            if(null==busiParamAppendixVothree.getAValue() && null==busiParamAppendixVothree.getBValue()){
                temp=x.multiply(busiParamAppendixVothree.getValue());
                this.json(type,x,temp,busiParamAppendixVothree);
                count+=temp.doubleValue();
                break;
            }
            temp= this.temp(x,busiParamAppendixVothree);
            this.json(type,x,temp,busiParamAppendixVothree);
            count+=temp.doubleValue();

        }
        return  new BigDecimal(count);
    }

    /**
     * 计算x
     * @param x
     * @param busiParamAppendixVothree
     * @return
     */
    public  BigDecimal temp(BigDecimal x,BusiParamAppendixVo busiParamAppendixVothree){
        BigDecimal temp=BigDecimal.ZERO;
        if ("2".equals(busiParamAppendixVothree.getModel())) {
            temp = AppendixCal.clacFormulaDesc(busiParamAppendixVothree.getAValue().doubleValue(), busiParamAppendixVothree.getBValue().doubleValue(), x.doubleValue(), busiParamAppendixVothree.getValue().doubleValue(), busiParamAppendixVothree.getIsAttend());
        } else if("1".equals(busiParamAppendixVothree.getModel())){
            temp = AppendixCal.clacFormulaAsc(busiParamAppendixVothree.getAValue().doubleValue(), busiParamAppendixVothree.getBValue().doubleValue(), x.doubleValue(), busiParamAppendixVothree.getValue().doubleValue(), busiParamAppendixVothree.getIsAttend());
        }else{
            temp=x.multiply(busiParamAppendixVothree.getValue());
        }
        return temp;
    }

    /**
     * 组装监测设备的值
     * @param busiParamAppendixVo
     * @param appendixCalDto
     * @return
     */
    public  BigDecimal calX(BusiParamAppendixVo busiParamAppendixVo,AppendixCalDto appendixCalDto,TransformerEvaluateDataVo transformerEvaluateDataVo,String type){
        String testItem="套管试验";
        String  date = DateUtils.parseDateToStr( DateUtils.YYYY_MM_DD,DateUtils.addDays(new Date(),-1));
        BigDecimal x=BigDecimal.ONE;
        String mainTreeId = appendixCalDto.getMainTreeId();
        //末屏绝缘电阻（MΩ /  / // /
        if("jueyuandianzu".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getInsulationResistance())){
                x=new BigDecimal(transformerEvaluateDataVo.getInsulationResistance());
            }

        }
        //套管介损（tgδ） 例行试验
        if("tgjslx".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getCasingDielectricLoss())){
                x=new BigDecimal(transformerEvaluateDataVo.getCasingDielectricLoss());
            }
        }
        // 末屏介损
        if("wpjs".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getEndScreenDielectricDamage())){
                x=new BigDecimal(transformerEvaluateDataVo.getEndScreenDielectricDamage());
            }
        }
        //套管H2（μL/L）
        if("tgh2".equals(busiParamAppendixVo.getName()) ){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getCasingH2())){
                x=new BigDecimal(transformerEvaluateDataVo.getCasingH2());
            }
        }
        //套管CH4（μL/L）
        if("tgch4".equals(busiParamAppendixVo.getName()) ){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getCasingH2())){
                x=new BigDecimal(transformerEvaluateDataVo.getCasingCh4());
            }
        }
        //套管C2H2（μL/L）
        if("tgc2h2".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getCasingH2())){
                x=new BigDecimal(transformerEvaluateDataVo.getCasingC2h2());
            }
        }

        //油位下降% --在线监测
        if("ywxj".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getOilLevelDrop())){
                x=new BigDecimal(transformerEvaluateDataVo.getOilLevelDrop());
            }
        }
        //漏油次数
        if("lycs".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getOilLeaksCount())){
                x=new BigDecimal(transformerEvaluateDataVo.getOilLeaksCount());
            }
        }
        //变压器噪声（dB) --在线监测
        if("byqzs".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                EpaSoundVibrationVo soundEvaluateData = transformerDateOnlineService.getSoundEvaluateData(mainTreeId);
                x = new BigDecimal(soundEvaluateData.getNoisePoint());
            }else {
                if (StringUtils.isNotEmpty(transformerEvaluateDataVo.getTransformerNoise())) {
                    x = new BigDecimal(transformerEvaluateDataVo.getTransformerNoise());
                }
            }
        }
        EpaRunStatusDataVo runStatusEvaluateData = null;
        //水温 --在线监测
        if("sw".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                runStatusEvaluateData = transformerDateOnlineService.getRunStatusEvaluateData(mainTreeId);
                x=new BigDecimal(runStatusEvaluateData.getExitPressure());
            }else {
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getWaterTemperature())){
                    x=new BigDecimal(transformerEvaluateDataVo.getWaterTemperature());
                }
            }

        }
        //水压 --在线监测
        if("sy".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                runStatusEvaluateData = transformerDateOnlineService.getRunStatusEvaluateData(mainTreeId);
                x=new BigDecimal(runStatusEvaluateData.getOutletTemperature());
            }else {
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getWaterPressure())){
                    x=new BigDecimal(transformerEvaluateDataVo.getWaterPressure());
                }
            }

        }
        //环境温度 --在线监测
        if("hjwd".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                EpaEnvironmentDataVo epaEnvironmentDataVo = transformerDateOnlineService.getEnvironmentEvaluateData(mainTreeId);
                x=new BigDecimal(epaEnvironmentDataVo.getTemperature());
            }else {
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getEnvironmentTemperature())){
                    x=new BigDecimal(transformerEvaluateDataVo.getEnvironmentTemperature());
                }
            }

        }
        //全电流-- 在线监测·
        if("quandianliu".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                EpaCapacitanceDataVo epaCapacitanceDataVo = transformerDateOnlineService.getCapacitanceEvaluateData(mainTreeId);
                x=new BigDecimal(epaCapacitanceDataVo.getTotalCurrent());
            }else {
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getTotalCurrent())){
                    x=new BigDecimal(transformerEvaluateDataVo.getTotalCurrent());

                }
            }

        }
        //容性电流-- 在线监测·
        if("rxdl".equals(busiParamAppendixVo.getName())){

                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getCapacitiveCurrent())){
                    x=new BigDecimal(transformerEvaluateDataVo.getCapacitiveCurrent());
                }


        }
        //阻性电流-- 在线监测·
        if("zxdl".equals(busiParamAppendixVo.getName())){

                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getResistiveCurrent())){
                    x=new BigDecimal(transformerEvaluateDataVo.getResistiveCurrent());
                }


        }
        //电容量
        if("drl".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                EpaCapacitanceDataVo epaCapacitanceDataVo = transformerDateOnlineService.getCapacitanceEvaluateData(mainTreeId);
                x=new BigDecimal(epaCapacitanceDataVo.getCapacitance());
            }else {
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getResistiveCurrent())){
                    x=new BigDecimal(transformerEvaluateDataVo.getResistiveCurrent());
                }
            }

        }

        //红外温度-- 在线监测·
        if("hwwd".equals(busiParamAppendixVo.getName())){
            if("2".equals(type)){
                EpaInfraredMonitorDataVo epaInfraredMonitorDataVo = transformerDateOnlineService.getInfraredMonitorEvaluateData(mainTreeId);
                x=new BigDecimal(epaInfraredMonitorDataVo.getAvgTemp());
            }else{
                if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getInfraredTemperature())){
                    x=new BigDecimal(transformerEvaluateDataVo.getInfraredTemperature());
                }
            }

        }

        //风机损坏检修次数
        if("fjshjxcs".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getResistiveCurrent())){
                x=new BigDecimal(transformerEvaluateDataVo.getResistiveCurrent());
            }
        }
        //油击穿电压变化率（Kv，%）
        if("yjcdybhl".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getOilPuncture())){
                x=new BigDecimal(transformerEvaluateDataVo.getOilPuncture());
            }
        }
        //传动机构有无问题
        if("cdjgywwt".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getTransmissionGear())){
                x=new BigDecimal(transformerEvaluateDataVo.getTransmissionGear());
            }
        }
        //继电器动作
        if("jdqdz".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getRelayAction())){
                x=new BigDecimal(transformerEvaluateDataVo.getRelayAction());
            }
        }
        //压力释放阀动作
        if("ylsgfdz".equals(busiParamAppendixVo.getName())){
            if(StringUtils.isNotEmpty(transformerEvaluateDataVo.getReliefValveAction())){
                x=new BigDecimal(transformerEvaluateDataVo.getReliefValveAction());
            }
        }

        return x;
    }
    /**
     * 组装json
     * @param temp
     * @param busiParamAppendixVothree
     */
    public  void json(String type,BigDecimal x,BigDecimal temp,BusiParamAppendixVo busiParamAppendixVothree){
        if("taoguan".equals(type)){
            jsonObjecttaoguan.clear();
            jsonObjecttaoguan.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
            jsonObjecttaoguan.put("a值", busiParamAppendixVothree.getAValue());
            jsonObjecttaoguan.put("b值", busiParamAppendixVothree.getBValue());
            jsonObjecttaoguan.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
            jsonObjecttaoguan.put("权重", busiParamAppendixVothree.getValue());
            GisAssessUtilsNew.setStep(jsonArraytaoguan, step1, busiParamAppendixVothree.getDescription(), jsonObjecttaoguan.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));

        }
        if("qishen".equals(type)){
            jsonObjectqishen.clear();
            jsonObjectqishen.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
            jsonObjectqishen.put("a值", busiParamAppendixVothree.getAValue());
            jsonObjectqishen.put("b值", busiParamAppendixVothree.getBValue());
            jsonObjectqishen.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
            jsonObjectqishen.put("权重", busiParamAppendixVothree.getValue());
            GisAssessUtilsNew.setStep(jsonArrayqishen, step2, busiParamAppendixVothree.getDescription(), jsonObjectqishen.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));

        }
        if("lengque".equals(type)){
            jsonObjectlengque.clear();
            jsonObjectlengque.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
            jsonObjectlengque.put("a值", busiParamAppendixVothree.getAValue());
            jsonObjectlengque.put("b值", busiParamAppendixVothree.getBValue());
            jsonObjectlengque.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
            jsonObjectlengque.put("权重", busiParamAppendixVothree.getValue());
            GisAssessUtilsNew.setStep(jsonArraylengque, step3, busiParamAppendixVothree.getDescription(), jsonObjectlengque.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));

        }
        if("feijiekaiguan".equals(type)){
            jsonObjectfeijiekaiguan.clear();
            jsonObjectfeijiekaiguan.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
            jsonObjectfeijiekaiguan.put("a值", busiParamAppendixVothree.getAValue());
            jsonObjectfeijiekaiguan.put("b值", busiParamAppendixVothree.getBValue());
            jsonObjectfeijiekaiguan.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
            jsonObjectfeijiekaiguan.put("权重", busiParamAppendixVothree.getValue());
            GisAssessUtilsNew.setStep(jsonArrayfeijiekaiguan, step4, busiParamAppendixVothree.getDescription(), jsonObjectfeijiekaiguan.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));

        }
        if("baohuzhuangzhi".equals(type)){
            jsonObjectbaohuzhuangzhi.clear();
            jsonObjectbaohuzhuangzhi.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
            jsonObjectbaohuzhuangzhi.put("a值", busiParamAppendixVothree.getAValue());
            jsonObjectbaohuzhuangzhi.put("b值", busiParamAppendixVothree.getBValue());
            jsonObjectbaohuzhuangzhi.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
            jsonObjectbaohuzhuangzhi.put("权重", busiParamAppendixVothree.getValue());
            GisAssessUtilsNew.setStep(jsonArraybaohuzhuangzhi, step5, busiParamAppendixVothree.getDescription()+"计算", jsonObjectbaohuzhuangzhi.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));

        }
        jsonObject.clear();
        jsonObject.put("检测值", x.setScale(4, BigDecimal.ROUND_HALF_UP).toString());
        jsonObject.put("a值", busiParamAppendixVothree.getAValue());
        jsonObject.put("b值", busiParamAppendixVothree.getBValue());
        jsonObject.put("人工打分", new BigDecimal(busiParamAppendixVothree.getCalculatedValue()));
        jsonObject.put("权重", busiParamAppendixVothree.getValue());
        GisAssessUtilsNew.setStep(jsonArray, step, "计算", busiParamAppendixVothree.getDescription()+jsonObject.toJSONString(), String.valueOf(temp.setScale(4, BigDecimal.ROUND_HALF_UP)));
    }
}
