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

import com.alibaba.fastjson.JSONArray;
import com.huatek.busi.common.util.ComputeUtil;
import com.huatek.busi.dto.BusiOfflineGisRepairDto;
import com.huatek.busi.entity.*;
import com.huatek.busi.service.BusiOutlineGisExperimentDataService;
import com.huatek.busi.service.IecBreakerParamService;
import com.huatek.busi.service.arrester.RptGisMonitorService;
import com.huatek.busi.service.gis.*;
import com.huatek.busi.service.param.BusiParamGisService;
import com.huatek.busi.service.substation.SubstationMicGisService;
import com.huatek.busi.service.transformer.TransformerPdStatisticsService;
import com.huatek.busi.util.GisAssessUtils;
import com.huatek.busi.util.GisCreateUtil;
import com.huatek.busi.vo.*;
import com.huatek.torch.util.uuid.Uuid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
//@Service(interfaceClass = GisAssessService.class) 原算法
@Transactional(rollbackFor = Exception.class)
//public class GisAssessServiceImpl implements GisAssessService { 原算法
public class GisAssessServiceImpl{

	// 报告路径
	private String filePath = "dev/gis";

	// 804
	public static final String GIS_804 = "5eab181e80bc4a8f82b904cab4c9a963";

	// path
	public static final String PATH = "/script/formula_gis.js";

	@Value("${dataoutput.base.path}")
	private String basePath2;

	@Autowired
	private BusiParamGisService busiParamGisService;

	@Autowired
	private GisMechanicalPropertiesService gisMechanicalPropertiesService;

	@Autowired
	private BusiOutlineGisExperimentDataService busiOutlineGisExperimentdataService;

	@Autowired
	private BusiOfflineGisBrandService busiOfflineGisBrandService;

	@Autowired
	private BusiOfflineGisRepairService busiOfflineGisRepairService;

	@Autowired
	private IecBreakerParamService iecBreakerParamService;

	@Autowired
	private SubstationMicGisService substationMicGisService;

	@Autowired
	private RptGisMonitorSf6ChartsService rptGisMonitorSf6ChartsService;

	@Autowired
	private TransformerPdStatisticsService transformerPdStatisticsService;

	@Autowired
	private GisAssessmentResultService gisAssessmentResultService;

	@Autowired
	private RptGisMonitorService rptGisMonitorService;

	@Autowired
	private GisAssessmentResultDataService gisAssessmentResultDataService;

//	@Override 原算法
	public GisAssessmentResult assessmentForGis(String siteId, String mainTreeId) {
		if(!GIS_804.equals(mainTreeId)) {
			return null;
		}

		// Gis评估结果
		GisAssessmentResult gisAssessmentResult = new GisAssessmentResult();
		FileReader fileReader = null;
		try {
			// 加载js引擎
			String basePath = this.getClass().getResource(PATH).getPath();
			fileReader = ComputeUtil.readerJsFile(basePath);
			ScriptEngine engine = ComputeUtil.loadJsScriptEngine(fileReader);

			// 通过systemCode查找 GIS标牌信息
			BusiOfflineGisBrandVo busiOfflineGisBrandVo = busiOfflineGisBrandService.findBusiOfflineGISBrand(siteId, mainTreeId);
			String gisId = busiOfflineGisBrandVo.getId();
			String gisName = busiOfflineGisBrandVo.getGisName();
			// 组织文件名
			DateTimeFormatter dateTimeFormater2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
			LocalDate localDate = LocalDate.now();
			String date = dateTimeFormater2.format(localDate);
			String fileName = gisName + "_" + date + ".xml";
			log.info("--->> GIS名称：{}, id{}", gisName, gisId);

			// 获取最新的gis评测数据
			List<IecBreakerParam> iecBreakerParams;
			List<GisAssessmentResultData> gisAssessmentResultDataList = gisAssessmentResultDataService.findGisAssessmentResultDataByGisId(gisId);
			if(gisAssessmentResultDataList.isEmpty()){
				// GIS断开数据
				iecBreakerParams = iecBreakerParamService.findIecBreakerParam(siteId, mainTreeId);
			}else {
				//获取前一天的断开数据
				iecBreakerParams = iecBreakerParamService.findIecBreakerParamNow(siteId, mainTreeId,localDate.plusDays(-1));
			}
			
			TransformerPdStatistics transformerPdStatistics = new TransformerPdStatistics();
			transformerPdStatistics.setPdType("024001");
			transformerPdStatistics.setSiteId(siteId);
			transformerPdStatistics.setMainTreeId(mainTreeId);

			// 获取Gis的权重系数维护表
			Map<String, BusiParamGisVo> busiParamGisMap = new HashMap<>();
			List<BusiParamGisVo> busiParamGisVo = busiParamGisService.findBusiParamGisWeights(siteId, mainTreeId);
			if (!busiParamGisVo.isEmpty()) {
				busiParamGisMap = GisAssessUtils.busiParamGisList2Map(busiParamGisVo);
			}

			// 权重
			BigDecimal score_a = GisAssessUtils.getVal(busiParamGisMap, "yunxingshuju");
			BigDecimal score_b = GisAssessUtils.getVal(busiParamGisMap, "jueyuanjiezhi");
			BigDecimal score_c = GisAssessUtils.getVal(busiParamGisMap, "duankaimosun");
			BigDecimal score_d = GisAssessUtils.getVal(busiParamGisMap, "yunxingcanshu");
			IecBreakerParam iecBreakerParam = new IecBreakerParam();

			BigDecimal eddl = new BigDecimal("0");
			if (busiOfflineGisBrandVo != null) {

				eddl = GisAssessUtils.geteddl(busiOfflineGisBrandVo);
				log.info("额定电流(A)-标牌: {}", eddl);
			}

			BigDecimal dkdl = new BigDecimal("0");
			List<IecBreakerParam> iecBreakerList = iecBreakerParamService.findIecBreakerParam(siteId, mainTreeId);
			if (!iecBreakerList.isEmpty()) {
				IecBreakerParam iecBreaker = iecBreakerList.get(0);
				if (null != iecBreaker && null != iecBreaker.getAbortCurrent()) {
					dkdl = new BigDecimal(iecBreaker.getAbortCurrent());
					log.info("断开电流（短路器参数表中电流）:" + dkdl);
				}
			}

			log.info("---------------------------权重数据-------------------------------------------------------------------");
			log.info("运行数据权重：{}", score_a);
			log.info("绝缘介质权重：{}", score_b);
			log.info("断开磨损权重：{}", score_c);
			log.info("运行参数权重：{}", score_d);

			BigDecimal ws_miehushi = GisAssessUtils.getVal(busiParamGisMap, "jyjz_ws_miehushi");
			log.info("灭弧室权重：{}", ws_miehushi);

			GisMechanicalPropertiesVo gisMechanical = gisMechanicalPropertiesService.lastGisMechanicalProperties(siteId, mainTreeId);
			SubstationMicGisVo substationMicGis = substationMicGisService.findSubstationMicGis(siteId, mainTreeId);
			BigDecimal yxsj_a = GisAssessUtils.getVal(busiParamGisMap, "yxsj_daodianhuiludianzu");

			BigDecimal gis_yxsj_ddhldz_val = new BigDecimal("0");
			BigDecimal gis_yxsj_ddhldz = new BigDecimal("1");
			BusiOutlineGisExperimentData busiOutlineGisExperimentdata = busiOutlineGisExperimentdataService.findBusiOutlineDataByEquip(mainTreeId, siteId);
			if (busiOutlineGisExperimentdata != null) {
				gis_yxsj_ddhldz_val = GisAssessUtils.getDdhldz(busiOutlineGisExperimentdata);
				log.info("导电回路电阻(微欧)：{}", gis_yxsj_ddhldz_val);

				BigDecimal aVal = GisAssessUtils.getaVal(busiParamGisMap, "yxsj_daodianhuiludianzu");
				BigDecimal bVal = GisAssessUtils.getbVal(busiParamGisMap, "yxsj_daodianhuiludianzu");
				gis_yxsj_ddhldz = GisAssessUtils.formulaForUpAndDown(gis_yxsj_ddhldz_val, "down", aVal, bVal);
			}

			BigDecimal h1;
			BigDecimal h2;
			BigDecimal h3;
			BigDecimal h4;
			BigDecimal h5;
			BigDecimal h6;
			BigDecimal h7;
			BigDecimal ddhldz_result = GisAssessUtils.calcValue(gis_yxsj_ddhldz, yxsj_a, score_a);
			log.info("----------------------------------导电回路电阻begin----------------------------------");
			log.info("  导电回路电阻计算公式：r1=(导电回路电阻计算值）*e1*m4(运行数据权重）");
			log.info("  e1=导电回路电阻权重,m4=运行参数权重");
			log.info(" 导电回路电阻计算值：{}, 导电回路电阻权重e1：{}, 运行数据权重 m4：{} ", gis_yxsj_ddhldz, yxsj_a, score_a);
			log.info("  导电回路电阻 r1 = {}", ddhldz_result);
			log.info("----------------------------------导电回路电阻end----------------------------------");

			BigDecimal yxsj_b = GisAssessUtils.getVal(busiParamGisMap, "yxsj_shijiacanshu");
			BigDecimal yxsj_c = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sdtz_qitafangmian");
			log.info("时间参数权重: {}, 其他方面权重: {}", yxsj_b, yxsj_c);

			String gis_yxsj_sjcs = "1";
			BigDecimal hz_btq_val = new BigDecimal(0);
			BigDecimal hz_btq = new BigDecimal(0);
			BigDecimal fz_btq_val = new BigDecimal(0);
			BigDecimal fz_btq = new BigDecimal(0);
			BigDecimal sjcs_a = new BigDecimal(0);
			BigDecimal sjcs_b = new BigDecimal(0);
			BigDecimal hzbtq_result = new BigDecimal(0);
			BigDecimal yxsj_sudutezheng = new BigDecimal(0);
			if (gisMechanical != null) {
				hz_btq_val = GisAssessUtils.getHzbtq(gisMechanical);

				// 合闸不同期
				hz_btq = GisAssessUtils.formulaForUpAndDown(hz_btq_val, "down",
						GisAssessUtils.getaVal(busiParamGisMap, "yxsj_sjcs_hezhabutongqi"),
						GisAssessUtils.getbVal(busiParamGisMap, "yxsj_sjcs_hezhabutongqi"));

				fz_btq_val = GisAssessUtils.getFzbtq(gisMechanical);

				//分闸不同期
				fz_btq = GisAssessUtils.formulaForUpAndDown(fz_btq_val, "down",
						GisAssessUtils.getaVal(busiParamGisMap, "yxsj_sjcs_fenzhabutongqi"),
						GisAssessUtils.getbVal(busiParamGisMap, "yxsj_sjcs_fenzhabutongqi"));
				
				sjcs_a = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sjcs_hezhabutongqi");
				log.info("合闸不同期权重值：{}", sjcs_a);

				sjcs_b = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sjcs_fenzhabutongqi");
				log.info("分闸不同期权重值：{}", sjcs_b);

				// 速度特性权重
				yxsj_sudutezheng = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sudutezheng");
				// 合闸不同期,分闸不同期最终计算结果
				hzbtq_result = GisAssessUtils.gethzbtqAndfzbtqValue(hz_btq, sjcs_a, fz_btq, sjcs_b, yxsj_b, score_d);
				log.info("-----------------------合闸不同期,分闸不同期begin----------------------------------");
				log.info("合闸不同期分闸不同期计算公式：r2={(合闸不同期）*f1+（分闸不同期）*f2}*f3（时间参数权重）*m4");
				log.info("f1=合闸不同期权重，f2=分闸不同期权重，f3=时间参数权重,m4=运行参数权重");
				log.info("  合闸不同期升降计算结果：{}, 合闸不同期权重值 f1：{}, 分闸不同期升降计算结果：{}, 分闸不同期权重值 f2：{}, 时间参数权重：{}, 运行参数权重 m4 ：{}", hz_btq, sjcs_a, hz_btq, sjcs_b, yxsj_b, score_d);
				log.info("  合闸不同期,分闸不同期计算结果r2 = {}", hzbtq_result);
				log.info("-----------------------合闸不同期,分闸不同期end----------------------------------");

				gis_yxsj_sjcs = ComputeUtil.eval(engine, "gis_yxsj_sjcs", hz_btq, fz_btq, sjcs_a, sjcs_b);
				log.info("运行时间-时间参数：" + gis_yxsj_sjcs);
			}

			BigDecimal gfSpeend_val = GisAssessUtils.getGfSpeend(gisMechanical);
			log.info("刚分速度：{}", gfSpeend_val);

			BigDecimal gfSpeend = GisAssessUtils.formulaForUpAndDown(gfSpeend_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "yxsj_sdtz_gangfensudu"),
					GisAssessUtils.getbVal(busiParamGisMap, "yxsj_sdtz_gangfensudu"));
			log.info("刚分速度升降计算结果：{}", gfSpeend);

			BigDecimal yxsd_a = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sdtz_gangfensudu");
			log.info("刚分速度权重值：{}", yxsd_a);

			BigDecimal ghSpeend_val = GisAssessUtils.getGhSpeend(gisMechanical);
			log.info("刚分速度：{}", ghSpeend_val);

			BigDecimal ghSpeend = GisAssessUtils.formulaForUpAndDown(ghSpeend_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "yxsj_sdtz_ganghesudu"),
					GisAssessUtils.getbVal(busiParamGisMap, "yxsj_sdtz_ganghesudu"));
			log.info("刚合速度：{}", ghSpeend);

