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

model

上级 fd82d109
......@@ -34,6 +34,22 @@ export default class AppFormJson extends Vue {
*/
@Prop() public data!: any;
/**
* 数据格式
*
* @type {*}
* @memberof AppFormJson
*/
@Prop() public schema?: any;
/**
* 格式选项
*
* @type {*}
* @memberof AppFormJson
*/
@Prop() public options?: any;
/**
* 当前值
*
......@@ -104,6 +120,37 @@ export default class AppFormJson extends Vue {
*/
public editor: any;
public getSchema(): any{
if(this.schema)
return this.schema;
else
return {};
}
public getOptions(): any{
let _options={
theme: "bootstrap3",
iconlib: "fontawesome4",
disable_edit_json: true,
display_required_only: true,
disable_collapse: true,
disable_array_delete_last_row: true,
ajax: true,
};
_options["schema"]=this.getSchema();
if (this.CurrentVal) {
_options["startval"] = JSON.parse(this.CurrentVal);
}
if(this.options){
return Object.assign({},_options,this.options)
}
return _options;
}
/**
* 编辑器生成
*
......@@ -116,157 +163,8 @@ export default class AppFormJson extends Vue {
this.editor.destroy();
}
let _schema = {
$ref: "#/definitions/model",
definitions: {
model: {
title: "模型",
headerTemplate: "{{ self.dataModelName }}",
type: "object",
format: "grid",
properties: {
dataModelName: {
title: "模型名",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 1,
},
objectProperties: {
title: "对象参数集合",
type: "array",
format: "tabs",
uniqueItems: true,
items: {
title: "对象",
headerTemplate: "{{ self.propertyName }}",
type: "object",
properties: {
propertyName: {
title: "对象",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 1,
},
system: {
title: "系统",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 2,
},
propertyEntity: {
title: "结构实体",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 3,
},
propertyMappings: {
title: "对象关系映射",
type: "array",
format: "table",
uniqueItems: true,
items: {
title: "映射",
type: "object",
properties: {
selfPropertyColumn: {
title: "列",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 1,
},
joinPropertyName: {
title: "关联对象",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 2,
},
joinPropertyColumn: {
title: "关联列",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 3,
},
},
},
propertyOrder: 4,
},
},
},
propertyOrder: 2,
},
nestedDataModels: {
title: "嵌套子模型集合",
type: "array",
format: "tabs",
uniqueItems: true,
items: {
title: "子模型",
$ref: "#/definitions/model",
},
propertyOrder: 3,
},
layerMappings: {
title: "模型上下级映射",
type: "array",
format: "table",
uniqueItems: true,
items: {
title: "映射",
type: "object",
properties: {
selfPropertyColumn: {
title: "列",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 1,
},
parentPropertyColumn: {
title: "父模型列",
type: "string",
options: {
grid_columns: 4,
},
propertyOrder: 2,
},
},
},
propertyOrder: 4,
},
},
},
},
};
let opt: any = {
schema: _schema,
theme: "bootstrap3",
iconlib: "fontawesome4",
disable_edit_json: true,
display_required_only: true,
disable_collapse: true,
disable_array_delete_last_row: true,
ajax: true,
};
if (this.CurrentVal) {
opt["startval"] = JSON.parse(this.CurrentVal);
}
this.editor = new JSONEditor(element, opt);
this.editor = new JSONEditor(element, _this.getOptions());
this.editor.on("change", () => {
let value = _this.editor.getValue();
......
......@@ -98,7 +98,12 @@
<artifactId>jobs-spring-boot-starter</artifactId>
</dependency>
<!--达梦数据库-->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>Dm7JdbcDriver17</artifactId>
<version>7.6.0.165</version>
</dependency>
</dependencies>
<properties>
......
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.extensions.domain.Setting;
import cn.ibizlab.core.lite.service.IDstDataSourceService;
import cn.ibizlab.core.lite.service.impl.DstDataSourceServiceImpl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.creator.DruidDataSourceCreator;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.lite.domain.DstDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.util.*;
/**
......@@ -23,13 +34,71 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
/**
* [BuildDS:buildDS] 行为扩展
* @param et
* @param dstDataSource
* @return
*/
@Override
@Transactional
public DstDataSource buildDS(DstDataSource et) {
return super.buildDS(et);
public DstDataSource buildDS(DstDataSource dstDataSource) {
if(!(StringUtils.isEmpty(dstDataSource.getDsCfg())))
{
DataSourceProperty dataSourceProperty = new DataSourceProperty();
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
List<Setting> settings= JSONArray.parseArray(dstDataSource.getDsCfg(),Setting.class);
for(Setting setting:settings)
{
if(setting.getProperty().equalsIgnoreCase("driver-class-name"))
dataSourceProperty.setDriverClassName(setting.getValue());
else if(setting.getProperty().equalsIgnoreCase("username"))
dataSourceProperty.setUsername(setting.getValue());
else if(setting.getProperty().equalsIgnoreCase("password"))
dataSourceProperty.setPassword(setting.getValue());
else if(setting.getProperty().equalsIgnoreCase("url"))
dataSourceProperty.setUrl(setting.getValue());
else if(setting.getProperty().equalsIgnoreCase("defaultSchema"))
dataSourceProperty.setSchema(setting.getValue());
}
ds.addDataSource(dstDataSource.getDsName(), dataSource);
}
return super.buildDS(dstDataSource);
}
@Autowired
private DataSource dataSource;
@Autowired
private DruidDataSourceCreator druidDataSourceCreator;
public void initDataSource(String dsName)
{
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
if(ds.getDataSource(dsName)==null)
{
DstDataSource dstDataSource=this.getOne(Wrappers.<DstDataSource>lambdaQuery().eq(DstDataSource::getDsId,dsName).or().eq(DstDataSource::getDsName,dsName),false);
if(dstDataSource!=null)
{
dstDataSource.setDsName(dsName);
buildDS(dstDataSource);
}
}
}
@Override
public boolean update(DstDataSource et) {
if(!super.update(et))
return false;
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
if(ds.getDataSource(et.getDsId())!=null)
ds.removeDataSource(et.getDsId());
if(ds.getDataSource(et.getDsName())!=null)
ds.removeDataSource(et.getDsName());
buildDS(et);
return true;
}
}
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.domain.DstDataSource;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.service.IDstDataSourceService;
import cn.ibizlab.core.lite.service.impl.DstSystemServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.sql.Wrapper;
/**
* 实体[系统] 自定义服务对象
*/
......@@ -18,5 +25,35 @@ public class DstSystemExService extends DstSystemServiceImpl {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
@Autowired
private IDstDataSourceService dstDataSourceService;
@Override
public DstSystem initDefaultDataSource(DstSystem et) {
String dsName=et.getPssystemid()+"-master";
if(dstDataSourceService.count(Wrappers.<DstDataSource>lambdaQuery().eq(DstDataSource::getDsId,dsName).or().eq(DstDataSource::getDsName,dsName))>0)
return et;
DstDataSource dstDataSource=new DstDataSource();
dstDataSource.setDsId(dsName);
dstDataSource.setDsName(dsName);
dstDataSourceService.create(dstDataSource);
return super.initDefaultDataSource(et);
}
@Override
public boolean create(DstSystem et) {
if(!super.create(et))
return false;
initDefaultDataSource(et);
return true;
}
@Override
public boolean update(DstSystem et) {
if(!super.create(et))
return false;
initDefaultDataSource(et);
return true;
}
}
......@@ -17,22 +17,22 @@ public class DataObj<K,V> extends ConcurrentHashMap<K,V> {
public String getRowKey()
{
return this.getStringValue("ROWKEY","");
return this.getStringValue("_ROWKEY","");
}
public <T> T setRowKey(String rowKey)
{
return this.set("ROWKEY",(V)rowKey);
return this.set("_ROWKEY",(V)rowKey);
}
public Timestamp getTimestamp()
{
return getTimestampBegin("TIMESTAMP");
return getTimestampBegin("_TIMESTAMP");
}
public <T> T setTimestamp(Timestamp timestamp)
{
return this.set("TIMESTAMP",(V)DataObject.getTimestampValue(timestamp,DataObject.getBeginDate()));
return this.set("_TIMESTAMP",(V)DataObject.getTimestampValue(timestamp,DataObject.getBeginDate()));
}
public <T> T set(String key, V value)
......
......@@ -76,7 +76,8 @@ public class EntityModel {
return fieldMap;
}
@JsonIgnore
@JSONField(serialize = false)
private FieldModel lastModifyField;
@JsonIgnore
@JSONField(serialize = false)
......@@ -238,13 +239,12 @@ public class EntityModel {
{
if(!(StringUtils.isEmpty(this.getEntity().getExtParams())))
{
JSONArray ja=JSONArray.parseArray(this.getEntity().getExtParams());
for(int i=0;i<ja.size();i++)
List<Setting> settings=JSONArray.parseArray(this.getEntity().getExtParams(),Setting.class);
for(Setting setting:settings)
{
JSONObject jo=ja.getJSONObject(i);
if(jo.containsKey("property")&&key.equals(jo.getString("property")))
if(key.equals(setting.getValue()))
{
return jo.getString("value");
return setting.getValue();
}
}
}
......
......@@ -4,35 +4,30 @@ package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
public class EntityObj extends DataObj<String,Object> {
@JsonIgnore
@JSONField(serialize = false)
private EntityModel entityModel;
@JsonIgnore
@JSONField(serialize = false)
public EntityModel getEntityModel()
{
return entityModel;
return getProperty().getEntityModel();
}
@JsonIgnore
@JSONField(serialize = false)
private DataModel dataModel;
@JsonIgnore
@JSONField(serialize = false)
public DataModel getDataModel() {
return dataModel;
return getProperty().getOwnerDataModel();
}
@JsonIgnore
......@@ -53,39 +48,55 @@ public class EntityObj extends DataObj<String,Object> {
this.setDstSystemId(property.getSystem());
if(!StringUtils.isEmpty(property.getPropertyEntity()))
this.setMetaEntityName(property.getPropertyEntity());
this.entityModel=property.getEntityModel();
this.dataModel=property.getOwnerDataModel();
if(!StringUtils.isEmpty(property.getPropertyName()))
this.setPropertyName(property.getPropertyName());
}
this.property = property;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
public String getPropertyName()
{
return this.getStringValue("_PROPERTYNAME","");
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setPropertyName(String propertyName)
{
return this.set("_PROPERTYNAME",propertyName);
}
@JsonIgnore
@JSONField(serialize = false)
public String getMetaEntityName()
{
return this.getStringValue("METAENTITYNAME","");
return this.getStringValue("_METAENTITYNAME","");
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setMetaEntityName(String metaEntityName)
{
return this.set("METAENTITYNAME",metaEntityName);
return this.set("_METAENTITYNAME",metaEntityName);
}
@JsonIgnore
@JSONField(serialize = false)
public String getDstSystemId()
{
return this.getStringValue("DSTSYSTEMID","");
return this.getStringValue("_DSTSYSTEMID","");
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setDstSystemId(String dstSystemId)
{
return this.set("DSTSYSTEMID",dstSystemId);
return this.set("_DSTSYSTEMID",dstSystemId);
}
......@@ -118,7 +129,18 @@ public class EntityObj extends DataObj<String,Object> {
return rowKey;
}
public void findModel(List<ModelObj> modelObjs)
@Override
public Timestamp getTimestamp() {
Timestamp lastModify=super.getTimestamp();
if(lastModify.equals(DataObject.getBeginDate())&&this.getEntityModel().getLastModifyField()!=null)
{
lastModify=this.getTimestampBegin(this.getEntityModel().getLastModifyField().getColumnName());
this.setTimestamp(lastModify);
}
return super.getTimestamp();
}
public void findModel(List<ModelObj> modelObjs)
{
HashMap<String,ModelObj> tmps=new HashMap<String,ModelObj>();
modelObjs.forEach(obj->tmps.put(obj.getRowKey(),obj));
......
......@@ -29,10 +29,29 @@ public class ModelObj extends DataObj<String,Object> {
@JsonIgnore
@JSONField(serialize = false)
public ModelObj setDataModel(DataModel dataModel) {
if(dataModel!=null) {
if (!StringUtils.isEmpty(dataModel.getDataModelId()))
this.setDataModelId(dataModel.getDataModelId());
}
this.dataModel = dataModel;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
public String getDataModelId()
{
return this.getStringValue("_DATAMODELID","");
}
@JsonIgnore
@JSONField(serialize = false)
public EntityObj setDataModelId(String dataModelId)
{
return this.set("_DATAMODELID",dataModelId);
}
@JsonIgnore
@JSONField(serialize = false)
private ModelObj parent;
......
package cn.ibizlab.core.lite.extensions.domain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class Setting {
private String property;
private String value;
}
......@@ -60,6 +60,21 @@ public class DataModel {
return this.getRootFactPorperty().getFactPorperty();
}
@JSONField(ordinal = 0)
private String dataModelId;
public String getDataModelId()
{
if(StringUtils.isEmpty(dataModelId))
{
if(this.getParentDataModel()!=null)
return this.getRootDataModel().getDataModelId()+":"+this.getDataModelName();
else
return this.getDataModelName();
}
return dataModelId;
}
@JSONField(ordinal = 1)
private String dataModelName;
public String getDataModelName()
......
package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.domain.DstDataSource;
import cn.ibizlab.core.lite.extensions.domain.*;
import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.core.extensions.mapper.DbEntityMapper;
import cn.ibizlab.core.lite.service.IDstDataSourceService;
import cn.ibizlab.util.filter.QueryFilter;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -19,7 +18,9 @@ import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.sql.Timestamp;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
......@@ -30,6 +31,13 @@ import java.util.List;
@Slf4j
public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> implements CommonEntityService{
@Autowired
private IDstDataSourceService dstDataSourceService;
@Override
public List<EntityObj> selectBase(EntityModel entityModel, QueryFilter filter) {
return search("BASE",entityModel,filter);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册