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

提交

上级 11dbd457
......@@ -2,7 +2,7 @@ spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/a_A_5d9d78509?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true&useTimezone=true&serverTimezone=GMT%2B8
url: jdbc:mysql://172.16.100.77:3306/a_A_5d9d78509?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&allowMultiQueries=true&useTimezone=true&serverTimezone=GMT%2B8
isSyncDBSchema: false
dynamic:
druid: #以下是全局默认值,可以全局更改
......
spring:
profiles:
include: sys ,nacos, web-dev, api-dev, dev
include: sys ,nacos, web-dev, api-dev, dev, boot
application:
name: ibzdata
main:
......
package cn.ibizlab.core.data.domain;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -28,6 +27,7 @@ import org.springframework.data.annotation.Transient;
import cn.ibizlab.util.annotation.Audit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;
/**
......@@ -106,6 +106,27 @@ public class DOModel extends EntityBase implements Serializable {
@ApiModelProperty("模型")
private String model;
public void setSchema(PojoSchema schema) {
if(schema!=null)
{
if(StringUtils.isEmpty(schema.getId()))
schema.setId(schema.getSystem()+".domain."+schema.getName());
this.setId(schema.getId());
if(!StringUtils.isEmpty(schema.getName()))
this.setName(schema.getName());
if(!StringUtils.isEmpty(schema.getSystem()))
this.setSystemId(schema.getSystem());
if(!StringUtils.isEmpty(schema.getTitle()))
this.setTitle(schema.getTitle());
if(!StringUtils.isEmpty(schema.getDescription()))
this.setDescription(schema.getDescription());
if(!StringUtils.isEmpty(schema.getPackage()))
this.setPackageName(schema.getPackage());
}
this.schema = schema;
}
/**
* 存储
*/
......@@ -114,12 +135,23 @@ public class DOModel extends EntityBase implements Serializable {
@ApiModelProperty("存储")
private String poModels;
@JSONField(serialize = false)
@JsonIgnore
public String getKeyPropertyName()
{
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().values())))
return this.schema.getKeyMap().values().iterator().next();
return "id";
}
@JSONField(serialize = false)
@JsonIgnore
public String getKeyFieldName()
{
return "";
if(this.getSchema()!=null&&(!ObjectUtils.isEmpty(this.schema.getKeyMap().keySet())))
return this.schema.getKeyMap().keySet().iterator().next();
return "id";
}
......@@ -128,9 +160,47 @@ public class DOModel extends EntityBase implements Serializable {
@JsonIgnore
public String getDefaultDataSource()
{
return "";
return getSchema()!=null?getSchema().getDefaultDataSoruce():"";
}
@JSONField(serialize = false)
@JsonIgnore
private Map<String,POSchema> poSchemas;
@JSONField(serialize = false)
@JsonIgnore
public POSchema getDefaultPOSchema()
{
return getPOSchema("default");
}
public DOModel addPOSchema(String name,POSchema poSchema)
{
if(poSchemas==null)
poSchemas=new LinkedHashMap<>();
poSchemas.put(name,poSchema);
return this;
}
public POSchema getPOSchema(String name)
{
if(poSchemas==null)
poSchemas=new LinkedHashMap<>();
if(poSchemas.containsKey(name))
{
return poSchemas.get(name);
}
else if(this.getSchema()!=null&&("default".equals(name)||this.getSchema().getDefaultTableName().equals(name)))
{
POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this.getSchema());
if(defaultPOSchema!=null) {
poSchemas.put("default", defaultPOSchema);
poSchemas.put(this.getSchema().getDefaultTableName(),defaultPOSchema);
return defaultPOSchema;
}
}
return null;
}
}
......@@ -28,6 +28,7 @@ import org.springframework.data.annotation.Transient;
import cn.ibizlab.util.annotation.Audit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;
/**
......@@ -98,6 +99,27 @@ public class DTOModel extends EntityBase implements Serializable {
@ApiModelProperty("定义")
private PojoSchema schema;
public void setSchema(PojoSchema schema) {
if(schema!=null)
{
if(StringUtils.isEmpty(schema.getId()))
schema.setId(schema.getSystem()+".dto."+schema.getName());
this.setId(schema.getId());
if(!StringUtils.isEmpty(schema.getName()))
this.setName(schema.getName());
if(!StringUtils.isEmpty(schema.getSystem()))
this.setSystemId(schema.getSystem());
if(!StringUtils.isEmpty(schema.getTitle()))
this.setTitle(schema.getTitle());
if(!StringUtils.isEmpty(schema.getDescription()))
this.setDescription(schema.getDescription());
if(!StringUtils.isEmpty(schema.getPackage()))
this.setPackageName(schema.getPackage());
}
this.schema = schema;
}
/**
* 模型
*/
......
......@@ -65,7 +65,7 @@ public class DataObj<K,V> extends HashMap<K,V> {
public Integer getIntegerValue(String objValue) {
return getIntegerValue(objValue, Integer.MIN_VALUE);
}
public int getIntegerValue( String strParamName, int nDefault) {
public Integer getIntegerValue( String strParamName, Integer nDefault) {
return DataObject.getIntegerValue(this.get(strParamName),nDefault);
}
......
......@@ -44,6 +44,16 @@ public class RequestData<T> extends BaseData
return this.getStringValue("system");
}
public RequestData setScope(String scope)
{
return this.set("scope",scope);
}
public String getScope()
{
return this.getStringValue("scope","default");
}
public RequestData setEntity(String entity)
{
return this.set("entity",entity);
......
package cn.ibizlab.core.data.lite;
import cn.ibizlab.util.helper.DataObject;
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 org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = "handler")
public class EntityModel {
@JsonIgnore
@JSONField(serialize = false)
public String getEntityId() {
return getEntity().getEntityId();
}
@JsonIgnore
@JSONField(serialize = false)
public String getCodeName() {
return getEntity().getCodeName();
}
@JsonIgnore
@JSONField(serialize = false)
public String getEntityName() {
return getEntity().getEntityName();
}
@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();
}
private MetaEntityModel entity;
private List<Map> dataSets;
private List<FieldModel> fields;
private List<RelationshipModel> references;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,RelationshipModel> refMaps;
@JsonIgnore
@JSONField(serialize = false)
public Map<String,RelationshipModel> getRefMaps()
{
if(refMaps==null)
refMaps=new LinkedHashMap<>();
if(references!=null)
{
references.forEach(ship->{
if(!StringUtils.isEmpty(ship.getCodeName()))
refMaps.put(ship.getCodeName(),ship);
if(!StringUtils.isEmpty(ship.getRelation())) {
String fkname= DataObject.getStringValue(ship.getRelation().get("name"),"");
if(!StringUtils.isEmpty(fkname))
refMaps.put(fkname, ship);
}
});
}
return refMaps;
}
private List<RelationshipModel> nesteds;
@JsonIgnore
@JSONField(serialize = false)
private Map<String, FieldModel> fieldMap = null;
@JsonIgnore
@JSONField(serialize = false)
public Map<String, FieldModel> getFieldMap()
{
if(fields!=null&&fieldMap==null)
{
fieldMap=new LinkedHashMap<>();
fields.forEach(field->{
fieldMap.put(field.getColumnName(),field);
fieldMap.put(field.getCodeName(),field);
});
}
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)
if(fieldModel.isLastModifyField())
{
lastModifyField=fieldModel;
return lastModifyField;
}
return lastModifyField;
}
@JsonIgnore
@JSONField(serialize = false)
private boolean isLogicValid=true;
@JsonIgnore
@JSONField(serialize = false)
public boolean isLogicValid()
{
if(isLogicValid&&logicValidField==null) {
if (fields != null) {
for (FieldModel fieldModel : fields) {
if (fieldModel.isLogicValidField()) {
logicValidField = fieldModel;
return isLogicValid;
}
}
}
isLogicValid = false;
}
return isLogicValid;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel logicValidField;
@JsonIgnore
@JSONField(serialize = false)
public FieldModel getLogicValidField() {
if(isLogicValid&&logicValidField==null) {
if (fields != null) {
for (FieldModel fieldModel : fields) {
if (fieldModel.isLogicValidField()) {
logicValidField = fieldModel;
return logicValidField;
}
}
}
isLogicValid = false;
}
return logicValidField;
}
@JsonIgnore
@JSONField(serialize = false)
private String logicVal;
@JsonIgnore
@JSONField(serialize = false)
public String getLogicVal()
{
if(StringUtils.isEmpty(logicVal))
logicVal=this.getExtParams("logicval");
if(StringUtils.isEmpty(logicVal))
logicVal="1";
return logicVal;
}
@JsonIgnore
@JSONField(serialize = false)
private String logicDelVal;
@JsonIgnore
@JSONField(serialize = false)
public String getLogicDelVal()
{
if(StringUtils.isEmpty(logicVal))
logicDelVal=this.getExtParams("logicdelval");
if(StringUtils.isEmpty(logicDelVal))
logicDelVal="0";
return logicDelVal;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel keyField;
@JsonIgnore
@JSONField(serialize = false)
public FieldModel getKeyField() {
if(fields!=null&&keyField==null)
for(FieldModel fieldModel:fields)
if(fieldModel.isKeyField()) {
keyField=fieldModel;
return keyField;
}
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<>();
for (FieldModel fieldModel : fields)
if (fieldModel.isUnionKeyField())
unionKeyFields.add(fieldModel);
}
return unionKeyFields;
}
@JsonIgnore
@JSONField(serialize = false)
public List<FieldModel> getKeyFields() {
if(this.getKeyField()!=null&&this.getKeyField().isPhysicalField()) {
List<FieldModel> keyFields = new ArrayList<>();
keyFields.add(getKeyField());
return keyFields;
}
else
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;
}
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
{
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))
{
dsName=this.getSystemId()+"-master";
}
return dsName;
}
public String getExtParams(String key)
{
return Setting.getValue(this.getEntity().getExtParams(),key);
}
}
package cn.ibizlab.core.data.lite;
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 org.springframework.util.StringUtils;
@Getter
@Setter
@NoArgsConstructor
@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 "data-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";
}
}
package cn.ibizlab.core.data.lite;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* 实体[MetaModel] 服务对象接口
*/
@Component
public class LiteModelFallback implements LiteModelFeignClient {
@Override
public EntityModel getProxyEntityModel(String system, String entity) {
return null;
}
}
package cn.ibizlab.core.data.lite;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* 实体[MetaModel] 服务对象接口
*/
@FeignClient(value = "${ibiz.ref.service.ibzlite-api:ibzlite-api}", contextId = "LiteModel", fallback = LiteModelFallback.class)
public interface LiteModelFeignClient {
String defaultToken="Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJpYnphZG1pbiIsImV4cCI6MTkzMzI0MTkzNywiaWF0IjoxNjE3ODgxOTM3fQ.dFmy-Sx0SlKQcDhbbAs9_bPkbAfy8eRLlGdtl-YZhfU82bCuS4n56ESK8fE0xQqqNJJM87X7U9CnWxRk9z9Xh_dqch-GW8qPj5s25cFsR96V2Ke-6XirCnS-fTRfY9ZIcqVT2gvFUE1MiSbEC-7SPgxcGrNZv0bLzmlW3drlSyQ";
@GetMapping( "/lite/{system}/entitys/{entity}")
@Cacheable( value="entitymodel",key = "'row:'+#p0+'.'+#p1")
EntityModel getProxyEntityModel(@PathVariable("system") String system, @PathVariable("entity") String entity);
}
package cn.ibizlab.core.data.lite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class LiteStorage {
private static LiteModelFeignClient service;
public static void setLiteModelService(LiteModelFeignClient service)
{
if(LiteStorage.service==null)
LiteStorage.service=service;
}
public static LiteModelFeignClient getLiteModelService()
{
return service;
}
@Autowired
private LiteModelFeignClient client;
@PostConstruct
public void init(){
LiteStorage.setLiteModelService(client);
}
}
package cn.ibizlab.core.data.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 lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.sql.Timestamp;
/**
* 实体[实体]
*/
@Getter
@Setter
@NoArgsConstructor
@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;
}
package cn.ibizlab.core.data.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 java.sql.Timestamp;
/**
* 实体[属性]
*/
@Getter
@Setter
@NoArgsConstructor
@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 = "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;
}
package cn.ibizlab.core.data.lite;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = "handler")
public class RelationshipModel {
private String codeName;
private String entityName;
private String entityCodeName;
private String entityLogicName;
private String systemId;
private String dataSourceName;
private String tableName;
private String entityId;
private Map relation;
}
package cn.ibizlab.core.data.lite;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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 <T extends EntityBase> T getEntity(String configString, T entityBase)
{
if(entityBase!=null) {
Map map=getMap(configString);
map.keySet().forEach(key->{
entityBase.set(key.toString(),map.get(key));
});
}
return entityBase;
}
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;
}
}
......@@ -21,10 +21,10 @@ public interface DbDataMapper {
int save(@Param("schema") POSchema schema, @Param("data") BaseData data);
int insert(@Param("schema") POSchema schema, @Param("data") BaseData data);
int insertData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int update(@Param("schema") POSchema schema, @Param("data") BaseData data);
int updateData(@Param("schema") POSchema schema, @Param("data") BaseData data);
int remove(@Param("schema") POSchema schema, @Param("data") BaseData data);
int removeData(@Param("schema") POSchema schema, @Param("data") BaseData data);
}
\ No newline at end of file
......@@ -29,10 +29,32 @@ public class POSchema {
private String defaultDataSource;
private String logicVal;
private String logicDelVal;
private List<Column> columns;
public POSchema addColumn(Column column)
{
if(columns==null)
columns=new ArrayList<>();
columns.add(column);
if(columnMaps!=null)
columnMaps=null;
return this;
}
private List<ForeignKeyConstraint> foreignKeyConstraints;
public POSchema addForeignKeyConstraint(ForeignKeyConstraint foreignKeyConstraint)
{
if(foreignKeyConstraints==null)
foreignKeyConstraints=new ArrayList<>();
foreignKeyConstraints.add(foreignKeyConstraint);
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Column> columnMaps;
......@@ -214,7 +236,7 @@ public class POSchema {
@JSONField(serialize = false)
public boolean isPrimaryKey()
{
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey();
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey()!=null&&this.getConstraints().getPrimaryKey()==true;
}
@JsonIgnore
......@@ -249,10 +271,33 @@ public class POSchema {
@JSONField(serialize = false)
public boolean isText()
{
return this.getType().toUpperCase().indexOf("TEXT")>=0||this.getType().toUpperCase().indexOf("CHAR")>=0;
return this.getType().toUpperCase().indexOf("TEXT")>=0||this.getType().toUpperCase().indexOf("CHAR")>=0||this.getType().toUpperCase().indexOf("LOB")>=0;
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isNumber()
{
return this.getType().toUpperCase().indexOf("NUM")>=0||this.getType().toUpperCase().indexOf("FLOAT")>=0||this.getType().toUpperCase().indexOf("DOUBLE")>=0||this.getType().toUpperCase().indexOf("DECIMAL")>=0;
}
@JsonIgnore
@JSONField(serialize = false)
public boolean isInt()
{
return this.getType().toUpperCase().indexOf("INT")==0;
}
private Constraints constraints;
public Constraints getConstraints(boolean createWhenNotExist)
{
if(createWhenNotExist)
{
if(constraints==null)
constraints=new Constraints();
}
return constraints;
}
}
@Getter
......@@ -359,20 +404,47 @@ public class POSchema {
if(isLogicValid())
{
String defaultVal=this.getLogicValidColumn().getDefaultValue();
if(StringUtils.isEmpty(defaultVal))
defaultVal="1";
sql += " where t."+this.getLogicValidColumn().getName()+"=";
if(this.getLogicValidColumn().isText())
sql+=("'"+defaultVal+"'" );
else
sql+=(defaultVal+" ");
sql += " where t."+this.getLogicValidCond();
}
defaultQueryScript.setBody(sql);
}
return defaultQueryScript;
}
@JsonIgnore
@JSONField(serialize = false)
public String logicValidCond;
@JsonIgnore
@JSONField(serialize = false)
public String logicValidDelCond;
@JsonIgnore
@JSONField(serialize = false)
public synchronized String getLogicValidCond()
{
if(isLogicValid()&&logicValidCond==null)
{
if(logicVal==null)
logicVal="1";
if(logicDelVal==null)
logicDelVal="0";
logicValidCond = this.getLogicValidColumn().getName()+"=";
logicValidDelCond = this.getLogicValidColumn().getName()+"=";
if(this.getLogicValidColumn().isText()) {
logicValidCond += ("'" + logicVal + "'");
logicValidDelCond += ("'" + logicDelVal + "'");
}
else {
logicValidCond += (logicVal + " ");
logicValidDelCond += (logicDelVal + " ");
}
}
else
logicValidCond="";
return logicValidCond;
}
@JsonIgnore
@JSONField(serialize = false)
private String baseColumns;
......@@ -401,18 +473,29 @@ public class POSchema {
return baseColumns;
}
@JsonIgnore
@JSONField(serialize = false)
public Script getDefaultInsertScript()
{
Script defaultInsertScrip=new Script();
defaultInsertScrip.setName("insert");
defaultInsertScrip.setVendorProvider("mysql,oracle,postgresql");
String sql="";
defaultInsertScrip.setBody(sql);
return defaultInsertScrip;
}
@JSONField(serialize = false)
@JsonIgnore
private boolean built = false;
@JSONField(serialize = false)
@JsonIgnore
public synchronized POSchema build()
{
if(!built)
{
getColumnMaps();
getBaseColumns();
getLastModifyField();
getCreateTimeColumn();
getLogicValidColumn();
getLogicValidCond();
getTenantColumn();
built=true;
}
return this;
}
}
......@@ -38,6 +38,22 @@ public class PojoOption extends DataObj
return this.set("name",name);
}
public String getSystem(){
return this.getStringValue("system_id",this.getStringValue("system_name",this.getStringValue("system")));
}
public String getPackage(){
return this.getStringValue("module_name",this.getStringValue("module",this.getStringValue("moduleid")));
}
public String getTableName(){
return this.getStringValue("table_name",getName());
}
public String getDefaultDataSoruce(){
return this.getStringValue("ds_name",this.getSystem()+"-master");
}
public Boolean isLogicValid() {
return this.getBooleanValue("logicValid");
......@@ -66,7 +82,7 @@ public class PojoOption extends DataObj
}
public String getFieldName() {
return this.getStringValue("field_name");
return this.getStringValue("field_name",getName());
}
public PojoOption setFieldName(String code) {
......@@ -82,6 +98,16 @@ public class PojoOption extends DataObj
return this.set("relation_name",relationName);
}
public String getRelationCodeName() {
return this.getStringValue("relation_code_name");
}
public PojoOption setRelationCodeName(String relationCodeName) {
return this.set("relation_code_name",relationCodeName);
}
public String getRefEntityName() {
return this.getStringValue("ref_entity_name");
}
......@@ -90,6 +116,14 @@ public class PojoOption extends DataObj
return this.set("ref_entity_name",refEntityName);
}
public String getRefTableName() {
return this.getStringValue("ref_table_name",getRefEntityName());
}
public PojoOption setRefTableName(String refTableName) {
return this.set("ref_table_name",refTableName);
}
public String getRefFieldName() {
return this.getStringValue("ref_field_name");
}
......@@ -123,7 +157,7 @@ public class PojoOption extends DataObj
}
public Boolean isPhysicalField() {
return this.getBooleanValue("physical_field",true);
return this.getBooleanValue("physical_field",this.getBooleanValue("persisent",true));
}
public PojoOption setPhysicalField(Boolean physicalField) {
......@@ -131,7 +165,7 @@ public class PojoOption extends DataObj
}
public Boolean isNullable() {
return this.getBooleanValue("nullable",true);
return this.getBooleanValue("nullable",!this.getBooleanValue("required",true));
}
public PojoOption setNullable(Boolean nullable) {
......@@ -161,7 +195,13 @@ public class PojoOption extends DataObj
public PojoOption setDict(String dict) {
return this.set("dict",dict);
}
public String getDefaultValue() {
return this.getStringValue("defaultValue");
}
public PojoOption setDefaultValue(String defaultValue) {
return this.set("defaultValue",defaultValue);
}
public String getDataType() {
return this.getStringValue("data_type");
}
......@@ -171,7 +211,7 @@ public class PojoOption extends DataObj
}
public Integer getDataLength() {
return this.getIntegerValue("data_length");
return this.getIntegerValue("data_length",this.getIntegerValue("length",null));
}
public PojoOption setDataLength(Integer dataLength) {
......@@ -179,7 +219,7 @@ public class PojoOption extends DataObj
}
public Integer getDataPreci() {
return this.getIntegerValue("data_preci");
return this.getIntegerValue("data_preci",this.getIntegerValue("precision",this.getIntegerValue("preci",null)));
}
public PojoOption setDataPreci(Integer dataPreci) {
......
......@@ -57,6 +57,34 @@ public class PojoSchema {
return this;
}
@JSONField(serialize = false)
@JsonIgnore
public String getSystem()
{
return this.getOptions()==null?"":this.getOptions().getSystem();
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultDataSoruce()
{
return this.getOptions()==null?"":this.getOptions().getDefaultDataSoruce();
}
@JSONField(serialize = false)
@JsonIgnore
public String getDefaultTableName()
{
return this.getOptions()==null?"":this.getOptions().getTableName();
}
@JSONField(serialize = false)
@JsonIgnore
public String getPackage()
{
return this.getOptions()==null?"":this.getOptions().getSystem();
}
@JSONField(ordinal = 3)
......@@ -132,7 +160,7 @@ public class PojoSchema {
return properties;
}
public PojoSchema addProperties(String name,PojoSchema property)
public PojoSchema addProperty(String name,PojoSchema property)
{
if(StringUtils.isEmpty(name))
return this;
......@@ -175,6 +203,36 @@ public class PojoSchema {
private Integer maxProperties;
@JsonIgnore
@JSONField(serialize = false)
private Map<String,String> keyMap;
@JsonIgnore
@JSONField(serialize = false)
public synchronized Map<String,String> getKeyMap()
{
if(Type.object.getCode().equals(this.type))
{
if(keyMap==null)
{
keyMap=new LinkedHashMap<>();
getProperties().values().forEach(sub->{
if(sub.getOptions().isKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub.getName());
});
if(keyMap.isEmpty())
{
getProperties().values().forEach(sub->{
if(sub.getOptions().isUnionKeyField()&&sub.getOptions().isPhysicalField())
keyMap.put(sub.getOptions().getFieldName(),sub.getName());
});
}
}
}
return keyMap;
}
//// array
......@@ -225,8 +283,8 @@ public class PojoSchema {
public static void main(String[] args) {
PojoSchema schema=new PojoSchema().setType("object").setRef("#/definitions/entity");
PojoSchema def=new PojoSchema();
def.setType("object").setTitle("部门").addProperties("deptCode",new PojoSchema().setType("string").setTitle("部门编码"))
.addProperties("deptName",new PojoSchema().setType("string").setTitle("部门名称")).addProperties("parent",def);
def.setType("object").setTitle("部门").addProperty("deptCode",new PojoSchema().setType("string").setTitle("部门编码"))
.addProperty("deptName",new PojoSchema().setType("string").setTitle("部门名称")).addProperty("parent",def);
System.out.println(JSON.toJSONString(schema));
}
......
package cn.ibizlab.core.data.model;
import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.FieldModel;
import cn.ibizlab.core.data.lite.RelationshipModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.StringUtils;
public class TransUtils {
......@@ -54,8 +58,10 @@ public class TransUtils {
sub.getOptions().setNullable(false);
if(!StringUtils.isEmpty(property.getDict()))
sub.getOptions().setDict(property.getDict());
if(!StringUtils.isEmpty(property.getDefaultValue()))
sub.getOptions().setDefaultValue(property.getDefaultValue());
pojoSchema.addProperties(sub.getName(),sub);
pojoSchema.addProperty(sub.getName(),sub);
}
......@@ -109,6 +115,130 @@ public class TransUtils {
return pojoModel;
}
public static PojoSchema LiteEntityModelModel2Schema(EntityModel entityModel)
{
PojoSchema pojoSchema=new PojoSchema().setName(entityModel.getEntityName()).setType("object").setTitle(entityModel.getLogicName()).setId(entityModel.getEntityId())
.setOptions(new PojoOption().setLogicValid(entityModel.isLogicValid()).setLogicVal(entityModel.getLogicVal()).setLogicDelVal(entityModel.getLogicDelVal()));
pojoSchema.getOptions().setAll(JSONObject.parseObject(JSON.toJSONString(entityModel.getEntity())));
int order=1;
PojoSchema sub=null;
for(FieldModel fieldModel:entityModel.getFields())
{
String propType=fieldModel.getPropType();
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()))));
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());
}
}
pojoSchema.addProperty(sub.getName(),sub);
}
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);
if(!sub.getOptions().isPhysicalField())
continue;
String dataType=sub.getOptions().getDataType();
Integer length=sub.getOptions().getDataLength();
Integer precision=sub.getOptions().getDataPreci();
POSchema.Column column=new POSchema.Column().setAlias(name).setName(sub.getOptions().getFieldName()).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(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();
if(primaryKeyName.length()>30)
primaryKeyName=primaryKeyName.substring(0,30);
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("PICKUP".equals(sub.getOptions().getFieldType())&&sub.getOptions().isPhysicalField())
{
String fkName=sub.getOptions().getRelationName().toUpperCase();
if((!StringUtils.isEmpty(sub.getOptions().getRefTableName()))&&(!StringUtils.isEmpty(fkName))) {
if(fkName.length()>30)
fkName=fkName.substring(0,30);
column.getConstraints(true).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()).setForeignKeyName(fkName);
poSchema.addForeignKeyConstraint(new POSchema.ForeignKeyConstraint().setConstraintName(fkName).setBaseTableName(poSchema.getName()).setBaseColumnNames(column.getName()).setReferencedTableName(sub.getOptions().getRefTableName()).setReferencedColumnNames(sub.getOptions().getRefFieldName()));
}
}
poSchema.addColumn(column);
}
return poSchema;
}
public static void main(String[] args) {
String str="{\"code\":\"CaseInfo\",\"name\":\"案件基本信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"send_id\",\"name\":\"请求ID标识\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"req_type\",\"name\":\"业务请求类型\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"ajbh\",\"name\":\"公共案件编号\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"ajmc\",\"name\":\"公共案件名称\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"ab\",\"name\":\"案由代码\",\"required\":false,\"uniqueKeys\":false,\"dict\":\"案由\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"gajgysrdh\",\"name\":\"移送人电话\",\"required\":false,\"uniqueKeys\":false,\"dict\":\"\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"case_status\",\"name\":\"案件状态\",\"required\":true,\"dict\":\"案件类型\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"CaseSuspect_List\",\"name\":\"嫌疑人自然人信息列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"nested\",\"model\":{\"code\":\"CaseSuspect\",\"name\":\"嫌疑人自然人信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"rybh\",\"name\":\"人员编号\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"rybs\",\"name\":\"公安人员标识\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"xm\",\"name\":\"姓名\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"SuspectCoercive_List\",\"name\":\"嫌疑人强制措施信息列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"nested\",\"model\":{\"code\":\"SuspectCoercive\",\"name\":\"嫌疑人强制措施信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"gabs\",\"name\":\"公安唯一标识\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"cslb\",\"name\":\"强制措施种类代码\",\"required\":false,\"uniqueKeys\":true,\"dict\":\"强制措施种类\",\"defaultValue\":\"\",\"propertyType\":\"string\"}],\"extensions\":{}}}],\"extensions\":{}}},{\"code\":\"SuspectCompany_List\",\"name\":\"涉案单位信息列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"nested\",\"model\":{\"code\":\"SuspectCompany\",\"name\":\"涉案人单位信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"gabs\",\"name\":\"公安唯一标识\",\"required\":true,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"dwmc\",\"name\":\"单位名称\",\"required\":false,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"}],\"extensions\":{}}},{\"code\":\"CaseSHR_List\",\"name\":\"受害人列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"nested\",\"model\":{\"code\":\"CaseSHR\",\"name\":\"受害人基本信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"xm\",\"name\":\"姓名\",\"required\":false,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"}],\"extensions\":{}}},{\"code\":\"CaseSAWP_List\",\"name\":\"涉案物品列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"nested\",\"model\":{\"code\":\"CaseSAWP\",\"name\":\"涉案物品信息\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"sawpmc\",\"name\":\"名称\",\"required\":false,\"uniqueKeys\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"}],\"extensions\":{}}},{\"code\":\"CaseStatus_List\",\"name\":\"案件移送记录列表\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"object\",\"model\":{\"code\":\"CaseStatus\",\"name\":\"提请逮捕移送记录\",\"group\":\"0预处理/2.预处理接口\",\"propertyList\":[{\"code\":\"send_dept\",\"name\":\"发送部门代码\",\"required\":true,\"dict\":\"单位\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"send_deptname\",\"name\":\"发送部门名称\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"receive_dept\",\"name\":\"接收部门代码\",\"required\":true,\"dict\":\"单位\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"receive_deptname\",\"name\":\"接收部门名称\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"send_time\",\"name\":\"发送时间\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"date\"},{\"code\":\"send_type\",\"name\":\"移送状态\",\"required\":true,\"uniqueKeys\":true,\"dict\":\"案件类型\",\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"send_type_zh\",\"name\":\"移送状态名称\",\"required\":true,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"wh_zh\",\"name\":\"文书名称\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"string\"},{\"code\":\"wh\",\"name\":\"移送文书文号\",\"required\":false,\"defaultValue\":\"\",\"propertyType\":\"string\"}],\"extensions\":{}}}]}";
PojoModel pojoModel= JSON.parseObject(str,PojoModel.class);
......
......@@ -17,11 +17,11 @@ public interface IDataService
default ResponseData call(String system,String entity,String method,RequestData requestData)
{
return call(system,entity,method,"",requestData);
return call(system,"",entity,method,"",requestData);
}
default ResponseData call(RequestData requestData)
{
return call(getDOModel(requestData.getSystem(),requestData.getEntity()),requestData.getMethod(),requestData.getDataSource(),requestData);
return call(getDOModel(requestData.getSystem(),requestData.getEntity()),requestData.getScope(),requestData.getMethod(),requestData.getDataSource(),requestData);
}
default boolean create(String system,String entity,BaseData et)
{
......@@ -89,7 +89,7 @@ public interface IDataService
DOModel getDOModel(String system,String entity);
ResponseData call(DOModel model,String method,String datasource, RequestData requestData);
ResponseData call(DOModel model,String scope,String method,String datasource, RequestData requestData);
boolean create(DOModel model,String datasource,BaseData et);
void createBatch(DOModel model,String datasource,List<BaseData> list);
......@@ -113,10 +113,10 @@ public interface IDataService
return list(model,"default",datasource,context);
}
default ResponseData call(String system,String entity,String method,String datasource,RequestData requestData)
default ResponseData call(String system,String scope,String entity,String method,String datasource,RequestData requestData)
{
requestData.setSystem(system).setEntity(entity).setMethod(method).setDataSource(datasource);
return call(getDOModel(system,entity),method,datasource,requestData);
requestData.setSystem(system).setScope(scope).setEntity(entity).setMethod(method).setDataSource(datasource);
return call(getDOModel(system,entity),scope,method,datasource,requestData);
}
default boolean create(String system,String entity,String datasource,BaseData et)
{
......
package cn.ibizlab.core.data.service;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.LiteStorage;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
@Service
@Slf4j
public class ModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Autowired
private IDOModelService doModelService;
public DOModel getDOModel(String system,String entity)
{
return doModelService.get(system+".domain."+entity);
}
}
......@@ -6,6 +6,7 @@ import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.filter.SearchContextBase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -30,7 +31,7 @@ public class BaseDataService implements IDataService {
@Override
public DOModel getDOModel(String system, String entity)
{
return null;
return modelService.getDOModel(system,entity);
}
@Autowired
......@@ -39,6 +40,9 @@ public class BaseDataService implements IDataService {
@Autowired
private MongoDataServiceImpl mongoProxyService;
@Autowired
private ModelService modelService;
public IDataService getProxyService(String datasource)
{
if(datasource.indexOf("mongo")>0)
......@@ -49,7 +53,7 @@ public class BaseDataService implements IDataService {
@Override
public ResponseData call(DOModel model, String method, String datasource, RequestData requestBody)
public ResponseData call(DOModel model,String scope, String method, String datasource, RequestData requestBody)
{
if("create".equalsIgnoreCase(method))
{
......@@ -76,7 +80,7 @@ public class BaseDataService implements IDataService {
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName());
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
if(remove(model, datasource, key))
......@@ -88,7 +92,7 @@ public class BaseDataService implements IDataService {
{
Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName());
key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入");
BaseData data=get(model,datasource,key);
......
package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
......@@ -12,6 +18,11 @@ import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;
import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.LiteStorage;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,6 +51,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap;
@Service
public class DOModelServiceImpl implements IDOModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Override
public boolean create(DOModel et) {
......@@ -69,9 +82,49 @@ public class DOModelServiceImpl implements IDOModelService {
@Override
public DOModel get(String key) {
DOModel et = new DOModel();
et.setId(key);
return et;
DOModel doModel=new DOModel();
PojoSchema schema= null;
String[] args=key.split("[.]");
String system=args[0];
String entity=args[2];
File domainDir = new File(modelPath+system+File.separator+"domain");
if(!domainDir.exists())
domainDir.mkdirs();
File schemaJson=new File(domainDir,entity+".json");
if(!schemaJson.exists())
{
EntityModel entityModel= LiteStorage.getLiteModelService().getProxyEntityModel(system,entity);
if(entityModel!=null) {
schema=TransUtils.LiteEntityModelModel2Schema(entityModel);
}
}
else
{
try {
String schemaJSON=new String(Files.readAllBytes(Paths.get(domainDir.getAbsolutePath(),entity+".json")),StandardCharsets.UTF_8);
schema=JSON.parseObject(schemaJSON,PojoSchema.class);
} catch (IOException e) {
}
}
if(schema!=null)
{
doModel.setSchema(schema);
try {
Files.write(Paths.get(domainDir.getAbsolutePath(),entity+".json"), JSON.toJSONString(schema).getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
} catch (IOException e) {
}
}
else
{
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
}
return doModel;
}
@Override
......
package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
......@@ -12,6 +18,13 @@ import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.LiteStorage;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,6 +53,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap;
@Service
public class DTOModelServiceImpl implements IDTOModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Override
public boolean create(DTOModel et) {
......@@ -69,9 +84,54 @@ public class DTOModelServiceImpl implements IDTOModelService {
@Override
public DTOModel get(String key) {
DTOModel et = new DTOModel();
et.setId(key);
return et;
DTOModel dtoModel=new DTOModel();
PojoSchema schema= null;
String[] args=key.split("[.]");
String system=args[0];
String dto=args[2];
File domainDir = new File(modelPath+system+File.separator+"dto");
if(!domainDir.exists())
domainDir.mkdirs();
File schemaJson=new File(domainDir,dto+".json");
if(!schemaJson.exists())
{
String entity=dto;
if(entity.endsWith("DTO"))
entity=entity.substring(0,entity.length()-3);
EntityModel entityModel= LiteStorage.getLiteModelService().getProxyEntityModel(system,entity);
if(entityModel!=null) {
schema= JSONObject.parseObject(JSON.toJSONString(TransUtils.LiteEntityModelModel2Schema(entityModel)),PojoSchema.class);
schema.setName(dto);
schema.setId(key);
}
}
else
{
try {
String schemaJSON=new String(Files.readAllBytes(Paths.get(domainDir.getAbsolutePath(),dto+".json")), StandardCharsets.UTF_8);
schema= JSON.parseObject(schemaJSON,PojoSchema.class);
} catch (IOException e) {
}
}
if(schema!=null)
{
dtoModel.setSchema(schema);
try {
Files.write(Paths.get(domainDir.getAbsolutePath(),dto+".json"), JSON.toJSONString(schema).getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
} catch (IOException e) {
}
}
else
{
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
}
return dtoModel;
}
@Override
......
......@@ -35,7 +35,7 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
public boolean create(DOModel model, String datasource, BaseData et)
{
return false;
return dbDataMapper.insertData(model.getDefaultPOSchema().build(),et)==1;
}
@Override
......@@ -47,7 +47,8 @@ public class DbDataServiceImpl extends BaseDataService {
@Override
public boolean update(DOModel model, String datasource, BaseData et)
{
return false;
dbDataMapper.updateData(model.getDefaultPOSchema().build(),et);
return true;
}
@Override
......
......@@ -15,7 +15,7 @@
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
<insert id="insert" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<insert id="insertData" parameterType="cn.ibizlab.core.data.dto.BaseData">
INSERT INTO ${schema.name}
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
......@@ -25,40 +25,40 @@
VALUES
(
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
#data[${value}]
#{data[${value}]}
</foreach>
)
</insert>
<update id="update" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
update ${schema.name}
set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
<if test="data['_'+value+'dirtyflag']==true">${key}= #data[${value}]</if>
<if test="data.keys.contains(value)">${key}= #{data[${value}]}</if>
</foreach>
where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}]
${key}= #{data[${value}]}
</foreach>
</update>
<update id="remove" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<update id="removeData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
<if test="schema.logicValidColumn!=null">
update ${schema.name}
set
<foreach collection="schema.resultMap" item="value" index="key" separator=",">
${schema.logicValidColumn.name}= 0
${schema.logicValidDelCond}
</foreach>
where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}]
${key}= #{data[${value}]}
</foreach>
</if>
<if test="schema.logicValidColumn==null">
delete from ${schema.name} where
<foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}]
${key}= #{data[${value}]}
</foreach>
</if>
......
......@@ -29,12 +29,14 @@ public class DataResource
public IDataService dataService;
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/{method}")
public ResponseEntity<BaseData> call(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) {
ResponseData<BaseData> responseData=dataService.call(system,entity,method,datasource,new RequestData().setBody(baseData));
@RequestMapping(method = RequestMethod.POST, value = {"/{system}/{entity}/{method}","/{system}/{scope}/{entity}/{method}"})
public ResponseEntity<BaseData> call(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "scope",required = false) String scope,@PathVariable(name = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) {
ResponseData<BaseData> responseData=dataService.call(system,scope,entity,method,datasource,new RequestData().setBody(baseData));
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
}
@ApiOperation(value = "新建数据", tags = {"数据" }, notes = "新建数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}")
public ResponseEntity<BaseData> create(@PathVariable(name = "system",required = true) String system,@PathVariable(name = "entity",required = true) String entity,@RequestParam(name = "datasource",required = false) String datasource, @Validated @RequestBody BaseData baseData) {
......
......@@ -189,7 +189,7 @@ public class DataObject {
return Double.parseDouble(strValue);
}
final static public int getIntegerValue( Object objValue, Integer nDefault) {
final static public Integer getIntegerValue( Object objValue, Integer nDefault) {
if (objValue == null) {
return nDefault;
......@@ -378,11 +378,7 @@ public class DataObject {
return new java.sql.Timestamp(lValue);
}
if(objValue instanceof Integer)
{
int lValue = (int)objValue;
return new java.sql.Timestamp(lValue);
}
if(objValue instanceof oracle.sql.TIMESTAMP)
{
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册