			BigDecimal yxsd_b = GisAssessUtils.getVal(busiParamGisMap, "yxsj_sdtz_ganghesudu");
			log.info("刚合速度权重值：{}", yxsd_b);

			BigDecimal gfSpeend_result = GisAssessUtils.gethzbtqAndfzbtqValue(gfSpeend, yxsd_a, ghSpeend, yxsd_b,
					yxsj_sudutezheng, score_d);
			log.info("-----------------------刚分速度,刚合速度  begin----------------------------------");
			log.info("  刚分速度,刚合速度计算公式：r3={(刚分速度）*g1+（刚合速度）*g2}*g3（速度特性权重）*m4");
			log.info("  g1=刚合速度权重，g2=刚分速度权重，g3=速度特性权重");
			log.info("  刚分速度：{}, 刚分速度权重g1：{}, 刚合速度：{}, 刚合速度权重g2：{}, 速度特性权重 g3 ：{}, 运行参数权重 m4 ：{}", gfSpeend, yxsd_a, ghSpeend_val, yxsd_a, yxsj_sudutezheng, score_d);
			log.info("  刚分速度,刚合速度 r3 = {}", gfSpeend_result);
			log.info("-----------------------刚分速度,刚合速度  end----------------------------------");

			h1 = ddhldz_result.add(hzbtq_result).add(gfSpeend_result);
			log.info("---------------------------------h1  begin----------------------------------");
			log.info("  h1计算公式：h1=r1+r2+r3");
			log.info("  导电回路电阻 r1 = {},  分闸不同期,合闸不同期计算结果r2：{},  刚分速度,刚合速度r3：{}", ddhldz_result, hzbtq_result, gfSpeend_result);
			log.info(" h1计算结果 = " + h1);
			log.info("---------------------------------h1   end----------------------------------");


