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

model

上级 3a12d7aa
......@@ -19,11 +19,15 @@ public class EntityObj extends DataObj<String,Object> {
@JSONField(serialize = false)
public EntityModel getEntityModel()
{
if(entityModel==null)
entityModel=LiteStorage.getLiteModelService().getEntityModel(this.getDstSystemId(),this.getMetaEntityName());
return entityModel;
}
public EntityObj setEntityModel(EntityModel entityModel)
{
this.entityModel=entityModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private DataModel dataModel;
......@@ -61,6 +65,7 @@ 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.property = property;
return this;
......
......@@ -44,6 +44,13 @@ public class FieldModel {
return "";
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isPhysicalField()
{
return 1==this.getField().getPhysicalField();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isKeyField()
......
......@@ -26,8 +26,9 @@ public class ModelObj extends DataObj<String,Object> {
@JsonIgnore
@JSONField(serialize = false)
public void setDataModel(DataModel dataModel) {
public ModelObj setDataModel(DataModel dataModel) {
this.dataModel = dataModel;
return this;
}
@JsonIgnore
......@@ -42,8 +43,9 @@ public class ModelObj extends DataObj<String,Object> {
@JsonIgnore
@JSONField(serialize = false)
public void setParent(ModelObj parent) {
public ModelObj setParent(ModelObj parent) {
this.parent = parent;
return this;
}
public EntityObj getEntity(String name)
......
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.FieldModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -11,7 +14,9 @@ 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;
@Getter
@Setter
......@@ -107,6 +112,13 @@ public class DataModel {
return null;
}
@JsonIgnore
@JSONField(serialize = false)
public EntityModel getFactEntityModel()
{
return this.getFactPorperty().getEntityModel();
}
public Property getObjectProperty(String name)
{
if(this.getObjectProperties()!=null&&(!StringUtils.isEmpty(name)))
......@@ -216,4 +228,62 @@ public class DataModel {
", layerMappings=" + getLayerMappings() +
"}\r\n";
}
public String lookup(List<EntityObj> parentEntityList)
{
String sql="";
String cond="";
List<String> selfCols=new ArrayList<>();
List<String> parentCols=new ArrayList<>();
if(layerMappings.size()>0)
{
layerMappings.forEach(layerMapping -> {
selfCols.add(layerMapping.getSelfPropertyColumn());
parentCols.add(layerMapping.getParentPropertyColumn());
});
}
else
{
EntityModel entityModel=this.getFactEntityModel();
if(entityModel.getKeyField().isPhysicalField())
{
selfCols.add(entityModel.getKeyField().getColumnName());
parentCols.add(entityModel.getKeyField().getColumnName());
}
else
entityModel.getUnionKeyFields().forEach(fieldModel -> {
selfCols.add(fieldModel.getColumnName());
parentCols.add(fieldModel.getColumnName());
});
}
for (String selfCol : selfCols)
{
if (!StringUtils.isEmpty(sql))
sql += ",";
sql += selfCol;
}
for(EntityObj entityObj:parentEntityList)
{
String condItem="";
for(String parentCol:parentCols)
{
Object val=entityObj.get(parentCol);
if(val instanceof String)
{
val="'"+val.toString()+"'";
}
if (!StringUtils.isEmpty(condItem))
condItem += ",";
condItem += val;
}
if (!StringUtils.isEmpty(cond))
cond += ",";
cond=cond+"("+condItem+")";
}
return "("+sql+") in ("+cond+")";
}
}
package cn.ibizlab.core.lite.extensions.model;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -83,4 +85,19 @@ public class Property {
", propertyMappings=" + getPropertyMappings() +
"}\r\n";
}
@JsonIgnore
@JSONField(serialize = false)
private EntityModel entityModel;
@JsonIgnore
@JSONField(serialize = false)
public synchronized EntityModel getEntityModel()
{
if(entityModel==null)
entityModel= LiteStorage.getLiteModelService().getEntityModel(this.getSystem(),this.getPropertyEntity());
return entityModel;
}
}
......@@ -20,6 +20,7 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@Service
......@@ -54,7 +55,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
DynamicDataSourceContextHolder.push(dsName);
DbEntitySearchContext context=new DbEntitySearchContext();
context.setFilter(filter);
return baseMapper.search(sql,context.getSelectCond());
return baseMapper.search(sql,context.getSelectCond().apply(filter.getCustSqlSegment()));
}
catch(Exception ex)
{
......@@ -74,7 +75,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
public List<ModelObj> getModelObjs(DataModel dataModel,Timestamp lastModify)
{
EntityModel entityModel=liteModelService.getEntityModel(dataModel.getFactPorperty().getSystem(), dataModel.getFactPorperty().getPropertyEntity());
EntityModel entityModel=dataModel.getFactEntityModel();
FieldModel lastModifyField=entityModel.getLastModifyField();
QueryFilter filter=new QueryFilter();
......@@ -86,4 +87,25 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
return new ArrayList<>();
}
public List<ModelObj> getModelObjs(DataModel dataModel, List<EntityObj> kEntityObjs)
{
EntityModel entityModel=dataModel.getFactEntityModel();
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);
rt.put(rowKey,modelObj);
});
return null;
}
}
......@@ -124,6 +124,22 @@ public class QueryFilter {
}
@JsonIgnore
@Transient
private String custSqlSegment;
public QueryFilter cust(String custSqlSegment)
{
this.custSqlSegment=custSqlSegment;
return null;
}
@JsonIgnore
@Transient
public String getCustSqlSegment()
{
return this.custSqlSegment;
}
@Override
public String toString() {
return "QueryFilter{" +
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册