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

修正加载逻辑

上级 9d4a0b8c
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.service.IPSDEServiceAPI;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ApiEntityModel extends BaseModel{
public ApiEntityModel(ApiModel apiModel,IPSDEServiceAPI apiDataEntity)
{
this.opt=apiDataEntity;
this.api=apiModel;
this.setCodeName(apiDataEntity.getCodeName());
this.setName(apiDataEntity.getName());
this.setId(String.format("%1$s-%2$s",api.getCodeName(),apiDataEntity.getCodeName()));
}
public IPSDEServiceAPI getApiDataEntity()
{
return (IPSDEServiceAPI)opt;
}
private ApiModel api;
}
package cn.ibizlab.codegen.model;
import net.ibizsys.model.app.IPSApplication;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.service.IPSSysServiceAPI;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class ApiModel extends BaseModel{
public ApiModel(IPSSysServiceAPI api)
{
this.opt=api;
this.setCodeName(api.getCodeName());
this.setName(api.getName());
apiEntities=new ArrayList<>();
if(getSysServiceApi().getPSDEServiceAPIs()!=null)
{
getSysServiceApi().getPSDEServiceAPIs().forEach(item->{
apiEntities.add(new ApiEntityModel(this,item));
});
}
}
private List<ApiEntityModel> apiEntities;
public IPSSysServiceAPI getSysServiceApi()
{
return (IPSSysServiceAPI)opt;
}
}
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.app.dataentity.IPSAppDataEntity;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class AppEntityModel extends BaseModel{
public AppEntityModel(AppModel appModel,IPSAppDataEntity appDataEntity)
{
this.opt=appDataEntity;
this.app=appModel;
this.setCodeName(appDataEntity.getCodeName());
this.setName(appDataEntity.getName());
this.setId(String.format("%1$s-%2$s",app.getCodeName(),appDataEntity.getCodeName()));
}
public IPSAppDataEntity getAppDataEntity()
{
return (IPSAppDataEntity)opt;
}
private AppModel app;
}
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.app.IPSApplication;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class AppModel extends BaseModel{
public IPSApplication getApplication()
public AppModel(IPSApplication application)
{
return (IPSApplication)opt;
this.opt=application;
this.setCodeName(application.getCodeName());
this.setName(application.getName());
appEntities=new ArrayList<>();
if(getApplication().getAllPSAppDataEntities()!=null)
{
getApplication().getAllPSAppDataEntities().forEach(item->{
appEntities.add(new AppEntityModel(this,item));
});
}
pages=new ArrayList<>();
if(getApplication().getAllPSAppViews()!=null)
{
getApplication().getAllPSAppViews().forEach(item->{
pages.add(new PageModel(this,item));
});
}
}
public String getMain()
private List<AppEntityModel> appEntities;
private List<PageModel> pages;
public IPSApplication getApplication()
{
return getApplication().getDefaultPSAppIndexView().getName();
return (IPSApplication)opt;
}
}
package cn.ibizlab.codegen.model;
import org.springframework.util.StringUtils;
public class BaseModel {
protected String id;
protected String codeName;
protected String name;
public String getId() {
if(StringUtils.isEmpty(id)&&(!StringUtils.isEmpty(getCodeName())))
id=this.getCodeName();
return id;
}
public <T> T setId(String id) {
this.id = id;
return (T)this;
}
public String getCodeName() {
return codeName;
}
public <T> T setCodeName(String codeName) {
this.codeName = codeName;
return (T)this;
}
public String getName() {
return name;
}
public <T> T setName(String name) {
this.name = name;
return (T)this;
}
protected Object opt;
public <T> T setOpt(Object opt)
......
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class CtrlModel extends BaseModel{
......
......@@ -20,6 +20,17 @@ import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
@Accessors(chain = true)
public class DataSetModel extends BaseModel{
public DataSetModel(EntityModel entityModel,IPSDEDataSet dataSet)
{
this.opt=dataSet;
this.entity=entityModel;
this.setCodeName(dataSet.getCodeName());
this.setName(dataSet.getName());
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),dataSet.getCodeName()));
}
private EntityModel entity;
/**
* 标识
*/
......@@ -28,24 +39,19 @@ public class DataSetModel extends BaseModel{
* 名称
*/
private String datasetName;
/**
* 实体标识
*/
private String entityId;
/**
* 实体
*/
private String entityName;
/**
* 代码名称
*/
private String codeName;
@Override
public DataSetModel setCodeName(String codeName) {
super.setCodeName(codeName);
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),codeName));
return this;
}
/**
* 代码
*/
private String dsCode;
/**
* 模型
* SQL
*/
private String dsModel;
......
package cn.ibizlab.codegen.model;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import net.ibizsys.model.database.IPSDEFDTColumn;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCode;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCodeCond;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DynamicModelStorage {
private static DynamicModelStorage instance=null;
public static DynamicModelStorage getInstance()
{
if(instance==null)
instance=new DynamicModelStorage();
return instance;
}
private String modelPath;
public String getModelPath()
{
return modelPath;
}
public DynamicModelStorage modelPath(String modelPath)
{
this.modelPath=modelPath;
return this;
}
private SystemModel systemModel = null;
public SystemModel getSystemModel()
{
if(systemModel==null) {
String strPSModelFolderPath=null;
if(Files.exists(Paths.get(getModelPath(),"PSSYSTEM.json"))) {
strPSModelFolderPath= Paths.get(getModelPath()).toString();
}
else if(Files.exists(Paths.get(getModelPath(),"model","PSSYSTEM.json"))) {
strPSModelFolderPath= Paths.get(getModelPath(),"model").toString();
}
Assert.hasLength(strPSModelFolderPath,"加载系统模型错误,未找到对应模型目录");
PSModelServiceImpl psModelService = new PSModelServiceImpl();
psModelService.setPSModelFolderPath(strPSModelFolderPath);
try {
IPSSystem iPSSystem = psModelService.getPSSystem();
systemModel = new SystemModel().setOpt(iPSSystem);
Assert.notNull(iPSSystem,"加载系统模型错误:"+strPSModelFolderPath);
} catch (Exception e) {
throw new RuntimeException("加载系统模型错误"+strPSModelFolderPath,e);
}
}
return systemModel;
}
private Map<String,EntityModel> entities=new HashMap<>();
public EntityModel getDynamicEntity(String entity) throws Exception
{
if(entities.containsKey(entity))
return entities.get(entity);
IPSSystem iPSSystem=getSystemModel().getSystem();
IPSDataEntity dataEntity = iPSSystem.getPSDataEntity(entity,true);
Assert.notNull(dataEntity,"未找到对应的实体模型:"+entity);
EntityModel entityModel=new EntityModel().setOpt(dataEntity);
entityModel.setStorageMode(dataEntity.getStorageMode());
List<String> dsTypes=new ArrayList<>();
if(dataEntity.getAllPSDEDBConfigs()!=null)
{
dataEntity.getAllPSDEDBConfigs().forEach(item->{
dsTypes.add(item.getDBType().toLowerCase().replace("mysql5","mysql"));
if(!entityModel.getTableName().equalsIgnoreCase(item.getTableName()))
entityModel.set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName());
});
}
if(dsTypes.size()>0)
entityModel.set("ds_types", String.join(",",dsTypes));
if(dataEntity.getMinorPSDERs()!=null)
{
for(IPSDERBase der : dataEntity.getMinorPSDERs())
{
RelationshipModel rel=new RelationshipModel().setOpt(der);
rel.setName(der.getName()).setRelationType(der.getDERType()).setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId())
.setEntityCodeName(der.getMajorPSDataEntity().getCodeName()).setEntityName(der.getMajorPSDataEntity().getName())
.setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName());
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
rel.addLookup(lookupModel);
}
entityModel.addReference(rel);
}
}
if(dataEntity.getMajorPSDERs()!=null)
{
for(IPSDERBase der : dataEntity.getMajorPSDERs())
{
if(StringUtils.isEmpty(der.getMinorCodeName()))
continue;
RelationshipModel rel=new RelationshipModel().setOpt(der);
rel.setName(der.getName()).setRelationType(der.getDERType()).setCodeName(der.getMinorCodeName()).setEntityId(der.getMinorPSDataEntity().getId())
.setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName())
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
rel.addLookup(lookupModel);
}
entityModel.addNested(rel);
}
}
Map<String,FieldModel> fieldMaps=new LinkedHashMap<>();
for(IPSDEField defield:dataEntity.getAllPSDEFields())
{
String dict=null;
try { dict=defield.getPSCodeList()!=null?defield.getPSCodeList().getCodeName():null; } catch (Exception ex){}
FieldModel fieldModel=new FieldModel().setOpt(defield);
if(defield.getAllPSDEFDTColumns()!=null)
{
defield.getAllPSDEFDTColumns().forEach(col->{
if(!fieldModel.getFieldName().equalsIgnoreCase(col.getColumnName()))
fieldModel.set("column-"+col.getDBType().toLowerCase().replace("mysql5","mysql"),col.getColumnName());
if(StringUtils.isEmpty(fieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp())))
fieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]",""));
});
}
if(defield.isLinkDEField() && defield instanceof IPSLinkDEField)
{
IPSLinkDEField linkDEField = (IPSLinkDEField)defield;
String relfieldname=linkDEField.getObjectNode().get("getRelatedPSDEField").get("name").asText();
String relfieldcodename=linkDEField.getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
linkDEField.getRelatedPSDEField();
fieldModel.setRefFieldName(relfieldname).setRefFieldCodeName(relfieldcodename);
if(!StringUtils.isEmpty(linkDEField.getPSDER().getCodeName()))
{
RelationshipModel relationshipModel=entityModel.getRefMaps().get(linkDEField.getPSDER().getCodeName());
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getCodeName()))) {
relationshipModel.addField(fieldModel);
fieldModel.setReference(relationshipModel);
}
}
}
fieldMaps.put(fieldModel.getFieldName(),fieldModel);
entityModel.addField(fieldModel);
}
if(dataEntity.getAllPSDEDataQueries()!=null)
{
dataEntity.getAllPSDEDataQueries().forEach(dataQuery->{
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code=getQueryCode(dq);
DataSetModel dsModel=new DataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(code);
entityModel.addDataSet(dsModel);
});
}
} catch (Exception exception) {
}
});
}
if(dataEntity.getAllPSDEDataSets()!=null)
{
dataEntity.getAllPSDEDataSets().forEach(dataSet->{
try {
if(dataSet.getPSDEDataQueries()!=null)
{
Map<String, String> map =new HashMap<>();
dataSet.getPSDEDataQueries().forEach(dataQuery->{
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code="";
if(!map.containsKey(dq.getDBType())) {
map.put(dq.getDBType(), "");
code="";
}
else {
code = map.get(dq.getDBType());
code = code+"\r\n union all \r\n";
}
code = code+ getQueryCode(dq);
;//"<include refid=\""+entityModel.getEntityName().toLowerCase()+"_dq_"+dataQuery.getCodeName()+"_"+dq.getDBType().toLowerCase()+"\"/>";
map.put(dq.getDBType(),"select t1.* from ("+code+") t1");
});
}
} catch (Exception exception) {
}
});
for(Map.Entry<String, String> entry:map.entrySet())
{
String sql=null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null)
{
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql="select ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(i>0)sql=sql.concat(",");
if(groupParam.isEnableGroup())
{
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
}
else
sql=sql.concat(groupParam.getGroupCode());
sql=sql.concat(" as ").concat(groupParam.getName().toLowerCase());
i++;
}
sql=sql.concat(" from ( %s ) t1");
}
else
sql="select t1.* from ( %s ) t1";
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql=sql.concat(" group by ");
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(groupParam.isEnableGroup())
{
if(i>0)sql=sql.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
i++;
}
}
}
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(" order by ").concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null)
{
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMinorSortDir());
}
}
}
DataSetModel dsModel=new DataSetModel().setOpt(dataSet);
dsModel.setDatasetId(entityModel.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(entry.getValue().toLowerCase().replace("mysql5","mysql")).setDsModel(sql);
entityModel.addDataSet(dsModel);
}
}
} catch (Exception exception) {
}
});
}
entities.put(entity,entityModel);
return entityModel;
}
public EntityModel getEntitySchema(String entity)
{
EntityModel entityModel= null;
try {
entityModel = getDynamicEntity(entity);
} catch (Exception exception) {
exception.printStackTrace();
}
Assert.notNull(entityModel,"loadDOModel未找到实体"+"."+entity);
for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
if (poSchema != null) {
entityModel.addPOSchema(dsType, poSchema);
}
}
return entityModel;
}
private String contextParamConvert(String contextParam)
{
String resultParam=getJavaSqlCode(contextParam).replaceAll("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\${srf.$2.$3})");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}","#{srf.$1.$2}");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)'\\)}","#{srf.$1.$2}");
Pattern p = Pattern.compile("srf.(datacontext|sessioncontext|webcontext).(\\w+)");
Matcher m = p.matcher(resultParam);
StringBuffer sb = new StringBuffer();
while(m.find()){
String match = m.group();
resultParam=resultParam.replace(match,match.toLowerCase());
}
resultParam=resultParam.replace("AND t11.SRFDCID = '__SRFSAASDCID__'","");
return resultParam;
}
private String getQueryCode(IPSDEDataQueryCode dq)
{
String code=contextParamConvert(dq.getQueryCode());
if(dq.getPSDEDataQueryCodeConds()!=null)
{
int i=0;
boolean b=checkIgnoreNullvalueCond(dq.getPSDEDataQueryCodeConds());
for(IPSDEDataQueryCodeCond cond:dq.getPSDEDataQueryCodeConds())
{
if(i==0)
code=code.concat(" where ");
else if(i>0)
code=code.concat(" and ");
code=code.concat(b?checkNullContextParamConvert(cond.getCustomCond()):contextParamConvert(cond.getCustomCond()));
i++;
}
}
return code;
}
private String getJavaSqlCode(String strSQLCode)
{
strSQLCode = strSQLCode.replace("\r\n", " ");
strSQLCode = strSQLCode.replace("\r", " ");
strSQLCode = strSQLCode.replace("\n", " ");
strSQLCode = strSQLCode.replace("\"", "\\\"");
return strSQLCode;
}
private String checkNullContextParamConvert(String contextParam) {
String resultParam = getJavaSqlCode(contextParam).replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\(\\$\\{_value}\\)<#else>1=1</#if>"," ('${srf.$1.$2}'=null or '${srf.$1.$2}'='' or $4 \\${srf.$1.$2} ");
resultParam = resultParam.replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\$\\{_value}(.*?)?<#else>1=1</#if>", " (#{srf.$1.$2}=null or #{srf.$1.$2}='' or $4#{srf.$1.$2}$5)");
resultParam=contextParamConvert(resultParam);
return resultParam;
}
private boolean checkIgnoreNullvalueCond(List<IPSDEDataQueryCodeCond> list)
{
if(list!=null)
{
for(IPSDEDataQueryCodeCond cond:list)
{
if(getJavaSqlCode(cond.getCustomCond()).matches("(.*?)srf(datacontext|sessioncontext|webcontext)(.*?)\\\\\"ignoreempty\\\\\":true(.*?)"))
return true;
}
}
return false;
}
}
......@@ -7,13 +7,19 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.database.IPSDEFDTColumn;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Getter
@Setter
......@@ -22,16 +28,7 @@ import java.util.Map;
public class EntityModel extends BaseModel {
public String getEntityId() {
return getEntity().getId();
}
public String getCodeName() {
return getEntity().getCodeName();
}
......@@ -106,11 +103,9 @@ public class EntityModel extends BaseModel {
references.forEach(ship->{
if(!StringUtils.isEmpty(ship.getCodeName()))
refMaps.put(ship.getCodeName(),ship);
if(!StringUtils.isEmpty(ship.getName())) {
String fkname= DataObject.getStringValue(ship.getRelation().getName(),"");
if(!StringUtils.isEmpty(fkname))
refMaps.put(fkname, ship);
}
String fkname= DataObject.getStringValue(ship.getName(),"");
if(!StringUtils.isEmpty(fkname))
refMaps.put(fkname, ship);
});
}
return refMaps;
......@@ -267,15 +262,6 @@ public class EntityModel extends BaseModel {
}
public List<String> getDsTypes()
{
List<String> dsTypes=new ArrayList<>();
String strDsTypes=this.getStringValue("ds_types","");
for(String dsType:strDsTypes.split(","))
dsTypes.add(dsType);
return dsTypes;
}
......@@ -355,4 +341,293 @@ public class EntityModel extends BaseModel {
{
return extParams.getStringValue(key,defaultVal);
}
public EntityModel(IPSDataEntity dataEntity)
{
Assert.notNull(dataEntity,"未找到对应的实体模型:"+dataEntity.getId());
this.opt=dataEntity;
this.setCodeName(dataEntity.getCodeName());
this.setName(dataEntity.getName());
this.setStorageMode(dataEntity.getStorageMode());
List<String> dsTypes=new ArrayList<>();
if(dataEntity.getAllPSDEDBConfigs()!=null)
{
dataEntity.getAllPSDEDBConfigs().forEach(item->{
dsTypes.add(item.getDBType().toLowerCase().replace("mysql5","mysql"));
if(!this.getTableName().equalsIgnoreCase(item.getTableName()))
this.set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName());
});
}
if(dataEntity.getMinorPSDERs()!=null)
{
for(IPSDERBase der : dataEntity.getMinorPSDERs())
{
RelationshipModel rel=new RelationshipModel(this,der);
rel.setRelationType(der.getDERType()).setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId())
.setEntityCodeName(der.getMajorPSDataEntity().getCodeName()).setEntityName(der.getMajorPSDataEntity().getName())
.setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName());
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
rel.addLookup(lookupModel);
}
this.addReference(rel);
}
}
if(dataEntity.getMajorPSDERs()!=null)
{
for(IPSDERBase der : dataEntity.getMajorPSDERs())
{
if(StringUtils.isEmpty(der.getMinorCodeName()))
continue;
RelationshipModel rel=new RelationshipModel(this,der);
rel.setRelationType(der.getDERType()).setCodeName(der.getMinorCodeName()).setEntityId(der.getMinorPSDataEntity().getId())
.setEntityCodeName(der.getMinorPSDataEntity().getCodeName()).setEntityName(der.getMinorPSDataEntity().getName())
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
if(der instanceof IPSDER1N)
{
IPSDER1N der1n=(IPSDER1N)der;
String relfieldname=der1n.getPSPickupDEField().getObjectNode().get("getRelatedPSDEField").get("name").asText();
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
rel.addLookup(lookupModel);
}
this.addNested(rel);
}
}
Map<String,FieldModel> fieldMaps=new LinkedHashMap<>();
for(IPSDEField defield:dataEntity.getAllPSDEFields())
{
String dict=null;
try { dict=defield.getPSCodeList()!=null?defield.getPSCodeList().getCodeName():null; } catch (Exception ex){}
FieldModel fieldModel=new FieldModel(this,defield);
if(defield.getAllPSDEFDTColumns()!=null)
{
defield.getAllPSDEFDTColumns().forEach(col->{
if(!fieldModel.getFieldName().equalsIgnoreCase(col.getColumnName()))
fieldModel.set("column-"+col.getDBType().toLowerCase().replace("mysql5","mysql"),col.getColumnName());
if(StringUtils.isEmpty(fieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp())))
fieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]",""));
});
}
if(defield.isLinkDEField() && defield instanceof IPSLinkDEField)
{
IPSLinkDEField linkDEField = (IPSLinkDEField)defield;
String relfieldname=linkDEField.getObjectNode().get("getRelatedPSDEField").get("name").asText();
String relfieldcodename=linkDEField.getObjectNode().get("getRelatedPSDEField").get("codeName").asText();
linkDEField.getRelatedPSDEField();
fieldModel.setRefFieldName(relfieldname).setRefFieldCodeName(relfieldcodename);
if(!StringUtils.isEmpty(linkDEField.getPSDER().getCodeName()))
{
RelationshipModel relationshipModel=this.getRefMaps().get(linkDEField.getPSDER().getCodeName());
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getCodeName()))) {
relationshipModel.addField(fieldModel);
fieldModel.setReference(relationshipModel);
}
}
}
fieldMaps.put(fieldModel.getFieldName(),fieldModel);
this.addField(fieldModel);
}
if(dataEntity.getAllPSDEDataQueries()!=null)
{
dataEntity.getAllPSDEDataQueries().forEach(dataQuery->{
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code=TransUtils.getQueryCode(dq);
DataSetModel dsModel=new DataSetModel();
dsModel.setEntity(this);
dsModel.setName(dataQuery.getName());
dsModel.setDatasetId(this.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setDsCode(code);
this.addDataSet(dsModel);
});
}
} catch (Exception exception) {
}
});
}
if(dataEntity.getAllPSDEDataSets()!=null)
{
dataEntity.getAllPSDEDataSets().forEach(dataSet->{
try {
if(dataSet.getPSDEDataQueries()!=null)
{
Map<String, String> map =new HashMap<>();
dataSet.getPSDEDataQueries().forEach(dataQuery->{
try {
if(dataQuery.getAllPSDEDataQueryCodes()!=null)
{
dataQuery.getAllPSDEDataQueryCodes().forEach(dq->{
String code="";
if(!map.containsKey(dq.getDBType())) {
map.put(dq.getDBType(), "");
code="";
}
else {
code = map.get(dq.getDBType());
code = code+"\r\n union all \r\n";
}
code = code+ TransUtils.getQueryCode(dq);
;//"<include refid=\""+this.getEntityName().toLowerCase()+"_dq_"+dataQuery.getCodeName()+"_"+dq.getDBType().toLowerCase()+"\"/>";
map.put(dq.getDBType(),"select t1.* from ("+code+") t1");
});
}
} catch (Exception exception) {
}
});
for(Map.Entry<String, String> entry:map.entrySet())
{
String sql=null;
if(dataSet.getGroupMode()==1||dataSet.getMajorSortPSDEField()!=null)
{
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql="select ";
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(i>0)sql=sql.concat(",");
if(groupParam.isEnableGroup())
{
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
}
else
sql=sql.concat(groupParam.getGroupCode());
sql=sql.concat(" as ").concat(groupParam.getName().toLowerCase());
i++;
}
sql=sql.concat(" from ( %s ) t1");
}
else
sql="select t1.* from ( %s ) t1";
if(dataSet.getGroupMode()==1&&(!ObjectUtils.isEmpty(dataSet.getPSDEDataSetGroupParams())))
{
sql=sql.concat(" group by ");
int i=0;
for(IPSDEDataSetGroupParam obj:dataSet.getPSDEDataSetGroupParams())
{
if(!(obj instanceof PSDEDataSetGroupParamImpl))
continue;
PSDEDataSetGroupParamImpl groupParam=(PSDEDataSetGroupParamImpl)obj;
if(groupParam.isEnableGroup())
{
if(i>0)sql=sql.concat(",");
if(!StringUtils.isEmpty(groupParam.getGroupCode()))
sql=sql.concat(groupParam.getGroupCode());
else
sql=sql.concat(groupParam.getName());
i++;
}
}
}
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(" order by ").concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null)
{
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMinorSortDir());
}
}
}
DataSetModel dsModel=new DataSetModel(this,dataSet);
dsModel.setDatasetId(this.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setDsCode(entry.getValue().toLowerCase().replace("mysql5","mysql")).setDsModel(sql);
this.addDataSet(dsModel);
}
}
} catch (Exception exception) {
}
});
}
for (String dsType : dsTypes) {
POSchema poSchema = TransUtils.EntityModelModel2PO(this, dsType);
if (poSchema != null) {
this.addPOSchema(dsType, poSchema);
}
}
}
}
......@@ -20,31 +20,42 @@ import java.util.Set;
@JsonIgnoreProperties(value = "handler")
public class FieldModel extends BaseModel {
public FieldModel(EntityModel entityModel,IPSDEField deField)
{
this.opt=deField;
this.entity=entityModel;
this.setCodeName(deField.getCodeName());
this.setName(deField.getName());
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),deField.getCodeName()));
}
public String getCodeName() {
return getField().getCodeName();
return getDataEntityField().getCodeName();
}
public String getFieldName() {
return getField().getName();
return getDataEntityField().getName();
}
public String getLogicName() {
return getField().getLogicName();
return getDataEntityField().getLogicName();
}
public PropType getType()
{
return PropType.findType(this.getField().getStdDataType());
return PropType.findType(this.getDataEntityField().getStdDataType());
}
private String expression;
public IPSDEField getField()
public IPSDEField getDataEntityField()
{
return (IPSDEField)opt;
}
private EntityModel entity;
private RelationshipModel reference;
private String refFieldName;
......@@ -53,50 +64,50 @@ public class FieldModel extends BaseModel {
public boolean isPhisicalDEField()
{
return this.getField().isPhisicalDEField();
return this.getDataEntityField().isPhisicalDEField();
}
public boolean isKeyDEField()
{
return this.getField().isKeyDEField();
return this.getDataEntityField().isKeyDEField();
}
public boolean isLogicValidField()
{
return "LOGICVALID".equals(this.getField().getPredefinedType());
return "LOGICVALID".equals(this.getDataEntityField().getPredefinedType());
}
public boolean isLastModifyField()
{
return "UPDATEDATE".equals(this.getField().getPredefinedType());
return "UPDATEDATE".equals(this.getDataEntityField().getPredefinedType());
}
public boolean isCreateTimeField()
{
return "CREATEDATE".equals(this.getField().getPredefinedType());
return "CREATEDATE".equals(this.getDataEntityField().getPredefinedType());
}
public boolean isUnionKeyField()
{
return !StringUtils.isEmpty(this.getField().getUnionKeyValue());
return !StringUtils.isEmpty(this.getDataEntityField().getUnionKeyValue());
}
public String getDefaultValue()
{
if((!StringUtils.isEmpty(getField().getDefaultValueType()))||(!StringUtils.isEmpty(getField().getDefaultValue())))
if((!StringUtils.isEmpty(getDataEntityField().getDefaultValueType()))||(!StringUtils.isEmpty(getDataEntityField().getDefaultValue())))
{
String defaultValue="";
if(StringUtils.isEmpty(getField().getDefaultValueType())||"NONE".equalsIgnoreCase(getField().getDefaultValueType()))
if(StringUtils.isEmpty(getDataEntityField().getDefaultValueType())||"NONE".equalsIgnoreCase(getDataEntityField().getDefaultValueType()))
{
defaultValue=getField().getDefaultValue();
defaultValue=getDataEntityField().getDefaultValue();
}
else if(!StringUtils.isEmpty(getField().getDefaultValue()))
else if(!StringUtils.isEmpty(getDataEntityField().getDefaultValue()))
{
defaultValue= String.format("${%1$s.%2$s}",getField().getDefaultValueType(),getField().getDefaultValue());
defaultValue= String.format("${%1$s.%2$s}",getDataEntityField().getDefaultValueType(),getDataEntityField().getDefaultValue());
}
else
{
defaultValue= String.format("${%1$s}",getField().getDefaultValueType());
defaultValue= String.format("${%1$s}",getDataEntityField().getDefaultValueType());
}
return defaultValue;
}
......@@ -106,11 +117,11 @@ public class FieldModel extends BaseModel {
public Set<String> getSearchMode()
{
Set<String> modes=new LinkedHashSet<>();
if(getField().getAllPSDEFSearchModes()!=null)
if(getDataEntityField().getAllPSDEFSearchModes()!=null)
{
getField().getAllPSDEFSearchModes().forEach(item->modes.add(item.getValueOP().toLowerCase()));
getDataEntityField().getAllPSDEFSearchModes().forEach(item->modes.add(item.getValueOP().toLowerCase()));
}
if(getField().isEnableQuickSearch())
if(getDataEntityField().isEnableQuickSearch())
modes.add("query");
return modes;
}
......
......@@ -6,9 +6,11 @@ import cn.ibizlab.codegen.CodegenConstants;
import cn.ibizlab.codegen.templating.TemplateFileType;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
......@@ -32,11 +34,42 @@ public class ModelStorage {
public ModelStorage config(CodegenConfig config)
{
this.config=config;
DynamicModelStorage.getInstance().modelPath(config.getInputSpec());
return this;
}
private DynamicModelStorage dynamicService=DynamicModelStorage.getInstance();
private SystemModel systemModel = null;
public SystemModel getSystemModel()
{
if(systemModel==null) {
String modelPath=config.getInputSpec();
String strPSModelFolderPath=null;
if(Files.exists(Paths.get(modelPath,"PSSYSTEM.json"))) {
strPSModelFolderPath= Paths.get(modelPath).toString();
}
else if(Files.exists(Paths.get(modelPath,"model","PSSYSTEM.json"))) {
strPSModelFolderPath= Paths.get(modelPath,"model").toString();
}
Assert.hasLength(strPSModelFolderPath,"加载系统模型错误,未找到对应模型目录");
PSModelServiceImpl psModelService = new PSModelServiceImpl();
psModelService.setPSModelFolderPath(strPSModelFolderPath);
try {
IPSSystem iPSSystem = psModelService.getPSSystem();
systemModel = new SystemModel(iPSSystem);
Assert.notNull(iPSSystem,"加载系统模型错误:"+strPSModelFolderPath);
} catch (Exception e) {
throw new RuntimeException("加载系统模型错误"+strPSModelFolderPath,e);
}
}
return systemModel;
}
......@@ -46,7 +79,7 @@ public class ModelStorage {
opt.putAll(config.getAdditionalProperties());
opt.setTemplateFileType(type);
SystemModel systemModel=dynamicService.getSystemModel();
SystemModel systemModel=getSystemModel();
if(StringUtils.isEmpty(config.getAdditionalProperties().get(CodegenConstants.PROJECT_NAME)))
opt.setProjectName(systemModel.getProjectName());
if(StringUtils.isEmpty(config.getAdditionalProperties().get(CodegenConstants.PROJECT_DESC)))
......@@ -69,49 +102,49 @@ public class ModelStorage {
CliData rt=new CliData();
if(type.equals(TemplateFileType.api))
{
if(dynamicService.getSystemModel().getSystem().getAllPSSysServiceAPIs()!=null)
{
dynamicService.getSystemModel().getSystem().getAllPSSysServiceAPIs().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.api).baseData(item,item.getCodeName().toLowerCase());
getSystemModel().getApis().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.api).baseData(item,item.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
else if(type.equals(TemplateFileType.apiEntity))
{
getSystemModel().getApis().forEach(api->{
api.getApiEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.apiEntity).baseData(item,item.getCodeName()).set("apis",api.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
});
}
else if(type.equals(TemplateFileType.app))
{
if(dynamicService.getSystemModel().getSystem().getAllPSApps()!=null)
{
dynamicService.getSystemModel().getSystem().getAllPSApps().forEach(item->{
AppModel appModel=new AppModel().setOpt(item);
CliOption opt=newCliOption(TemplateFileType.app).baseData(appModel,item.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
getSystemModel().getApps().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.app).baseData(item,item.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
else if(type.equals(TemplateFileType.serviceApi))
else if(type.equals(TemplateFileType.appEntity))
{
dynamicService.getSystemModel().getSystem().getAllPSSysServiceAPIs().forEach(api->{
if(api.getPSDEServiceAPIs()!=null)
{
api.getPSDEServiceAPIs().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.serviceApi).baseData(item,item.getCodeName());
rt.addOption(opt);
});
}
getSystemModel().getApps().forEach(app->{
app.getAppEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.appEntity).baseData(item,item.getCodeName()).set("apps",app.getCodeName().toLowerCase());
rt.addOption(opt);
});
});
}
else if(type.equals(TemplateFileType.entity))
{
dynamicService.getSystemModel().getSystem().getAllPSDataEntities().forEach(item->{
EntityModel schema=dynamicService.getEntitySchema(item.getId());
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(schema.getStorageMode()).setModule(schema.getModule())
.baseData(schema,item.getCodeName());
getSystemModel().getEntities().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(item.getStorageMode()).setModule(item.getModule())
.baseData(item,item.getCodeName());
rt.addOption(opt);
});
}
else if(type.equals(TemplateFileType.module))
{
dynamicService.getSystemModel().getSystem().getAllPSSystemModules().forEach(item->{
getSystemModel().getSystem().getAllPSSystemModules().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.module)
.baseData(item,item.getCodeName());
rt.addOption(opt);
......@@ -119,28 +152,19 @@ public class ModelStorage {
}
else if(type.equals(TemplateFileType.page))
{
dynamicService.getSystemModel().getSystem().getAllPSApps().forEach(app->{
if(app.getAllPSAppViews()!=null)
{
app.getAllPSAppViews().forEach(item->{
PageModel pageModel=new PageModel().setOpt(item);
CliOption opt=newCliOption(TemplateFileType.page)
.set("apps",app.getCodeName().toLowerCase())
.set("appModules",pageModel.getAppModule())
.baseData(pageModel,item.getCodeName().toLowerCase());
rt.addOption(opt);
});
}
getSystemModel().getApps().forEach(app->{
app.getPages().forEach(item->{
CliOption opt=newCliOption(TemplateFileType.page).baseData(item,item.getCodeName().toLowerCase()).set("apps",app.getCodeName().toLowerCase()).set("appModules",item.getAppModule());
rt.addOption(opt);
});
});
}
else if(type.equals(TemplateFileType.supportingFiles))
{
CliOption opt=newCliOption(TemplateFileType.supportingFiles)
.set(TemplateFileType.app.value(),getTemplateData(TemplateFileType.app))
.set(TemplateFileType.api.value(),getTemplateData(TemplateFileType.api))
.set(TemplateFileType.module.value(),getTemplateData(TemplateFileType.module));
.set(TemplateFileType.app.value(),getTemplateData(TemplateFileType.app).getOptions())
.set(TemplateFileType.api.value(),getTemplateData(TemplateFileType.api).getOptions())
.set(TemplateFileType.module.value(),getTemplateData(TemplateFileType.module).getOptions());
rt.addOption(opt);
}
......
package cn.ibizlab.codegen.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.app.view.IPSAppView;
import org.springframework.util.StringUtils;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class PageModel extends BaseModel{
public PageModel(AppModel appModel,IPSAppView appView)
{
this.opt=appView;
this.app=appModel;
this.setCodeName(appView.getCodeName());
this.setName(appView.getName());
this.setId(String.format("%1$s-%2$s",app.getCodeName(),appView.getCodeName()));
}
public IPSAppView getAppView()
{
return (IPSAppView)opt;
}
private AppModel app;
public String getAppModule()
{
if(getAppView().getPSAppDataEntity()==null)
......
......@@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import java.util.ArrayList;
......@@ -16,9 +17,21 @@ import java.util.List;
@Accessors(chain = true)
public class RelationshipModel extends BaseModel{
private String name;
public RelationshipModel(EntityModel entityModel, IPSDERBase der)
{
this.opt=der;
this.entity=entityModel;
this.setName(der.getName());
}
@Override
public RelationshipModel setCodeName(String codeName) {
super.setCodeName(codeName);
this.setId(String.format("%1$s-%2$s",entity.getCodeName(),codeName));
return this;
}
private String codeName;
private EntityModel entity;
private String entityName;
......@@ -26,14 +39,15 @@ public class RelationshipModel extends BaseModel{
private String entityLogicName;
private String entityId;
private String tableName;
private String entityId;
private String relationType;
public IPSDERBase getRelation()
public IPSDERBase getDer()
{
return (IPSDERBase)opt;
}
......
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.templating.TemplateFileType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.database.IPSDEFDTColumn;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCode;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCodeCond;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class SystemModel extends BaseModel {
public SystemModel(IPSSystem system)
{
this.opt=system;
}
public IPSSystem getSystem()
{
return (IPSSystem)opt;
......@@ -24,4 +55,47 @@ public class SystemModel extends BaseModel {
return getSystem().getCodeName().toLowerCase();
}
private List<EntityModel> entities;
public List<EntityModel> getEntities(){
if(entities==null) {
entities = new ArrayList<>();
getSystem().getAllPSDataEntities().forEach(dataEntity -> {
entities.add(new EntityModel(dataEntity));
});
}
return entities;
}
private List<AppModel> apps;
public List<AppModel> getApps()
{
if(apps==null)
{
apps=new ArrayList<>();
if(getSystem().getAllPSApps()!=null) {
getSystem().getAllPSApps().forEach(item -> {
apps.add(new AppModel(item));
});
}
}
return apps;
}
private List<ApiModel> apis;
public List<ApiModel> getApis()
{
if(apis==null)
{
apis=new ArrayList<>();
getSystem().getAllPSSysServiceAPIs().forEach(api->{
apis.add(new ApiModel(api));
});
}
return apis;
}
}
package cn.ibizlab.codegen.model;
import net.ibizsys.model.database.IPSDEFDTColumn;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCode;
import net.ibizsys.model.dataentity.ds.IPSDEDataQueryCodeCond;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TransUtils {
private static String contextParamConvert(String contextParam)
{
String resultParam=getJavaSqlCode(contextParam).replaceAll("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\${srf.$2.$3})");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}","#{srf.$1.$2}");
resultParam=resultParam.replaceAll("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)'\\)}","#{srf.$1.$2}");
Pattern p = Pattern.compile("srf.(datacontext|sessioncontext|webcontext).(\\w+)");
Matcher m = p.matcher(resultParam);
StringBuffer sb = new StringBuffer();
while(m.find()){
String match = m.group();
resultParam=resultParam.replace(match,match.toLowerCase());
}
resultParam=resultParam.replace("AND t11.SRFDCID = '__SRFSAASDCID__'","");
return resultParam;
}
public static String getQueryCode(IPSDEDataQueryCode dq)
{
String code=contextParamConvert(dq.getQueryCode());
if(dq.getPSDEDataQueryCodeConds()!=null)
{
int i=0;
boolean b=checkIgnoreNullvalueCond(dq.getPSDEDataQueryCodeConds());
for(IPSDEDataQueryCodeCond cond:dq.getPSDEDataQueryCodeConds())
{
if(i==0)
code=code.concat(" where ");
else if(i>0)
code=code.concat(" and ");
code=code.concat(b?checkNullContextParamConvert(cond.getCustomCond()):contextParamConvert(cond.getCustomCond()));
i++;
}
}
return code;
}
private static String getJavaSqlCode(String strSQLCode)
{
strSQLCode = strSQLCode.replace("\r\n", " ");
strSQLCode = strSQLCode.replace("\r", " ");
strSQLCode = strSQLCode.replace("\n", " ");
strSQLCode = strSQLCode.replace("\"", "\\\"");
return strSQLCode;
}
private static String checkNullContextParamConvert(String contextParam) {
String resultParam = getJavaSqlCode(contextParam).replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\(\\$\\{_value}\\)<#else>1=1</#if>"," ('${srf.$1.$2}'=null or '${srf.$1.$2}'='' or $4 \\${srf.$1.$2} ");
resultParam = resultParam.replaceAll("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)\\$\\{_value}(.*?)?<#else>1=1</#if>", " (#{srf.$1.$2}=null or #{srf.$1.$2}='' or $4#{srf.$1.$2}$5)");
resultParam=contextParamConvert(resultParam);
return resultParam;
}
private static boolean checkIgnoreNullvalueCond(List<IPSDEDataQueryCodeCond> list)
{
if(list!=null)
{
for(IPSDEDataQueryCodeCond cond:list)
{
if(getJavaSqlCode(cond.getCustomCond()).matches("(.*?)srf(datacontext|sessioncontext|webcontext)(.*?)\\\\\"ignoreempty\\\\\":true(.*?)"))
return true;
}
}
return false;
}
public static POSchema PojoSchema2DocumentPO(PojoSchema pojoSchema)
{
POSchema poSchema=new POSchema().setName(pojoSchema.getCodeName().toLowerCase()).setDefaultDataSource(pojoSchema.getDefaultDataSoruce())
......@@ -128,7 +215,7 @@ public class TransUtils {
int order = 1;
for (FieldModel fieldModel : entityModel.getFields()) {
IPSDEField sub=fieldModel.getField();
IPSDEField sub=fieldModel.getDataEntityField();
String colName=fieldModel.getColumnName(dataSourceType);
......
......@@ -5,7 +5,7 @@ public enum TemplateFileType {
ctrl(Constants.CTRLS),
page(Constants.PAGES),
appEntity(Constants.APP_ENTITIES),
serviceApi(Constants.SERVICE_APIS),
apiEntity(Constants.API_ENTITIES),
entity(Constants.ENTITIES),
module(Constants.MODULES),
api(Constants.APIS),
......@@ -44,7 +44,7 @@ public enum TemplateFileType {
public static final String APIS = "apis";
public static final String APPS = "apps";
public static final String ENTITIES = "entities";
public static final String SERVICE_APIS = "serviceApis";
public static final String API_ENTITIES = "apiEntities";
public static final String APP_ENTITIES = "appEntities";
public static final String MODULES = "modules";
public static final String PAGES = "pages";
......
......@@ -10,7 +10,6 @@
<description></description>
<packaging>pom</packaging>
{{>../{{projectName}}-util/pom.xml}}
<parent>
<groupId>{{packageName}}</groupId>
<artifactId>{{projectName}}-dependencies</artifactId>
......
package {{packageName}}.{{module}}.domain;
//{{entity.dsTypes}} {{entity.ds_types}} {{entity.dataAccCtrlArch}}
// {{entity.dataAccCtrlArch}}
public class {{entity.codeName}}
{
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册