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

自动填充完成

上级 da055f93
......@@ -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){
for(K field : this.keySet()){
Object value=this.get(field);
......
......@@ -8,6 +8,9 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
public class EntityObj extends DataObj<String,Object> {
......@@ -22,12 +25,6 @@ public class EntityObj extends DataObj<String,Object> {
return entityModel;
}
public EntityObj setEntityModel(EntityModel entityModel)
{
this.entityModel=entityModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private DataModel dataModel;
......@@ -35,18 +32,9 @@ public class EntityObj extends DataObj<String,Object> {
@JsonIgnore
@JSONField(serialize = false)
public DataModel getDataModel() {
if(this.dataModel==null&&this.getProperty()!=null)
this.dataModel=this.getProperty().getOwnerDataModel();
return dataModel;
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Property property;
......@@ -65,7 +53,8 @@ public class EntityObj extends DataObj<String,Object> {
this.setDstSystemId(property.getSystem());
if(!StringUtils.isEmpty(property.getPropertyEntity()))
this.setMetaEntityName(property.getPropertyEntity());
this.setEntityModel(property.getEntityModel());
this.entityModel=property.getEntityModel();
this.dataModel=property.getOwnerDataModel();
}
this.property = property;
return this;
......@@ -117,5 +106,36 @@ public class EntityObj extends DataObj<String,Object> {
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> {
@JSONField(serialize = false)
public ModelObj setParent(ModelObj parent) {
this.parent = parent;
if(parent!=null)
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
return this;
}
......@@ -63,7 +65,7 @@ public class ModelObj extends DataObj<String,Object> {
Property property=this.getDataModel().getObjectProperty(name);
if(property!=null) {
return new EntityObj().setDataModel(this.getDataModel()).setProperty(property).setRowKey(this.getRowKey());
return new EntityObj().setProperty(property).setRowKey(this.getRowKey());
}
if(recursion)
......@@ -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)
{
if(entityObj!=null)
{
if(entityObj.getModelObj()==null)
entityObj.setModelObj(this);
this.set(name, entityObj);
}
return this;
}
public ModelObj setFactEntity(EntityObj entityObj)
{
this.set(this.getDataModel().getFactPorperty().getPropertyName(),entityObj);
this.setEntity(this.getDataModel().getFactPorperty().getPropertyName(),entityObj);
return this;
}
......@@ -109,11 +116,16 @@ public class ModelObj extends DataObj<String,Object> {
{
Object list=this.get(name);
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);
if(model!=null)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
return new NestedArray().setParent(this);
if(recursion)
{
......@@ -137,7 +149,7 @@ public class ModelObj extends DataObj<String,Object> {
{
subarry=subarry.getSubNested(steps.get(i));
if(subarry.size()==0)
return new NestedArray().setDataModel(this.getDataModel()).setParent(this);
return new NestedArray().setParent(this);
}
return subarry;
}
......@@ -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> {
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)
{
ModelObj parent= uplayerObjs.iterator().next();
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
this.setParent(uplayerObjs.iterator().next());
return this;
}
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
......@@ -188,9 +210,7 @@ public class ModelObj extends DataObj<String,Object> {
});
if(tmps.size()==1)
{
ModelObj parent= tmps.values().iterator().next();
this.setParent(parent);
parent.getNested(this.getDataModel().getDataModelName(),false).add(this);
this.setParent(tmps.values().iterator().next());
}
return this;
}
......
......@@ -18,13 +18,6 @@ public class NestedArray extends ArrayList<ModelObj> {
return dataModel;
}
@JsonIgnore
@JSONField(serialize = false)
public NestedArray setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private ModelObj parent;
......@@ -39,6 +32,8 @@ public class NestedArray extends ArrayList<ModelObj> {
@JSONField(serialize = false)
public NestedArray setParent(ModelObj parent) {
this.parent = parent;
if(parent!=null&&this.getDataModel()==null)
this.dataModel=(parent.getDataModel());
return this;
}
......@@ -48,11 +43,12 @@ public class NestedArray extends ArrayList<ModelObj> {
for(ModelObj modelObj:this)
{
Object list=modelObj.get(name);
if(list!=null&&list instanceof NestedArray)
rt.addAll((NestedArray)list);
NestedArray list=modelObj.getNested(name,false);
if(list!=null)
rt.addAll(list);
}
return rt;
}
}
package cn.ibizlab.core.lite.extensions.model;
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 com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
......@@ -13,7 +15,10 @@ import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Getter
@Setter
......@@ -100,4 +105,43 @@ public class Property {
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;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext;
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.extensions.mapper.DbEntityMapper;
import cn.ibizlab.util.filter.QueryFilter;
......@@ -20,6 +21,7 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
......@@ -91,27 +93,32 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
public List<ModelObj> getModelObjs(DataModel dataModel, List<EntityObj> kEntityObjs)
{
EntityModel entityModel=dataModel.getFactEntityModel();
LinkedHashMap<String,ModelObj> rt=new LinkedHashMap<>();
List<ModelObj> rt=new ArrayList<>();
List<EntityObj> factEntityList = this.selectBase(entityModel,QueryFilter.createQuery().cust(dataModel.lookup(kEntityObjs)));
factEntityList.forEach(entityObj->{
String rowKey=entityObj.getStringValue(entityModel.getKeyField().getColumnName());
ModelObj modelObj=new ModelObj().setDataModel(dataModel).setFactEntity(entityObj).setRowKey(rowKey);
entityObj.setProperty(dataModel.getFactPorperty()).setDataModel(dataModel).setModelObj(modelObj);
rt.put(rowKey,modelObj);
});
factEntityList.forEach(entityObj->
rt.add(new ModelObj().setDataModel(dataModel).setFactEntity(entityObj.setProperty(dataModel.getFactPorperty()))));
fillEntityObj(dataModel,rt);
dataModel.getNestedDataModels().forEach(subModel->
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);
subObjs.forEach(subObj->{
subObj.findParent(rt.values());
if(property.getPropertyName().equals(dataModel.getFactPorperty().getPropertyName()))
continue;
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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册