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

push

上级 30c6f92b
......@@ -18,20 +18,15 @@
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.ignore.CodegenIgnoreProcessor;
import cn.ibizlab.codegen.lite.DynamicModelStorage;
import cn.ibizlab.codegen.model.CliOption;
import cn.ibizlab.codegen.model.ModelStorage;
import cn.ibizlab.codegen.templating.*;
import cn.ibizlab.codegen.templating.TemplatePathLocator;
import cn.ibizlab.codegen.templating.TemplateProcessor;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.templating.*;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
......
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class DstSystemModel {
/**
* 系统标识
*/
@JSONField(name = "pssystemid")
@JsonProperty("pssystemid")
private String pssystemid;
/**
* 系统名称
*/
@JSONField(name = "pssystemname")
@JsonProperty("pssystemname")
private String pssystemname;
/**
* 结构
*/
@JSONField(name = "sysstructure")
@JsonProperty("sysstructure")
private Map sysstructure;
/**
* 应用
*/
@JSONField(name = "apps")
@JsonProperty("apps")
private List<App> apps;
public DstSystemModel addApp(App app)
{
if(apps==null)
apps=new ArrayList<>();
apps.add(app.setSystemid(this.pssystemid));
return this;
}
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public static class App{
private String id;
private String label;
private String systemid;
private String fullname;
private String type;
private String group;
private String icon;
private Integer visabled;
private String addr;
}
/**
* 校验
*/
@JSONField(name = "md5check")
@JsonProperty("md5check")
private String md5check;
/**
* 排序
*/
@JSONField(name = "showorder")
@JsonProperty("showorder")
private Integer showorder;
private Map<String, Object> extensionparams;
public DstSystemModel setDynamicModelPath(String dynamic_model_path)
{
if(extensionparams==null)
extensionparams=new HashMap<String, Object>();
extensionparams.put("dynamic_model_path",dynamic_model_path);
return this;
}
@JSONField(serialize = false)
@JsonIgnore
public String getDynamicModelPath()
{
if(extensionparams!=null&&extensionparams.get("dynamic_model_path")!=null)
return extensionparams.get("dynamic_model_path").toString();
return null;
}
public DstSystemModel setLastModify(Long lastModify)
{
if(extensionparams==null)
extensionparams=new HashMap<String, Object>();
extensionparams.put("last_modify",lastModify);
return this;
}
@JSONField(serialize = false)
@JsonIgnore
public Long getLastModify()
{
if(extensionparams!=null&&extensionparams.get("last_modify")!=null)
return DataObject.getLongValue(extensionparams.get("last_modify"),0L);
return 0L;
}
public DstSystemModel fromPath(Path path)
{
try {
if(!Files.exists(path))
throw new IllegalArgumentException("读取文件失败DstSystem:"+path.toString());
JSONObject jo= JSON.parseObject(new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
this.setPssystemid(jo.getString("codeName"));
this.setPssystemname(jo.getString("logicName"));
this.setLastModify(path.toFile().lastModified());
if(jo.containsKey("getAllPSApps"))
{
JSONArray array=jo.getJSONArray("getAllPSApps");
array.forEach(obj->{
JSONObject app=(JSONObject)obj;
String appPath=app.getString("path");
if(!StringUtils.isEmpty(appPath))
{
String[] args=appPath.split("/");
if(args.length==3)
{
String appId=args[1];
this.addApp(new App().setId(appId).setLabel(appId));
}
}
});
}
this.setDynamicModelPath(path.getParent().toAbsolutePath().toString());
} catch (IOException e) {
throw new IllegalArgumentException("读取文件失败DstSystem:"+path.toString());
}
return this;
}
}
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class FieldModel {
private String columnName;
private String codeName;
private String unionName;
private String showName;
private String comment;
private MetaFieldModel field;
private RelationshipModel reference;
@JsonIgnore
@JSONField(serialize = false)
public String getColumnExp()
{
if(field.getPhysicalField()!=null && 1==field.getPhysicalField())
{
return columnName+" as \""+columnName.toUpperCase()+"\"";
}
else if(!StringUtils.isEmpty(field.getExpression()))
{
return field.getExpression()+" as \""+columnName.toUpperCase()+"\"";
}
return "";
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isPhysicalField()
{
return this.getField().getPhysicalField()!=null && 1==this.getField().getPhysicalField();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isKeyField()
{
return this.getField().getKeyField()!=null && 1==this.getField().getKeyField();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isLogicValidField()
{
return "LOGICVALID".equals(this.getField().getPredefined());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isLastModifyField()
{
return "UPDATEDATE".equals(this.getField().getPredefined());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isCreateTimeField()
{
return "CREATEDATE".equals(this.getField().getPredefined());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isUnionKeyField()
{
return !StringUtils.isEmpty(this.getField().getUnionKey());
}
public String getPropType()
{
String dataType=this.getField().getDataType().toUpperCase();
if( dataType.indexOf("TEXT")>=0||dataType.indexOf("CHAR")>=0||dataType.indexOf("LOB")>=0)
return "string";
else if(dataType.indexOf("TIME")>=0)
return "date-time";
else if(dataType.indexOf("DATE")>=0)
return "date";
else if(dataType.indexOf("NUM")>=0||dataType.indexOf("FLOAT")>=0||dataType.indexOf("DOUBLE")>=0||dataType.indexOf("DECIMAL")>=0)
return "number";
else if(dataType.indexOf("INT")==0)
return "integer";
return "string";
}
public String getColumnName(String dsType)
{
return DataObject.getStringValue(field.get("column-"+dsType.toLowerCase()),getColumnName());
}
@JsonIgnore
@JSONField(serialize = false)
private Object node;
}
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 实体[实体]
*/
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class MetaEntityModel{
/**
* 标识
*/
@JSONField(name = "entity_id")
@JsonProperty("entity_id")
private String entityId;
/**
* 实体名
*/
@JSONField(name = "entity_name")
@JsonProperty("entity_name")
private String entityName;
/**
* 逻辑名称
*/
@JSONField(name = "logic_name")
@JsonProperty("logic_name")
private String logicName;
/**
* 代码名称
*/
@JSONField(name = "code_name")
@JsonProperty("code_name")
private String codeName;
/**
* 表名称
*/
@JSONField(name = "table_name")
@JsonProperty("table_name")
private String tableName;
/**
* 系统标识
*/
@JSONField(name = "system_id")
@JsonProperty("system_id")
private String systemId;
/**
* 系统
*/
@JSONField(name = "system_name")
@JsonProperty("system_name")
private String systemName;
/**
* 数据源标识
*/
@JSONField(name = "ds_id")
@JsonProperty("ds_id")
private String dsId;
/**
* 数据源
*/
@JSONField(name = "ds_name")
@JsonProperty("ds_name")
private String dsName;
/**
* 模块标识
*/
@JSONField(name = "module_id")
@JsonProperty("module_id")
private String moduleId;
/**
* 模块
*/
@JSONField(name = "module_name")
@JsonProperty("module_name")
private String moduleName;
/**
* 扩展参数
*/
@JSONField(name = "ext_params")
@JsonProperty("ext_params")
private String extParams;
/**
* 排序
*/
@JSONField(name = "show_order")
@JsonProperty("show_order")
private Integer showOrder;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "createdate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("createdate")
private Timestamp createdate;
/**
* 最后修改时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "updatedate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("updatedate")
private Timestamp updatedate;
@JSONField(serialize = false)
@JsonIgnore
private Map<String, Object> extensionparams;
public Object get(String key)
{
if(extensionparams==null)
extensionparams=Setting.getMap(extParams);
return extensionparams.get(key);
}
public MetaEntityModel set(String key, Object value)
{
if(value==null)
return this;
if(extensionparams==null)
extensionparams=Setting.getMap(extParams);
extensionparams.put(key,value);
List<Setting> settingList=new ArrayList<>();
for(Map.Entry<String, Object> entry:extensionparams.entrySet()) {
if(!entry.getKey().equalsIgnoreCase("param"))
settingList.add(new Setting().setProperty(entry.getKey()).setValue(DataObject.getStringValue(entry.getValue(), "")));
}
return setExtParams(JSON.toJSONString(settingList));
}
}
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import cn.ibizlab.codegen.utils.DataObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 实体[属性]
*/
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@ApiModel("属性")
public class MetaFieldModel {
/**
* 属性标识
*/
@JSONField(name = "field_id")
@JsonProperty("field_id")
@ApiModelProperty("属性标识")
private String fieldId;
/**
* 属性名称
*/
@JSONField(name = "field_name")
@JsonProperty("field_name")
@ApiModelProperty("属性名称")
private String fieldName;
/**
* 代码名称
*/
@JSONField(name = "code_name")
@JsonProperty("code_name")
@ApiModelProperty("代码名称")
private String codeName;
/**
* 实体标识
*/
@JSONField(name = "entity_id")
@JsonProperty("entity_id")
@ApiModelProperty("实体标识")
private String entityId;
/**
* 实体名称
*/
@JSONField(name = "entity_name")
@JsonProperty("entity_name")
@ApiModelProperty("实体名称")
private String entityName;
/**
* 实体代码名称
*/
@JSONField(name = "entity_code_name")
@JsonProperty("entity_code_name")
@ApiModelProperty("实体代码名称")
private String entityCodeName;
/**
* 系统
*/
@JSONField(name = "system_id")
@JsonProperty("system_id")
@ApiModelProperty("系统")
private String systemId;
/**
* 属性逻辑名
*/
@JSONField(name = "field_logic_name")
@JsonProperty("field_logic_name")
@ApiModelProperty("属性逻辑名")
private String fieldLogicName;
/**
* 属性全路径名称
*/
@JSONField(name = "field_uni_name")
@JsonProperty("field_uni_name")
@ApiModelProperty("属性全路径名称")
private String fieldUniName;
/**
* 显示名称
*/
@JSONField(name = "field_show_name")
@JsonProperty("field_show_name")
@ApiModelProperty("显示名称")
private String fieldShowName;
/**
* 引用属性标识
*/
@JSONField(name = "ref_field_id")
@JsonProperty("ref_field_id")
@ApiModelProperty("引用属性标识")
private String refFieldId;
/**
* 引用属性名称
*/
@JSONField(name = "ref_field_name")
@JsonProperty("ref_field_name")
@ApiModelProperty("引用属性名称")
private String refFieldName;
/**
* 引用属性代码名称
*/
@JSONField(name = "ref_field_code_name")
@JsonProperty("ref_field_code_name")
@ApiModelProperty("引用属性代码名称")
private String refFieldCodeName;
/**
* 引用关系标识
*/
@JSONField(name = "relation_id")
@JsonProperty("relation_id")
@ApiModelProperty("引用关系标识")
private String relationId;
/**
* 引用关系
*/
@JSONField(name = "relation_name")
@JsonProperty("relation_name")
@ApiModelProperty("引用关系")
private String relationName;
/**
* 关系代码
*/
@JSONField(name = "relation_code_name")
@JsonProperty("relation_code_name")
@ApiModelProperty("关系代码")
private String relationCodeName;
/**
* 引用实体
*/
@JSONField(name = "ref_entity_name")
@JsonProperty("ref_entity_name")
@ApiModelProperty("引用实体")
private String refEntityName;
/**
* 主键
*/
@JSONField(name = "key_field")
@JsonProperty("key_field")
@ApiModelProperty("主键")
private Integer keyField;
/**
* 主信息
*/
@JSONField(name = "major_field")
@JsonProperty("major_field")
@ApiModelProperty("主信息")
private Integer majorField;
/**
* 联合主键
*/
@JSONField(name = "union_key")
@JsonProperty("union_key")
@ApiModelProperty("联合主键")
private String unionKey;
/**
* 属性类型
*/
@JSONField(name = "field_type")
@JsonProperty("field_type")
@ApiModelProperty("属性类型")
private String fieldType;
/**
* 预定义类型
*/
@JSONField(name = "predefined")
@JsonProperty("predefined")
@ApiModelProperty("预定义类型")
private String predefined;
/**
* 数据字典
*/
@JSONField(name = "dict")
@JsonProperty("dict")
@ApiModelProperty("数据字典")
private String dict;
/**
* 允许为空
*/
@JSONField(name = "nullable")
@JsonProperty("nullable")
@ApiModelProperty("允许为空")
private Integer nullable;
/**
* 物理属性
*/
@JSONField(name = "physical_field")
@JsonProperty("physical_field")
@ApiModelProperty("物理属性")
private Integer physicalField;
/**
* 数据类型
*/
@JSONField(name = "data_type")
@JsonProperty("data_type")
@ApiModelProperty("数据类型")
private String dataType;
/**
* 长度
*/
@JSONField(name = "data_length")
@JsonProperty("data_length")
@ApiModelProperty("长度")
private Integer dataLength;
/**
* 精度
*/
@JSONField(name = "data_preci")
@JsonProperty("data_preci")
@ApiModelProperty("精度")
private Integer dataPreci;
/**
* 逻辑表达式
*/
@JSONField(name = "expression")
@JsonProperty("expression")
@ApiModelProperty("逻辑表达式")
private String expression;
/**
* 扩展属性
*/
@JSONField(name = "extension_field")
@JsonProperty("extension_field")
@ApiModelProperty("扩展属性")
private Integer extensionField;
/**
* 审计
*/
@JSONField(name = "is_enable_audit")
@JsonProperty("is_enable_audit")
@ApiModelProperty("审计")
private Integer isEnableAudit;
/**
* 排序
*/
@JSONField(name = "show_order")
@JsonProperty("show_order")
@ApiModelProperty("排序")
private Integer showOrder;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "createdate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("createdate")
@ApiModelProperty("创建时间")
private Timestamp createdate;
/**
* 最后修改时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "updatedate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("updatedate")
@ApiModelProperty("最后修改时间")
private Timestamp updatedate;
/**
* 扩展参数
*/
@JSONField(name = "ext_params")
@JsonProperty("ext_params")
private String extParams;
@JSONField(serialize = false)
@JsonIgnore
private Map<String, Object> extensionparams;
public Object get(String key)
{
if(extensionparams==null)
extensionparams=Setting.getMap(extParams);
return extensionparams.get(key);
}
public MetaFieldModel set(String key, Object value)
{
if(value==null)
return this;
if(extensionparams==null)
extensionparams=Setting.getMap(extParams);
extensionparams.put(key,value);
List<Setting> settingList=new ArrayList<>();
for(Map.Entry<String, Object> entry:extensionparams.entrySet()) {
if(!entry.getKey().equalsIgnoreCase("param"))
settingList.add(new Setting().setProperty(entry.getKey()).setValue(DataObject.getStringValue(entry.getValue(), "")));
}
return setExtParams(JSON.toJSONString(settingList));
}
}
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
/**
* 实体[实体关系]
*/
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@ApiModel("实体关系")
public class MetaRelationshipModel implements Serializable {
/**
* 关系标识
*/
@JSONField(name = "id")
@JsonProperty("id")
@ApiModelProperty("关系标识")
private String id;
/**
* 关系名称
*/
@JSONField(name = "name")
@JsonProperty("name")
@ApiModelProperty("关系名称")
private String name;
/**
* 类型
*/
@JSONField(name = "relation_type")
@JsonProperty("relation_type")
@ApiModelProperty("类型")
private String relationType;
/**
* 代码名称
*/
@JSONField(name = "code_name")
@JsonProperty("code_name")
@ApiModelProperty("代码名称")
private String codeName;
/**
* 实体标识
*/
@JSONField(name = "entity_id")
@JsonProperty("entity_id")
@ApiModelProperty("实体标识")
private String entityId;
/**
* 实体名称
*/
@JSONField(name = "entity_name")
@JsonProperty("entity_name")
@ApiModelProperty("实体名称")
private String entityName;
/**
* 实体代码名称
*/
@JSONField(name = "entity_code_name")
@JsonProperty("entity_code_name")
@ApiModelProperty("实体代码名称")
private String entityCodeName;
/**
* 引用实体标识
*/
@JSONField(name = "ref_entity_id")
@JsonProperty("ref_entity_id")
@ApiModelProperty("引用实体标识")
private String refEntityId;
/**
* 引用实体名称
*/
@JSONField(name = "ref_entity_name")
@JsonProperty("ref_entity_name")
@ApiModelProperty("引用实体名称")
private String refEntityName;
/**
* 引用实体代码名称
*/
@JSONField(name = "ref_entity_code_name")
@JsonProperty("ref_entity_code_name")
@ApiModelProperty("引用实体代码名称")
private String refEntityCodeName;
/**
* 嵌套代码名称
*/
@JSONField(name = "nested_name")
@JsonProperty("nested_name")
@ApiModelProperty("嵌套代码名称")
private String nestedName;
/**
* 系统
*/
@JSONField(name = "system_id")
@JsonProperty("system_id")
@ApiModelProperty("系统")
private String systemId;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "createdate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("createdate")
@ApiModelProperty("创建时间")
private Timestamp createdate;
/**
* 最后修改时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "updatedate", format = "yyyy-MM-dd HH:mm:ss")
@JsonProperty("updatedate")
@ApiModelProperty("最后修改时间")
private Timestamp updatedate;
/**
* lookup
*/
@JSONField(name = "lookups")
@JsonProperty("lookups")
private List<MetaLookupModel> lookup;
public MetaRelationshipModel addLookup(MetaLookupModel obj)
{
if(lookup==null)
lookup=new ArrayList<>();
lookup.add(obj);
return this;
}
}
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class Setting {
private String property;
private String value;
public static String getValue(String configString, String propertyName)
{
return DataObject.getStringValue(getMap(configString).get(propertyName),"");
}
public static Map getMap(String configString)
{
Map map=new HashMap();
map.put("param",configString);
if(!(StringUtils.isEmpty(configString)))
{
try
{
Object obj= JSON.parse(configString);
if(obj==null)
return map;
else if (obj instanceof JSONArray)
{
List<Setting> settings= JSONArray.parseArray(configString,Setting.class);
for(Setting setting:settings)
map.put(setting.getProperty(),setting.getValue());
}
else if (obj instanceof JSONObject)
{
JSONObject jo = (JSONObject)obj;
jo.keySet().forEach(key->{
map.put(key,jo.get(key));
});
}
}
catch (Exception ex)
{
if(configString.indexOf("=")>0)
{
Properties proper = new Properties();
try {
proper.load(new StringReader(configString)); //把字符串转为reader
} catch (IOException e) {
}
Enumeration enum1 = proper.propertyNames();
while (enum1.hasMoreElements()) {
String strKey = (String) enum1.nextElement();
String strValue = proper.getProperty(strKey);
map.put(strKey, strValue);
}
}
}
}
return map;
}
}
package cn.ibizlab.codegen.lite;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......@@ -19,7 +19,7 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@ApiModel("数据集")
public class MetaDataSetModel {
public class DataSetModel {
/**
* 标识
......
package cn.ibizlab.codegen.lite;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.JSON;
import cn.ibizlab.codegen.utils.Inflector;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import net.ibizsys.model.database.IPSDEFDTColumn;
......@@ -18,9 +16,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
......@@ -64,12 +60,7 @@ public class DynamicModelStorage {
else if(Files.exists(Paths.get(getModelPath(),"model","PSSYSTEM.json"))) {
strPSModelFolderPath= Paths.get(getModelPath(),"model").toString();
}
else
{
DstSystemModel dynamicModel=getDstSystemModel();
if(dynamicModel!=null)
strPSModelFolderPath = dynamicModel.getDynamicModelPath();
}
Assert.hasLength(strPSModelFolderPath,"加载系统模型错误,未找到对应模型目录");
......@@ -88,110 +79,19 @@ public class DynamicModelStorage {
}
private DstSystemModel dstSystemModel=null;
public DstSystemModel getDstSystemModel()
{
if(dstSystemModel==null)
{
dstSystemModel=loopModelDir(new File(getModelPath()));
}
return dstSystemModel;
}
private DstSystemModel loopModelDir(File dir)
{
if(dir.isDirectory())
{
Path path= Paths.get(dir.getAbsolutePath(),"PSSYSTEM.json");
File check=path.toFile();
if(check.exists())
{
DstSystemModel dstSystemModel=new DstSystemModel().fromPath(path);
if(dstSystemModel!=null&&(!StringUtils.isEmpty(dstSystemModel.getPssystemid())))
{
String system=dstSystemModel.getPssystemid();
return dstSystemModel;
}
}
else
{
for(File sub:dir.listFiles())
{
DstSystemModel dstSystemModel=loopModelDir(sub);
if(dstSystemModel!=null)
return dstSystemModel;
}
}
}
return null;
}
private Map<String,MetaEntityModel> entities=null;
public Map<String,MetaEntityModel> getEntities() throws Exception
{
if(entities==null)
{
entities=new HashMap<>();
IPSSystem iPSSystem=getPSSystem();
int i=1;
for(IPSDataEntity dataEntity:iPSSystem.getAllPSDataEntities()){
MetaEntityModel metaEntityModel=new MetaEntityModel();
metaEntityModel.setEntityId(dataEntity.getId()).setEntityName(dataEntity.getName())
.setLogicName(dataEntity.getLogicName()).setCodeName(dataEntity.getCodeName()).setTableName(dataEntity.getTableName())
.setDsId(iPSSystem.getCodeName()+"-"+((StringUtils.isEmpty(dataEntity.getDSLink())||dataEntity.getDSLink().equalsIgnoreCase("DEFAULT"))?"master":dataEntity.getDSLink()))
.setDsName(metaEntityModel.getDsId())
.setSystemId(iPSSystem.getCodeName()).setSystemName(iPSSystem.getLogicName()).setShowOrder(i);
if(dataEntity.getPSSystemModule()!=null)
metaEntityModel.setModuleId(dataEntity.getPSSystemModule().getCodeName()).setModuleName(dataEntity.getPSSystemModule().getName());
i++;
entities.put(metaEntityModel.getCodeName(),metaEntityModel);
if(!metaEntityModel.getCodeName().toLowerCase().equals(metaEntityModel.getCodeName()))
entities.put(metaEntityModel.getCodeName().toLowerCase(),metaEntityModel);
if(!entities.containsKey(metaEntityModel.getEntityName())) {
entities.put(metaEntityModel.getEntityName(), metaEntityModel);
}
if(!entities.containsKey(metaEntityModel.getEntityName().toLowerCase())) {
entities.put(metaEntityModel.getEntityName().toLowerCase(), metaEntityModel);
}
String pluralize= Inflector.getInstance().pluralize(metaEntityModel.getCodeName()).toLowerCase();
if(!entities.containsKey(pluralize)) {
entities.put(pluralize, metaEntityModel);
}
}
}
return entities;
}
private Map<String,EntityModel> entities=new HashMap<>();
public EntityModel getDynamicEntity(String entity) throws Exception
{
MetaEntityModel metaEntityModel=getEntities().get(entity);
Assert.notNull(metaEntityModel,"未找到对应的实体模型:"+entity);
if(entities.containsKey(entity))
return entities.get(entity);
IPSSystem iPSSystem=getPSSystem();
IPSDataEntity dataEntity = iPSSystem.getPSDataEntity(metaEntityModel.getEntityId(),true);
IPSDataEntity dataEntity = iPSSystem.getPSDataEntity(entity,true);
Assert.notNull(dataEntity,"未找到对应的实体模型:"+entity);
EntityModel entityModel=new EntityModel();
entityModel.setNode(dataEntity);
entityModel.setStorageMode(dataEntity.getStorageMode());
if(dataEntity.isLogicValid())
{
List<Setting> settingList=new ArrayList<>();
String val=dataEntity.getValidLogicValue();
if(StringUtils.isEmpty(val))val="1";
String deVal=dataEntity.getInvalidLogicValue();
if(StringUtils.isEmpty(deVal))deVal="0";
settingList.add(new Setting().setProperty("logicval").setValue(val));
settingList.add(new Setting().setProperty("logicdelval").setValue(deVal));
metaEntityModel.setExtParams(JSON.toJSONString(settingList));
}
entityModel.setEntity(metaEntityModel);
entityModel.setEntity(dataEntity);
List<String> dsTypes=new ArrayList<>();
if(dataEntity.getAllPSDEDBConfigs()!=null)
......@@ -199,113 +99,37 @@ public class DynamicModelStorage {
dataEntity.getAllPSDEDBConfigs().forEach(item->{
dsTypes.add(item.getDBType().toLowerCase().replace("mysql5","mysql"));
if(!entityModel.getTableName().equalsIgnoreCase(item.getTableName()))
entityModel.getEntity().set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName());
entityModel.set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName());
});
}
if(dsTypes.size()>0)
entityModel.getEntity().set("ds_types", String.join(",",dsTypes));
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();
fieldModel.setNode(defield);
MetaFieldModel metaFieldModel=new MetaFieldModel();
metaFieldModel.setFieldId(defield.getId()).setFieldName(defield.getName()).setCodeName(defield.getCodeName()).setFieldLogicName(defield.getLogicName())
.setEntityId(dataEntity.getId()).setEntityCodeName(dataEntity.getCodeName()).setEntityName(dataEntity.getName()).setSystemId(metaEntityModel.getSystemId())
.setFieldUniName(dataEntity.getName()+"."+defield.getName()).setFieldShowName(String.format("%1$s-%2$s[%3$s]",defield.getName(),defield.getLogicName(),dataEntity.getName()))
.setKeyField(defield.isKeyDEField()?1:null).setMajorField(defield.isMajorDEField()?1:null).setUnionKey(defield.getUnionKeyValue()).setFieldType(defield.getDataType())
.setPredefined(defield.getPredefinedType()).setDict(dict).setNullable(defield.isAllowEmpty()?1:0)
.setPhysicalField(defield.isPhisicalDEField()?1:0).setDataType(DataType.findTypeName(defield.getStdDataType())).setDataLength(defield.getLength()).setDataPreci(defield.getPrecision())
.setIsEnableAudit(defield.isEnableAudit()?1:null).setShowOrder(defield.getImportOrder());
if(defield.getAllPSDEFDTColumns()!=null)
{
defield.getAllPSDEFDTColumns().forEach(col->{
if(!metaFieldModel.getFieldName().equalsIgnoreCase(col.getColumnName()))
metaFieldModel.set("column-"+col.getDBType().toLowerCase().replace("mysql5","mysql"),col.getColumnName());
if(StringUtils.isEmpty(metaFieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp())))
metaFieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]",""));
});
}
entityModel.set("ds_types", String.join(",",dsTypes));
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();
metaFieldModel.setRefFieldId(relfieldcodename)
.setRefFieldName(relfieldname).setRelationId(linkDEField.getPSDER().getId())
.setRelationName(linkDEField.getPSDER().getName()).setRelationCodeName(linkDEField.getPSDER().getCodeName()).setRefEntityName(linkDEField.getPSDER().getMajorPSDataEntity().getName())
.setRefFieldCodeName(relfieldcodename);
}
if(!ObjectUtils.isEmpty(defield.getAllPSDEFSearchModes()))
{
List<String> modes=new ArrayList<>();
defield.getAllPSDEFSearchModes().forEach(item->modes.add(item.getValueOP().toLowerCase()));
if(defield.isEnableQuickSearch())
modes.add("query");
metaFieldModel.set("search_modes", String.join(",",modes));
}
if((!StringUtils.isEmpty(defield.getDefaultValueType()))||(!StringUtils.isEmpty(defield.getDefaultValue())))
{
String defaultValue="";
if(StringUtils.isEmpty(defield.getDefaultValueType())||"NONE".equalsIgnoreCase(defield.getDefaultValueType()))
{
defaultValue=defield.getDefaultValue();
}
else if(!StringUtils.isEmpty(defield.getDefaultValue()))
{
defaultValue= String.format("${%1$s.%2$s}",defield.getDefaultValueType(),defield.getDefaultValue());
}
else
{
defaultValue= String.format("${%1$s}",defield.getDefaultValueType());
}
metaFieldModel.set("default_value",defaultValue);
}
fieldModel.setCodeName(metaFieldModel.getCodeName()).setColumnName(metaFieldModel.getFieldName()).setUnionName(metaFieldModel.getFieldUniName()).setShowName(metaFieldModel.getFieldShowName())
.setComment(metaFieldModel.getFieldLogicName()).setField(metaFieldModel);
fieldMaps.put(fieldModel.getColumnName(),fieldModel);
entityModel.addField(fieldModel);
}
if(dataEntity.getMinorPSDERs()!=null)
{
for(IPSDERBase der : dataEntity.getMinorPSDERs())
{
RelationshipModel rel=new RelationshipModel();
rel.setNode(der);
rel.setCodeName(der.getCodeName()).setEntityId(der.getMajorPSDataEntity().getId())
rel.setRelation(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()).setSystemId(iPSSystem.getCodeName()).setTableName(der.getMajorPSDataEntity().getTableName());
.setEntityLogicName(der.getMajorPSDataEntity().getLogicName()).setTableName(der.getMajorPSDataEntity().getTableName());
MetaRelationshipModel metaRel=new MetaRelationshipModel();
metaRel.setId(der.getId()).setName(der.getName()).setRelationType(der.getDERType()).setCodeName(der.getCodeName()).setRefEntityId(der.getMajorPSDataEntity().getId())
.setRefEntityName(der.getMajorPSDataEntity().getName()).setRefEntityCodeName(der.getMajorPSDataEntity().getCodeName())
.setEntityId(dataEntity.getId()).setEntityName(dataEntity.getName()).setEntityCodeName(dataEntity.getCodeName()).setNestedName(der.getMinorCodeName())
.setSystemId(iPSSystem.getCodeName());
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())
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
metaRel.addLookup(lookupModel);
rel.addLookup(lookupModel);
}
rel.setRelation(metaRel);
entityModel.addReference(rel);
}
......@@ -318,32 +142,73 @@ public class DynamicModelStorage {
if(StringUtils.isEmpty(der.getMinorCodeName()))
continue;
RelationshipModel rel=new RelationshipModel();
rel.setNode(der);
rel.setCodeName(der.getMinorCodeName()).setEntityId(der.getMinorPSDataEntity().getId())
rel.setRelation(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()).setSystemId(iPSSystem.getCodeName()).setTableName(der.getMinorPSDataEntity().getTableName());
.setEntityLogicName(der.getMinorPSDataEntity().getLogicName()).setTableName(der.getMinorPSDataEntity().getTableName());
MetaRelationshipModel metaRel=new MetaRelationshipModel();
metaRel.setId(der.getId()).setName(der.getName()).setRelationType(der.getDERType()).setCodeName(der.getCodeName()).setRefEntityId(der.getMajorPSDataEntity().getId())
.setRefEntityName(der.getMajorPSDataEntity().getName()).setRefEntityCodeName(der.getMajorPSDataEntity().getCodeName())
.setEntityId(dataEntity.getId()).setEntityName(dataEntity.getName()).setEntityCodeName(dataEntity.getCodeName()).setNestedName(der.getMinorCodeName())
.setSystemId(iPSSystem.getCodeName());
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())
LookupModel lookupModel=new LookupModel().setRelationid(der.getId())
.setFieldname(der1n.getPickupDEFName()).setReffieldname(relfieldname);
metaRel.addLookup(lookupModel);
rel.addLookup(lookupModel);
}
rel.setRelation(metaRel);
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();
fieldModel.setField(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->{
......@@ -355,7 +220,7 @@ public class DynamicModelStorage {
String code=getQueryCode(dq);
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql"))
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);
......@@ -482,7 +347,7 @@ public class DynamicModelStorage {
}
}
}
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
DataSetModel dsModel=new DataSetModel().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);
......@@ -498,6 +363,7 @@ public class DynamicModelStorage {
}
entities.put(entity,entityModel);
return entityModel;
}
......@@ -505,66 +371,27 @@ public class DynamicModelStorage {
public static enum DataType {
UNKNOWN(0,"UNKNOWN"),
BIGINT(1,"BIGINT"),
BINARY(2,"BINARY"),
BIT(3,"BIT"),
CHAR(4,"CHAR"),
DATETIME(5,"DATETIME"),
DECIMAL(6,"DECIMAL"),
FLOAT(7,"FLOAT"),
IMAGE(8,"IMAGE"),
INT(9,"INT"),
MONEY(10,"MONEY"),
NCHAR(11,"NCHAR"),
NTEXT(12,"NTEXT"),
NVARCHAR(13,"NVARCHAR"),
NUMERIC(14,"NUMERIC"),
REAL(15,"REAL"),
SMALLDATETIME(16,"SMALLDATETIME"),
SMALLINT(17,"SMALLINT"),
SMALLMONEY(18,"SMALLMONEY"),
SQL_VARIANT(19,"SQL_VARIANT"),
SYSNAME(20,"SYSNAME"),
TEXT(21,"TEXT"),
TIMESTAMP(22,"TIMESTAMP"),
TINYINT(23,"TINYINT"),
VARBINARY(24,"VARBINARY"),
VARCHAR(25,"VARCHAR"),
UNIQUEIDENTIFIER(26,"UNIQUEIDENTIFIER"),
DATE(27,"DATE"),
TIME(28,"TIME");
public final int code;
public final String name;
private DataType(int code, String name) {
this.code = code;
this.name = name;
}
public int getCode() {
return code;
}
public String getName() {
return name;
public EntityModel getEntitySchema(String entity)
{
EntityModel entityModel= null;
try {
entityModel = getDynamicEntity(entity);
} catch (Exception exception) {
exception.printStackTrace();
}
Assert.notNull(entityModel,"loadDOModel未找到实体"+"."+entity);
public static String findTypeName(Integer type) {
for (DataType userTypeEnum : DataType.values()) {
if (userTypeEnum.getCode()==type) {
return userTypeEnum.getName();
}
for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
if (poSchema != null) {
entityModel.addPOSchema(dsType, poSchema);
}
return VARCHAR.getName();
}
return entityModel;
}
private String contextParamConvert(String contextParam)
{
String resultParam=getJavaSqlCode(contextParam).replaceAll("(IN|in) \\(\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}\\)","$1 (\\${srf.$2.$3})");
......@@ -641,39 +468,8 @@ public class DynamicModelStorage {
}
private Map<String, Long> systemModifyMap=new HashMap<>();
public void resetSystem()
{
this.entities=null;
this.dstSystemModel=null;
this.iPSSystem=null;
this.entitykeys=null;
}
private Map<String, String> entitykeys = null;
public Map<String, String> getEntitiyIds() throws Exception {
if(entitykeys==null)
{
entitykeys = new HashMap<>();
DstSystemModel dstSystemModel=getDstSystemModel();
if(dstSystemModel!=null)
{
Map<String, MetaEntityModel> entityModels = getEntities();
entityModels.entrySet().forEach(entry->{
String id=entry.getValue().getSystemId().concat(".domain.").concat(entry.getValue().getEntityName());
entitykeys.put(entry.getKey(),id);
});
}
}
return entitykeys;
}
}
package cn.ibizlab.codegen.lite;
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.IPSDataEntity;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
......@@ -19,50 +19,49 @@ import java.util.Map;
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class EntityModel {
public class EntityModel {
@JsonIgnore
@JSONField(serialize = false)
public String getEntityId() {
return getEntity().getEntityId();
return getEntity().getId();
}
@JsonIgnore
@JSONField(serialize = false)
public String getCodeName() {
return getEntity().getCodeName();
}
@JsonIgnore
@JSONField(serialize = false)
public String getEntityName() {
return getEntity().getEntityName();
return getEntity().getName();
}
@JsonIgnore
@JSONField(serialize = false)
public String getTableName() {
return getEntity().getTableName();
}
@JsonIgnore
@JSONField(serialize = false)
public String getLogicName() {
return getEntity().getLogicName();
}
@JsonIgnore
@JSONField(serialize = false)
public String getSystemId() {
return getEntity().getSystemId();
public String getModule() {
if(getEntity().getPSSystemModule()!=null)
return getEntity().getPSSystemModule().getCodeName();
return "Ungroup";
}
private MetaEntityModel entity;
private IPSDataEntity entity;
private List<MetaDataSetModel> dataSets;
private List<DataSetModel> dataSets;
public EntityModel addDataSet(MetaDataSetModel dataSet)
public EntityModel addDataSet(DataSetModel dataSet)
{
if(dataSets==null)
dataSets=new ArrayList<>();
......@@ -90,11 +89,11 @@ public class EntityModel {
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String,RelationshipModel> refMaps;
@JsonIgnore
@JSONField(serialize = false)
public Map<String,RelationshipModel> getRefMaps()
{
if(refMaps==null)
......@@ -124,12 +123,12 @@ public class EntityModel {
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String, FieldModel> fieldMap = null;
@JsonIgnore
@JSONField(serialize = false)
public Map<String, FieldModel> getFieldMap()
{
if(fields!=null&&fieldMap==null)
......@@ -143,11 +142,11 @@ public class EntityModel {
return fieldMap;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel lastModifyField;
@JsonIgnore
@JSONField(serialize = false)
public FieldModel getLastModifyField() {
if(fields!=null&&lastModifyField==null)
for(FieldModel fieldModel:fields)
......@@ -159,12 +158,12 @@ public class EntityModel {
return lastModifyField;
}
@JsonIgnore
@JSONField(serialize = false)
private boolean isLogicValid=true;
@JsonIgnore
@JSONField(serialize = false)
public boolean isLogicValid()
{
if(isLogicValid&&logicValidField==null) {
......@@ -180,11 +179,11 @@ public class EntityModel {
}
return isLogicValid;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel logicValidField;
@JsonIgnore
@JSONField(serialize = false)
public FieldModel getLogicValidField() {
if(isLogicValid&&logicValidField==null) {
if (fields != null) {
......@@ -200,37 +199,37 @@ public class EntityModel {
return logicValidField;
}
@JsonIgnore
@JSONField(serialize = false)
private String logicVal;
@JsonIgnore
@JSONField(serialize = false)
public String getLogicVal()
private String validLogicValue;
public String getValidLogicValue()
{
if(StringUtils.isEmpty(logicVal))
logicVal=this.getExtParams("logicval");
if(StringUtils.isEmpty(logicVal))
logicVal="1";
return logicVal;
if(StringUtils.isEmpty(validLogicValue))
validLogicValue=this.getEntity().getValidLogicValue();
if(StringUtils.isEmpty(validLogicValue))
validLogicValue="1";
return validLogicValue;
}
@JsonIgnore
@JSONField(serialize = false)
private String logicDelVal;
@JsonIgnore
@JSONField(serialize = false)
public String getLogicDelVal()
private String invalidLogicValue;
public String getInvalidLogicValue()
{
if(StringUtils.isEmpty(logicVal))
logicDelVal=this.getExtParams("logicdelval");
if(StringUtils.isEmpty(logicDelVal))
logicDelVal="0";
return logicDelVal;
if(StringUtils.isEmpty(invalidLogicValue))
invalidLogicValue=this.getEntity().getInvalidLogicValue();
if(StringUtils.isEmpty(invalidLogicValue))
invalidLogicValue="0";
return invalidLogicValue;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel keyField;
@JsonIgnore
@JSONField(serialize = false)
public FieldModel getKeyField() {
if(fields!=null&&keyField==null)
for(FieldModel fieldModel:fields)
......@@ -241,11 +240,11 @@ public class EntityModel {
return keyField;
}
@JsonIgnore
@JSONField(serialize = false)
private List<FieldModel> unionKeyFields;
@JsonIgnore
@JSONField(serialize = false)
public List<FieldModel> getUnionKeyFields() {
if(fields!=null&&unionKeyFields==null) {
unionKeyFields = new ArrayList<>();
......@@ -256,8 +255,8 @@ public class EntityModel {
return unionKeyFields;
}
@JsonIgnore
@JSONField(serialize = false)
public List<FieldModel> getKeyFields() {
if(this.getKeyField()!=null&&this.getKeyField().isPhysicalField()) {
List<FieldModel> keyFields = new ArrayList<>();
......@@ -268,238 +267,38 @@ public class EntityModel {
return getUnionKeyFields();
}
public FieldModel getField(String name)
{
if(StringUtils.isEmpty(name))
return null;
if(fields==null)
return null;
if(getFieldMap()!=null)
return getFieldMap().get(name);
return null;
}
@JsonIgnore
@JSONField(serialize = false)
public String getDefaultQueryScript()
{
if(this.getDataSets()!=null)
{
for(MetaDataSetModel set:this.getDataSets()){
if(StringUtils.isEmpty(set.getDsCode()))
continue;
if("view".equalsIgnoreCase(set.getDatasetId())||
set.getDatasetId().startsWith("dq-view-")||
set.getDatasetId().startsWith(getEntityName().toLowerCase()+"-dq-view-"))
{
return set.getDsCode().replace("`","").replace("[","").replace("]","");
}
}
for(MetaDataSetModel set:this.getDataSets()){
if(StringUtils.isEmpty(set.getDsCode()))
continue;
if("default".equalsIgnoreCase(set.getDatasetId())||
set.getDatasetId().startsWith("dq-default-")||
set.getDatasetId().startsWith(getEntityName().toLowerCase()+"-dq-default-"))
{
return set.getDsCode().replace("`","").replace("[","").replace("]","");
}
}
}
return "";
}
public String getSqlSegment(String dataSet)
{
if("CORE".equalsIgnoreCase(dataSet))
{
String columnSet=this.getKeyField().getColumnExp();
for(FieldModel fieldModel:this.getUnionKeyFields())
{
String columnExp=fieldModel.getColumnExp();
if(StringUtils.isEmpty(columnExp))
continue;
columnSet = columnSet + "," + columnExp;
}
return "select "+columnSet+" from "+this.getTableName()+" ";
}
else if("COUNT".equalsIgnoreCase(dataSet))
{
return "select count(1) from "+this.getTableName()+" ";
}
else if(this.getDataSets()!=null)
{
for(MetaDataSetModel set:this.getDataSets()){
if(StringUtils.isEmpty(set.getDsCode()))
continue;
if(dataSet.equalsIgnoreCase(set.getDatasetId())||
set.getDatasetId().indexOf("ds-"+dataSet.toLowerCase()+"-")>=0||
set.getDatasetId().startsWith(getEntityName().toLowerCase()+"-ds-"+dataSet.toLowerCase()+"-"))
{
return set.getDsCode().replace("`","").replace("[","").replace("]","");
}
}
for(MetaDataSetModel set:this.getDataSets()){
if(StringUtils.isEmpty(set.getDsCode()))
continue;
if(dataSet.equalsIgnoreCase(set.getDatasetId())||
set.getDatasetId().indexOf("dq-"+dataSet.toLowerCase()+"-")>=0||
set.getDatasetId().startsWith(getEntityName().toLowerCase()+"-dq-"+dataSet.toLowerCase()+"-"))
{
return set.getDsCode().replace("`","").replace("[","").replace("]","");
}
}
}
if(dataSet.equalsIgnoreCase("VIEW")||dataSet.equalsIgnoreCase("DEFAULT"))
{
return "";
}
else
{
String columnSet="";
for(FieldModel fieldModel:fields)
{
String columnExp=fieldModel.getColumnExp();
if(StringUtils.isEmpty(columnExp))
continue;
if(!StringUtils.isEmpty(columnSet)){
columnSet=columnSet+",";
}
columnSet=columnSet+columnExp;
}
return "select "+columnSet+" from "+this.getTableName()+" t ";
}
}
@JsonIgnore
@JSONField(serialize = false)
public String getMergeColumnSegment()
{
String sql="";
boolean first=true;
for(FieldModel fieldModel:this.getFields())
{
if(!fieldModel.isPhysicalField())
continue;
if(first)
first=false;
else
sql+=",";
sql+=("#{item."+fieldModel.getColumnName().toUpperCase()+"} "+fieldModel.getColumnName().toUpperCase());
}
return sql;
}
@JsonIgnore
@JSONField(serialize = false)
public String getMergeSegment()
{
String sql="";
sql+= " ON (";
boolean first=true;
for(FieldModel fieldModel:this.getKeyFields())
{
if(!fieldModel.isPhysicalField())
continue;
if(first)
first=false;
else
sql+=" and ";
sql+=("T1."+fieldModel.getColumnName().toUpperCase()+"=T2."+fieldModel.getColumnName().toUpperCase());
}
sql+=")\n" +
" WHEN NOT MATCHED THEN INSERT(";
first=true;
for(FieldModel fieldModel:this.getFields())
{
if(!fieldModel.isPhysicalField())
continue;
if(first)
first=false;
else
sql+=",";
sql+=(fieldModel.getColumnName().toUpperCase());
}
sql+=") VALUES (" ;
first=true;
for(FieldModel fieldModel:this.getFields())
{
if(!fieldModel.isPhysicalField())
continue;
if(first)
first=false;
else
sql+=",";
sql+=("T2."+fieldModel.getColumnName().toUpperCase());
}
sql+=")\n" +
" WHEN MATCHED THEN UPDATE SET " ;
first=true;
for(FieldModel fieldModel:this.getFields())
{
if(!fieldModel.isPhysicalField())
continue;
if(fieldModel.isKeyField())
continue;
if(fieldModel.isUnionKeyField())
continue;
if(first)
first=false;
else
sql+=",";
sql+=("T1."+fieldModel.getColumnName().toUpperCase()+"=T2."+fieldModel.getColumnName().toUpperCase());
}
return sql;
}
@JsonIgnore
@JSONField(serialize = false)
public String getDsName()
{
String dsName=this.getEntity().getDsId();
if(StringUtils.isEmpty(dsName))
String dsName=this.getEntity().getDSLink();
if(StringUtils.isEmpty(dsName)||"DEFAULT".equalsIgnoreCase(dsName))
{
dsName=this.getSystemId()+"-master";
dsName="master";
}
return dsName;
}
public String getExtParams(String key)
{
return DataObject.getStringValue(entity.get(key),"");
}
public String getTableName(String dsType)
{
return DataObject.getStringValue(entity.get("table-"+dsType.toLowerCase()),getTableName());
return this.getStringValue("table-"+dsType.toLowerCase(),getTableName());
}
@JsonIgnore
@JSONField(serialize = false)
public List<String> getDsTypes()
{
List<String> dsTypes=new ArrayList<>();
String strDsTypes=DataObject.getStringValue(entity.get("ds_types"),"");
String strDsTypes=this.getStringValue("ds_types","");
for(String dsType:strDsTypes.split(","))
dsTypes.add(dsType);
return dsTypes;
}
@JsonIgnore
@JSONField(serialize = false)
private Object node;
private String storageMode="SQL";
......@@ -527,4 +326,69 @@ public class EntityModel {
{
this.storageMode=type;
}
@JSONField(serialize = false)
@JsonIgnore
private Map<String, POSchema> poSchemas;
@JSONField(serialize = false)
@JsonIgnore
public POSchema getDefaultPOSchema()
{
return getPOSchema("default");
}
public EntityModel addPOSchema(String name, POSchema poSchema)
{
if(poSchema!=null)
{
if(poSchemas==null)
poSchemas=new LinkedHashMap<>();
poSchemas.put(name,poSchema.build());
}
return this;
}
public POSchema getPOSchema(String name)
{
if(StringUtils.isEmpty(name)&&(!StringUtils.isEmpty(this.getDsName())))
name=this.getDsName();
if(StringUtils.isEmpty(name))
name="mysql";
if(poSchemas==null)
poSchemas=new LinkedHashMap<>();
if(poSchemas.containsKey(name))
{
return poSchemas.get(name);
}
String vendorProvider=POSchema.provider.get(name.toLowerCase());
if((!StringUtils.isEmpty(vendorProvider))&&(!name.equalsIgnoreCase(vendorProvider))&&poSchemas.containsKey(vendorProvider))
return poSchemas.get(vendorProvider);
if(poSchemas.size()>0)
return poSchemas.values().iterator().next();
return null;
}
private DataObj extParams=new DataObj();
public EntityModel set(String key,Object val)
{
extParams.set(key,val);
return this;
}
public Object get(String key)
{
return key;
}
public String getStringValue(String key,String defaultVal)
{
return extParams.getStringValue(key,defaultVal);
}
}
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
import java.util.Set;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
public class FieldModel {
public String getCodeName() {
return getField().getCodeName();
}
public String getFieldName() {
return getField().getName();
}
public String getColumnName(){
return getField().getName();
}
public String getLogicName() {
return getField().getLogicName();
}
public DataType getType()
{
return DataType.findTypeName(this.getField().getStdDataType());
}
private String expression;
private IPSDEField field;
private RelationshipModel reference;
private String refFieldName;
private String refFieldCodeName;
@JsonIgnore
@JSONField(serialize = false)
public boolean isPhysicalField()
{
return this.getField().isPhisicalDEField();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isKeyField()
{
return this.getField().isKeyDEField();
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isLogicValidField()
{
return "LOGICVALID".equals(this.getField().getPredefinedType());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isLastModifyField()
{
return "UPDATEDATE".equals(this.getField().getPredefinedType());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isCreateTimeField()
{
return "CREATEDATE".equals(this.getField().getPredefinedType());
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isUnionKeyField()
{
return !StringUtils.isEmpty(this.getField().getUnionKeyValue());
}
public String getDefaultValue()
{
if((!StringUtils.isEmpty(getField().getDefaultValueType()))||(!StringUtils.isEmpty(getField().getDefaultValue())))
{
String defaultValue="";
if(StringUtils.isEmpty(getField().getDefaultValueType())||"NONE".equalsIgnoreCase(getField().getDefaultValueType()))
{
defaultValue=getField().getDefaultValue();
}
else if(!StringUtils.isEmpty(getField().getDefaultValue()))
{
defaultValue= String.format("${%1$s.%2$s}",getField().getDefaultValueType(),getField().getDefaultValue());
}
else
{
defaultValue= String.format("${%1$s}",getField().getDefaultValueType());
}
return defaultValue;
}
return null;
}
public Set<String> getSearchMode()
{
Set<String> modes=new LinkedHashSet<>();
if(getField().getAllPSDEFSearchModes()!=null)
{
getField().getAllPSDEFSearchModes().forEach(item->modes.add(item.getValueOP().toLowerCase()));
}
if(getField().isEnableQuickSearch())
modes.add("query");
return modes;
}
private DataObj extParams=new DataObj();
public FieldModel set(String key,Object val)
{
extParams.set(key,val);
return this;
}
public String getStringValue(String key,String defaultVal)
{
return extParams.getStringValue(key,defaultVal);
}
public String getColumnName(String dsType)
{
return this.getStringValue("column-"+dsType.toLowerCase(),getColumnName());
}
public static enum DataType {
UNKNOWN(0,"UNKNOWN","string","String"),
BIGINT(1,"BIGINT","number","Long"),
BINARY(2,"BINARY","string","String"),
BIT(3,"BIT","boolean","Boolean"),
CHAR(4,"CHAR","string","String"),
DATETIME(5,"DATETIME","string", "Timestamp"),
DECIMAL(6,"DECIMAL","number", "BigDecimal"),
FLOAT(7,"FLOAT","number", "BigDecimal"),
IMAGE(8,"IMAGE","string","String"),
INT(9,"INT","number","Integer"),
MONEY(10,"MONEY","number", "BigDecimal"),
NCHAR(11,"NCHAR","string","String"),
NTEXT(12,"NTEXT","string","String"),
NVARCHAR(13,"NVARCHAR","string","String"),
NUMERIC(14,"NUMERIC","number", "BigDecimal"),
REAL(15,"REAL","number","Float"),
SMALLDATETIME(16,"SMALLDATETIME","string", "Timestamp"),
SMALLINT(17,"SMALLINT","number","Integer"),
SMALLMONEY(18,"SMALLMONEY","number", "BigDecimal"),
SQL_VARIANT(19,"SQL_VARIANT","string","String"),
SYSNAME(20,"SYSNAME","string","String"),
TEXT(21,"TEXT","string","String"),
TIMESTAMP(22,"TIMESTAMP","string","Timestamp"),
TINYINT(23,"TINYINT","number","Integer"),
VARBINARY(24,"VARBINARY","string","String"),
VARCHAR(25,"VARCHAR","string","String"),
UNIQUEIDENTIFIER(26,"UNIQUEIDENTIFIER","string","String"),
DATE(27,"DATE","string", "Timestamp"),
TIME(28,"TIME","string", "Timestamp");
public final int code;
public final String name;
public final String prop;
public final String java;
private DataType(int code, String name, String prop, String java) {
this.code = code;
this.name = name;
this.prop = prop;
this.java = java;
}
public int getCode() {
return code;
}
public String getName() {
return name;
}
public String getProp() {
return prop;
}
public String getJava() {
return java;
}
public static DataType findTypeName(Integer type) {
for (DataType userTypeEnum : DataType.values()) {
if (userTypeEnum.getCode()==type) {
return userTypeEnum;
}
}
return VARCHAR;
}
}
}
package cn.ibizlab.codegen.lite;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -20,7 +20,7 @@ import java.io.Serializable;
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel("lookup")
public class MetaLookupModel implements Serializable {
public class LookupModel implements Serializable {
/**
* 标识
......
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.lite.DynamicModelStorage;
import cn.ibizlab.codegen.lite.EntityModel;
import cn.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConstants;
......@@ -60,25 +58,7 @@ public class ModelStorage {
}
public PojoSchema getEntitySchema(String entity)
{
EntityModel entityModel= null;
try {
entityModel = dynamicService.getDynamicEntity(entity);
} catch (Exception exception) {
exception.printStackTrace();
}
Assert.notNull(entityModel,"loadDOModel未找到实体"+"."+entity);
PojoSchema schema = TransUtils.EntityModelModel2Schema(entityModel);
Assert.notNull(schema,"loadDOModel未找到实体"+"."+entity);
for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
if (poSchema != null) {
schema.addPOSchema(dsType, poSchema);
}
}
return schema;
}
private Map<TemplateFileType,CliData> templateData=new HashMap<>();
......@@ -122,9 +102,9 @@ public class ModelStorage {
else if(type.equals(TemplateFileType.entity))
{
dynamicService.getPSSystem().getAllPSDataEntities().forEach(item->{
PojoSchema pojoSchema=this.getEntitySchema(item.getName());
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(pojoSchema.getStorageMode()).setModule(pojoSchema.getModule())
.baseData(pojoSchema,item.getCodeName());
EntityModel schema=dynamicService.getEntitySchema(item.getId());
CliOption opt=newCliOption(TemplateFileType.entity).setCliSubType(schema.getStorageMode()).setModule(schema.getModule())
.baseData(schema,item.getCodeName());
rt.addOption(opt);
});
}
......
......@@ -626,16 +626,7 @@ public class PojoSchema {
}
}
if(("default".equals(name)||this.getDefaultDataSoruce().equalsIgnoreCase(name)))
{
POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this);
if(defaultPOSchema!=null) {
poSchemas.put("default", defaultPOSchema);
if(!StringUtils.isEmpty(this.getDefaultDataSoruce()))
poSchemas.put(this.getDefaultDataSoruce().toLowerCase(),defaultPOSchema);
return defaultPOSchema;
}
}
return null;
}
......
package cn.ibizlab.codegen.lite;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
......@@ -15,6 +17,8 @@ import lombok.experimental.Accessors;
@JsonIgnoreProperties(value = "handler")
public class RelationshipModel {
private String name;
private String codeName;
private String entityName;
......@@ -23,18 +27,34 @@ public class RelationshipModel {
private String entityLogicName;
private String systemId;
private String dataSourceName;
private String tableName;
private String entityId;
private MetaRelationshipModel relation;
private String relationType;
private IPSDERBase relation;
private List<FieldModel> fields;
public RelationshipModel addField(FieldModel obj)
{
if(fields==null)
fields=new ArrayList<>();
fields.add(obj);
return this;
}
private List<LookupModel> lookup;
public RelationshipModel addLookup(LookupModel obj)
{
if(lookup==null)
lookup=new ArrayList<>();
lookup.add(obj);
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Object node;
}
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.lite.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import cn.ibizlab.codegen.lite.*;
import net.ibizsys.model.dataentity.defield.IPSDEField;
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;
public class TransUtils {
public static PojoSchema EntityModelModel2Schema(EntityModel entityModel)
{
PojoSchema pojoSchema=new PojoSchema().setName(entityModel.getEntityName()).setType("object").setTitle(entityModel.getLogicName()).setId(entityModel.getEntityId())
.setOptions(new PojoOption().setDsTypes(String.join(",",entityModel.getDsTypes())).setLogicValid(entityModel.isLogicValid()).setLogicVal(entityModel.getLogicVal()).setLogicDelVal(entityModel.getLogicDelVal()).setStorageMode(entityModel.getStorageMode()));
pojoSchema.getOptions().setAll(JSONObject.parseObject(JSON.toJSONString(entityModel.getEntity()))).remove("ext_params");
pojoSchema.setNode(entityModel.getNode());
int order=1;
for(FieldModel fieldModel:entityModel.getFields())
{
String propType=fieldModel.getPropType();
PojoSchema sub=null;
if("date".equals(propType))
sub=new PojoSchema().setType(PojoSchema.Type.string.getCode()).setFormat("date");
else if("date-time".equals(propType))
sub=new PojoSchema().setType(PojoSchema.Type.string.getCode()).setFormat("date-time");
else
sub=new PojoSchema().setType(propType);
sub.setName(fieldModel.getCodeName()).setTitle(fieldModel.getField().getFieldLogicName()).setPropertyOrder(order)
.setOptions(new PojoOption().setAll(JSONObject.parseObject(JSON.toJSONString(fieldModel.getField()))));
Object searchModes=fieldModel.getField().get("search_modes");
if(!ObjectUtils.isEmpty(searchModes))
sub.getOptions().setSearchModes(searchModes.toString());
Object defaultValue=fieldModel.getField().get("default_value");
if(!ObjectUtils.isEmpty(defaultValue))
sub.getOptions().setDefaultValue(defaultValue.toString());
sub.getOptions().remove("ext_params");
sub.setNode(fieldModel.getNode());
if("PICKUP".equals(fieldModel.getField().getFieldType())&&fieldModel.isPhysicalField())
{
if(!StringUtils.isEmpty(sub.getOptions().getRelationCodeName()))
{
RelationshipModel relationshipModel=entityModel.getRefMaps().get(sub.getOptions().getRelationCodeName());
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName())))
sub.getOptions().setRefTableName(relationshipModel.getTableName());
}
String smode=sub.getOptions().getSearchModes();
if((!smode.startsWith("eq"))&&smode.indexOf(",eq")<0)
sub.getOptions().setSearchModes(smode.concat(StringUtils.isEmpty(smode)?"":",").concat("eq"));
}
pojoSchema.addProperty(sub.getName(),sub);
order++;
}
if(entityModel.getReferences()!=null)
{
for(RelationshipModel rel:entityModel.getReferences())
{
PojoSchema sub=new PojoSchema().setType(PojoSchema.Type.object.getCode()).setName(rel.getCodeName()).setTitle(rel.getCodeName()+rel.getEntityLogicName())
.setPropertyOrder(order).setOptions(new PojoOption()
.set("logic_name",rel.getEntityLogicName())
.set("entity_name",rel.getEntityName())
.set("system_id",(StringUtils.isEmpty(rel.getSystemId())?entityModel.getSystemId():rel.getSystemId()))
.set("entity_id",rel.getEntityId()).set("code_name",rel.getEntityCodeName())
.set("table_name",rel.getTableName()).set("ds_name",rel.getDataSourceName())
.set("relation_name",rel.getRelation().getName())
.set("relation",JSONObject.parseObject(JSON.toJSONString(rel.getRelation()), MetaRelationshipModel.class))
)
.setRef("domain."+rel.getEntityName());
sub.setNode(rel.getNode());
pojoSchema.addProperty(sub.getName(),sub);
order++;
}
}
if(entityModel.getNesteds()!=null)
{
for(RelationshipModel nest:entityModel.getNesteds())
{
PojoSchema sub=new PojoSchema().setType(PojoSchema.Type.array.getCode()).setName(nest.getCodeName()).setTitle(nest.getCodeName()+nest.getEntityLogicName())
.setPropertyOrder(order).setOptions(new PojoOption()
.set("logic_name",nest.getEntityLogicName())
.set("entity_name",nest.getEntityName())
.set("system_id",(StringUtils.isEmpty(nest.getSystemId())?entityModel.getSystemId():nest.getSystemId()))
.set("entity_id",nest.getEntityId()).set("code_name",nest.getEntityCodeName())
.set("table_name",nest.getTableName()).set("ds_name",nest.getDataSourceName())
.set("relation_name",nest.getRelation().getName())
.set("relation",JSONObject.parseObject(JSON.toJSONString(nest.getRelation()), MetaRelationshipModel.class))
)
.setItems(new PojoSchema().setType(PojoSchema.Type.object.getCode()).setName(nest.getEntityName()).setTitle(nest.getEntityLogicName())
.setRef("domain."+nest.getEntityName())
.setOptions(new PojoOption()
.set("logic_name",nest.getEntityLogicName())
.set("entity_name",nest.getEntityName())
.set("system_id",(StringUtils.isEmpty(nest.getSystemId())?entityModel.getSystemId():nest.getSystemId()))
.set("entity_id",nest.getEntityId()).set("code_name",nest.getEntityCodeName())
.set("table_name",nest.getTableName()).set("ds_name",nest.getDataSourceName())
)
);
sub.setNode(nest.getNode());
pojoSchema.addProperty(sub.getName(),sub);
order++;
}
}
return pojoSchema;
}
public static POSchema PojoSchema2PO(PojoSchema pojoSchema)
{
POSchema poSchema=new POSchema().setName(pojoSchema.getDefaultTableName()).setDefaultDataSource(pojoSchema.getDefaultDataSoruce())
.setRemarks(pojoSchema.getTitle()).setLogicVal(pojoSchema.getOptions().getLogicVal()).setLogicDelVal(pojoSchema.getOptions().getLogicDelVal());
for(String name:pojoSchema.getProperties().keySet())
{
PojoSchema sub=pojoSchema.getProperties().get(name);
String dataType=sub.getOptions().getDataType();
Integer length=sub.getOptions().getDataLength();
Integer precision=sub.getOptions().getDataPreci();
POSchema.Column column=new POSchema.Column().setName(sub.getOptions().getFieldName()).setAlias(name).setRemarks(sub.getTitle()).setDefaultValue(sub.getOptions().getDefaultValue()).setPredefined(sub.getOptions().getPredefined()).setLength(length);
if(PojoSchema.Type.object.getCode().equals(sub.getType())||PojoSchema.Type.array.getCode().equals(sub.getType()))
{
if(!sub.getOptions().isPhysicalField())
continue;
if(StringUtils.isEmpty(dataType))dataType="TEXT";
column.setType(dataType);
column.setLength(null);
}
else if(PojoSchema.Type.string.getCode().equals(sub.getType())&&(!StringUtils.isEmpty(sub.getFormat())))
{
if(StringUtils.isEmpty(dataType)&&(sub.getFormat().indexOf("date")>=0))
dataType="DATETIME";
else
dataType="VARCHAR";
column.setType(dataType);
}
else if(PojoSchema.Type.integer.getCode().equals(sub.getType()) )
{
if(StringUtils.isEmpty(dataType))dataType="INT";
column.setType(dataType);
}
else if(PojoSchema.Type.number.getCode().equals(sub.getType()) )
{
if(StringUtils.isEmpty(dataType))dataType="NUMBER";
column.setType(dataType);
}
else {
if(StringUtils.isEmpty(dataType))dataType="VARCHAR";
column.setType(dataType);
}
if(column.isNumber())
column.setPrecision(precision);
if((pojoSchema.getRequired()!=null&&pojoSchema.getRequired().contains(name))||(!pojoSchema.getOptions().isNullable()))
column.getConstraints(true).setNullable(false);
if(pojoSchema.getKeyMap()!=null&&pojoSchema.getKeyMap().containsKey(column.getName())) {
String primaryKeyName="PK_"+poSchema.getName().toUpperCase()+"_"+ column.getName().toUpperCase();
column.getConstraints(true).setPrimaryKey(true).setPrimaryKeyName(primaryKeyName);
}
if(sub.getOptions().isLogicValidField())
{
if(!StringUtils.isEmpty(pojoSchema.getOptions().getLogicVal()))
column.setDefaultValue(pojoSchema.getOptions().getLogicVal());
else
column.setDefaultValue("1");
}
if(!StringUtils.isEmpty(sub.getOptions().getSearchModes()))
column.putSearchModes(sub.getOptions().getSearchModes());
if("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField())
{
PojoSchema relationshipModel=pojoSchema.getRefSchema(sub.getOptions().getRelationName());
String fkName=sub.getOptions().getRelationName().toUpperCase();
if((!StringUtils.isEmpty(relationshipModel.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(relationshipModel.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()));
}
}
else if((!StringUtils.isEmpty(sub.getOptions().getRelationName()))) {
PojoSchema relationshipModel=pojoSchema.getRefSchema(sub.getOptions().getRelationName());
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getOptions().getTableName()))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getOptions().getTableName())
.setReferencedColumnNames(sub.getOptions().getRefFieldName());
}
}
if(!sub.getOptions().isPhysicalField())
poSchema.addTransient(column.setComputed(true));
else
poSchema.addColumn(column);
}
String defaultQueryScript=pojoSchema.getOptions().getDefaultQueryScript();
if(!StringUtils.isEmpty(defaultQueryScript))
poSchema.setDefaultQueryScriptSQL(defaultQueryScript);
return poSchema;
}
public static POSchema PojoSchema2DocumentPO(PojoSchema pojoSchema)
......@@ -333,32 +118,31 @@ public class TransUtils {
final String dataSourceType=dsType.toLowerCase();
POSchema poSchema=new POSchema().setDsType(dataSourceType).setName(entityModel.getTableName(dataSourceType)).setDefaultDataSource(entityModel.getDsName())
.setRemarks(entityModel.getLogicName()).setLogicVal(entityModel.getLogicVal()).setLogicDelVal(entityModel.getLogicDelVal());
.setRemarks(entityModel.getLogicName()).setLogicVal(entityModel.getValidLogicValue()).setLogicDelVal(entityModel.getInvalidLogicValue());
poSchema.setNode(entityModel.getNode());
poSchema.setNode(entityModel.getEntity());
Map<String,FieldModel> keyMap=new LinkedHashMap<>();
Map<String,RelationshipModel> relationshipModelMap = new LinkedHashMap<>();
if(entityModel.getKeyFields()!=null)entityModel.getKeyFields().forEach(model->keyMap.put(model.getColumnName(),model));
if(entityModel.getReferences()!=null)entityModel.getReferences().forEach(model->relationshipModelMap.put(model.getRelation().getName(),model));
int order = 1;
for (FieldModel fieldModel : entityModel.getFields()) {
MetaFieldModel sub=fieldModel.getField();
IPSDEField sub=fieldModel.getField();
String colName=fieldModel.getColumnName(dataSourceType);
Integer length=sub.getDataLength();
Integer precision=sub.getDataPreci();
Integer length=sub.getLength();
Integer precision=sub.getPrecision();
POSchema.Column column=new POSchema.Column().setName(colName).setAlias(sub.getCodeName()).setRemarks(sub.getFieldLogicName()).setPredefined(sub.getPredefined()).setLength(length).setType(sub.getDataType());
POSchema.Column column=new POSchema.Column().setName(colName).setAlias(sub.getCodeName()).setRemarks(sub.getLogicName()).setPredefined(sub.getPredefinedType()).setLength(length).setType(sub.getDataType());
column.setNode(fieldModel.getNode());
column.setNode(sub);
if(column.isNumber())
column.setPrecision(precision);
if(sub.getNullable()!=null&&sub.getNullable()==0)
if(!sub.isAllowEmpty())
column.getConstraints(true).setNullable(false);
if(keyMap.containsKey(column.getName())) {
......@@ -367,38 +151,40 @@ public class TransUtils {
}
if(fieldModel.isLogicValidField())
{
if(!StringUtils.isEmpty(entityModel.getLogicVal()))
column.setDefaultValue(entityModel.getLogicVal());
if(!StringUtils.isEmpty(entityModel.getValidLogicValue()))
column.setDefaultValue(entityModel.getValidLogicValue());
else
column.setDefaultValue("1");
}
Object searchModes=fieldModel.getField().get("search_modes");
if(searchModes!=null)
column.putSearchModes(searchModes.toString());
Set<String> searchModes=fieldModel.getSearchMode();
if(!ObjectUtils.isEmpty(searchModes))
column.setSearchModes(searchModes);
if("PICKUP".equals(sub.getFieldType())&&fieldModel.isPhysicalField())
if(fieldModel.getReference()!=null&&sub.isLinkDEField())
{
RelationshipModel relationshipModel=relationshipModelMap.get(sub.getRelationName());
String fkName=sub.getRelationName().toUpperCase();
RelationshipModel relationshipModel=fieldModel.getReference();
String fkName=relationshipModel.getName().toUpperCase();
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getTableName())
.setReferencedColumnNames(sub.getRefFieldName()).setForeignKeyName(fkName);
.setReferencedColumnNames(fieldModel.getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName)
.setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName())
.setReferencedTableName(relationshipModel.getTableName()).setReferencedColumnNames(sub.getRefFieldName()));
.setReferencedTableName(relationshipModel.getTableName()).setReferencedColumnNames(fieldModel.getRefFieldName()));
}
if(column.getSearchModes()==null)
column.setSearchModes(new LinkedHashSet<>());
if(!column.getSearchModes().contains("eq"))
column.getSearchModes().add("eq");
}
else if((!StringUtils.isEmpty(sub.getRelationName()))) {
RelationshipModel relationshipModel = relationshipModelMap.get(sub.getRelationName());
String fkName=sub.getRelationName().toUpperCase();
else if(fieldModel.getReference()!=null) {
RelationshipModel relationshipModel = fieldModel.getReference();
String fkName=relationshipModel.getName().toUpperCase();
if(relationshipModel!=null&&(!StringUtils.isEmpty(relationshipModel.getTableName()))&&(!StringUtils.isEmpty(fkName))) {
column.getConstraints(true).setReferencedTableName(relationshipModel.getTableName())
.setReferencedColumnNames(sub.getRefFieldName());
.setReferencedColumnNames(fieldModel.getRefFieldName());
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册