			BigDecimal yl_val;
			BigDecimal yl;
			BigDecimal wshl_val;
			BigDecimal wshl;
			BigDecimal qtxl_a = GisAssessUtils.getVal(busiParamGisMap, "jyjz_qitiyali");
			BigDecimal qtxl_b = GisAssessUtils.getVal(busiParamGisMap, "jyjz_weishui");
			// TODO 3 绝缘介质总和
			String gis_qtxl = "1";
			BigDecimal jyjz_qitiyali = GisAssessUtils.getVal(busiParamGisMap, "jyjz_qitiyali");
			log.info("绝缘介质 -->> 3.1 气体压力权重：{}", jyjz_qitiyali);
			BigDecimal jyjz_weishui = GisAssessUtils.getVal(busiParamGisMap, "jyjz_weishui");
			log.info("绝缘介质 -->> 3.2 气体压力微水含量权重：{}", jyjz_weishui);
			BigDecimal kdms_jfl = GisAssessUtils.getVal(busiParamGisMap, "kdms_jfl");
			log.info("绝缘介质 -->>3.3 气体压力局放量权重：{}", kdms_jfl);
			BigDecimal kdmo_jfcs = GisAssessUtils.getVal(busiParamGisMap, "kdmo_jfcs");
			log.info("绝缘介质 -->>3.4 局放次数权重：{}", kdmo_jfcs);

			List<RptGisMonitorSf6Charts> rptGisMonitorSf6Chartses = rptGisMonitorSf6ChartsService
					.findRptGisMonitorSf6Chartses(siteId, mainTreeId);

			yl_val = GisAssessUtils.getQtxl(mainTreeId, mainTreeId, rptGisMonitorSf6Chartses);

			yl = GisAssessUtils.formulaForUpAndDown(yl_val, "up",
					GisAssessUtils.getaVal(busiParamGisMap, "jyjz_qitiyali"),
					GisAssessUtils.getbVal(busiParamGisMap, "jyjz_qitiyali"));

			wshl_val = GisAssessUtils.getWshl(mainTreeId, mainTreeId, rptGisMonitorSf6Chartses);

