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

model

上级 b8d21011
package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.LayerMapping;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -9,6 +9,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class ModelObj extends DataObj<String,Object> {
......@@ -49,6 +51,11 @@ public class ModelObj extends DataObj<String,Object> {
}
public EntityObj getEntity(String name)
{
return getEntity(name,true);
}
public EntityObj getEntity(String name,boolean recursion)
{
Object obj=this.get(name);
if(obj!=null&&obj instanceof EntityObj)
......@@ -58,19 +65,47 @@ public class ModelObj extends DataObj<String,Object> {
if(property!=null) {
return new EntityObj().setDataModel(this.getDataModel()).setProperty(property).setRowKey(this.getRowKey());
}
property=this.getDataModel().findObjectProperty(name,"UP");
if(property!=null){
int layerDiff=this.getDataModel().getLayerNo()-property.getLayerNo();
ModelObj parentObj=this;
for(int i=0;i<layerDiff;i++)
parentObj=parentObj.getParent();
return parentObj.getEntity(name);
}
if(recursion)
{
property=this.getDataModel().findObjectProperty(name,"UP");
if(property!=null){
int layerDiff=this.getDataModel().getLayerNo()-property.getLayerNo();
ModelObj parentObj=this;
for(int i=0;i<layerDiff;i++)
parentObj=parentObj.getParent();
return parentObj.getEntity(name,false);
}
}
return new EntityObj().setDataModel(this.getDataModel()).setDstSystemId(this.getDataModel().getFactPorperty().getSystem()).setMetaEntityName(name).setRowKey(this.getRowKey());
}
public ModelObj setEntity(String name,EntityObj entityObj)
{
this.set(name, entityObj);
return this;
}
public ModelObj setFactEntity(EntityObj entityObj)
{
this.set(this.getDataModel().getFactPorperty().getPropertyName(),entityObj);
return this;
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj getFactEntity()
{
return this.getEntity(this.getDataModel().getFactPorperty().getPropertyName(),false);
}
public NestedArray getNested(String name)
{
return getNested(name,true);
}
public NestedArray getNested(String name,boolean recursion)
{
Object list=this.get(name);
if(list!=null&&list instanceof NestedArray)
......@@ -80,34 +115,36 @@ public class ModelObj extends DataObj<String,Object> {
if(model!=null)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
model=this.getDataModel().findDataModel(name,"DOWN");
if(model!=null)
if(recursion)
{
List<String> steps=new ArrayList<>();
DataModel tmpModel=model;
while (tmpModel.getParentDataModel()!=null&&!tmpModel.getParentDataModel().getDataModelName().equalsIgnoreCase(this.getDataModel().getDataModelName()))
model=this.getDataModel().findDataModel(name,"DOWN");
if(model!=null)
{
tmpModel=model.getParentDataModel();
steps.add(0,tmpModel.getDataModelName());
}
if(steps.size()>1)
{
NestedArray subarry=this.getNested(steps.get(0));
if(subarry.size()>0)
List<String> steps=new ArrayList<>();
DataModel tmpModel=model;
while (tmpModel.getParentDataModel()!=null&&!tmpModel.getParentDataModel().getDataModelName().equalsIgnoreCase(this.getDataModel().getDataModelName()))
{
tmpModel=model.getParentDataModel();
steps.add(0,tmpModel.getDataModelName());
}
if(steps.size()>1)
{
for(int i=1;i<steps.size();i++)
NestedArray subarry=this.getNested(steps.get(0),false);
if(subarry.size()>0)
{
subarry=subarry.getSubNested(steps.get(i));
if(subarry.size()==0)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
for(int i=1;i<steps.size();i++)
{
subarry=subarry.getSubNested(steps.get(i));
if(subarry.size()==0)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
}
return subarry;
}
return subarry;
}
}
}
}
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
}
......@@ -130,5 +167,32 @@ public class ModelObj extends DataObj<String,Object> {
return super.get(key);
}
public ModelObj findParent(Collection<ModelObj> uplayerObjs)
{
if(uplayerObjs.size()==1)
{
ModelObj parent= uplayerObjs.iterator().next();
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
return this;
}
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
uplayerObjs.forEach(obj->tmps.put(obj.getRowKey(),obj));
this.getDataModel().getLayerMappings().forEach(layerMapping->{
String selfVal=this.getFactEntity().getStringValue(layerMapping.getSelfPropertyColumn());
uplayerObjs.forEach(parent->{
String parentVal=parent.getFactEntity().getStringValue(layerMapping.getParentPropertyColumn());
if((StringUtils.isEmpty(parentVal))||(!parentVal.equals(selfVal)))
tmps.remove(parent.getRowKey());
});
});
if(tmps.size()==1)
{
ModelObj parent= tmps.values().iterator().next();
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
}
return this;
}
}
......@@ -95,13 +95,20 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
LinkedHashMap<String,ModelObj> rt=new LinkedHashMap<>();
List<EntityObj> factEntityList = this.selectBase(entityModel,QueryFilter.createQuery().cust(dataModel.lookup(kEntityObjs)));
factEntityList.forEach(entityObj->{
entityObj.setProperty(dataModel.getFactPorperty()).setDataModel(dataModel);
String rowKey=entityObj.getStringValue(entityModel.getKeyField().getColumnName());
ModelObj modelObj=new ModelObj().setDataModel(dataModel).setRowKey(rowKey);
modelObj.set(dataModel.getFactPorperty().getPropertyName(),entityObj);
ModelObj modelObj=new ModelObj().setDataModel(dataModel).setFactEntity(entityObj).setRowKey(rowKey);
entityObj.setProperty(dataModel.getFactPorperty()).setDataModel(dataModel).setModelObj(modelObj);
rt.put(rowKey,modelObj);
});
for(DataModel subModel:dataModel.getNestedDataModels())
{
List<ModelObj> subObjs=this.getModelObjs(subModel, factEntityList);
subObjs.forEach(subObj->{
subObj.findParent(rt.values());
});
}
return null;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册