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

tableschema 接口,模型刷新

上级 5ad47856
......@@ -175,7 +175,7 @@
<dependency>
<groupId>net.ibizsys.model</groupId>
<artifactId>ibizlab-model</artifactId>
<version>1.2.7</version>
<version>1.2.9</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
......
......@@ -216,8 +216,8 @@ public class DOModel implements Serializable {
{
return poSchemas.get(name);
}
String vendorProvider=POSchema.provider.get(name);
if((!StringUtils.isEmpty(vendorProvider))&&(!name.equals(vendorProvider))&&poSchemas.containsKey(vendorProvider))
String vendorProvider=POSchema.provider.get(name.toLowerCase());
if((!StringUtils.isEmpty(vendorProvider))&&(!name.equalsIgnoreCase(vendorProvider))&&poSchemas.containsKey(vendorProvider))
return poSchemas.get(vendorProvider);
......
......@@ -88,6 +88,7 @@ public class DynamicModelService {
psModelService.setPSModelFolderPath(strPSModelFolderPath);
try {
iPSSystem = psModelService.getPSSystem();
if (iPSSystem == null)
throw new BadRequestAlertException("加载系统模型错误", "DynamicSystem", system);
dynamicSystems.put(system, iPSSystem);
......@@ -252,10 +253,13 @@ public class DynamicModelService {
if(defield.isLinkDEField() && defield instanceof IPSLinkDEField)
{
IPSLinkDEField linkDEField = (IPSLinkDEField)defield;
metaFieldModel.setRefFieldId(linkDEField.getRelatedPSDEField().getId())
.setRefFieldName(linkDEField.getRelatedPSDEField().getName()).setRelationId(linkDEField.getPSDER().getId())
String relfieldname=linkDEField.getObjectNode().get("getRelatedPSDEField").get("name").asText();
String relfieldcodename=linkDEField.getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
linkDEField.getRelatedPSDEField();
metaFieldModel.setRefFieldId(relfieldcodename)
.setRefFieldName(relfieldname).setRelationId(linkDEField.getPSDER().getId())
.setRelationName(linkDEField.getPSDER().getName()).setRelationCodeName(linkDEField.getPSDER().getCodeName()).setRefEntityName(linkDEField.getPSDER().getMajorPSDataEntity().getName())
.setRefFieldCodeName(linkDEField.getRelatedPSDEField().getCodeName());
.setRefFieldCodeName(relfieldcodename);
}
if(!ObjectUtils.isEmpty(defield.getAllPSDEFSearchModes()))
......@@ -309,8 +313,10 @@ public class DynamicModelService {
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
MetaLookupModel lookupModel=new MetaLookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(der1n.getPSPickupDEField().getRelatedPSDEField().getName());
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
metaRel.addLookup(lookupModel);
}
......@@ -340,8 +346,10 @@ public class DynamicModelService {
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
MetaLookupModel lookupModel=new MetaLookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(der1n.getPSPickupDEField().getRelatedPSDEField().getName());
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
metaRel.addLookup(lookupModel);
}
......@@ -671,34 +679,49 @@ public class DynamicModelService {
return initDynamicSystem(system.getPssystemid(),system.getDynamicModelPath());
}
public Map<String,Map<String,Long>> getAllDynamicModelVersion()
public synchronized Map<String,Long> getAllDynamicModelVersion()
{
Map<String,Map<String,Long>> ret=new LinkedHashMap<>();
Set<String> set=new HashSet<>();
Map<String,Long> ret=new LinkedHashMap<>();
this.findAllDynamicModel().values().forEach(dstSystemModel -> {
if(ret.containsKey(dstSystemModel.getPssystemid()))
if(set.contains(dstSystemModel.getPssystemid()))
return;
ret.putAll(getDynamicModelVersion(dstSystemModel));
});
return ret;
}
public synchronized Map<String,Long> getDynamicModelVersion(String system)
{
DstSystemModel dstSystemModel=this.findAllDynamicModel().get(system);
if(dstSystemModel==null)
return getDynamicModelVersion(dstSystemModel);
return new LinkedHashMap<>();
}
public synchronized Map<String,Long> getDynamicModelVersion(DstSystemModel dstSystemModel)
{
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());
reloadDynamicSystem(dstSystemModel);
}
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()))
String key=dstSystemModel.getPssystemid().concat(".").concat(metaEntityModel.getEntityName());
if(entities.containsKey(key))
return;
entities.put(metaEntityModel.getEntityName(),dstSystemModel.getLastModify());
entities.put(key,dstSystemModel.getLastModify());
});
} catch (Exception exception) {
}
});
return ret;
return entities;
}
......
......@@ -846,7 +846,7 @@ public class POSchema {
File dir=path.getParent().toFile();
if(!dir.exists())
dir.mkdirs();
Files.write(path, JSON.toJSONBytes(poSchema), StandardOpenOption.CREATE);
Files.write(path, JSON.toJSONBytes(poSchema));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","POSchema",path.toString());
}
......
......@@ -514,7 +514,7 @@ public class PojoSchema {
if(!dir.exists())
dir.mkdirs();
Files.write(path, JSON.toJSONBytes(pojoSchema), StandardOpenOption.CREATE);
Files.write(path, JSON.toJSONBytes(pojoSchema));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","PojoSchema",path.toString());
}
......
......@@ -5,6 +5,7 @@ import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.security.AuthenticationUser;
import com.alibaba.fastjson.JSONObject;
......@@ -35,6 +36,10 @@ public class DataResource
@Autowired
public IDataService dataService;
@Autowired
public ModelService modelService;
@ApiOperation(value = "callMethod数据", tags = {"数据" }, notes = "callMethod数据")
@RequestMapping(method = {RequestMethod.GET}, value = {"/{entity}/call{method}","/{entity}/{key}/call{method}"})
public ResponseEntity call(@PathVariable(name = "system",required = true) String system,
......@@ -423,10 +428,9 @@ public class DataResource
@PathVariable(name = "parentKey2",required = false) String parentKey2,
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestParam Map map) {
FilterData context=FilterData.fromContext(map);
return doSelect(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,dataquery,context);
return doSelect(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,context);
}
@ApiOperation(value = "查询数据", tags = {"数据" } ,notes = "查询数据,POST,返回body<list>+header<page,total>")
......@@ -439,7 +443,6 @@ public class DataResource
@PathVariable(name = "parentKey2",required = false) String parentKey2,
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@PathVariable(name = "dataquery",required = true) String dataquery,
@RequestBody(required = false) FilterData context) {
if(context==null)context=new FilterData();
context.addParent(parentEntity,parentKey).addParent(parentEntity2,parentKey2);
......@@ -601,7 +604,11 @@ public class DataResource
.body(new PageImpl(baseDatas.getContent(), context.getPageable(), baseDatas.getTotalElements()));
}
@RequestMapping(method = RequestMethod.GET, value = {"/reload"})
public ResponseEntity<Boolean> reload(@PathVariable(name = "system",required = true) String systemId) {
modelService.refreshDynamicModel(systemId);
return ResponseEntity.ok(true);
}
@Value("${ibiz.enablePermissionValid:false}")
......
......@@ -74,49 +74,9 @@ public class DOModelServiceImpl implements IDOModelService {
String[] args=key.split("[.]");
String system=args[0];
String entity=args[2];
Path storePath = Paths.get(ModelService.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
if(!Files.exists(storePath))
{
try {
String entityId=modelService.getEntitiyIdsBySystem(system).get(entity);
if(StringUtils.isEmpty(entityId))
throw new BadRequestAlertException("获取模型失败","DOModel",key);
if(!key.equals(entityId))
{
args=entityId.split("[.]");
system=args[0];
entity=args[2];
storePath = Paths.get(ModelService.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
}
} catch (Exception exception) {
throw new BadRequestAlertException("获取模型失败","DOModel",key);
}
}
if(!Files.exists(storePath))
if(Files.exists(storePath))
{
doModel = modelService.loadDOModel(system,entity);
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());
}
}
schema.writeTo(Paths.get(ModelService.MODEL_PATH,doModel.getSystemId(),"repo",doModel.getName(),"domain",doModel.getName()+".json"));
}
}
else {
doModel = new DOModel();
schema = PojoSchema.fromPath(storePath);
if(schema!=null) {
......@@ -132,8 +92,6 @@ public class DOModelServiceImpl implements IDOModelService {
}
}
}
if(schema==null)
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
......
......@@ -7,6 +7,7 @@ import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.service.IDSSettingService;
import cn.ibizlab.core.data.service.IPersistentService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,6 +35,8 @@ public class DbPersistentServiceImpl implements IPersistentService {
@Autowired
private DbDataMapper repository;
@Autowired
private ModelService modelService;
@Override
public BaseData create(DSLink link, POSchema poSchema, BaseData et, boolean bGet) {
......@@ -345,6 +348,6 @@ public class DbPersistentServiceImpl implements IPersistentService {
@Override
public POSchema getSchema(DSLink link, String system, String table) {
return null;
return modelService.getPOSchema(system,table,link.getType());
}
}
......@@ -7,6 +7,7 @@ import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.repository.MongoDataRepository;
import cn.ibizlab.core.data.service.IDSSettingService;
import cn.ibizlab.core.data.service.IPersistentService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,6 +29,8 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Autowired
private MongoDataRepository repository;
@Autowired
private ModelService modelService;
@Override
public BaseData create(DSLink link, POSchema poSchema, BaseData et, boolean bGet) {
......@@ -251,6 +254,6 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Override
public POSchema getSchema(DSLink link, String system, String table) {
return null;
return modelService.getPOSchema(system,table,link.getType());
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册