package com.changhong.epc.parsing.service.autosubmit.tool; import com.changhong.epc.parsing.service.autosubmit.info.FormCpn; import com.changhong.epc.parsing.service.autosubmit.info.impl.cpn.ChildCpn; import com.changhong.epc.parsing.service.autosubmit.prop.Attribute; import java.util.Map; import java.util.Objects; public class FormCpnTool{ public static double sumValByCpn(FormCpn formCpn){ FormCpn parent = formCpn.getParentCpn(); if(parent == null || !(parent instanceof ChildCpn)){ return 0; } Map> 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 col:values.values()){ sum += Double.parseDouble(Objects.toString(col.get(formCpn.getFieldId()).get(Attribute.value), "0")); } }catch (NumberFormatException e) { sum = 0; } return sum; } }