|
@@ -32,7 +32,89 @@ public class ExecutorCalc extends FormulaExecutor {
|
|
|
/*通用计算*/
|
|
|
generalCalc(tec);
|
|
|
}
|
|
|
+
|
|
|
public void generalCalc(TableElementConverter tec){
|
|
|
+ /*关键内容,常量变量集合,计算时变量集合,依赖元素,公式,输出元素,是否批量运算*/
|
|
|
+ for(FormData fd:tec.formDataList){
|
|
|
+ if(fd.verify()){
|
|
|
+ Formula formula =fd.getFormula();
|
|
|
+ String f=formula.getFormula();
|
|
|
+ if(Func.isNotBlank(f)){
|
|
|
+ try{
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(tec.constantMap);
|
|
|
+ List<String> relyList = fd.getFormula().getRelyList();
|
|
|
+ if(CollectionUtil.isNotEmpty(relyList)){
|
|
|
+ /*存在依赖*/
|
|
|
+ List<FormData> ele = new ArrayList<>();
|
|
|
+ relyList.forEach(rely->{
|
|
|
+ FormData formData= tec.getFormDataMap().get(rely);
|
|
|
+ if(formData!=null&&!formData.empty()){
|
|
|
+ ele.add(formData);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*并不是所有依赖都用FormData表示*/
|
|
|
+ if(ele.size()<relyList.size()){
|
|
|
+ tec.getLog().put(FormulaLog.RELY,fd.getCode()+"@"+fd.getEName()+"@"+fd.getFormula().getFormula().replaceAll("'", ""));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FormulaUtils.putEle(f,ele,currentMap,fd);
|
|
|
+ Object data = Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
|
+ FormulaUtils.write(fd,data);
|
|
|
+ }else{
|
|
|
+ Object data =Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
|
+ FormulaUtils.write(fd,data);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ tec.getLog().put(FormulaLog.CALC,fd.getEName()+"("+formula+")");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ fd.setUpdate(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ interface Calculation {
|
|
|
+ void calculate(Formula formula, List<FormData> ele, TableElementConverter tec);
|
|
|
+ }
|
|
|
+
|
|
|
+ static class SimpleCalculation implements Calculation{
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void calculate(Formula formula, List<FormData> ele, TableElementConverter tec) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class BatchCalculation implements Calculation{
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void calculate(Formula formula, List<FormData> ele, TableElementConverter tec) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ interface DependenceHandler {
|
|
|
+ boolean handle(String rely, TableElementConverter tec);
|
|
|
+ }
|
|
|
+
|
|
|
+ static class FormDataDependenceHandler implements DependenceHandler {
|
|
|
+ @Override
|
|
|
+ public boolean handle(String rely, TableElementConverter tec) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class OtherDependenceHandler implements DependenceHandler {
|
|
|
+ @Override
|
|
|
+ public boolean handle(String rely, TableElementConverter tec) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void generalCalcOld(TableElementConverter tec){
|
|
|
String checkTable ="";
|
|
|
Optional<NodeTable> op=tec.getTableAll().stream().filter(e->StringUtils.isEquals(1,e.getTableType())).findAny();
|
|
|
if(op.isPresent()){
|
|
@@ -92,4 +174,5 @@ public class ExecutorCalc extends FormulaExecutor {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|