提交 a0387894 编写于 作者: sq3536's avatar sq3536

自动填充完成

上级 da055f93
...@@ -178,6 +178,22 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> { ...@@ -178,6 +178,22 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
} }
} }
} }
else if(targetEntity instanceof EntityObj){
for(K field : this.keySet()){
Object value=this.get(field);
if( !ObjectUtils.isEmpty(value) || ObjectUtils.isEmpty(value) && bIncEmpty ){
((EntityObj) targetEntity).set((String)field,value);
}
}
}
else if(targetEntity instanceof ModelObj){
for(K field : this.keySet()){
Object value=this.get(field);
if( !ObjectUtils.isEmpty(value) || ObjectUtils.isEmpty(value) && bIncEmpty ){
((ModelObj) targetEntity).set((String)field,value);
}
}
}
else if(targetEntity instanceof DataObj){ else if(targetEntity instanceof DataObj){
for(K field : this.keySet()){ for(K field : this.keySet()){
Object value=this.get(field); Object value=this.get(field);
......
...@@ -8,6 +8,9 @@ import com.alibaba.fastjson.annotation.JSONField; ...@@ -8,6 +8,9 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
public class EntityObj extends DataObj<String,Object> { public class EntityObj extends DataObj<String,Object> {
...@@ -22,12 +25,6 @@ public class EntityObj extends DataObj<String,Object> { ...@@ -22,12 +25,6 @@ public class EntityObj extends DataObj<String,Object> {
return entityModel; return entityModel;
} }
public EntityObj setEntityModel(EntityModel entityModel)
{
this.entityModel=entityModel;
return this;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private DataModel dataModel; private DataModel dataModel;
...@@ -35,18 +32,9 @@ public class EntityObj extends DataObj<String,Object> { ...@@ -35,18 +32,9 @@ public class EntityObj extends DataObj<String,Object> {
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public DataModel getDataModel() { public DataModel getDataModel() {
if(this.dataModel==null&&this.getProperty()!=null)
this.dataModel=this.getProperty().getOwnerDataModel();
return dataModel; return dataModel;
} }
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Property property; private Property property;
...@@ -65,7 +53,8 @@ public class EntityObj extends DataObj<String,Object> { ...@@ -65,7 +53,8 @@ public class EntityObj extends DataObj<String,Object> {
this.setDstSystemId(property.getSystem()); this.setDstSystemId(property.getSystem());
if(!StringUtils.isEmpty(property.getPropertyEntity())) if(!StringUtils.isEmpty(property.getPropertyEntity()))
this.setMetaEntityName(property.getPropertyEntity()); this.setMetaEntityName(property.getPropertyEntity());
this.setEntityModel(property.getEntityModel()); this.entityModel=property.getEntityModel();
this.dataModel=property.getOwnerDataModel();
} }
this.property = property; this.property = property;
return this; return this;
...@@ -117,5 +106,36 @@ public class EntityObj extends DataObj<String,Object> { ...@@ -117,5 +106,36 @@ public class EntityObj extends DataObj<String,Object> {
return this; return this;
} }
@Override
public String getRowKey()
{
String rowKey=super.getRowKey();
if(StringUtils.isEmpty(rowKey))
{
rowKey=this.getStringValue(this.getEntityModel().getKeyField().getColumnName());
this.setRowKey(rowKey);
}
return rowKey;
}
public void findModel(List<ModelObj> modelObjs)
{
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
modelObjs.forEach(obj->tmps.put(obj.getRowKey(),obj));
this.getProperty().getPropertyMappings().forEach(mapping->{
String selfVal=this.getStringValue(mapping.getSelfPropertyColumn());
modelObjs.forEach(modelObj->{
String parentVal=modelObj.getEntity(mapping.getJoinPropertyEntity()).getStringValue(mapping.getJoinPropertyColumn());
if((StringUtils.isEmpty(parentVal))||(!parentVal.equals(selfVal)))
tmps.remove(modelObj.getRowKey());
});
});
if(tmps.size()>0)
{
tmps.values().forEach(obj->{
EntityObj copy=this.copyTo(new EntityObj(),true).setProperty(this.getProperty());
obj.setEntity(this.getProperty().getPropertyName(),copy);
});
}
}
} }
...@@ -47,6 +47,8 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -47,6 +47,8 @@ public class ModelObj extends DataObj<String,Object> {
@JSONField(serialize = false) @JSONField(serialize = false)
public ModelObj setParent(ModelObj parent) { public ModelObj setParent(ModelObj parent) {
this.parent = parent; this.parent = parent;
if(parent!=null)
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
return this; return this;
} }
...@@ -63,7 +65,7 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -63,7 +65,7 @@ public class ModelObj extends DataObj<String,Object> {
Property property=this.getDataModel().getObjectProperty(name); Property property=this.getDataModel().getObjectProperty(name);
if(property!=null) { if(property!=null) {
return new EntityObj().setDataModel(this.getDataModel()).setProperty(property).setRowKey(this.getRowKey()); return new EntityObj().setProperty(property).setRowKey(this.getRowKey());
} }
if(recursion) if(recursion)
...@@ -78,18 +80,23 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -78,18 +80,23 @@ public class ModelObj extends DataObj<String,Object> {
} }
} }
return new EntityObj().setDataModel(this.getDataModel()).setDstSystemId(this.getDataModel().getFactPorperty().getSystem()).setMetaEntityName(name).setRowKey(this.getRowKey()); return new EntityObj().setDstSystemId(this.getDataModel().getFactPorperty().getSystem()).setMetaEntityName(name).setRowKey(this.getRowKey());
} }
public ModelObj setEntity(String name,EntityObj entityObj) public ModelObj setEntity(String name,EntityObj entityObj)
{ {
if(entityObj!=null)
{
if(entityObj.getModelObj()==null)
entityObj.setModelObj(this);
this.set(name, entityObj); this.set(name, entityObj);
}
return this; return this;
} }
public ModelObj setFactEntity(EntityObj entityObj) public ModelObj setFactEntity(EntityObj entityObj)
{ {
this.set(this.getDataModel().getFactPorperty().getPropertyName(),entityObj); this.setEntity(this.getDataModel().getFactPorperty().getPropertyName(),entityObj);
return this; return this;
} }
...@@ -109,11 +116,16 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -109,11 +116,16 @@ public class ModelObj extends DataObj<String,Object> {
{ {
Object list=this.get(name); Object list=this.get(name);
if(list!=null&&list instanceof NestedArray) if(list!=null&&list instanceof NestedArray)
return (NestedArray)list; {
NestedArray nestedArray=(NestedArray) list;
if(nestedArray.getParent()==null)
nestedArray.setParent(this);
return nestedArray;
}
DataModel model=this.getDataModel().getNestedDataModel(name); DataModel model=this.getDataModel().getNestedDataModel(name);
if(model!=null) if(model!=null)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this); return new NestedArray().setParent(this);
if(recursion) if(recursion)
{ {
...@@ -137,7 +149,7 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -137,7 +149,7 @@ public class ModelObj extends DataObj<String,Object> {
{ {
subarry=subarry.getSubNested(steps.get(i)); subarry=subarry.getSubNested(steps.get(i));
if(subarry.size()==0) if(subarry.size()==0)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this); return new NestedArray().setParent(this);
} }
return subarry; return subarry;
} }
...@@ -145,7 +157,7 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -145,7 +157,7 @@ public class ModelObj extends DataObj<String,Object> {
} }
} }
return new NestedArray().setDataModel(this.getDataModel()).setParent(this); return new NestedArray().setParent(this);
} }
...@@ -167,13 +179,23 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -167,13 +179,23 @@ public class ModelObj extends DataObj<String,Object> {
return super.get(key); return super.get(key);
} }
public ModelObj findParent(Collection<ModelObj> uplayerObjs) @Override
public String getRowKey()
{
String rowKey=super.getRowKey();
if(StringUtils.isEmpty(rowKey))
{
rowKey=this.getFactEntity().getRowKey();
this.setRowKey(rowKey);
}
return rowKey;
}
public ModelObj findParent(List<ModelObj> uplayerObjs)
{ {
if(uplayerObjs.size()==1) if(uplayerObjs.size()==1)
{ {
ModelObj parent= uplayerObjs.iterator().next(); this.setParent(uplayerObjs.iterator().next());
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
return this; return this;
} }
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>(); HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
...@@ -188,9 +210,7 @@ public class ModelObj extends DataObj<String,Object> { ...@@ -188,9 +210,7 @@ public class ModelObj extends DataObj<String,Object> {
}); });
if(tmps.size()==1) if(tmps.size()==1)
{ {
ModelObj parent= tmps.values().iterator().next(); this.setParent(tmps.values().iterator().next());
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
} }
return this; return this;
} }
......
...@@ -18,13 +18,6 @@ public class NestedArray extends ArrayList<ModelObj> { ...@@ -18,13 +18,6 @@ public class NestedArray extends ArrayList<ModelObj> {
return dataModel; return dataModel;
} }
@JsonIgnore
@JSONField(serialize = false)
public NestedArray setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private ModelObj parent; private ModelObj parent;
...@@ -39,6 +32,8 @@ public class NestedArray extends ArrayList<ModelObj> { ...@@ -39,6 +32,8 @@ public class NestedArray extends ArrayList<ModelObj> {
@JSONField(serialize = false) @JSONField(serialize = false)
public NestedArray setParent(ModelObj parent) { public NestedArray setParent(ModelObj parent) {
this.parent = parent; this.parent = parent;
if(parent!=null&&this.getDataModel()==null)
this.dataModel=(parent.getDataModel());
return this; return this;
} }
...@@ -48,11 +43,12 @@ public class NestedArray extends ArrayList<ModelObj> { ...@@ -48,11 +43,12 @@ public class NestedArray extends ArrayList<ModelObj> {
for(ModelObj modelObj:this) for(ModelObj modelObj:this)
{ {
Object list=modelObj.get(name); NestedArray list=modelObj.getNested(name,false);
if(list!=null&&list instanceof NestedArray) if(list!=null)
rt.addAll((NestedArray)list); rt.addAll(list);
} }
return rt; return rt;
} }
} }
package cn.ibizlab.core.lite.extensions.model; package cn.ibizlab.core.lite.extensions.model;
import cn.ibizlab.core.lite.extensions.domain.EntityModel; import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.extensions.util.LiteStorage; import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -13,7 +15,10 @@ import lombok.experimental.Accessors; ...@@ -13,7 +15,10 @@ import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Getter @Getter
@Setter @Setter
...@@ -100,4 +105,43 @@ public class Property { ...@@ -100,4 +105,43 @@ public class Property {
return entityModel; return entityModel;
} }
public String lookup(List<ModelObj> modelObjList)
{
String sql="";
Set<String> conds= new LinkedHashSet<>();
if(propertyMappings.size()>0)
{
for(PropertyMapping mapping:propertyMappings){
if (!StringUtils.isEmpty(sql))
sql += ",";
sql += mapping.getSelfPropertyColumn();
}
for(ModelObj modelObj:modelObjList)
{
String condItem="";
for(PropertyMapping mapping:propertyMappings)
{
Object val=modelObj.getEntity(mapping.getJoinPropertyEntity()).get(mapping.getJoinPropertyColumn());
if(val instanceof String)
val="'"+val.toString()+"'";
if (!StringUtils.isEmpty(condItem))
condItem += ",";
condItem += val;
}
conds.add("("+condItem+")");
}
}
String cond="";
for(String val:conds)
{
if(!StringUtils.isEmpty(cond))
cond += ",";
else
cond += val;
}
return "("+sql+") in ("+cond+")";
}
} }
...@@ -6,6 +6,7 @@ import cn.ibizlab.core.lite.extensions.domain.FieldModel; ...@@ -6,6 +6,7 @@ import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.ModelObj; import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext; import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext;
import cn.ibizlab.core.lite.extensions.model.DataModel; import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.util.LiteStorage; import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.core.extensions.mapper.DbEntityMapper; import cn.ibizlab.core.extensions.mapper.DbEntityMapper;
import cn.ibizlab.util.filter.QueryFilter; import cn.ibizlab.util.filter.QueryFilter;
...@@ -20,6 +21,7 @@ import org.springframework.util.StringUtils; ...@@ -20,6 +21,7 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
...@@ -91,27 +93,32 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl ...@@ -91,27 +93,32 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
public List<ModelObj> getModelObjs(DataModel dataModel, List<EntityObj> kEntityObjs) public List<ModelObj> getModelObjs(DataModel dataModel, List<EntityObj> kEntityObjs)
{ {
EntityModel entityModel=dataModel.getFactEntityModel(); EntityModel entityModel=dataModel.getFactEntityModel();
List<ModelObj> rt=new ArrayList<>();
LinkedHashMap<String,ModelObj> rt=new LinkedHashMap<>();
List<EntityObj> factEntityList = this.selectBase(entityModel,QueryFilter.createQuery().cust(dataModel.lookup(kEntityObjs))); List<EntityObj> factEntityList = this.selectBase(entityModel,QueryFilter.createQuery().cust(dataModel.lookup(kEntityObjs)));
factEntityList.forEach(entityObj->{ factEntityList.forEach(entityObj->
String rowKey=entityObj.getStringValue(entityModel.getKeyField().getColumnName()); rt.add(new ModelObj().setDataModel(dataModel).setFactEntity(entityObj.setProperty(dataModel.getFactPorperty()))));
ModelObj modelObj=new ModelObj().setDataModel(dataModel).setFactEntity(entityObj).setRowKey(rowKey); fillEntityObj(dataModel,rt);
entityObj.setProperty(dataModel.getFactPorperty()).setDataModel(dataModel).setModelObj(modelObj); dataModel.getNestedDataModels().forEach(subModel->
rt.put(rowKey,modelObj); this.getModelObjs(subModel, factEntityList).forEach(subObj->subObj.findParent(rt)));
}); return rt;
}
for(DataModel subModel:dataModel.getNestedDataModels()) public void fillEntityObj(DataModel dataModel,List<ModelObj> modelObjs)
{
if(dataModel.getObjectProperties().size()>1)
{
for(Property property:dataModel.getObjectProperties())
{ {
List<ModelObj> subObjs=this.getModelObjs(subModel, factEntityList); if(property.getPropertyName().equals(dataModel.getFactPorperty().getPropertyName()))
subObjs.forEach(subObj->{ continue;
subObj.findParent(rt.values()); EntityModel entityModel=property.getEntityModel();
List<EntityObj> entityObjs = this.selectBase(entityModel,QueryFilter.createQuery().cust(property.lookup(modelObjs)));
entityObjs.forEach(entityObj -> {
entityObj.setProperty(property);
entityObj.findModel(modelObjs);
}); });
} }
}
return null;
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册