package cn.autoform.web.formula.tool;
|
|
import java.util.Map;
|
import java.util.Objects;
|
|
import cn.autoform.web.formula.info.FormCpn;
|
import cn.autoform.web.formula.info.impl.cpn.ChildCpn;
|
import cn.autoform.web.formula.prop.Attribute;
|
|
public class FormCpnTool{
|
|
public static double sumValByCpn(FormCpn formCpn){
|
FormCpn parent = formCpn.getParentCpn();
|
if(parent == null || !(parent instanceof ChildCpn)){
|
return 0;
|
}
|
Map<Integer, Map<String, FormCpn>> values = ((ChildCpn)parent).getFormCpnValues();
|
double sum = 0;
|
try{
|
if(values == null || values.isEmpty()){
|
return Double.parseDouble(Objects.toString(formCpn.get(Attribute.value), "0"));
|
}
|
for(Map<String, FormCpn> col:values.values()){
|
sum += Double.parseDouble(Objects.toString(col.get(formCpn.getFieldId()).get(Attribute.value), "0"));
|
}
|
}catch (NumberFormatException e) {
|
sum = 0;
|
}
|
return sum;
|
}
|
|
}
|