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

model

上级 11ae7e27
......@@ -6,10 +6,14 @@ import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
......@@ -32,7 +36,7 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
public <T> T setTimestamp(Timestamp timestamp)
{
return this.set("_TIMESTAMP",(V)DataObject.getTimestampValue(timestamp,DataObject.getBeginDate()));
return this.set("_TIMESTAMP",(V) DataObject.getTimestampValue(timestamp, DataObject.getBeginDate()));
}
public <T> T set(String key, V value)
......@@ -128,7 +132,7 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
public Timestamp getTimestampBegin( String strParamName) {
return getTimestampValue(strParamName,DataObject.getBeginDate());
return getTimestampValue(strParamName, DataObject.getBeginDate());
}
public Timestamp getTimestampEnd( String strParamName) {
......@@ -137,7 +141,7 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
return DataObject.getEndDate();
}
try {
Timestamp t= DataObject.getTimestampValue(objValue,DataObject.getEndDate());
Timestamp t= DataObject.getTimestampValue(objValue, DataObject.getEndDate());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String time = df.format(t);
Calendar cl=Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
......
......@@ -2,12 +2,8 @@ package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.domain.MetaDataSet;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
......@@ -15,7 +11,10 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
......@@ -193,18 +192,18 @@ public class EntityModel {
String columnExp=fieldModel.getColumnExp();
if(StringUtils.isEmpty(columnExp))
continue;
if(fieldModel.isPhysicalField())
continue;
// if(fieldModel.isPhysicalField())
// continue;
if(!StringUtils.isEmpty(columnSet)){
columnSet=columnSet+",";
}
columnSet=columnSet+columnExp;
}
if(!StringUtils.isEmpty(columnSet)){
columnSet=columnSet+",";
}
columnSet=columnSet+"t.*";
// if(!StringUtils.isEmpty(columnSet)){
// columnSet=columnSet+",";
// }
//columnSet=columnSet+"t.*";
return "select "+columnSet+" from "+this.getTableName()+" t ";
}
else if("CORE".equalsIgnoreCase(dataSet))
......@@ -232,7 +231,7 @@ public class EntityModel {
public String getDsName()
{
String dsName=this.getEntity().getDsName();
String dsName=this.getEntity().getDsId();
if(StringUtils.isEmpty(dsName))
{
dsName=this.getSystemId()+"-master";
......
......@@ -3,7 +3,6 @@ package cn.ibizlab.core.lite.extensions.domain;
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.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -149,7 +148,7 @@ public class EntityObj extends DataObj<String,Object> {
public void findModel(List<ModelObj> modelObjs)
{
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
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());
......
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 cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -11,7 +9,6 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
......@@ -104,7 +101,7 @@ public class ModelObj extends DataObj<String,Object> {
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)
{
......@@ -255,7 +252,7 @@ public class ModelObj extends DataObj<String,Object> {
this.setParent(uplayerObjs.iterator().next());
return this;
}
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
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());
......
......@@ -20,9 +20,9 @@ public class PermissionNode
private List<PermissionNode> children = new ArrayList<>();
private String fullName;
private cn.ibizlab.core.lite.extensions.domain.PermissionType type;
private PermissionType type;
public cn.ibizlab.core.lite.extensions.domain.PermissionNode setUniKey(String systemid, String id)
public PermissionNode setUniKey(String systemid, String id)
{
this.systemid=systemid;
this.id=systemid+"-"+id;
......
package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
......
......@@ -7,6 +7,7 @@ import lombok.Data;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.*;
@Data
......@@ -75,7 +76,7 @@ public class SysModel {
* @return
*/
public Collection<MetaRelationship> getRelation(){
Map<String,MetaRelationship> relations =new HashMap<>();
Map<String, MetaRelationship> relations =new HashMap<>();
this.entities.forEach(entityNode->{
List<MetaRelationship> parentRelation= entityNode.getParentEntitys();
List<MetaRelationship> subRelation= entityNode.getSubEntitys();
......@@ -89,7 +90,7 @@ public class SysModel {
return relations.values();
}
private void addToRelations(Map<String,MetaRelationship> relations, List<MetaRelationship> entityRelations){
private void addToRelations(Map<String, MetaRelationship> relations, List<MetaRelationship> entityRelations){
entityRelations.forEach(entityRelation->{
entityRelation.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityRelation.getEntityName()).getBytes()));
entityRelation.setRefEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityRelation.getRefEntityName()).getBytes()));
......
......@@ -10,8 +10,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.sql.Timestamp;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Data
public class SysStructure
......@@ -32,13 +34,13 @@ public class SysStructure
private List<AppNode> apps;
public PermissionNode getPermissionTree(cn.ibizlab.core.lite.extensions.domain.PermissionType type)
public PermissionNode getPermissionTree(PermissionType type)
{
PermissionNode root = PermissionNode.builder().id(systemid).label(systemname).systemid(systemid).build();
switch (type)
{
case OPPRIV:
Map<String,PermissionNode> moudlemap = new LinkedHashMap<>();
Map<String, PermissionNode> moudlemap = new LinkedHashMap<>();
PermissionNode emptyMoudle = PermissionNode.builder().label("未分类模块").build().setUniKey(systemid,"Ungroup");
for(EntityNode node:this.entities) {
PermissionNode moudle = null;
......@@ -68,7 +70,7 @@ public class SysStructure
datasetname="查询"+datasetname+"数据";
String fullname = systemid+"/操作能力/"+enode.getLabel()+"/"+datasetname;
PermissionNode dataSetNode = PermissionNode.builder()
.label(datasetname).type(cn.ibizlab.core.lite.extensions.domain.PermissionType.OPPRIV).fullName(fullname).build()
.label(datasetname).type(PermissionType.OPPRIV).fullName(fullname).build()
.setUniKey(systemid,node.getDename()+"-search"+dataset.getId()+"-all");
enode.getChildren().add(dataSetNode);
});
......@@ -92,7 +94,7 @@ public class SysStructure
String fullname = systemid+"/操作能力/"+enode.getLabel()+"/"+actionname+"任意数据";
enode.getChildren().add(
PermissionNode.builder()
.label(actionname).type(cn.ibizlab.core.lite.extensions.domain.PermissionType.OPPRIV)
.label(actionname).type(PermissionType.OPPRIV)
.fullName(fullname).build()
.setUniKey(systemid, node.getDename() + "-" + action.getId() + "-all"));
}
......@@ -122,7 +124,7 @@ public class SysStructure
return;
actionNode.getChildren().add(
PermissionNode.builder()
.label(scopename).type(cn.ibizlab.core.lite.extensions.domain.PermissionType.OPPRIV)
.label(scopename).type(PermissionType.OPPRIV)
.fullName(preFullname+scopename).build()
.setUniKey(systemid, node.getDename() + "-" + action.getId() + "-" + scope.getId()));
});
......@@ -139,7 +141,7 @@ public class SysStructure
{
this.getUniResIds().forEach(uniRes->{
root.getChildren().add(PermissionNode.builder()
.label(uniRes.getUniresname()).type(cn.ibizlab.core.lite.extensions.domain.PermissionType.UNIRES)
.label(uniRes.getUniresname()).type(PermissionType.UNIRES)
.fullName(systemid+"/自定义资源/"+uniRes.getUniresname()).build()
.setUniKey(systemid, uniRes.getUnirescode()));
});
......@@ -178,10 +180,10 @@ public class SysStructure
return root;
}
private PermissionNode loopMenuItem(String appId,String menuId,String fullName,FuncItem item)
private PermissionNode loopMenuItem(String appId, String menuId, String fullName, FuncItem item)
{
fullName=fullName+"/"+item.getName();
PermissionNode itemNode = PermissionNode.builder().label(item.getName()).fullName(fullName).type(cn.ibizlab.core.lite.extensions.domain.PermissionType.APPMENU).build().setUniKey(systemid,appId+"-"+menuId+"-"+item.getId());
PermissionNode itemNode = PermissionNode.builder().label(item.getName()).fullName(fullName).type(PermissionType.APPMENU).build().setUniKey(systemid,appId+"-"+menuId+"-"+item.getId());
if(item.getItems()!=null)
{
......
package cn.ibizlab.core.lite.extensions.filter;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.util.filter.QueryWrapperContext;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* 关系型数据实体[MetaEntity] 查询条件对象
......
......@@ -2,9 +2,6 @@ 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;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
......@@ -192,7 +189,7 @@ public class DataModel {
return null;
}
public DataModel findDataModel(String name,String direction)
public DataModel findDataModel(String name, String direction)
{
if(StringUtils.isEmpty(direction))
direction="ALL";
......@@ -301,4 +298,38 @@ public class DataModel {
}
return "("+sql+") in ("+cond+")";
}
@JsonIgnore
@JSONField(serialize = false)
public List<DataModel> getSubDataModel()
{
List<DataModel> sublist=new ArrayList<>();
if(this.getNestedDataModels()!=null)
{
for (DataModel dataModel:this.getNestedDataModels())
sublist.add(dataModel);
for (DataModel dataModel:this.getNestedDataModels())
sublist.addAll(dataModel.getSubDataModel());
}
return sublist;
}
@JsonIgnore
@JSONField(serialize = false)
public List<Property> getParentProperty()
{
List<Property> properties=new ArrayList<>();
this.getObjectProperties().forEach(property -> properties.add(property));
DataModel parent = this.getParentDataModel();
while (parent != null) {
parent.getObjectProperties().forEach(property -> properties.add(property));
parent = parent.getParentDataModel();
}
return properties;
}
}
package cn.ibizlab.core.lite.extensions.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
@Getter
@Setter
......
......@@ -3,15 +3,10 @@ package cn.ibizlab.core.lite.extensions.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
@Getter
@Setter
......
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;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
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;
......
package cn.ibizlab.core.lite.extensions.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
@Getter
@Setter
@NoArgsConstructor
......
......@@ -4,7 +4,6 @@ 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.util.filter.QueryFilter;
import com.sun.jndi.toolkit.dir.SearchFilter;
import java.sql.Timestamp;
import java.util.List;
......@@ -14,9 +13,9 @@ public interface CommonEntityService {
List<EntityObj> selectBase(EntityModel entityModel, QueryFilter filter);
List<EntityObj> selectCore(EntityModel entityModel, QueryFilter filter);
List<EntityObj> search(String dataSet,EntityModel entityModel, QueryFilter filter);
List<EntityObj> search(String dataSet, EntityModel entityModel, QueryFilter filter);
List<EntityObj> search(String dsName,String sql, QueryFilter filter);
List<EntityObj> search(String dsName, String sql, QueryFilter filter);
List<ModelObj> getModelObjs(String metaModelId, Timestamp lastModify);
ModelObj getModelObjs(String metaModelId, Object factKey);
......
package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.extensions.mapper.DbEntityMapper;
import cn.ibizlab.core.extensions.service.DstDataSourceExService;
import cn.ibizlab.core.lite.domain.DstDataSource;
import cn.ibizlab.core.lite.extensions.domain.*;
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 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.core.lite.service.IDstDataSourceService;
import cn.ibizlab.core.lite.service.IMetaModelService;
import cn.ibizlab.util.filter.QueryFilter;
import com.alibaba.fastjson.JSON;
......@@ -16,18 +16,15 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Timestamp;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@Service
......@@ -74,7 +71,58 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
if(!StringUtils.isEmpty(filter.getCustSqlSegment()))
qw.apply(filter.getCustSqlSegment());
return baseMapper.search(sql,qw);
List<EntityObj> list=baseMapper.search(sql,qw);
list.forEach(entityObj -> {
entityObj.keySet().forEach(key->{
Object value=entityObj.get(key);
if(value!=null&&value instanceof java.sql.Clob)
{
// Clob类型 转String
BufferedReader br =null;
Reader is = null;
try {
String reString = "";
is = ((java.sql.Clob)value).getCharacterStream();
br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
entityObj.put(key,reString);
}
catch (Exception ex)
{
}
finally {
try
{
if(br!=null){
br.close();
}
}
catch (Exception ex)
{}
try
{
if(is!=null){
is.close();
}
}
catch (Exception ex)
{}
}
}
});
});
return list;
}
catch(Exception ex)
{
......@@ -95,9 +143,9 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
@Override
public List<ModelObj> getModelObjs(String metaModelId,Timestamp lastModify)
public List<ModelObj> getModelObjs(String metaModelId, Timestamp lastModify)
{
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()),DataModel.class);
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()), DataModel.class);
EntityModel entityModel=dataModel.getFactEntityModel();
FieldModel lastModifyField=entityModel.getLastModifyField();
QueryFilter filter=new QueryFilter();
......@@ -113,7 +161,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
@Override
public ModelObj getModelObjs(String metaModelId, Object factKey)
{
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()),DataModel.class);
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()), DataModel.class);
List<EntityObj> kEntityObjs = new ArrayList<>();
kEntityObjs.add(new EntityObj().set(dataModel.getFactEntityModel().getKeyField().getColumnName(),factKey));
List<ModelObj> list = getModelObjs(dataModel,kEntityObjs);
......@@ -125,7 +173,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
@Override
public ModelObj getModelObjs(String metaModelId, Object... factUniKey)
{
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()),DataModel.class);
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()), DataModel.class);
List<EntityObj> kEntityObjs = new ArrayList<>();
EntityObj entityObj = new EntityObj();
List<FieldModel> uniKeys = dataModel.getFactEntityModel().getUnionKeyFields();
......@@ -141,7 +189,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
@Override
public List<ModelObj> getModelObjs(String metaModelId, List<EntityObj> kEntityObjs)
{
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()),DataModel.class);
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()), DataModel.class);
return getModelObjs(dataModel,kEntityObjs);
}
......@@ -149,7 +197,8 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
{
EntityModel entityModel=dataModel.getFactEntityModel();
List<ModelObj> rt=new ArrayList<>();
List<EntityObj> factEntityList = this.selectBase(entityModel,QueryFilter.createQuery().cust(dataModel.lookup(kEntityObjs)));
List<EntityObj> factEntityList = new ArrayList<>();
splitList(kEntityObjs,1000).forEach(list -> factEntityList.addAll(this.selectBase(entityModel, QueryFilter.createQuery().cust(dataModel.lookup(list)))));
factEntityList.forEach(entityObj->
rt.add(new ModelObj().setDataModel(dataModel).setFactEntity(entityObj.setProperty(dataModel.getFactPorperty()))));
fillEntityObj(dataModel,rt);
......@@ -159,7 +208,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
return rt;
}
public void fillEntityObj(DataModel dataModel,List<ModelObj> modelObjs)
public void fillEntityObj(DataModel dataModel, List<ModelObj> modelObjs)
{
if(dataModel.getObjectProperties().size()>1)
{
......@@ -168,7 +217,9 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
if(property.getPropertyName().equals(dataModel.getFactPorperty().getPropertyName()))
continue;
EntityModel entityModel=property.getEntityModel();
List<EntityObj> entityObjs = this.selectBase(entityModel,QueryFilter.createQuery().cust(property.lookup(modelObjs)));
List<EntityObj> entityObjs = new ArrayList<>();
splitList(modelObjs,1000).forEach(list -> entityObjs.addAll(this.selectBase(entityModel, QueryFilter.createQuery().cust(property.lookup(list)))));
entityObjs.forEach(entityObj -> {
entityObj.setProperty(property);
entityObj.findModel(modelObjs);
......@@ -178,4 +229,20 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
}
private <T> List<List<T>> splitList(List<T> list, int groupSize){
int length = list.size();
// 计算可以分成多少组
int num = ( length + groupSize - 1 )/groupSize ; // TODO
List<List<T>> newList = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
// 开始位置
int fromIndex = i * groupSize;
// 结束位置
int toIndex = (i+1) * groupSize < length ? ( i+1 ) * groupSize : length ;
newList.add(list.subList(fromIndex,toIndex)) ;
}
return newList ;
}
}
......@@ -36,12 +36,12 @@ public class DstAppService extends DstAppServiceImpl
@Autowired
private IDstSystemService sysPSSystemService;
@Autowired
private LiteModelService liteModelService;
@Override
public DstApp get(String key)
......
......@@ -5,15 +5,22 @@ import cn.ibizlab.core.lite.extensions.domain.MetaEntityModel;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.extensions.mapping.MetaEntityMapping;
import cn.ibizlab.core.lite.service.*;
import cn.ibizlab.util.errors.BadRequestAlertException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.*;
@Service
......@@ -170,4 +177,32 @@ public class LiteCoreService {
if(list.size()>0)
relationService.saveBatch(list);
}
@Autowired
@Lazy
private IDstComponentService dstComponentService;
@Cacheable( value="dstcomponent",key = "'row:'+#p0+'.'+#p1")
public DstComponent getComponent(String app, String component) {
DstComponent dstComponent = dstComponentService.getOne(Wrappers.<DstComponent>lambdaQuery().eq(DstComponent::getAppId, app).and(
wrapper ->
wrapper.eq(DstComponent::getCodeName, component).or().eq(DstComponent::getName, component)),
true);
if (dstComponent==null|| StringUtils.isEmpty(dstComponent.getConfig()))
throw new BadRequestAlertException("未找到配置", "DstComponent", component);
return dstComponent;
}
@CacheEvict( value="dstcomponent",key = "'row:'+#p0+'.'+#p1")
public void resetComponent(String app, String component)
{
}
}
......@@ -4,6 +4,7 @@ import cn.ibizlab.core.lite.domain.*;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.RelationshipModel;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.core.lite.filter.MetaEntitySearchContext;
import cn.ibizlab.core.lite.filter.MetaFieldSearchContext;
......@@ -54,9 +55,6 @@ public class LiteModelService {
@Lazy
private IMetaRelationshipService metaRelationshipService;
@Autowired
@Lazy
private IDstSystemService dstSystemService;
@Autowired
@Lazy
......@@ -66,10 +64,6 @@ public class LiteModelService {
@Lazy
private IMetaDataSetService metaDataSetService;
@Autowired
@Lazy
private IDstComponentService dstComponentService;
@Autowired
@Lazy
private LiteModelService proxyService;
......@@ -177,6 +171,27 @@ public class LiteModelService {
});
}
@Autowired
@Lazy
private IMetaModelService metaModelService;
public DataModel getDataModel(String dataModelId)
{
return JSON.toJavaObject(JSON.parseObject(metaModelService.get(dataModelId).getConfig()),DataModel.class);
}
public DataModel getDataModel(String rootDataModelId,String subDataModelName)
{
DataModel dataModel=getDataModel(rootDataModelId);
if(StringUtils.isEmpty(subDataModelName))
return dataModel;
return dataModel.findDataModel(subDataModelName,"ALL");
}
@Autowired
@Lazy
private IDstSystemService dstSystemService;
@Cacheable( value="syspssystem",key = "'row:all-dst-apps'")
public LinkedHashMap<String, DstApp> getApps() {
......@@ -229,25 +244,4 @@ public class LiteModelService {
return list;
}
@Cacheable( value="dstcomponent",key = "'row:'+#p0+'.'+#p1")
public DstComponent getComponent(String app, String component) {
DstComponent dstComponent = dstComponentService.getOne(Wrappers.<DstComponent>lambdaQuery().eq(DstComponent::getAppId, app).and(
wrapper ->
wrapper.eq(DstComponent::getCodeName, component).or().eq(DstComponent::getName, component)),
true);
if (dstComponent==null||StringUtils.isEmpty(dstComponent.getConfig()))
throw new BadRequestAlertException("未找到配置", "DstComponent", component);
return dstComponent;
}
@CacheEvict( value="dstcomponent",key = "'row:'+#p0+'.'+#p1")
public void resetComponent(String app, String component)
{
}
}
......@@ -3,21 +3,19 @@ package cn.ibizlab.core.lite.extensions.util;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class LiteStorage {
private static Map<String,MetaEntity> metaEntityStorage= new HashMap<String, MetaEntity>();
private static Map<String, MetaEntity> metaEntityStorage= new HashMap<String, MetaEntity>();
private static Object entityLock=new Object();
public static Map<String,MetaEntity> putMetaEntity(MetaEntity metaEntity)
public static Map<String, MetaEntity> putMetaEntity(MetaEntity metaEntity)
{
synchronized (entityLock)
{
......
......@@ -3,12 +3,19 @@ package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.lite.domain.DstComponent;
import cn.ibizlab.core.lite.domain.DstConfig;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.extensions.domain.*;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.service.DbEntityService;
import cn.ibizlab.core.lite.extensions.service.LiteCoreService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.service.IDstComponentService;
import cn.ibizlab.core.lite.service.IDstConfigService;
import cn.ibizlab.util.client.IBZDictFeignClient;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.security.AuthenticationUser;
......@@ -28,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
......@@ -60,13 +68,86 @@ public class LiteCoreResource {
return ResponseEntity.ok(list);
}
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}","/lite/datamodels/{modelid}/name/{modelname}"})
public ResponseEntity<DataModel> getDataModel(@PathVariable(name="modelid") String modelid,
@PathVariable(name="modelname",required = false) String modelname)
{
return ResponseEntity.ok(liteModelService.getDataModel(modelid,modelname));
}
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}/submodels","/lite/datamodels/{modelid}/name/{modelname}/submodels"})
public ResponseEntity<List<Option>> getDataModelSubModels(@PathVariable(name="modelid") String modelid,
@PathVariable(name="modelname",required = false) String modelname)
{
List<Option> list = new ArrayList<>();
liteModelService.getDataModel(modelid,modelname).getSubDataModel().forEach(dataModel -> list.add(new Option().setId(dataModel.getDataModelName()).setLabel(dataModel.getFactPorperty().getEntityModel().getLogicName()+"["+dataModel.getDataModelName()+"]")));
return ResponseEntity.ok(list);
}
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}/propertys","/lite/datamodels/{modelid}/name/{modelname}/propertys"})
public ResponseEntity<List<Option>> getDataModelParentProperty(@PathVariable(name="modelid") String modelid,
@PathVariable(name="modelname",required = false) String modelname)
{
List<Option> list = new ArrayList<>();
liteModelService.getDataModel(modelid,modelname).getParentProperty().forEach(property -> {
Option option = new Option().setId(property.getPropertyName()).setLabel(property.getEntityModel().getLogicName()+"["+property.getPropertyName()+"]");
list.add(option);
});
return ResponseEntity.ok(list);
}
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}/propertys/{propertyname}/fields","/lite/datamodels/{modelid}/name/{modelname}/propertys/{propertyname}/fields"})
public ResponseEntity<List<Option>> getDataModelParentField(@PathVariable(name="modelid") String modelid,
@PathVariable(name="modelname",required = false) String modelname,
@PathVariable(name="propertyname",required = false) String propertyname)
{
List<Option> list = new ArrayList<>();
Property property=liteModelService.getDataModel(modelid,modelname).findObjectProperty(propertyname,"UP");
property.getEntityModel().getFields().forEach(field -> {
Option option = new Option().setId(property.getPropertyName()+"."+field.getColumnName()).setLabel(field.getComment()+"["+field.getColumnName()+"]");
list.add(option);
});
return ResponseEntity.ok(list);
}
@Autowired
private IBZDictFeignClient dictFeignClient;
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}/{propertyname}.{fieldname}/dict"})
public ResponseEntity<List<CodeItem>> getDataModelFieldDict(@PathVariable(name="modelid") String modelid,
@PathVariable(name="propertyname",required = false) String propertyname,
@PathVariable(name="fieldname",required = false) String fieldname)
{
List<CodeItem> list = new ArrayList<>();
Property property=liteModelService.getDataModel(modelid).findObjectProperty(propertyname,"ALL");
if(property!=null)
{
MetaField field=property.getEntityModel().getField(fieldname).getField();
if(field!=null)
{
String dict = field.getDict();
if(!StringUtils.isEmpty(dict))
{
CodeList codeList=dictFeignClient.getCodeList(dict);
if(codeList!=null)
list=codeList.getOptions();
}
}
}
return ResponseEntity.ok(list);
}
@RequestMapping(method = RequestMethod.GET, value = "/lite/{system}/entitys")
public ResponseEntity<List<EntityModel>> getEntityModel(@PathVariable("system") String system) {
return ResponseEntity.status(HttpStatus.OK).body(liteModelService.getEntityModel(system));
}
@RequestMapping(method = RequestMethod.GET, value = "/lite/{system}/entitys/{entity}")
public ResponseEntity<EntityModel> getEntityModel(@PathVariable("system") String system,@PathVariable("entity") String entity) {
public ResponseEntity<EntityModel> getEntityModel(@PathVariable("system") String system, @PathVariable("entity") String entity) {
return ResponseEntity.status(HttpStatus.OK).body(liteModelService.getEntityModel(system,entity));
}
......@@ -85,10 +166,11 @@ public class LiteCoreResource {
return ResponseEntity.status(HttpStatus.OK).body(liteModelService.getEntityModel(system,entity).getNesteds());
}
@RequestMapping(method = RequestMethod.GET, value = "/lite/{app}/components/{component}")
public ResponseEntity<JSON> getComponent(@PathVariable("app") String app, @PathVariable("component") String component) {
DstComponent dstComponent = liteModelService.getComponent(app,component);
DstComponent dstComponent = liteCoreService.getComponent(app,component);
return ResponseEntity.status(HttpStatus.OK).body(JSON.parseObject(dstComponent.getConfig()));
}
......
package cn.ibizlab.util.client;
import cn.ibizlab.util.dict.CodeList;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
@Component
public class IBZDictFallback implements IBZDictFeignClient {
@Override
public Boolean syncRuntimeDict(JSONArray catalogs) {
return null;
}
@Override
public CodeList getCodeList(@PathVariable("code") String code) {
return null;
}
}
package cn.ibizlab.util.client;
import cn.ibizlab.util.dict.CodeList;
import com.alibaba.fastjson.JSONArray;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(value = "${ibiz.ref.service.dict:ibzdict-api}",contextId = "dict",fallback = IBZDictFallback.class)
public interface IBZDictFeignClient
{
@RequestMapping(method = RequestMethod.POST, value = "/dictionarys/catalogs/sync")
Boolean syncRuntimeDict(@RequestBody JSONArray catalogs);
@RequestMapping(method = RequestMethod.GET, value = "/dictionarys/codelist/{code}")
CodeList getCodeList(@PathVariable("code") String code);
}
package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Catalog
{
private String code;
private String name;
@JSONField(name = "items")
@JsonProperty("items")
private List<Option> options = new ArrayList<>();
}
package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CodeItem
{
private String id;
private Object value;
private String label;
@JsonIgnore
@JSONField(serialize = false)
private List<CodeItem> children;
private String iconClass;
private String filter;
private Boolean disabled;
@JSONField(name = "pvalue")
@JsonProperty("pvalue")
private String parent;
private Map<String,Object> extension;
@JSONField(name = "text")
@JsonProperty("text")
public String getText()
{
return label;
}
}
package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CodeList
{
@JSONField(name = "srfkey")
@JsonProperty("srfkey")
private String code;
private String name;
@JSONField(name = "emptytext")
@JsonProperty("emptytext")
public String getEmptytext()
{
return "";
}
@JSONField(name = "items")
@JsonProperty("items")
private List<CodeItem> options = new ArrayList<>();
}
package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Option
{
private String id;
private Object value;
private String label;
private List<Option> children;
private String iconClass;
private String filter;
private Boolean disabled;
@JsonIgnore
@JSONField(serialize = false)
private String parent;
private Map<String,Object> extension;
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册