package cn.autoform.web.formula.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 cn.autoform.bean.form.CpnType;
|
import cn.autoform.web.formula.info.FormCpn;
|
import lombok.Getter;
|
|
/**
|
* 子表单
|
* @author WangYX
|
*
|
*/
|
public class ChildCpn extends AbstractBaseFormCpn{
|
|
/* 表单控件集合 */
|
private Map<String, FormCpn> formCpns;
|
|
/* 获得控件值 */
|
@Getter
|
private Map<Integer, Map<String, FormCpn>> 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<String, FormCpn> 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<String, FormCpn> 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<Map<String, Object>> value = new ArrayList<>(formCpnValues.size());
|
Map<String, Object> rowValue = null;
|
for(Map.Entry<Integer, Map<String, FormCpn>> entry : formCpnValues.entrySet()){
|
rowValue = new HashMap<>();
|
for(Map.Entry<String, FormCpn> rowEntry : formCpns.entrySet()){
|
rowValue.put(rowEntry.getKey(), entry.getValue().get(rowEntry.getKey()).getValue());
|
}
|
value.add(rowValue);
|
}
|
return value;
|
}
|
|
}
|