			wshl = GisAssessUtils.formulaForUpAndDown(wshl_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "jyjz_qitixieya_miehushi"),
					GisAssessUtils.getbVal(busiParamGisMap, "jyjz_qitixieya_miehushi"));

			jyjz_qitiyali = GisAssessUtils.getVal(busiParamGisMap, "jyjz_qitiyali");
			BigDecimal j1 = GisAssessUtils.calcValue(yl, jyjz_qitiyali, score_b);
			log.info("---------------------------------j1  begin----------------------------------");
			log.info("  j1计算公式：j1=(气体压力）*k1*n4");
			log.info("  k1=气体压力权重，n4=绝缘介质权重");
			log.info("  气体压力：{}, 气体压力权重k1：{}, 绝缘介质权重n4: {}", yl, jyjz_qitiyali, score_b);
			log.info("  j1 = {}", j1);
			log.info("---------------------------------j1  end----------------------------------");

			BigDecimal j2 = GisAssessUtils.calcValue(wshl, jyjz_weishui, score_b);
			log.info("---------------------------------j2  begin----------------------------------");
			log.info("  局放量计算公式：j2=(微水含量）*k2*n4");
			log.info("  k2=微水含量权重,n4=绝缘介质权重");
			log.info("   微水含量：{}, 微水含量权重k2：{}, 绝缘介质权重n4: {}", wshl, jyjz_weishui, score_b);
			log.info("  j2 = {}", j2);
			log.info("---------------------------------j2  end----------------------------------");

			BigDecimal jfcs_val;
			BigDecimal jfcs;
			List<TransformerPdStatistics> transformerGisPdStatistics = transformerPdStatisticsService.findTransformerGisPdStatistics(transformerPdStatistics);
			jfcs_val = GisAssessUtils.getJfcs(mainTreeId, mainTreeId, transformerGisPdStatistics);
			jfcs = GisAssessUtils.formulaForUpAndDown(jfcs_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "kdmo_jfcs"),
					GisAssessUtils.getbVal(busiParamGisMap, "kdmo_jfcs"));

			BigDecimal jfl;
			BigDecimal jfl_val;
			BigDecimal jf_a = GisAssessUtils.getVal(busiParamGisMap, "kdms_jfl");
			BigDecimal jf_b = GisAssessUtils.getVal(busiParamGisMap, "kdmo_jfcs");

			jfl_val = GisAssessUtils.getJfl(mainTreeId, mainTreeId, transformerGisPdStatistics);
			jfl = GisAssessUtils.formulaForUpAndDown(jfl_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "kdms_jfl"),
					GisAssessUtils.getbVal(busiParamGisMap, "kdms_jfl"));

			BigDecimal j3 = GisAssessUtils.calcfdcs(jfcs, jf_b, jfl, jf_a, score_b);
			log.info("---------------------------------j3 begin----------------------------------");
			log.info("  j3计算公式：j3={(局放次数）*k3+(局放放电量）*k4}*n4");
			log.info("  k3=局放次数权重，k4=局放放电量权重,n4=绝缘介质权重");
			log.info("   局放次数：{}, 局放次数权重k3：{}, 局放放电量: {}, 局放放电量权重k4: {}, 绝缘介质权重n4: {}", jfcs, jf_b, jfl, jf_a, score_b);
			log.info("   j3 = {}", j3);
			log.info("---------------------------------j3  end----------------------------------");

			h2 = j1.add(j2).add(j3);
			log.info("---------------------------------h2 begin----------------------------------");
			log.info("  h2计算公式：h2=j1+j2+j3");
			log.info("  j1 = {}, j2 = {}, j3 = {}", j1, j2, j3);
			log.info("  h2  = " + h2);
			log.info("----------------------------------h2   end----------------------------------");

			// 开断磨损
			String gis_kdms = "1";
			BusiOfflineGisRepairVo gisRepair = busiOfflineGisRepairService.findBusiOfflineGisRepair(mainTreeId, siteId);
			BigDecimal kdms_a = GisAssessUtils.getVal(busiParamGisMap, "dkms_leijidongzuocishu");
			BigDecimal kdms_b = GisAssessUtils.getVal(busiParamGisMap, "dkms_shiyongnianxian");
			BigDecimal kdms_c = GisAssessUtils.getVal(busiParamGisMap, "dkms_xiangduidianmosun");

			// 开断电流，开断次数
			RptGisMonitor rptGisMonitor = rptGisMonitorService.findRptGisMonitor(mainTreeId, siteId);

			// 使用年限得分
			String shiyongnianxian_total = "";
			// 累积动作次数得分
			String leijidongzuocishu_total = "";
			// 相对电磨损程度得分
			String xiangduidianmosun_total = "";
			// 开断磨损总得分
			String gis_kdmo_total = "";

			BigDecimal synx_val = new BigDecimal(0);
			BigDecimal synx = new BigDecimal(0);
			BigDecimal synxResult;
			if (busiOfflineGisBrandVo != null) {
				synx_val = GisAssessUtils.getSynx(mainTreeId, mainTreeId, busiOfflineGisBrandVo);
				log.info("使用年限时间：{}", synx_val);
				// synx升降后的计算使用年限
				synx = GisAssessUtils.formulaForUpAndDown(synx_val, "down",
						GisAssessUtils.getaVal(busiParamGisMap, "dkms_shiyongnianxian"),
						GisAssessUtils.getbVal(busiParamGisMap, "dkms_shiyongnianxian"));
			}

			BigDecimal xdmscd_val = new BigDecimal(0);
			BigDecimal dkcsFor100_val = new BigDecimal(0);
			BigDecimal dkcsFor100 = new BigDecimal(0);
			BigDecimal xdmscd;
			BigDecimal xdmsdResult;
			BigDecimal ljdkscResult;
			BigDecimal eddkdl = new BigDecimal("0");
			if (busiOfflineGisBrandVo != null) {
				eddkdl = GisAssessUtils.getEddkdl(busiOfflineGisBrandVo);
				eddkdl = eddkdl.multiply(new BigDecimal("1000"));
				log.info("触头额定断开电流(A)-标牌：{}", eddkdl);
			}

			//评测中间结果如果为空取全部数据进行评测
			if(gisAssessmentResultDataList.isEmpty()) {
				if (!iecBreakerParams.isEmpty()) {
					dkcsFor100_val = GisAssessUtils.getDkcsesFor100(iecBreakerParams, eddkdl);
					dkcsFor100 = GisAssessUtils.formulaForUpAndDown(dkcsFor100_val, "down",
							GisAssessUtils.getaVal(busiParamGisMap, "dkms_leijidongzuocishu"),
							GisAssessUtils.getbVal(busiParamGisMap, "dkms_leijidongzuocishu"));
					
					// 触头磨损率
					xdmscd_val = GisAssessUtils.getMslsForFh(iecBreakerParams, eddkdl);
					xdmscd = GisAssessUtils.formulaForUpAndDown(xdmscd_val, "down",
							GisAssessUtils.getaVal(busiParamGisMap, "dkms_xiangduidianmosun"),
							GisAssessUtils.getbVal(busiParamGisMap, "dkms_xiangduidianmosun"));

					shiyongnianxian_total = GisAssessUtils.calcMultiply(kdms_c, xdmscd).toString();
					log.info("使用年限得分：{}", shiyongnianxian_total);

					xiangduidianmosun_total = GisAssessUtils.calcMultiply(kdms_b, synx).toString();
					log.info("相对电磨损程度得分：{}", xiangduidianmosun_total);

					leijidongzuocishu_total = GisAssessUtils.calcMultiply(kdms_a, dkcsFor100).toString();
					log.info("累积动作次数得分：{}", leijidongzuocishu_total);

					gis_kdms = ComputeUtil.eval(engine, "gis_kdms", dkcsFor100, synx, xdmscd, kdms_a, kdms_b, kdms_c);
					gis_kdmo_total = GisAssessUtils.calcMultiply(score_c, new BigDecimal(gis_kdms)).toString();
					log.info("开断磨损得分：{}", gis_kdmo_total);
				} else {
					shiyongnianxian_total = kdms_b.toString();
					log.info("使用年限得分：{}", shiyongnianxian_total);
					leijidongzuocishu_total = kdms_a.toString();
					log.info("累积动作次数得分：{}", leijidongzuocishu_total);
					xiangduidianmosun_total = kdms_c.toString();
					log.info("相对电磨损程度得分：{}", xiangduidianmosun_total);
					gis_kdmo_total = score_c.toString();
					log.info("开断磨损得分：{}", gis_kdmo_total);
				}
			} else if(!gisAssessmentResultDataList.isEmpty() && iecBreakerParams.isEmpty()) {
				//评测中间结果不为空，参数表取得前一天评测数据为空，取评测中间结果数据最为评测
				GisAssessmentResultData gisAssessmentResultData = gisAssessmentResultDataList.get(0);
					dkcsFor100_val = new BigDecimal(gisAssessmentResultData.getDkcses());
					dkcsFor100 = GisAssessUtils.formulaForUpAndDown(dkcsFor100_val, "down",
							GisAssessUtils.getaVal(busiParamGisMap, "dkms_leijidongzuocishu"),
							GisAssessUtils.getbVal(busiParamGisMap, "dkms_leijidongzuocishu"));
					// 触头磨损率
					xdmscd_val = new BigDecimal(gisAssessmentResultData.getContactWearRate());
					xdmscd = GisAssessUtils.formulaForUpAndDown(xdmscd_val, "down",
							GisAssessUtils.getaVal(busiParamGisMap, "dkms_xiangduidianmosun"),
							GisAssessUtils.getbVal(busiParamGisMap, "dkms_xiangduidianmosun"));

					gis_kdms = ComputeUtil.eval(engine, "gis_kdms", dkcsFor100, synx, xdmscd, kdms_a, kdms_b, kdms_c);
			} else {
				//评测中间结果、参数表中前一天评测数据都不为空，评测数据+断开参数表作为新评测数据。
				GisAssessmentResultData gisAssessmentResultData = gisAssessmentResultDataList.get(0);
				dkcsFor100_val =new BigDecimal(gisAssessmentResultData.getContactWearRate()).add(GisAssessUtils.getDkcsesFor100(iecBreakerParams, eddkdl));
				dkcsFor100 = GisAssessUtils.formulaForUpAndDown(dkcsFor100_val, "down",
						GisAssessUtils.getaVal(busiParamGisMap, "dkms_leijidongzuocishu"),
						GisAssessUtils.getbVal(busiParamGisMap, "dkms_leijidongzuocishu"));

				// 触头磨损率
				xdmscd_val =new BigDecimal(gisAssessmentResultData.getDkcses()).add(GisAssessUtils.getDkcsesFor100(iecBreakerParams, eddkdl));
				xdmscd = GisAssessUtils.formulaForUpAndDown(xdmscd_val, "down",
						GisAssessUtils.getaVal(busiParamGisMap, "dkms_xiangduidianmosun"),
						GisAssessUtils.getbVal(busiParamGisMap, "dkms_xiangduidianmosun"));

				gis_kdms = ComputeUtil.eval(engine, "gis_kdms", dkcsFor100, synx, xdmscd, kdms_a, kdms_b, kdms_c);
			}

			BigDecimal ljdkcs = GisAssessUtils.getLjdkcs(mainTreeId, mainTreeId, rptGisMonitor);
			log.info("累计开断次数：{}", ljdkcs);
			// 相对磨损程度计算
			xdmsdResult = GisAssessUtils.calcValue(ljdkcs, kdms_a, score_c);
			log.info("----------------------------------相对磨损程度 t3 begin----------------------------------");
			log.info(" 相对磨损程度计算公式：t3=(累计动作次数）*a3*v4");
			log.info("  a3=累计动作次数权重，v4=开断磨损权重");
			log.info("  累计动作次数：{},累计动作次数权重 a3：{}, 断开磨损权重 v4：{}", ljdkcs, kdms_a, score_c);
			log.info("  相对磨损程度 t3 = {}", xdmsdResult);
			log.info("----------------------------------相对磨损程度 t3 end----------------------------------");

			// 使用年限最终结果: xdmsdResult 相对磨损程度 xiangduidianmosun_total 相对磨损程度权重 score_c 断开磨损权重
			synxResult = GisAssessUtils.calcValue(xdmsdResult, kdms_c, score_c);
			log.info("----------------------------------使用年限计算begin----------------------------------");
			log.info("  使用年限计算公式：t2=(相对磨损程度）*a2*v4");
			log.info("  a2=相对磨损程度权重，v4=开断磨损权重");
			log.info("  相对磨损程度：{},相对磨损程度权重：{}, 断开磨损权重 v4：{}", xdmsdResult, kdms_c, score_c);
			log.info("  使用年限 t2 = {}", synxResult);
			log.info("----------------------------------使用年限计算end----------------------------------");

			// 累计开断次数最终结果: synxResult 使用年限 xiangduidianmosun_total 相对磨损程度权重 score_c 断开磨损权重
			ljdkscResult = GisAssessUtils.calcValue(synxResult, kdms_b, score_c);
			log.info("----------------------------------累计开断次数begin----------------------------------");
			log.info("  累计开断次数计算公式：t1=（使用年限）*a1*v4");
			log.info("  a1=使用年限权重，v4=开断磨损权重");
			log.info("  使用年限：{},使用年限权重a1：{}, 断开磨损权重 v4：{}", synxResult, kdms_b, score_c);
			log.info("  累计开断次数最 t1 = {}", ljdkscResult);
			log.info("----------------------------------累计开断次数end----------------------------------");

			h3 = synxResult.add(xdmsdResult).add(ljdkscResult);
			log.info("----------------------------------h3 begin----------------------------------");
			log.info("  h3计算公式：h3=t1+t2+t3");
			log.info("  累计开断次数 t1：{},使用年限t2：{}, 相对磨损程度t3：{}", ljdkscResult, synxResult, xdmsdResult);
			log.info("  h3 = {}", h3);
			log.info("----------------------------------h3 end----------------------------------");

			// TODO 4.1 运行参数 --- >工作环境
			BigDecimal syhjwd_val;
			BigDecimal syhjwd;
			BigDecimal gzhj_a;
			BigDecimal syhjsd_val;
			BigDecimal syhjsd;
			BigDecimal gzhj_b;
			BigDecimal syhj;
			BigDecimal qtys;
			BigDecimal gzhj_d;
			BigDecimal gzhj_c;
			String gis_gzhj = "1";
			BigDecimal sxcs_a = GisAssessUtils.getVal(busiParamGisMap, "yxcs_gongzuohuanjing");
			// 外观权重
			BigDecimal sxcs_b = GisAssessUtils.getVal(busiParamGisMap, "yxcs_waiguang");
			// 厂家权重
			BigDecimal sxcs_c = GisAssessUtils.getVal(busiParamGisMap, "yxcs_changjia");
			BigDecimal wgqk_f = GisAssessUtils.getVal(busiParamGisMap, "yxcs_dlqwh");
			// 断路器维护权重
			BigDecimal yxcs_dlqwh = GisAssessUtils.getVal(busiParamGisMap, "yxcs_dlqwh");
			syhjwd_val = GisAssessUtils.getSyhjwd(mainTreeId, mainTreeId, substationMicGis);
			log.info("机械特性-使用环境温度：{}", syhjwd_val);

			syhjwd = GisAssessUtils.formulaForUpAndDown(syhjwd_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "yxcs_gzhj_wendu"),
					GisAssessUtils.getbVal(busiParamGisMap, "yxcs_gzhj_wendu"));

			gzhj_a = GisAssessUtils.getVal(busiParamGisMap, "yxcs_gzhj_wendu");
			syhjsd_val = GisAssessUtils.getSyhjsd(mainTreeId, mainTreeId, substationMicGis);
			log.info("机械特性-使用环境湿度：{}", syhjsd_val);

			syhjsd = GisAssessUtils.formulaForUpAndDown(syhjsd_val, "down",
					GisAssessUtils.getaVal(busiParamGisMap, "yxcs_gzhj_shidu"),
					GisAssessUtils.getbVal(busiParamGisMap, "yxcs_gzhj_shidu"));
			gzhj_b = GisAssessUtils.getVal(busiParamGisMap, "yxcs_gzhj_shidu");

			syhj = GisAssessUtils.getCafs(gisRepair);
			log.info("检修记录-尘埃、腐蚀：{}", syhj);

			qtys = GisAssessUtils.getQt(busiOfflineGisBrandVo);
			gzhj_d = GisAssessUtils.getVal(busiParamGisMap, "yxcs_gzhj_qitayinsu");
			gzhj_c = GisAssessUtils.getVal(busiParamGisMap, "yxcs_gzhj_chenai");
			log.info("其他因素权重：{}, 尘埃权重: {}", gzhj_d, gzhj_c);

			// syhjwd 使用环境温度 gzhj_a 使用环境温度权重 sxcs_a 工作环境权重
			BigDecimal wd = GisAssessUtils.calcValue(syhjwd, gzhj_a, sxcs_a);
			log.info("---------------------------------使用环境温度begin----------------------------------");
			log.info("  使用环境温度计算公式：(温度参数）*b2*d4");
			log.info("  温度参数(使用环境温度升降序计算结果)：{},使用环境温度权重b2：{}, 工作环境权重 d4：{}", syhjwd, gzhj_a, sxcs_a);
			log.info("  使用环境温度计算结果  = {}", wd);
			log.info("---------------------------------使用环境温度end----------------------------------");

			// syhjwd 使用环境湿度 gzhj_a 使用环境湿度权重 sxcs_a 工作环境权重
			BigDecimal sd = GisAssessUtils.calcValue(syhjsd, syhjsd, sxcs_a);
			log.info("---------------------------------使用环境湿度begin----------------------------------");
			log.info("  使用环境湿度计算公式：（湿度参数）*b1*d4");
			log.info("  湿度参数(使用环境湿度升降序计算结果)：{},使用环境湿度权重b1：{}, 工作环境权重 d4：{}", syhjsd, gzhj_b, sxcs_a);
			log.info("  使用环境湿度计算结果  = {}", sd);
			log.info("---------------------------------使用环境湿度end----------------------------------");

			// 检修记录-尘埃、腐蚀
			BigDecimal hj = GisAssessUtils.calcValue(syhj, gzhj_c, sxcs_a);
			log.info("---------------------------------空气质量begin----------------------------------");
			log.info("  空气质量计算公式：(尘埃、腐蚀）*b3*d4");
			log.info("  空气质量：{}, 尘埃、腐蚀权重b3：{}, 工作环境权重 d4：{}", syhj, gzhj_c, sxcs_a);
			log.info("  空气质量算结果  = {}", hj);
			log.info("---------------------------------空气质量end----------------------------------");

			BigDecimal ys = GisAssessUtils.calcValue(qtys, gzhj_d, gzhj_a);
			log.info("---------------------------------海拔begin----------------------------------");
			log.info("  海拔计算公式：(海拔）*b4*d4}");
			log.info("  海拔：{},海拔权重权重b3：{}, 工作环境权重 d4：{}", qtys, gzhj_d, gzhj_a);
			log.info("  海拔计算结果  = {}", ys);
			log.info("---------------------------------海拔end----------------------------------");

			h4 = wd.add(sd).add(hj).add(ys);
			h4 = h4.multiply(gzhj_a).setScale(4, BigDecimal.ROUND_HALF_UP);
			log.info("---------------------------------h4  begin----------------------------------");
			log.info("  h4计算公式：h4=w*{（湿度参数）*b1*d4+(温度参数）*b2*d4+(空气质量）*b3*d4+(海拔）*b4*d4}");
			log.info("  w=运行参数-工作环境权重");
			log.info("  湿度：{}, 温度：{}, 空气质量：{}, 海拔：{}", ys, sd, wd, hj);
			log.info("  h4  = {}", h4);
			log.info("---------------------------------h4  end----------------------------------");

			BusiOfflineGisRepairDto busiOfflineGisRepairDto = new BusiOfflineGisRepairDto();
			busiOfflineGisRepairDto.setMainEquipmentId(mainTreeId);
			busiOfflineGisRepairDto.setSiteId(siteId);
			List<BusiOfflineGisRepairVo> list = busiOfflineGisRepairService.findBusiOfflineGisRepairList(busiOfflineGisRepairDto);
			// 运行参数 -->> 4.2 外观情况
			String gis_wgqk = "1";
			BigDecimal czjgLubrication;
			BigDecimal wgqk_a;
			BigDecimal ztjgAppearance;
			BigDecimal wgqk_b;
			BigDecimal supportInsulation;
			BigDecimal wgqk_c;
			BigDecimal mainLoopTerminal;
			BigDecimal wgqk_d;
			BigDecimal tldlqMaintain;
			BigDecimal wgqk_e;
			// 操作机构润滑
			czjgLubrication = GisAssessUtils.getCzjgrh(mainTreeId, list);
			wgqk_a = GisAssessUtils.getVal(busiParamGisMap, "yxcs_wg_ruihua");
			// 主体、机构外观
			ztjgAppearance = GisAssessUtils.getZtjgwg(mainTreeId, list);
			wgqk_b = GisAssessUtils.getVal(busiParamGisMap, "yxcs_wg_benti");
			// 支持绝缘部分
			supportInsulation = GisAssessUtils.getZcjybf(mainTreeId, list);
			wgqk_c = GisAssessUtils.getVal(busiParamGisMap, "yxcs_wg_jueyuan");
			// 主回路端子
			mainLoopTerminal = GisAssessUtils.getZhldz(mainTreeId, list);
			wgqk_d = GisAssessUtils.getVal(busiParamGisMap, "yxcs_wg_zhuhuilu");
			// 断路器维护次数(检修记录)
			tldlqMaintain = GisAssessUtils.getTldlqwhcs(mainTreeId, list);
			wgqk_e = GisAssessUtils.getVal(busiParamGisMap, "yxcs_tldlqwhcs");

			wgqk_e = GisAssessUtils.str2BigDecimal("0");
			gis_wgqk = ComputeUtil.eval(engine, "gis_yxcs_wgqk", czjgLubrication, wgqk_a, ztjgAppearance, wgqk_b,
					supportInsulation, wgqk_c, mainLoopTerminal, wgqk_d, tldlqMaintain, wgqk_e);
			log.info("检修记录-操作机构润滑: {}", wgqk_a);
			log.info("检修记录-主体、机构外观: {}", wgqk_b);
			log.info("检修记录-支持绝缘部分: {}", wgqk_c);
			log.info("检修记录-主回路端子: {}", wgqk_d);
			log.info("检修记录-断路器维护次数(检修记录): {}", wgqk_e);
			log.info("检修记录-运行参数-外观情况: {}", wgqk_e);

			BigDecimal rh = czjgLubrication.multiply(wgqk_a).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal wg = ztjgAppearance.multiply(wgqk_b).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal dz = mainLoopTerminal.multiply(wgqk_d).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal zc = supportInsulation.multiply(wgqk_c).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal wgResult = rh.add(wg).add(dz).add(zc);
			log.info("---------------------------------操作机构润滑 begin----------------------------------");
			log.info("  操作机构润滑计算公式：(操作机构润滑）*c1");
			log.info("  c1=操作机构权重");
			log.info("  操作机构润滑：{}, 操作机构权重c1：{}", czjgLubrication, wgqk_a);
			log.info("  操作机构润滑海拔计算结果 = {}", rh);
			log.info("---------------------------------操作机构润滑  end----------------------------------");

			log.info("---------------------------------本体外观 begin----------------------------------");
			log.info("  本体外观计算公式：(本体外观）*c2");
			log.info("  c2=机构外观权重");
			log.info("  本体外观：{}, 操作机构权重c2：{}", czjgLubrication, wgqk_b);
			log.info("  本体外观计算结果  = {}", wg);
			log.info("---------------------------------本体外观  end----------------------------------");

			log.info("---------------------------------主回路端子 begin----------------------------------");
			log.info("  主回路端子计算公式：(主回路端子）*c3");
			log.info("  c3=主回路端子权重");
			log.info("  主回路端子：{},主回路端子权重c3：{}", mainLoopTerminal, wgqk_d);
			log.info("  主回路端子计算结果  = {}", wg);
			log.info("---------------------------------主回路端子 end----------------------------------");

			log.info("---------------------------------绝缘支撑 begin----------------------------------");
			log.info("  绝缘支撑计算公式：(绝缘支撑）*c4");
			log.info("  c4=绝缘支撑权重");
			log.info("  绝缘支撑：{},绝缘支撑权重c4：{}", supportInsulation, wgqk_c);
			log.info("  绝缘支撑计算结果  = {}", wg);
			log.info("---------------------------------绝缘支撑 end----------------------------------");

			h5 = GisAssessUtils.calcValue(sxcs_a, sxcs_b, wgResult);
			log.info("--------------------------------h5 begin----------------------------------");
			log.info("  绝缘支撑计算公式：h5=w*y4*{操作机构润滑+本体外观+主回路端子+绝缘支撑");
			log.info("  w=运行参数-工作环境权重，y=外观情况权重");
			log.info("  操作机构润滑：" + rh + ",本体外观：" + wg + ",主回路端子：" + dz + ",绝缘支撑：" + zc);
			log.info("  h5计算结果  = " + wg);
			log.info("---------------------------------h5 end----------------------------------");

			BigDecimal productMaturity = new BigDecimal("0");
			BigDecimal popularity = new BigDecimal("0");
			if (busiOfflineGisBrandVo != null) {
				productMaturity = GisAssessUtils.getCpcsd(busiOfflineGisBrandVo, mainTreeId);
				popularity = GisAssessUtils.getZmd(busiOfflineGisBrandVo, mainTreeId);
				log.info("产品成熟度-标牌: {}, 知名度（手动录入）-标牌: {}", productMaturity, popularity);
			}

			BigDecimal cjyc = new BigDecimal("0");
			if (!list.isEmpty()) {
				cjyc = GisAssessUtils.getCjyc(list);
				log.info("检修记录-厂家设备遗传: {}", cjyc);
			}

			BigDecimal sccj_a = GisAssessUtils.getVal(busiParamGisMap, "yxcs_cjsbyc");
			log.info("厂家设备遗传权重: {}", sccj_a);
			// TODO 4.4 运行参数 -->> 断路器维护 dlqMaintenance
			BigDecimal dlqMaintenance = new BigDecimal("1");
			if (!list.isEmpty()) {
				dlqMaintenance = GisAssessUtils.getDlqwh(mainTreeId, list);
				log.info("断路器维护-断路器维护: {}", dlqMaintenance);
			}

			// TODO 4.3运行参数 -->> 生产厂家 gis_sccj
			// 产品成熟度
			BigDecimal sccj_b = GisAssessUtils.getVal(busiParamGisMap, "yxcs_cj_chengshudu");
			// 知名度（手动录入）标牌
			BigDecimal sccj_c = GisAssessUtils.getVal(busiParamGisMap, "yxcs_cj_renzhidu");
			/// 厂家
			String gis_sccj = ComputeUtil.eval(engine, "gis_yxcs_sccj", cjyc, sccj_a, productMaturity, sccj_b,
					popularity, sccj_c);
			log.info("产品成熟度权重: {}", sccj_b);
			log.info("知名度（手动录入）标牌: {}", sccj_c);
			log.info("厂家设备遗传权重：{}", gis_sccj);

			BigDecimal yc = cjyc.multiply(sccj_a).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal csd = productMaturity.multiply(sccj_b).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal zmd = popularity.multiply(sccj_c).setScale(4, BigDecimal.ROUND_HALF_UP);
			BigDecimal ycResult = yc.add(csd).add(zmd);
			log.info("---------------------------------遗传 begin----------------------------------");
			log.info("  遗传计算公式：(遗传）*z1");
			log.info("  z1=遗传权重");
			log.info("  遗传：{}, 遗传权重z1：{}", cjyc, sccj_a);
			log.info("  遗传计算结果  = " + yc);
			log.info("---------------------------------遗传 end----------------------------------");

			log.info("---------------------------------产品知名度 begin----------------------------------");
			log.info("  产品知名度计算公式：(产品知名度）*z2");
			log.info("  z2=产品知名度权重");
			log.info("  产品知名度：{},产品知名度权重z2：{}", popularity, sccj_c);
			log.info("  产品知名度计算结果  = {}", zmd);
			log.info("---------------------------------产品知名度 end----------------------------------");

			log.info("---------------------------------产品成熟度 begin----------------------------------");
			log.info("  产品成熟度计算公式：(产品成熟度）*z3");
			log.info("  z3=产品成熟度权重");
			log.info("  产品成熟度：{},产品成熟度权重z2：{}", productMaturity, sccj_b);
			log.info("  产品成熟度计算结果  = {}", csd);
			log.info("---------------------------------产品成熟度 end----------------------------------");

			h6 = GisAssessUtils.calcValue(sxcs_a, sxcs_c, ycResult);
			log.info("---------------------------------h6 begin----------------------------------");
			log.info("  h6计算公式：h6=w*s4*{遗传+产品知名度+产品成熟度}");
			log.info("  w=运行参数-工作环境权重，s4=生产厂家权重");
			log.info("  运行参数-工作环境权重w：{}, 生产厂家权重s4：{}, 遗传: {}, 产品知名度: {}, 产品成熟度: {}", sxcs_a, sxcs_c, yc, zmd, csd);
			log.info("  h6计算结果  = {}", h6);
			log.info("---------------------------------h6 end----------------------------------");

			// 工作环境得分
			String yxcs_gongzuohuanjing_total = GisAssessUtils.calcMultiply(sxcs_a, new BigDecimal(gis_gzhj)).toString();
			// 外观得分
			String yxcs_waiguang_total = GisAssessUtils.calcMultiply(sxcs_b, new BigDecimal(gis_wgqk)).toString();
			// 厂家得分
			String yxcs_changjia_total = GisAssessUtils.calcMultiply(sxcs_c, new BigDecimal(gis_sccj)).toString();
			// 断路器维护得分
			String yxcs_dlqwh_total = GisAssessUtils.calcMultiply(yxcs_dlqwh, dlqMaintenance).toString();
			log.info("工作环境得分：{}", yxcs_gongzuohuanjing_total);
			log.info("外观得分：{}", yxcs_gongzuohuanjing_total);
			log.info("厂家得分：{}", yxcs_changjia_total);
			log.info("断路器维护得分：{}", yxcs_dlqwh_total);

			// 4.运行参数
			String gis_yxcs = ComputeUtil.eval(engine, "gis_yxcs", gis_gzhj, sxcs_a, gis_wgqk, sxcs_b, gis_sccj, sxcs_c,
					dlqMaintenance, yxcs_dlqwh);
			// 运行参数总得分
			String gis_yxcs_total = GisAssessUtils.calcMultiply(score_d, new BigDecimal(gis_yxcs)).toString();
			log.info("运行参数：{}, 运行参数总得分: {}", gis_yxcs, gis_yxcs_total);

			BigDecimal jxjlResult = tldlqMaintain.multiply(wgqk_e).setScale(4, BigDecimal.ROUND_HALF_UP);
			h7 = GisAssessUtils.calcValue(sxcs_a, new BigDecimal(yxcs_dlqwh_total), jxjlResult);
			log.info("---------------------------------h7 begin----------------------------------");
			log.info("  h7计算公式：h7=w*(维修记录）*z5");
			log.info("  w=运行参数-工作环境权重，z5=检修次数记录");
			log.info("  运行参数-工作环境权重w：{}, 维修记录：{}, 检修次数记录z5: {}", sxcs_a, yxcs_dlqwh_total, jxjlResult);
			log.info("  h7计算结果  = {}", h7);
			log.info("---------------------------------h7 end----------------------------------");

			String score = "100";
			if (busiParamGisVo.size() > 11) {
				score = h1.add(h2).add(h3).add(h4).add(h5).add(h6).add(h7) + "";
				log.info("设备打分（h1+h2+h3+h4+h5+h6+h7）:score=" + h1 + "+" + h2 + "+" + h3 + "+" + h4 + "+" + h5
						+ "+" + h6 + "+" + h7 + " = " + score);
				score = Math.round(Double.parseDouble((h1.add(h2).add(h3).add(h4).add(h5).add(h6).add(h7))
						.multiply(BigDecimal.valueOf(100)).setScale(4, BigDecimal.ROUND_HALF_UP) + "")) + "";
				log.info("score::" + score);
			}

			// 健康水平
			String gisStatus = GisAssessUtils.getGisStatus(GisAssessUtils.str2BigDecimal(score));
			// 检修建议
			String jxjy = GisAssessUtils.getJxjy(GisAssessUtils.str2BigDecimal(score));
			// 健康水平说明
			String healthLevelExplain = GisAssessUtils.getJkspsm(GisAssessUtils.str2BigDecimal(score));

			String gis_yxsj_sdtx = ComputeUtil.eval(engine, "gis_yxsj_sdtx", gfSpeend, ghSpeend, yxsd_a, yxsd_b);
			log.info("速度特性得分：" + gis_yxsj_sdtx);
			log.info("健康水平：" + gisStatus);
			log.info("检修建议：" + jxjy);
			log.info("健康水平说明：" + healthLevelExplain);

			BigDecimal sydkcs;
			log.info("累计开断次数：" + ljdkcs);
			Map<String, Object> iecBreakerParamMap = iecBreakerParamService.findYxdl(siteId, mainTreeId);
			BigDecimal yxdl = new BigDecimal("0");
			if (null != iecBreakerParam) {
				if (null != iecBreakerParamMap) {
					yxdl = new BigDecimal(iecBreakerParamMap.get("yxdl").toString());
				}
			}

			// yxdl运行电流 eddl额定电流
			BigDecimal yxfh = GisAssessUtils.getFh(yxdl, eddl);
			BigDecimal fh = GisAssessUtils.getFh(dkdl, eddkdl);
			log.info("负荷(%):" + fh);
			BigDecimal kdkcs = GisAssessUtils.getKdkcs(fh);
			String gis_yxsj = ComputeUtil.eval(engine, "gis_yxsj", gis_yxsj_ddhldz, gis_yxsj_sjcs, gis_yxsj_sdtx,
					yxsj_a, yxsj_b, yxsj_c);
			// TODO运行参数（数据）得分
			String gis_yxcs1_total = GisAssessUtils.calcMultiply(score_a, new BigDecimal(gis_yxsj)).toString();

			// TODO 时间参数得分
			String yxsj_shijiacanshu = GisAssessUtils.calcMultiply(yxsj_b, new BigDecimal(gis_yxsj_sjcs)).toString();
			// TODO 速度特性得分
			String yxsj_sdtz_qitafangmian = GisAssessUtils.calcMultiply(yxsj_c, new BigDecimal(gis_yxsj_sdtx)).toString();

			// 开断磨损
			List<GisEvaVo> list11 = new ArrayList<>();
			// 运行数据
			List<GisEvaVo> list21 = new ArrayList<>();
			// 绝缘介质
			List<GisEvaVo> list31 = new ArrayList<>();
			// 运行参数
			List<GisEvaVo> list41 = new ArrayList<>();

			GisEvaVo vo21 = new GisEvaVo(GisCreateUtil.TIME_PARAMETER, gis_yxsj_sjcs, "时间参数");
			GisEvaVo vo22 = new GisEvaVo(GisCreateUtil.VELOCITY_CHARACTERISTICS, yxsj_sdtz_qitafangmian, "速度特性");
			GisEvaVo vo23 = new GisEvaVo(GisCreateUtil.CONDUCTING_CIRCUIT_RESISTANCE, ddhldz_result + "", "导电回路电阻");
			list21.add(vo21);
			list21.add(vo22);
			list21.add(vo23);

			GisEvaVo vo31 = new GisEvaVo(GisCreateUtil.GAS_PRESSURE, yxsj_shijiacanshu, "气体压力");
			GisEvaVo vo32 = new GisEvaVo(GisCreateUtil.MICRO_WATER_CONTENT, yxsj_sdtz_qitafangmian, "微水含量");
			GisEvaVo vo33 = new GisEvaVo(GisCreateUtil.PARTIAL_DISCHARGE, jfl + "", "局放量");
			GisEvaVo vo34 = new GisEvaVo(GisCreateUtil.PARTIAL_DISCHARGE_COUNT, jfcs + "", "局放次数");
			GisEvaVo vo35 = new GisEvaVo(GisCreateUtil.JYJZ_WS_MIEHUSHI, ws_miehushi + "", "灭弧室");
			list31.add(vo31);
			list31.add(vo32);
			list31.add(vo33);
			list31.add(vo34);
			list31.add(vo35);

			GisEvaVo vo41 = new GisEvaVo(GisCreateUtil.WORK_ENVIRONMENT, yxcs_gongzuohuanjing_total, "工作环境");
			GisEvaVo vo42 = new GisEvaVo(GisCreateUtil.APPEARANCE, yxcs_waiguang_total, "外观情况");
			GisEvaVo vo43 = new GisEvaVo(GisCreateUtil.MAINTENANCE_RECORD, yxcs_dlqwh_total, "维修记录");
			GisEvaVo vo44 = new GisEvaVo(GisCreateUtil.Manufacturer, yxcs_changjia_total, "生产厂家");
			list41.add(vo41);
			list41.add(vo42);
			list41.add(vo43);
			list41.add(vo44);

			// 14-累计断开次数
			sydkcs = new BigDecimal("14").subtract(ljdkscResult);
			log.info("预期剩余断开次数：" + sydkcs);

			String uuid = Uuid.getUUID();
			gisAssessmentResult.setId(uuid);
			gisAssessmentResult.setSiteId(siteId);
			gisAssessmentResult.setMainTreeId(mainTreeId);
			gisAssessmentResult.setAssessTime(LocalDateTime.now());
			gisAssessmentResult.setHealthScore(
					GisAssessUtils.formatNumStr(score).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
			// 触头磨损率
			gisAssessmentResult.setHealthLevel(gisStatus);
			gisAssessmentResult.setHealthLevelExplain(healthLevelExplain);
			gisAssessmentResult.setContactWearRate(xdmscd_val.toString());
			// 取值待定标牌中数据
			gisAssessmentResult.setExpectedUsageCount(busiOfflineGisBrandVo.getServiceTime());
			gisAssessmentResult.setRemainingUsageCount(sydkcs.toString());
			gisAssessmentResult.setOverhaulSuggest(jxjy);
			// 断开时负荷
			gisAssessmentResult.setLoadFactor(yxfh.toString());
			gisAssessmentResultService.saveGisAssessmentResult(gisAssessmentResult);

			GisAssessmentResultData result = new GisAssessmentResultData();
			result.setId(Uuid.getUUID());
			result.setEvaluationId(uuid);
			result.setGisId(gisId);
			result.setGisName(gisName);
			result.setAssessTime(LocalDate.now());
			result.setHealthScore(GisAssessUtils.formatNumStr(score).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
			// 触头磨损率
			result.setHealthLevel(gisStatus);
			result.setContactWearRate(xdmscd_val.toString());
			result.setExpectedUsageCount(kdkcs.toString());
			result.setRemainingUsageCount(sydkcs.toString());
			result.setOverhaulSuggest(jxjy);
			result.setDkcses(dkcsFor100_val+"");

			// 开断磨损
			result.setBreakingWear(xdmsdResult + "");
			result.setOperationalData(gis_yxcs1_total);
			result.setOperationParameters(gis_yxcs_total);
			result.setInsulatingMedium(h2 + "");

			GisEvaVo vo11 = new GisEvaVo(GisCreateUtil.SERVICE_LIFE, synxResult + "", "使用年限");
			GisEvaVo vo12 = new GisEvaVo(GisCreateUtil.RELATIVE_WEAR_DEGREE, xdmsdResult + "", "相对磨损程度");
			GisEvaVo vo13 = new GisEvaVo(GisCreateUtil.CUMULATIVE_ACTION_TIMES, ljdkscResult + "", "累计动作次数");
			list11.add(vo11);
			list11.add(vo12);
			list11.add(vo13);

			String json1 = JSONArray.toJSONString(list11);
			String json2 = JSONArray.toJSONString(list21);
			String json3 = JSONArray.toJSONString(list31);
			String json4 = JSONArray.toJSONString(list41);
			result.setBreakingWearDetails(json1);
			result.setOperationalDataDetails(json2);
			result.setInsulatingMediumDetails(json3);
			result.setOperationParametersDetails(json4);
			gisAssessmentResultDataService.save(result);

			// 临时注释，调测后放开
			GisCreateUtil.createFile(result, true, basePath2, filePath, fileName, date);

			// 开发状态
			/************************** 测试数据 **********************/
			log.info("");
			log.info("");
			log.info("*********************gis评测中间值*************************");
			log.info("站点ID：" + siteId);
			log.info("Gis设备编码：" + mainTreeId);
			log.info("Gis打分：" + GisAssessUtils.formatNumStr(score));
			log.info("设备状态：" + gisStatus);
			log.info("健康水平描述：" + healthLevelExplain);
			log.info("检修建议：" + jxjy);
			log.info("累计断开次数：" + ljdkcs);
			log.info("----------------运行数据---------------------");
			log.info("运行数据：" + gis_yxsj + "(" + score_a + ")");
			log.info("\t导电回路电阻" + "(值" + gis_yxsj_ddhldz_val + ")" + "：" + gis_yxsj_ddhldz + "(权重" + yxsj_a + ")");
			log.info("\t运行数据-机械试验数据-时间参数：" + gis_yxsj_sjcs + "(" + yxsj_b + ")");
			log.info("\t\t合闸不同期" + "(值" + hz_btq_val + ")" + "：" + hz_btq + "(权重" + sjcs_a + ")");
			log.info("\t\t分闸不同期" + "(值" + fz_btq_val + ")" + "：" + fz_btq + "(权重" + sjcs_b + ")");
			log.info("\t运行数据-机械试验数据-速度参数：" + gis_yxsj_sdtx + "(" + yxsj_c + ")");
			log.info("\t\t刚分速度" + "(值" + gfSpeend_val + ")" + "：" + gfSpeend + "(权重" + yxsd_a + ")");
			log.info("\t\t刚和速度" + "(值" + ghSpeend_val + ")" + "：" + ghSpeend + "(权重" + yxsd_b + ")");
			log.info("----------------绝缘介质（0.189）-SF6在线数据---------------------");
			log.info("绝缘介质（0.189）-SF6在线数据）：" + gis_qtxl + "(权重" + score_b + ")");
			log.info("\t气室压力" + "(值" + yl_val + ")" + "：" + yl + "(权重" + qtxl_a + ")");
			log.info("\t气室微水" + "(值" + wshl_val + ")" + "：" + wshl + "(权重" + qtxl_b + ")");
			log.info("\t局放量" + "(值" + jfl_val + ")" + "：" + jfl + "(权重" + jf_a + ")");
			log.info("\t局放次数" + "(值" + jfcs_val + ")" + "：" + jfcs + "(权重" + jf_b + ")");
			log.info("----------------开断磨损数据---------------------");
			log.info("开断磨损数据：" + gis_kdms + "(" + score_c + ")");
			log.info("\t100%累计开断次数" + "(值" + dkcsFor100_val + ")" + "：" + dkcsFor100 + "(权重" + kdms_a + ")");
			log.info("\t使用年限" + "(值" + synx_val + ")" + "：" + synxResult + "(权重" + kdms_b + ")");
			log.info("\t相对磨损程度" + "(值" + xdmscd_val + ")" + "：" + xdmsdResult + "(权重" + kdms_c + ")");
			log.info("----------------运行参数---------------------");
			log.info("运行参数：" + GisAssessUtils.formatNumStr(gis_yxcs) + "(" + score_d + ")");
			log.info("\t运行参数-工作环境：" + GisAssessUtils.formatNumStr(gis_gzhj) + "(权重" + sxcs_a + ")");
			log.info("\t\t使用环境温度" + "(值" + syhjwd_val + ")" + "：" + syhjwd + "(权重" + gzhj_a + ")");
			log.info("\t\t使用环境湿度" + "(值" + syhjsd_val + ")" + "：" + syhjsd + "(权重" + gzhj_b + ")");
			log.info("\t\t尘埃、腐蚀：" + syhj + "(" + gzhj_c + ")");
			log.info("\t\t海拔：" + qtys + "(" + gzhj_d + ")");
			log.info("\t运行参数-外观情况：" + GisAssessUtils.formatNumStr(gis_wgqk) + "(" + sxcs_b + ")");
			log.info("\t\t操作机构润滑(检修记录)：" + czjgLubrication + "(" + wgqk_a + ")");
			log.info("\t\t主体、机构外观(检修记录)：" + ztjgAppearance + "(" + wgqk_b + ")");
			log.info("\t\t支持绝缘部分(检修记录)：" + supportInsulation + "(" + wgqk_c + ")");
			log.info("\t\t主回路端子(检修记录)：" + mainLoopTerminal + "(" + wgqk_d + ")");
			log.info("\t断路器维护(检修记录)：" + dlqMaintenance + "(" + wgqk_f + ")");
			log.info("\t运行参数-生产厂家：" + GisAssessUtils.formatNumStr(gis_sccj) + "(" + sxcs_c + ")");
			log.info("\t\t厂家设备遗传：" + cjyc + "(" + sccj_a + ")");
			log.info("\t\t产品成熟度（手动录入）标牌：" + productMaturity + "(" + sccj_b + ")");
			log.info("\t\t知名度（手动录入）标牌：" + popularity + "(" + sccj_c + ")");
			log.info("*********************gis评测end*************************");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (ScriptException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} finally {
			try {
				ComputeUtil.close(fileReader);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return gisAssessmentResult;
	}
}
