package com.changhong.epc.parsing.service.autosubmit.info.impl.cpn; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.TreeMap; import com.changhong.epc.bean.count.format.CpnType; import com.changhong.epc.parsing.service.autosubmit.info.FormCpn; import lombok.Getter; /** * 子表单 * @author WangYX * */ public class ChildCpn extends AbstractBaseFormCpn{ /* 表单控件集合 */ private Map formCpns; /* 获得控件值 */ @Getter private Map> formCpnValues; @Override public CpnType getCpnType() { return CpnType.subform; } @Override public Object get(Object key) { Object val = this.formCpns == null ? null : this.formCpns.get(key); if(val != null) return val; return super.get(key); } @Override public Object put(Object key, Object value) { if(Objects.equals(CHILD_CPN, key)){ if(this.formCpns == null) this.formCpns = new HashMap<>(); // 添加到控件集合中 this.formCpns.put(((FormCpn) value).getFieldId(), (FormCpn) value); // 添加控件form对象 ((FormCpn) value).put(FORM_KEY, this.get(FORM_KEY)); } return super.put(key, value); } @Override public Object get(Object key, Integer row) { if(this.formCpnValues == null) this.formCpnValues = new TreeMap<>(); Map rowFormCpn = this.formCpnValues.get(row); if(rowFormCpn == null) return null; if(key instanceof String) return rowFormCpn.get(key); else if(key instanceof FormCpn) return rowFormCpn.get(((FormCpn) key).getFieldId()); else return null; } @Override public Object put(Object key, Object value, Integer row) { if(!Objects.equals(CHILD_CPN_VAL, key)) return null; if(this.formCpnValues == null) this.formCpnValues = new HashMap<>(); Map rowFormCpn = this.formCpnValues.get(row); if(rowFormCpn == null) rowFormCpn = new HashMap<>(); AbstractBaseFormCpn cpn = (AbstractBaseFormCpn) value; cpn.setIndex(row); cpn.setParentFormCpn(this); rowFormCpn.put(cpn.getFieldId(), cpn); return this.formCpnValues.put(row, rowFormCpn); } @Override public Object getValue() { List> value = new ArrayList<>(formCpnValues.size()); Map rowValue = null; for(Map.Entry> entry : formCpnValues.entrySet()){ rowValue = new HashMap<>(); for(Map.Entry rowEntry : formCpns.entrySet()){ rowValue.put(rowEntry.getKey(), entry.getValue().get(rowEntry.getKey()).getValue()); } value.add(rowValue); } return value; } }