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

tableschema

上级 7e478f0b
...@@ -18,7 +18,9 @@ import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam; ...@@ -18,7 +18,9 @@ import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl; import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -58,12 +60,9 @@ public class DynamicModelService { ...@@ -58,12 +60,9 @@ public class DynamicModelService {
return initDynamicSystem(system); return initDynamicSystem(system);
} }
private IPSSystem initDynamicSystem(String system) private IPSSystem initDynamicSystem(String system)
{ {
if(dynamicSystems==null)
dynamicSystems=new HashMap<>();
IPSSystem iPSSystem = null;
String strPSModelFolderPath=null; String strPSModelFolderPath=null;
if(Files.exists(Paths.get(getModelPath(),system,"model","PSSYSTEM.json"))) { if(Files.exists(Paths.get(getModelPath(),system,"model","PSSYSTEM.json"))) {
strPSModelFolderPath=Paths.get(getModelPath(),system,"model").toString(); strPSModelFolderPath=Paths.get(getModelPath(),system,"model").toString();
...@@ -74,6 +73,14 @@ public class DynamicModelService { ...@@ -74,6 +73,14 @@ public class DynamicModelService {
if(allDynamicModel.containsKey(system)) if(allDynamicModel.containsKey(system))
strPSModelFolderPath = allDynamicModel.get(system).getDynamicModelPath(); strPSModelFolderPath = allDynamicModel.get(system).getDynamicModelPath();
} }
return initDynamicSystem(system,strPSModelFolderPath);
}
private IPSSystem initDynamicSystem(String system, String strPSModelFolderPath)
{
if(dynamicSystems==null)
dynamicSystems=new HashMap<>();
IPSSystem iPSSystem = null;
if(StringUtils.isEmpty(strPSModelFolderPath)) if(StringUtils.isEmpty(strPSModelFolderPath))
throw new BadRequestAlertException("加载系统模型错误,未找到对应模型目录", "DynamicSystem", system); throw new BadRequestAlertException("加载系统模型错误,未找到对应模型目录", "DynamicSystem", system);
...@@ -647,4 +654,52 @@ public class DynamicModelService { ...@@ -647,4 +654,52 @@ public class DynamicModelService {
} }
private Map<String,Long> systemModifyMap=new HashMap<>();
@Caching( evict = {
@CacheEvict( value="syspssystem",allEntries = true),
@CacheEvict( value="meta-entities", key = "'system:'+#p0"),
@CacheEvict( value="meta-entities", key = "'system:keymap-'+#p0")
})
public void resetSystem(String system)
{
}
private IPSSystem reloadDynamicSystem(DstSystemModel system)
{
return initDynamicSystem(system.getPssystemid(),system.getDynamicModelPath());
}
public Map<String,Map<String,Long>> getAllDynamicModelVersion()
{
Map<String,Map<String,Long>> ret=new LinkedHashMap<>();
this.findAllDynamicModel().values().forEach(dstSystemModel -> {
if(ret.containsKey(dstSystemModel.getPssystemid()))
return;
if((!systemModifyMap.containsKey(dstSystemModel.getPssystemid()))||systemModifyMap.get(dstSystemModel.getPssystemid())<dstSystemModel.getLastModify())
{
reloadDynamicSystem(dstSystemModel);
this.getProxy().resetSystem(dstSystemModel.getPssystemid());
if(!dstSystemModel.getPssystemid().equals(dstSystemModel.getPssystemid().toLowerCase()))
this.getProxy().resetSystem(dstSystemModel.getPssystemid().toLowerCase());
}
systemModifyMap.put(dstSystemModel.getPssystemid(),dstSystemModel.getLastModify());
Map<String,Long> entities=new LinkedHashMap<>();
ret.put(dstSystemModel.getPssystemid(),entities);
try {
this.getEntities(dstSystemModel.getPssystemid()).values().forEach(metaEntityModel -> {
if(entities.containsKey(metaEntityModel.getEntityName()))
return;
entities.put(metaEntityModel.getEntityName(),dstSystemModel.getLastModify());
});
} catch (Exception exception) {
}
});
return ret;
}
} }
...@@ -113,6 +113,19 @@ public class POSchema { ...@@ -113,6 +113,19 @@ public class POSchema {
return this; return this;
} }
@JsonIgnore
@JSONField(serialize = false)
public Set<String> getForeignKey()
{
Set<String> fks=new HashSet<>();
if(foreignKeyConstraints!=null)
{
foreignKeyConstraints.forEach(fk->fks.add(fk.getConstraintName()));
}
return fks;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,Column> columnMaps; private Map<String,Column> columnMaps;
...@@ -633,7 +646,19 @@ public class POSchema { ...@@ -633,7 +646,19 @@ public class POSchema {
put("h2", "mysql"); put("h2", "mysql");
}}; }};
public Segment getSegment(String tag)
{
if(segments!=null)
{
for(Segment script:segments)
{
String key=DataObject.getStringValue(script.getName(),"").concat(".").concat(DataObject.getStringValue(script.getVendorProvider(),""));
if(key.equals(tag))
return script;
}
}
return null;
}
public Segment getSegment(String name,String type) public Segment getSegment(String name,String type)
{ {
......
...@@ -41,7 +41,11 @@ public class PojoOption extends DataObj ...@@ -41,7 +41,11 @@ public class PojoOption extends DataObj
} }
public String getSystem(){ public String getSystem(){
return this.getStringValue("system_id",this.getStringValue("system_name",this.getStringValue("system"))); return this.getStringValue("system_id",this.getStringValue("system",this.getStringValue("system_name")));
}
public String getSystemName(){
return this.getStringValue("system_name",this.getStringValue("system",this.getStringValue("system_id")));
} }
public String getPackage(){ public String getPackage(){
......
...@@ -55,126 +55,126 @@ public interface IPersistentService { ...@@ -55,126 +55,126 @@ public interface IPersistentService {
default BaseData create(String datasource,String table,BaseData et,boolean bGet) default BaseData create(String system,String table,String datasource,BaseData et,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return create(link,getSchema(link,table),et,bGet); return create(link,getSchema(link,system,table),et,bGet);
} }
default List<BaseData> createBatch(String datasource,String table,List<BaseData> list,boolean bGet) default List<BaseData> createBatch(String system,String table,String datasource,List<BaseData> list,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return createBatch(link,getSchema(link,table),list,bGet); return createBatch(link,getSchema(link,system,table),list,bGet);
} }
default BaseData update(String datasource,String table,BaseData et,boolean bGet) default BaseData update(String system,String table,String datasource,BaseData et,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return update(link,getSchema(link,table),et,bGet); return update(link,getSchema(link,system,table),et,bGet);
} }
default List<BaseData> updateBatch(String datasource,String table,List<BaseData> list,boolean bGet) default List<BaseData> updateBatch(String system,String table,String datasource,List<BaseData> list,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return updateBatch(link,getSchema(link,table),list,bGet); return updateBatch(link,getSchema(link,system,table),list,bGet);
} }
default boolean remove(String datasource,String table,Serializable key) default boolean remove(String system,String table,String datasource,Serializable key)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return remove(link,getSchema(link,table),key); return remove(link,getSchema(link,system,table),key);
} }
default boolean removeBatch(String datasource,String table,List<Serializable> idList) default boolean removeBatch(String system,String table,String datasource,List<Serializable> idList)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return removeBatch(link,getSchema(link,table),idList); return removeBatch(link,getSchema(link,system,table),idList);
} }
default boolean removeByMap(String datasource,String table,BaseData et) default boolean removeByMap(String system,String table,String datasource,BaseData et)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return removeByMap(link,getSchema(link,table),et); return removeByMap(link,getSchema(link,system,table),et);
} }
default boolean removeByMapBatch(String datasource,String table,List<BaseData> list) default boolean removeByMapBatch(String system,String table,String datasource,List<BaseData> list)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return removeByMapBatch(link,getSchema(link,table),list); return removeByMapBatch(link,getSchema(link,system,table),list);
} }
default BaseData get(String datasource,String table,Serializable key) default BaseData get(String system,String table,String datasource,Serializable key)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return get(link,getSchema(link,table),key); return get(link,getSchema(link,system,table),key);
} }
default List<BaseData> getBatch(String datasource,String table,List<Serializable> idList) default List<BaseData> getBatch(String system,String table,String datasource,List<Serializable> idList)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return getBatch(link,getSchema(link,table),idList); return getBatch(link,getSchema(link,system,table),idList);
} }
default BaseData getByMap(String datasource,String table,BaseData et) default BaseData getByMap(String system,String table,String datasource,BaseData et)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return getByMap(link,getSchema(link,table),et); return getByMap(link,getSchema(link,system,table),et);
} }
default List<BaseData> getByMapBatch(String datasource,String table,List<BaseData> list) default List<BaseData> getByMapBatch(String system,String table,String datasource,List<BaseData> list)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return getByMapBatch(link,getSchema(link,table),list); return getByMapBatch(link,getSchema(link,system,table),list);
} }
default List<BaseData> getBatchKey(String datasource,String table,List<BaseData> list) default List<BaseData> getBatchKey(String system,String table,String datasource,List<BaseData> list)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return getBatchKey(link,getSchema(link,table),list); return getBatchKey(link,getSchema(link,system,table),list);
} }
default Long count(String datasource,String table,BaseData et) default Long count(String system,String table,String datasource,BaseData et)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return count(link,getSchema(link,table),et); return count(link,getSchema(link,system,table),et);
} }
default boolean checkKey(String datasource,String table,BaseData et) default boolean checkKey(String system,String table,String datasource,BaseData et)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return checkKey(link,getSchema(link,table),et); return checkKey(link,getSchema(link,system,table),et);
} }
default BaseData save(String datasource,String table,BaseData et,boolean bGet) default BaseData save(String system,String table,String datasource,BaseData et,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return save(link,getSchema(link,table),et,bGet); return save(link,getSchema(link,system,table),et,bGet);
} }
default List<BaseData> saveBatch(String datasource,String table,List<BaseData> list,boolean bGet) default List<BaseData> saveBatch(String system,String table,String datasource,List<BaseData> list,boolean bGet)
{ {
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return saveBatch(link,getSchema(link,table),list,bGet); return saveBatch(link,getSchema(link,system,table),list,bGet);
} }
default List<BaseData> select(String datasource,String table,BaseData et){ default List<BaseData> select(String system,String table,String datasource,BaseData et){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return select(link,getSchema(link,table),et); return select(link,getSchema(link,system,table),et);
} }
default Page<BaseData> select(String datasource,String table,BaseData et,Pageable pageable){ default Page<BaseData> select(String system,String table,String datasource,BaseData et,Pageable pageable){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return select(link,getSchema(link,table),et,pageable); return select(link,getSchema(link,system,table),et,pageable);
} }
default List<BaseData> query(String datasource,String table,String dataQuery,FilterData context){ default List<BaseData> query(String system,String table,String datasource,String dataQuery,FilterData context){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return query(link,getSchema(link,table),dataQuery,context); return query(link,getSchema(link,system,table),dataQuery,context);
} }
default Page<BaseData> query(String datasource,String table,String dataQuery,FilterData context,Pageable pageable){ default Page<BaseData> query(String system,String table,String datasource,String dataQuery,FilterData context,Pageable pageable){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return query(link,getSchema(link,table),dataQuery,context,pageable); return query(link,getSchema(link,system,table),dataQuery,context,pageable);
} }
default List<BaseData> selectRaw(String datasource,String table,String sql,FilterData context){ default List<BaseData> selectRaw(String system,String table,String datasource,String sql,FilterData context){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return selectRaw(link,getSchema(link,table),sql,context); return selectRaw(link,getSchema(link,system,table),sql,context);
} }
default boolean execRaw(String datasource,String table,String sql,BaseData param){ default boolean execRaw(String system,String table,String datasource,String sql,BaseData param){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return execRaw(link,getSchema(link,table),sql,param); return execRaw(link,getSchema(link,system,table),sql,param);
} }
default List<BaseData> fetch(String datasource,String table,String dataSet,FilterData context){ default List<BaseData> fetch(String system,String table,String datasource,String dataSet,FilterData context){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return fetch(link,getSchema(link,table),dataSet,context); return fetch(link,getSchema(link,system,table),dataSet,context);
} }
default Page<BaseData> fetch(String datasource,String table,String dataSet,FilterData context,Pageable pageable){ default Page<BaseData> fetch(String system,String table,String datasource,String dataSet,FilterData context,Pageable pageable){
DSLink link=getDSLink(datasource); DSLink link=getDSLink(datasource);
return fetch(link,getSchema(link,table),dataSet,context,pageable); return fetch(link,getSchema(link,system,table),dataSet,context,pageable);
} }
DSLink getDSLink(String datasource); DSLink getDSLink(String datasource);
POSchema getSchema(DSLink link,String table); POSchema getSchema(DSLink link,String system,String table);
} }
...@@ -2,17 +2,24 @@ package cn.ibizlab.core.data.service; ...@@ -2,17 +2,24 @@ package cn.ibizlab.core.data.service;
import cn.ibizlab.core.data.domain.DOModel; import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.lite.*; import cn.ibizlab.core.data.lite.*;
import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.core.data.model.POSchema; import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema; import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils; import cn.ibizlab.core.data.model.TransUtils;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.helper.Inflector; import cn.ibizlab.util.helper.Inflector;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -22,11 +29,11 @@ import java.io.File; ...@@ -22,11 +29,11 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.HashMap; import java.sql.Timestamp;
import java.util.List; import java.util.*;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
...@@ -48,7 +55,7 @@ public class ModelService { ...@@ -48,7 +55,7 @@ public class ModelService {
private IDOModelService doModelService; private IDOModelService doModelService;
@Autowired @Autowired
private LiteModelFeignClient liteService; private LiteModelFeignClient liteService1;
@Autowired @Autowired
@Lazy @Lazy
...@@ -68,39 +75,94 @@ public class ModelService { ...@@ -68,39 +75,94 @@ public class ModelService {
{ {
Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel(); Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel();
try // try
{ // {
List<DstSystemModel> liteSystems=liteService.getSysApps(); // List<DstSystemModel> liteSystems=liteService.getSysApps();
if(!ObjectUtils.isEmpty(liteSystems)) // if(!ObjectUtils.isEmpty(liteSystems))
{ // {
liteSystems.forEach(dstSystemModel->{ // liteSystems.forEach(dstSystemModel->{
// String system=dstSystemModel.getPssystemid();
// if(!models.containsKey(system))
// models.put(system, dstSystemModel);
// if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase())))
// models.put(system.toLowerCase(), dstSystemModel);
// });
// }
// }
// catch (Exception ex)
// {
// log.error("dst接口访问异常",ex);
// }
getLocalSystemModels().values().forEach(dstSystemModel->{
String system=dstSystemModel.getPssystemid(); String system=dstSystemModel.getPssystemid();
if(!models.containsKey(system)) if(!models.containsKey(system))
models.put(system, dstSystemModel); models.put(system, dstSystemModel);
if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase()))) if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase())))
models.put(system.toLowerCase(), dstSystemModel); models.put(system.toLowerCase(), dstSystemModel);
}); });
return models;
} }
}
catch (Exception ex) public Map<String, DstSystemModel> getLocalSystemModels()
{ {
log.error("dst接口访问异常",ex); Map<String,DstSystemModel> models=null;
File modelDir=new File(getModelPath());
Path systemJSON=Paths.get(modelDir.getAbsolutePath(),"SYSTEM.json");
try {
if(!Files.exists(systemJSON))
models=LoadLocalSystemModels();
else
models=JSON.parseObject(new String(Files.readAllBytes(systemJSON), StandardCharsets.UTF_8), new TypeReference<LinkedHashMap<String, DstSystemModel>>(){});;
} catch (IOException e) {
throw new BadRequestAlertException("解析文件失败","DstSystemModel","SYSTEM.json");
}
return models;
} }
public Map<String,DstSystemModel> LoadLocalSystemModels()
{
Map<String,DstSystemModel> models=new LinkedHashMap<>();
File modelDir=new File(getModelPath()); File modelDir=new File(getModelPath());
if(modelDir.exists()) if(modelDir.exists())
{ {
for(File sysDir:modelDir.listFiles()) for(File sysDir:modelDir.listFiles())
{ {
if(Files.exists(Paths.get(sysDir.getAbsolutePath(),"repo","domain"))) if(!sysDir.isDirectory())
continue;
File repoDir=new File(sysDir,"repo");
if(!repoDir.exists())
continue;
for(File entityDir:repoDir.listFiles())
{ {
String system=sysDir.getName(); Path json=Paths.get(repoDir.getAbsolutePath(),"domain",repoDir.getName()+".json");
DstSystemModel dstSystemModel=new DstSystemModel().setPssystemid(system).setPssystemname(system); if(Files.exists(json))
if(!models.containsKey(system)) {
models.put(system, dstSystemModel); try{
if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase()))) PojoSchema pojoSchema=PojoSchema.fromPath(json);
String system=pojoSchema.getSystem();
if(StringUtils.isEmpty(system))
system=sysDir.getName();
String systemName=pojoSchema.getOptions().getSystemName();
if(StringUtils.isEmpty(systemName))
systemName=system;
DstSystemModel dstSystemModel=new DstSystemModel().setPssystemid(system).setPssystemname(systemName).setLastModify(json.toFile().lastModified());
if((!models.containsKey(system.toLowerCase()))||(dstSystemModel.getLastModify()>models.get(system.toLowerCase()).getLastModify()))
models.put(system.toLowerCase(), dstSystemModel); models.put(system.toLowerCase(), dstSystemModel);
}catch (Exception ex){}
break;
}
}
}
if(models.size()>0)
{
try {
Files.write(Paths.get(modelDir.getAbsolutePath(),"SYSTEM.json"), JSON.toJSONBytes(models), StandardOpenOption.CREATE);
} catch (IOException e) {
} }
} }
} }
...@@ -108,7 +170,6 @@ public class ModelService { ...@@ -108,7 +170,6 @@ public class ModelService {
} }
@Cacheable( value="meta-entities", key = "'system:keymap-'+#p0") @Cacheable( value="meta-entities", key = "'system:keymap-'+#p0")
public Map<String,String> getEntitiyIdsBySystem(String system) throws Exception { public Map<String,String> getEntitiyIdsBySystem(String system) throws Exception {
DstSystemModel dstSystemModel=proxy.getAllSystemModels().get(system); DstSystemModel dstSystemModel=proxy.getAllSystemModels().get(system);
...@@ -124,35 +185,35 @@ public class ModelService { ...@@ -124,35 +185,35 @@ public class ModelService {
entities.put(entity.getKey(),id); entities.put(entity.getKey(),id);
}); });
try{ // try{
List<MetaEntityModel> liteEntities=liteService.getEntityModel(system); // List<MetaEntityModel> liteEntities=liteService.getEntityModel(system);
if(!ObjectUtils.isEmpty(liteEntities)) // if(!ObjectUtils.isEmpty(liteEntities))
{ // {
liteEntities.forEach(metaEntityModel->{ // liteEntities.forEach(metaEntityModel->{
String id=metaEntityModel.getSystemId().concat(".domain.").concat(metaEntityModel.getEntityName()); // String id=metaEntityModel.getSystemId().concat(".domain.").concat(metaEntityModel.getEntityName());
//
if(!entities.containsKey(metaEntityModel.getCodeName())) // if(!entities.containsKey(metaEntityModel.getCodeName()))
entities.put(metaEntityModel.getCodeName(),id); // entities.put(metaEntityModel.getCodeName(),id);
if(!entities.containsKey(metaEntityModel.getCodeName().toLowerCase())) // if(!entities.containsKey(metaEntityModel.getCodeName().toLowerCase()))
entities.put(metaEntityModel.getCodeName().toLowerCase(),id); // entities.put(metaEntityModel.getCodeName().toLowerCase(),id);
if(!entities.containsKey(metaEntityModel.getEntityName())) { // if(!entities.containsKey(metaEntityModel.getEntityName())) {
entities.put(metaEntityModel.getEntityName(), id); // entities.put(metaEntityModel.getEntityName(), id);
} // }
if(!entities.containsKey(metaEntityModel.getEntityName().toLowerCase())) { // if(!entities.containsKey(metaEntityModel.getEntityName().toLowerCase())) {
entities.put(metaEntityModel.getEntityName().toLowerCase(), id); // entities.put(metaEntityModel.getEntityName().toLowerCase(), id);
} // }
String pluralize= Inflector.getInstance().pluralize(metaEntityModel.getCodeName()).toLowerCase(); // String pluralize= Inflector.getInstance().pluralize(metaEntityModel.getCodeName()).toLowerCase();
if(!entities.containsKey(pluralize)) { // if(!entities.containsKey(pluralize)) {
entities.put(pluralize, id); // entities.put(pluralize, id);
} // }
//
}); // });
} // }
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
log.error("dst接口访问异常",ex); // log.error("dst接口访问异常",ex);
} // }
File dir=Paths.get(getModelPath(),system,"repo","domain").toFile(); File dir=Paths.get(getModelPath(),system,"repo","domain").toFile();
...@@ -203,16 +264,17 @@ public class ModelService { ...@@ -203,16 +264,17 @@ public class ModelService {
try { try {
entityModel = dynamicService.getDynamicEntity(system,entity); entityModel = dynamicService.getDynamicEntity(system,entity);
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace();
} throw new BadRequestAlertException("未找到实体"+system+"."+entity,"loadDOModel","");
try{
if(entityModel==null)
entityModel = liteService.getProxyEntityModel(system,entity);
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
} }
// try{
// if(entityModel==null)
// entityModel = liteService.getProxyEntityModel(system,entity);
// }
// catch (Exception ex)
// {
// log.error("dst接口访问异常",ex);
// }
return entityModel; return entityModel;
...@@ -221,10 +283,11 @@ public class ModelService { ...@@ -221,10 +283,11 @@ public class ModelService {
public DOModel loadDOModel(String system,String entity) public DOModel loadDOModel(String system,String entity)
{ {
EntityModel entityModel= proxy.getEntityModel(system,entity); EntityModel entityModel= proxy.getEntityModel(system,entity);
DOModel doModel=new DOModel();
if(entityModel!=null) { if(entityModel!=null) {
PojoSchema schema = TransUtils.EntityModelModel2Schema(entityModel); PojoSchema schema = TransUtils.EntityModelModel2Schema(entityModel);
if (schema != null) { if (schema != null) {
DOModel doModel=new DOModel();
doModel.setSchema(schema); doModel.setSchema(schema);
for (String dsType : entityModel.getDsTypes()) { for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType); POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
...@@ -234,7 +297,8 @@ public class ModelService { ...@@ -234,7 +297,8 @@ public class ModelService {
} }
} }
} }
return doModel; else throw new BadRequestAlertException("未找到实体"+system+"."+entity,"loadDOModel","");
return null;
} }
...@@ -250,4 +314,143 @@ public class ModelService { ...@@ -250,4 +314,143 @@ public class ModelService {
MODEL_PATH=this.getModelPath(); MODEL_PATH=this.getModelPath();
} }
@Caching( evict = {
@CacheEvict( value="domodel",key = "'row:'+#p0" )
})
public void resetDOModel(String tag)
{
}
public void resetDOModel(String system,String entity)
{
try {
proxy.getEntitiyIdsBySystem(system).entrySet().forEach(entry->{
String standardSystem="";
String standardEntity="";
String[] args=entry.getValue().split("[.]");
standardSystem=args[0];
standardEntity=args[2];
if(entry.getKey().equals(standardEntity)||entry.getKey().equals(entity)) {
proxy.resetDOModel(system.concat(".domain.").concat(entry.getKey()));
if(!system.equals(system.toLowerCase()))
proxy.resetDOModel(system.toLowerCase().concat(".domain.").concat(entry.getKey()));
proxy.resetDOModel(standardSystem.concat(".domain.").concat(entry.getKey()));
if(!standardSystem.equals(standardSystem.toLowerCase()))
proxy.resetDOModel(standardSystem.toLowerCase().concat(".domain.").concat(entry.getKey()));
}
});
} catch (Exception exception) {
}
}
@Scheduled(cron="0 */1 * * * ?")
public synchronized void refreshDynamicModel()
{
dynamicService.getAllDynamicModelVersion().entrySet().forEach(entry->{
String system=entry.getKey();
entry.getValue().entrySet().forEach(item->{
String entity=item.getKey();
Long systemModify=item.getValue();
File json=Paths.get(this.getModelPath(),system,"repo",entity,"domain",entity+".json").toFile();
Long doModify=0L;
if(json.exists())
doModify=json.lastModified();
if(doModify<systemModify)
{
DOModel doModel = loadDOModel(system,entity);
if(doModify==0L)
log.info("新增模型[".concat(doModel.getName()).concat("]").concat(doModel.getTitle()));
else {
resetDOModel(system,entity);
log.info("刷新模型[".concat(doModel.getName()).concat("]").concat(doModel.getTitle()).concat(",").concat(doModify.toString()).concat("->").concat(systemModify.toString()));
}
PojoSchema schema = doModel.getSchema();
if(schema!=null)
{
if(doModel.getPoSchemas()!=null)
{
Path poPath = Paths.get(ModelService.MODEL_PATH,doModel.getSystemId(),"repo",doModel.getName(),"repository",doModel.getName()+".json");
try {
File dir=poPath.getParent().toFile();
if(!dir.exists())
dir.mkdirs();
Files.write(poPath, JSON.toJSONBytes(doModel.getPoSchemas()), StandardOpenOption.CREATE);
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","POSchemas",poPath.toString());
}
doModel.getPoSchemas().values().forEach(poSchema->{
mergeTableSchema(doModel.getSystemId(),poSchema,systemModify);
});
}
schema.writeTo(Paths.get(ModelService.MODEL_PATH,doModel.getSystemId(),"repo",doModel.getName(),"domain",doModel.getName()+".json"));
}
}
});
});
}
public void mergeTableSchema(String system, POSchema poSchema, Long timestamp)
{
POSchema newSchema= JSONObject.parseObject(JSON.toJSONString(poSchema),POSchema.class);
File dir=Paths.get(ModelService.MODEL_PATH,system,"repo","_table",poSchema.getName().toUpperCase()).toFile();
if(!dir.exists())
dir.mkdirs();
Path json=Paths.get(ModelService.MODEL_PATH,system,"repo","_table",poSchema.getName().toUpperCase(),poSchema.getDsType().toLowerCase()+".json");
if(Files.exists(json)&&json.toFile().lastModified()>timestamp)
{
POSchema old=POSchema.fromPath(json);
if(old.getColumns()!=null)
{
old.getColumns().forEach(column -> {
POSchema.Column newColumn=newSchema.getColumn(column.getName());
if (newColumn==null)
{
newSchema.addColumn(JSON.parseObject(JSON.toJSONString(column),POSchema.Column.class));
}
else if(!ObjectUtils.isEmpty(column.getSearchModes()))
{
newColumn.putSearchModes(String.join(",",column.getSearchModes()));
}
});
}
if(old.getTransients()!=null)
{
old.getTransients().forEach(column -> {
POSchema.Column newColumn=newSchema.getColumn(column.getName());
if (newColumn==null)
{
newSchema.addTransient(JSON.parseObject(JSON.toJSONString(column),POSchema.Column.class));
}
else if(!ObjectUtils.isEmpty(column.getSearchModes()))
{
newColumn.putSearchModes(String.join(",",column.getSearchModes()));
}
});
}
if(!ObjectUtils.isEmpty(old.getForeignKeyConstraints()))
{
old.getForeignKeyConstraints().forEach(fk->{
if(!newSchema.getForeignKey().contains(fk.getConstraintName()))
newSchema.addForeignKeyConstraint(JSON.parseObject(JSON.toJSONString(fk),POSchema.ForeignKeyConstraint.class));
});
}
if(!ObjectUtils.isEmpty(old.getSegments()))
{
old.getSegments().forEach(script -> {
String key= DataObject.getStringValue(script.getName(),"").concat(".").concat(DataObject.getStringValue(script.getVendorProvider(),""));
if(newSchema.getSegment(key)==null)
{
newSchema.addSegment(JSON.parseObject(JSON.toJSONString(script),POSchema.Segment.class));
}
});
}
}
POSchema.writeTo(newSchema,json);
}
} }
...@@ -344,7 +344,7 @@ public class DbPersistentServiceImpl implements IPersistentService { ...@@ -344,7 +344,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
} }
@Override @Override
public POSchema getSchema(DSLink link, String table) { public POSchema getSchema(DSLink link, String system, String table) {
return null; return null;
} }
} }
...@@ -250,7 +250,7 @@ public class MongoPersistentServiceImpl implements IPersistentService { ...@@ -250,7 +250,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
} }
@Override @Override
public POSchema getSchema(DSLink link, String table) { public POSchema getSchema(DSLink link, String system, String table) {
return null; return null;
} }
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册