|
@@ -1,5 +1,6 @@
|
|
|
package com.syjy.calculate.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.googlecode.aviator.AviatorEvaluator;
|
|
|
import com.syjy.calculate.entity.CalculationFormula;
|
|
@@ -7,6 +8,7 @@ import com.syjy.calculate.repository.CalculationFormulaRepository;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -37,9 +39,9 @@ public class AccuracyPassRateCalculateService {
|
|
|
* @param compare 通过率对比系数
|
|
|
* @return 返回Json result:fail/success value: 99% msg:失败及原因
|
|
|
*/
|
|
|
- public JSONObject calculate(List<Map<String, Object>> powerData, BigDecimal rl, String provinceEnum, String type, BigDecimal compare) {
|
|
|
+ public JSONObject calculate(JSONArray powerData, BigDecimal rl, String provinceEnum, String type, BigDecimal compare) {
|
|
|
JSONObject jsonResult = new JSONObject();
|
|
|
- jsonResult.put("result", "fail");
|
|
|
+ jsonResult.put("result", false);
|
|
|
// 获取公式
|
|
|
List<CalculationFormula> calculationFormulaList = getCalculationFormulaData(type, provinceEnum);
|
|
|
if (calculationFormulaList == null || calculationFormulaList.size() == 0) {
|
|
@@ -62,13 +64,14 @@ public class AccuracyPassRateCalculateService {
|
|
|
// 获取sum后面的公式
|
|
|
formula = formula.split(":")[1];
|
|
|
// 循环执行sum后的公式
|
|
|
- for (Map<String, Object> dataMap : powerData) {
|
|
|
+ for (int i = 0; i < powerData.size(); i++) {
|
|
|
+ JSONObject dataJson = powerData.getJSONObject(i);
|
|
|
// 将执行过的公式结果放入dataMap
|
|
|
- dataMap.putAll(resultMap);
|
|
|
- dataMap.put("rl", rl);
|
|
|
- dataMap.put("count", count);
|
|
|
+ dataJson.putAll(resultMap);
|
|
|
+ dataJson.put("rl", rl);
|
|
|
+ dataJson.put("count", count);
|
|
|
try {
|
|
|
- BigDecimal thisResult = new BigDecimal(String.valueOf(AviatorEvaluator.execute(formula, dataMap)));
|
|
|
+ BigDecimal thisResult = new BigDecimal(String.valueOf(AviatorEvaluator.execute(formula, dataJson)));
|
|
|
// 如果是通过率计算
|
|
|
if (this.PASS.equals(type)) {
|
|
|
// 如果对比系数是0,返回计算失败
|
|
@@ -92,18 +95,18 @@ public class AccuracyPassRateCalculateService {
|
|
|
return jsonResult;
|
|
|
}
|
|
|
}
|
|
|
- // 非求和计算
|
|
|
+ // 非求和计算
|
|
|
} else {
|
|
|
if (powerData.size() > 0) {
|
|
|
// 获取数据测试
|
|
|
- Map<String, Object> dataMap = powerData.get(0);
|
|
|
+ JSONObject dataJson = powerData.getJSONObject(0);
|
|
|
// 将执行过的公式结果放入dataMap
|
|
|
- dataMap.putAll(resultMap);
|
|
|
- dataMap.put("rl", rl);
|
|
|
- dataMap.put("count", count);
|
|
|
+ dataJson.putAll(resultMap);
|
|
|
+ dataJson.put("rl", rl);
|
|
|
+ dataJson.put("count", count);
|
|
|
try {
|
|
|
// 根据公式进行计算
|
|
|
- formulaResult = new BigDecimal(String.valueOf(AviatorEvaluator.execute(formula, dataMap)));
|
|
|
+ formulaResult = new BigDecimal(String.valueOf(AviatorEvaluator.execute(formula, dataJson)));
|
|
|
} catch (Exception e) {
|
|
|
log.error("计算公式:" + formula + "错误:" + e.toString());
|
|
|
e.printStackTrace();
|
|
@@ -128,7 +131,7 @@ public class AccuracyPassRateCalculateService {
|
|
|
// 过滤准确率
|
|
|
bResult = filterResult(bResult);
|
|
|
lastResult = bResult + "%";
|
|
|
- jsonResult.put("result", "success");
|
|
|
+ jsonResult.put("result", true);
|
|
|
jsonResult.put("value", lastResult);
|
|
|
log.info("准确率:" + lastResult);
|
|
|
return jsonResult;
|
|
@@ -137,9 +140,8 @@ public class AccuracyPassRateCalculateService {
|
|
|
/**
|
|
|
* 获取当前省调的公式列表
|
|
|
*
|
|
|
- * @param type 类型
|
|
|
+ * @param type 类型
|
|
|
* @param provinceEnum 省调(在数据库中省调存储必须带分号,例如:E12;)
|
|
|
- *
|
|
|
* @return
|
|
|
*/
|
|
|
public List<CalculationFormula> getCalculationFormulaData(String type, String provinceEnum) {
|