Commit 56e74d5f by zhangkb

添加公式计算接口

parent a6bc68e9
...@@ -8,18 +8,10 @@ import java.util.Map; ...@@ -8,18 +8,10 @@ import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.keymobile.indicators.conf.MongoDBConfig;
import com.keymobile.indicators.model.entity.indicators.IndicatorsData; import com.keymobile.indicators.model.entity.indicators.IndicatorsData;
import com.keymobile.indicators.model.mapper.indmapper.IndicatorsDataMapper; import com.keymobile.indicators.model.mapper.indmapper.IndicatorsDataMapper;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
@Service @Service
public class BaseIndDataService { public class BaseIndDataService {
......
...@@ -18,6 +18,18 @@ import com.googlecode.aviator.AviatorEvaluator; ...@@ -18,6 +18,18 @@ import com.googlecode.aviator.AviatorEvaluator;
public class CalculateUtils { public class CalculateUtils {
private static Logger logger = LoggerFactory.getLogger(CalculateUtils.class); private static Logger logger = LoggerFactory.getLogger(CalculateUtils.class);
//根据公式和值计算数值
public static String calculateFormula(String formula,Map<String,String> dataMap) {
String result = "NaN";
if(StringUtils.isNotBlank(formula) && !dataMap.isEmpty()) {
for(Entry<String,String> entry : dataMap.entrySet()) {
formula = formula.replace("["+entry.getKey()+"]", entry.getValue());
}
result = AviatorEvaluator.execute(formula).toString();
}
return result;
}
//type:0 : 本期-同期 1:(本期-同期)/同期 //type:0 : 本期-同期 1:(本期-同期)/同期
public static String calGowth(String currentValue,String sameValue,String type) { public static String calGowth(String currentValue,String sameValue,String type) {
String gowthValue = ""; String gowthValue = "";
...@@ -226,15 +238,20 @@ public class CalculateUtils { ...@@ -226,15 +238,20 @@ public class CalculateUtils {
// map.put("1006", "NaN"); // map.put("1006", "NaN");
// map.put("1007", "NaN"); // map.put("1007", "NaN");
// map.put("1008", "NaN"); // map.put("1008", "NaN");
// CalculateUtils cal = new CalculateUtils(); CalculateUtils cal = new CalculateUtils();
// Map<String,Integer> result = cal.rankValue(map, "1"); // Map<String,Integer> result = cal.rankValue(map, "1");
// System.out.println(result); // System.out.println(result);
// //
// String formula = "([1001]+[1002])/2"; String formula = "([1001]+[1002])/2";
// formula = formula.replace("[1001]", "3"); Map<String,String> map = new HashMap<>();
// formula = formula.replace("[1002]", "5"); map.put("1001", "3");
// String result1 = AviatorEvaluator.execute(formula).toString(); map.put("1002", "5");
// System.out.println(result1); formula = formula.replace("[1001]", "3");
formula = formula.replace("[1002]", "5");
String result1 = AviatorEvaluator.execute(formula).toString();
String result2 = cal.calculateFormula(formula, map);
System.out.println(result1);
System.out.println(result2);
// Double b = (double) Math.abs(34-50); // Double b = (double) Math.abs(34-50);
// System.out.println(b); // System.out.println(b);
// List<String> listA = new ArrayList<>(); // List<String> listA = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment