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

提交

上级 11dbd457
...@@ -2,7 +2,7 @@ spring: ...@@ -2,7 +2,7 @@ spring:
datasource: datasource:
username: root username: root
password: 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 isSyncDBSchema: false
dynamic: dynamic:
druid: #以下是全局默认值,可以全局更改 druid: #以下是全局默认值,可以全局更改
......
spring: spring:
profiles: profiles:
include: sys ,nacos, web-dev, api-dev, dev include: sys ,nacos, web-dev, api-dev, dev, boot
application: application:
name: ibzdata name: ibzdata
main: main:
......
package cn.ibizlab.core.data.domain; package cn.ibizlab.core.data.domain;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema; import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
...@@ -28,6 +27,7 @@ import org.springframework.data.annotation.Transient; ...@@ -28,6 +27,7 @@ import org.springframework.data.annotation.Transient;
import cn.ibizlab.util.annotation.Audit; import cn.ibizlab.util.annotation.Audit;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;
/** /**
...@@ -106,6 +106,27 @@ public class DOModel extends EntityBase implements Serializable { ...@@ -106,6 +106,27 @@ public class DOModel extends EntityBase implements Serializable {
@ApiModelProperty("模型") @ApiModelProperty("模型")
private String model; 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 { ...@@ -114,12 +135,23 @@ public class DOModel extends EntityBase implements Serializable {
@ApiModelProperty("存储") @ApiModelProperty("存储")
private String poModels; 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) @JSONField(serialize = false)
@JsonIgnore @JsonIgnore
public String getKeyFieldName() 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 { ...@@ -128,9 +160,47 @@ public class DOModel extends EntityBase implements Serializable {
@JsonIgnore @JsonIgnore
public String getDefaultDataSource() 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; ...@@ -28,6 +28,7 @@ import org.springframework.data.annotation.Transient;
import cn.ibizlab.util.annotation.Audit; import cn.ibizlab.util.annotation.Audit;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;
/** /**
...@@ -98,6 +99,27 @@ public class DTOModel extends EntityBase implements Serializable { ...@@ -98,6 +99,27 @@ public class DTOModel extends EntityBase implements Serializable {
@ApiModelProperty("定义") @ApiModelProperty("定义")
private PojoSchema schema; 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> { ...@@ -65,7 +65,7 @@ public class DataObj<K,V> extends HashMap<K,V> {
public Integer getIntegerValue(String objValue) { public Integer getIntegerValue(String objValue) {
return getIntegerValue(objValue, Integer.MIN_VALUE); 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); return DataObject.getIntegerValue(this.get(strParamName),nDefault);
} }
......
...@@ -44,6 +44,16 @@ public class RequestData<T> extends BaseData ...@@ -44,6 +44,16 @@ public class RequestData<T> extends BaseData
return this.getStringValue("system"); 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) public RequestData setEntity(String entity)
{ {
return this.set("entity",entity); return this.set("entity",entity);
......
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 { ...@@ -21,10 +21,10 @@ public interface DbDataMapper {
int save(@Param("schema") POSchema schema, @Param("data") BaseData data); 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 { ...@@ -29,10 +29,32 @@ public class POSchema {
private String defaultDataSource; private String defaultDataSource;
private String logicVal;
private String logicDelVal;
private List<Column> columns; 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; private List<ForeignKeyConstraint> foreignKeyConstraints;
public POSchema addForeignKeyConstraint(ForeignKeyConstraint foreignKeyConstraint)
{
if(foreignKeyConstraints==null)
foreignKeyConstraints=new ArrayList<>();
foreignKeyConstraints.add(foreignKeyConstraint);
return this;
}
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private Map<String,Column> columnMaps; private Map<String,Column> columnMaps;
...@@ -214,7 +236,7 @@ public class POSchema { ...@@ -214,7 +236,7 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isPrimaryKey() public boolean isPrimaryKey()
{ {
return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey(); return this.getConstraints()!=null&&this.getConstraints().getPrimaryKey()!=null&&this.getConstraints().getPrimaryKey()==true;
} }
@JsonIgnore @JsonIgnore
...@@ -249,10 +271,33 @@ public class POSchema { ...@@ -249,10 +271,33 @@ public class POSchema {
@JSONField(serialize = false) @JSONField(serialize = false)
public boolean isText() 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; private Constraints constraints;
public Constraints getConstraints(boolean createWhenNotExist)
{
if(createWhenNotExist)
{
if(constraints==null)
constraints=new Constraints();
}
return constraints;
}
} }
@Getter @Getter
...@@ -359,20 +404,47 @@ public class POSchema { ...@@ -359,20 +404,47 @@ public class POSchema {
if(isLogicValid()) if(isLogicValid())
{ {
String defaultVal=this.getLogicValidColumn().getDefaultValue();
if(StringUtils.isEmpty(defaultVal)) sql += " where t."+this.getLogicValidCond();
defaultVal="1";
sql += " where t."+this.getLogicValidColumn().getName()+"=";
if(this.getLogicValidColumn().isText())
sql+=("'"+defaultVal+"'" );
else
sql+=(defaultVal+" ");
} }
defaultQueryScript.setBody(sql); defaultQueryScript.setBody(sql);
} }
return defaultQueryScript; 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 @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
private String baseColumns; private String baseColumns;
...@@ -401,18 +473,29 @@ public class POSchema { ...@@ -401,18 +473,29 @@ public class POSchema {
return baseColumns; 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 ...@@ -38,6 +38,22 @@ public class PojoOption extends DataObj
return this.set("name",name); 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() { public Boolean isLogicValid() {
return this.getBooleanValue("logicValid"); return this.getBooleanValue("logicValid");
...@@ -66,7 +82,7 @@ public class PojoOption extends DataObj ...@@ -66,7 +82,7 @@ public class PojoOption extends DataObj
} }
public String getFieldName() { public String getFieldName() {
return this.getStringValue("field_name"); return this.getStringValue("field_name",getName());
} }
public PojoOption setFieldName(String code) { public PojoOption setFieldName(String code) {
...@@ -82,6 +98,16 @@ public class PojoOption extends DataObj ...@@ -82,6 +98,16 @@ public class PojoOption extends DataObj
return this.set("relation_name",relationName); 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() { public String getRefEntityName() {
return this.getStringValue("ref_entity_name"); return this.getStringValue("ref_entity_name");
} }
...@@ -90,6 +116,14 @@ public class PojoOption extends DataObj ...@@ -90,6 +116,14 @@ public class PojoOption extends DataObj
return this.set("ref_entity_name",refEntityName); 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() { public String getRefFieldName() {
return this.getStringValue("ref_field_name"); return this.getStringValue("ref_field_name");
} }
...@@ -123,7 +157,7 @@ public class PojoOption extends DataObj ...@@ -123,7 +157,7 @@ public class PojoOption extends DataObj
} }
public Boolean isPhysicalField() { public Boolean isPhysicalField() {
return this.getBooleanValue("physical_field",true); return this.getBooleanValue("physical_field",this.getBooleanValue("persisent",true));
} }
public PojoOption setPhysicalField(Boolean physicalField) { public PojoOption setPhysicalField(Boolean physicalField) {
...@@ -131,7 +165,7 @@ public class PojoOption extends DataObj ...@@ -131,7 +165,7 @@ public class PojoOption extends DataObj
} }
public Boolean isNullable() { public Boolean isNullable() {
return this.getBooleanValue("nullable",true); return this.getBooleanValue("nullable",!this.getBooleanValue("required",true));
} }
public PojoOption setNullable(Boolean nullable) { public PojoOption setNullable(Boolean nullable) {
...@@ -161,7 +195,13 @@ public class PojoOption extends DataObj ...@@ -161,7 +195,13 @@ public class PojoOption extends DataObj
public PojoOption setDict(String dict) { public PojoOption setDict(String dict) {
return this.set("dict",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() { public String getDataType() {
return this.getStringValue("data_type"); return this.getStringValue("data_type");
} }
...@@ -171,7 +211,7 @@ public class PojoOption extends DataObj ...@@ -171,7 +211,7 @@ public class PojoOption extends DataObj
} }
public Integer getDataLength() { public Integer getDataLength() {
return this.getIntegerValue("data_length"); return this.getIntegerValue("data_length",this.getIntegerValue("length",null));
} }
public PojoOption setDataLength(Integer dataLength) { public PojoOption setDataLength(Integer dataLength) {
...@@ -179,7 +219,7 @@ public class PojoOption extends DataObj ...@@ -179,7 +219,7 @@ public class PojoOption extends DataObj
} }
public Integer getDataPreci() { 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) { public PojoOption setDataPreci(Integer dataPreci) {
......
...@@ -57,6 +57,34 @@ public class PojoSchema { ...@@ -57,6 +57,34 @@ public class PojoSchema {
return this; 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) @JSONField(ordinal = 3)
...@@ -132,7 +160,7 @@ public class PojoSchema { ...@@ -132,7 +160,7 @@ public class PojoSchema {
return properties; return properties;
} }
public PojoSchema addProperties(String name,PojoSchema property) public PojoSchema addProperty(String name,PojoSchema property)
{ {
if(StringUtils.isEmpty(name)) if(StringUtils.isEmpty(name))
return this; return this;
...@@ -175,6 +203,36 @@ public class PojoSchema { ...@@ -175,6 +203,36 @@ public class PojoSchema {
private Integer maxProperties; 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 //// array
...@@ -225,8 +283,8 @@ public class PojoSchema { ...@@ -225,8 +283,8 @@ public class PojoSchema {
public static void main(String[] args) { public static void main(String[] args) {
PojoSchema schema=new PojoSchema().setType("object").setRef("#/definitions/entity"); PojoSchema schema=new PojoSchema().setType("object").setRef("#/definitions/entity");
PojoSchema def=new PojoSchema(); PojoSchema def=new PojoSchema();
def.setType("object").setTitle("部门").addProperties("deptCode",new PojoSchema().setType("string").setTitle("部门编码")) def.setType("object").setTitle("部门").addProperty("deptCode",new PojoSchema().setType("string").setTitle("部门编码"))
.addProperties("deptName",new PojoSchema().setType("string").setTitle("部门名称")).addProperties("parent",def); .addProperty("deptName",new PojoSchema().setType("string").setTitle("部门名称")).addProperty("parent",def);
System.out.println(JSON.toJSONString(schema)); System.out.println(JSON.toJSONString(schema));
} }
......
...@@ -17,11 +17,11 @@ public interface IDataService ...@@ -17,11 +17,11 @@ public interface IDataService
default ResponseData call(String system,String entity,String method,RequestData requestData) 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) 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) default boolean create(String system,String entity,BaseData et)
{ {
...@@ -89,7 +89,7 @@ public interface IDataService ...@@ -89,7 +89,7 @@ public interface IDataService
DOModel getDOModel(String system,String entity); 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); boolean create(DOModel model,String datasource,BaseData et);
void createBatch(DOModel model,String datasource,List<BaseData> list); void createBatch(DOModel model,String datasource,List<BaseData> list);
...@@ -113,10 +113,10 @@ public interface IDataService ...@@ -113,10 +113,10 @@ public interface IDataService
return list(model,"default",datasource,context); 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); requestData.setSystem(system).setScope(scope).setEntity(entity).setMethod(method).setDataSource(datasource);
return call(getDOModel(system,entity),method,datasource,requestData); return call(getDOModel(system,entity),scope,method,datasource,requestData);
} }
default boolean create(String system,String entity,String datasource,BaseData et) 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; ...@@ -6,6 +6,7 @@ import cn.ibizlab.core.data.dto.DbDataQuery;
import cn.ibizlab.core.data.dto.RequestData; import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData; import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.core.data.service.IDataService; import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.filter.SearchContextBase; import cn.ibizlab.util.filter.SearchContextBase;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -30,7 +31,7 @@ public class BaseDataService implements IDataService { ...@@ -30,7 +31,7 @@ public class BaseDataService implements IDataService {
@Override @Override
public DOModel getDOModel(String system, String entity) public DOModel getDOModel(String system, String entity)
{ {
return null; return modelService.getDOModel(system,entity);
} }
@Autowired @Autowired
...@@ -39,6 +40,9 @@ public class BaseDataService implements IDataService { ...@@ -39,6 +40,9 @@ public class BaseDataService implements IDataService {
@Autowired @Autowired
private MongoDataServiceImpl mongoProxyService; private MongoDataServiceImpl mongoProxyService;
@Autowired
private ModelService modelService;
public IDataService getProxyService(String datasource) public IDataService getProxyService(String datasource)
{ {
if(datasource.indexOf("mongo")>0) if(datasource.indexOf("mongo")>0)
...@@ -49,7 +53,7 @@ public class BaseDataService implements IDataService { ...@@ -49,7 +53,7 @@ public class BaseDataService implements IDataService {
@Override @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)) if("create".equalsIgnoreCase(method))
{ {
...@@ -76,7 +80,7 @@ public class BaseDataService implements IDataService { ...@@ -76,7 +80,7 @@ public class BaseDataService implements IDataService {
{ {
Serializable key=requestBody.getKey(); Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName()); key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入"); return ResponseData.error(400,"key 没有输入");
if(remove(model, datasource, key)) if(remove(model, datasource, key))
...@@ -88,7 +92,7 @@ public class BaseDataService implements IDataService { ...@@ -88,7 +92,7 @@ public class BaseDataService implements IDataService {
{ {
Serializable key=requestBody.getKey(); Serializable key=requestBody.getKey();
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
key=requestBody.getBaseData().getSerializableValue(model.getKeyFieldName()); key=requestBody.getBaseData().getSerializableValue(model.getKeyPropertyName());
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
return ResponseData.error(400,"key 没有输入"); return ResponseData.error(400,"key 没有输入");
BaseData data=get(model,datasource,key); BaseData data=get(model,datasource,key);
......
package cn.ibizlab.core.data.service.impl; package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.IOException;
import java.io.Serializable; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -12,6 +18,11 @@ import java.util.Objects; ...@@ -12,6 +18,11 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.math.BigInteger; 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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -40,6 +51,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap; ...@@ -40,6 +51,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap;
@Service @Service
public class DOModelServiceImpl implements IDOModelService { public class DOModelServiceImpl implements IDOModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Override @Override
public boolean create(DOModel et) { public boolean create(DOModel et) {
...@@ -69,9 +82,49 @@ public class DOModelServiceImpl implements IDOModelService { ...@@ -69,9 +82,49 @@ public class DOModelServiceImpl implements IDOModelService {
@Override @Override
public DOModel get(String key) { public DOModel get(String key) {
DOModel et = new DOModel(); DOModel doModel=new DOModel();
et.setId(key); PojoSchema schema= null;
return et; 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 @Override
......
package cn.ibizlab.core.data.service.impl; package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.IOException;
import java.io.Serializable; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -12,6 +18,13 @@ import java.util.Objects; ...@@ -12,6 +18,13 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.math.BigInteger; 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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -40,6 +53,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap; ...@@ -40,6 +53,8 @@ import cn.ibizlab.util.helper.DEFieldCacheMap;
@Service @Service
public class DTOModelServiceImpl implements IDTOModelService { public class DTOModelServiceImpl implements IDTOModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Override @Override
public boolean create(DTOModel et) { public boolean create(DTOModel et) {
...@@ -69,9 +84,54 @@ public class DTOModelServiceImpl implements IDTOModelService { ...@@ -69,9 +84,54 @@ public class DTOModelServiceImpl implements IDTOModelService {
@Override @Override
public DTOModel get(String key) { public DTOModel get(String key) {
DTOModel et = new DTOModel(); DTOModel dtoModel=new DTOModel();
et.setId(key); PojoSchema schema= null;
return et; 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 @Override
......
...@@ -35,7 +35,7 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -35,7 +35,7 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean create(DOModel model, String datasource, BaseData et) public boolean create(DOModel model, String datasource, BaseData et)
{ {
return false; return dbDataMapper.insertData(model.getDefaultPOSchema().build(),et)==1;
} }
@Override @Override
...@@ -47,7 +47,8 @@ public class DbDataServiceImpl extends BaseDataService { ...@@ -47,7 +47,8 @@ public class DbDataServiceImpl extends BaseDataService {
@Override @Override
public boolean update(DOModel model, String datasource, BaseData et) public boolean update(DOModel model, String datasource, BaseData et)
{ {
return false; dbDataMapper.updateData(model.getDefaultPOSchema().build(),et);
return true;
} }
@Override @Override
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if> <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select> </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} INSERT INTO ${schema.name}
( (
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.resultMap" item="value" index="key" separator=",">
...@@ -25,40 +25,40 @@ ...@@ -25,40 +25,40 @@
VALUES VALUES
( (
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.resultMap" item="value" index="key" separator=",">
#data[${value}] #{data[${value}]}
</foreach> </foreach>
) )
</insert> </insert>
<update id="update" parameterType="cn.ibizlab.core.data.dto.BaseData" > <update id="updateData" parameterType="cn.ibizlab.core.data.dto.BaseData" >
update ${schema.name} update ${schema.name}
set set
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <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> </foreach>
where where
<foreach collection="schema.keyMap" item="value" index="key" separator="and"> <foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}] ${key}= #{data[${value}]}
</foreach> </foreach>
</update> </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"> <if test="schema.logicValidColumn!=null">
update ${schema.name} update ${schema.name}
set set
<foreach collection="schema.resultMap" item="value" index="key" separator=","> <foreach collection="schema.resultMap" item="value" index="key" separator=",">
${schema.logicValidColumn.name}= 0 ${schema.logicValidDelCond}
</foreach> </foreach>
where where
<foreach collection="schema.keyMap" item="value" index="key" separator="and"> <foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}] ${key}= #{data[${value}]}
</foreach> </foreach>
</if> </if>
<if test="schema.logicValidColumn==null"> <if test="schema.logicValidColumn==null">
delete from ${schema.name} where delete from ${schema.name} where
<foreach collection="schema.keyMap" item="value" index="key" separator="and"> <foreach collection="schema.keyMap" item="value" index="key" separator="and">
${key}= #data[${value}] ${key}= #{data[${value}]}
</foreach> </foreach>
</if> </if>
......
...@@ -29,12 +29,14 @@ public class DataResource ...@@ -29,12 +29,14 @@ public class DataResource
public IDataService dataService; public IDataService dataService;
@ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据") @ApiOperation(value = "保存数据", tags = {"数据" }, notes = "保存数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}/{method}") @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 = "entity",required = true) String entity,@PathVariable(name = "method",required = true) String method,@RequestParam(name = "datasource",required = false) String datasource,@RequestBody BaseData baseData) { 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,entity,method,datasource,new RequestData().setBody(baseData)); ResponseData<BaseData> responseData=dataService.call(system,scope,entity,method,datasource,new RequestData().setBody(baseData));
return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody()); return ResponseEntity.status(HttpStatus.OK).body(responseData.getBody());
} }
@ApiOperation(value = "新建数据", tags = {"数据" }, notes = "新建数据") @ApiOperation(value = "新建数据", tags = {"数据" }, notes = "新建数据")
@RequestMapping(method = RequestMethod.POST, value = "/{system}/{entity}") @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) { 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 { ...@@ -189,7 +189,7 @@ public class DataObject {
return Double.parseDouble(strValue); 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) { if (objValue == null) {
return nDefault; return nDefault;
...@@ -378,11 +378,7 @@ public class DataObject { ...@@ -378,11 +378,7 @@ public class DataObject {
return new java.sql.Timestamp(lValue); 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) if(objValue instanceof oracle.sql.TIMESTAMP)
{ {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册