commit | author | age
|
a18bfa
|
1 |
package cn.autoform.web.formula.tool; |
Z |
2 |
|
|
3 |
import java.util.Map; |
|
4 |
import java.util.Objects; |
|
5 |
|
|
6 |
import cn.autoform.web.formula.info.FormCpn; |
|
7 |
import cn.autoform.web.formula.info.impl.cpn.ChildCpn; |
|
8 |
import cn.autoform.web.formula.prop.Attribute; |
|
9 |
|
|
10 |
public class FormCpnTool{ |
|
11 |
|
|
12 |
public static double sumValByCpn(FormCpn formCpn){ |
|
13 |
FormCpn parent = formCpn.getParentCpn(); |
|
14 |
if(parent == null || !(parent instanceof ChildCpn)){ |
|
15 |
return 0; |
|
16 |
} |
|
17 |
Map<Integer, Map<String, FormCpn>> values = ((ChildCpn)parent).getFormCpnValues(); |
|
18 |
double sum = 0; |
|
19 |
try{ |
|
20 |
if(values == null || values.isEmpty()){ |
|
21 |
return Double.parseDouble(Objects.toString(formCpn.get(Attribute.value), "0")); |
|
22 |
} |
|
23 |
for(Map<String, FormCpn> col:values.values()){ |
|
24 |
sum += Double.parseDouble(Objects.toString(col.get(formCpn.getFieldId()).get(Attribute.value), "0")); |
|
25 |
} |
|
26 |
}catch (NumberFormatException e) { |
|
27 |
sum = 0; |
|
28 |
} |
|
29 |
return sum; |
|
30 |
} |
|
31 |
|
|
32 |
} |