Commit 2b596302 by hzc

数据填报运算公式参照对标运算

parent af0bcaa0
......@@ -576,7 +576,11 @@ public class TaskServiceImpl implements TaskService {
try {
Map<String,String> tmp = new HashMap<>();
for (String s : indIdList) {
tmp.put(s,dataMap.get(s+model.getId()));
String tmpValue = dataMap.get(s + model.getId());
if(StringUtils.isNotBlank(tmpValue)&&tmpValue.indexOf(".")<0) {
tmpValue += ".00";
}
tmp.put(s,tmpValue);
}
String nowValue = CalculateUtils.calculateFormula(indicator.getIndFormula(), tmp);
value.setIndValue(nowValue);
......
......@@ -7,24 +7,35 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.googlecode.aviator.AviatorEvaluator;
@Slf4j
public class CalculateUtils {
private static Logger logger = LoggerFactory.getLogger(CalculateUtils.class);
//根据公式和值计算数值
public static String calculateFormula(String formula,Map<String,String> dataMap) {
String result = "NaN";
Object tmp=null;
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();
try {
tmp = AviatorEvaluator.execute(formula);
result = String.format("%.8f", new BigDecimal((Double)tmp));
}catch (Exception e){
e.printStackTrace();
log.info("公式运算出错:数据确认-公式:{},结果:{},截取八位:{}",formula,tmp,result);
}
}
return result;
}
......
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