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

提交

上级 2cc4ed8f
......@@ -14,11 +14,6 @@
<description>Ibzdata Boot</description>
<dependencies>
<dependency>
<groupId>cn.ibizlab</groupId>
<artifactId>ibzdata-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cn.ibizlab</groupId>
<artifactId>ibzdata-core</artifactId>
......
......@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@EnableTransactionManagement
@EnableFeignClients(basePackages = {"cn.ibizlab" })
@SpringBootApplication(exclude = {
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
})
@ComponentScan(basePackages = {"cn.ibizlab"}
// ,excludeFilters = {
......
......@@ -14,6 +14,7 @@
<description>Ibzdata Core</description>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
......@@ -29,7 +30,15 @@
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
......@@ -42,6 +51,22 @@
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-shaded</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- Swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
......@@ -58,6 +83,23 @@
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- JBPM -->
<dependency>
......@@ -86,7 +128,6 @@
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
......@@ -104,6 +145,15 @@
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>
<!--MongoDB-->
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -126,6 +176,12 @@
<groupId>net.ibizsys.model</groupId>
<artifactId>ibizlab-model</artifactId>
<version>1.2.7</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
......
......@@ -6,6 +6,7 @@ import cn.ibizlab.core.data.dto.BaseData;
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.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -123,6 +124,13 @@ public class DOModel implements Serializable {
@ApiModelProperty("存储")
private String poModels;
public String getPoModels()
{
if(StringUtils.isEmpty(poModels)&&this.poSchemas!=null)
poModels= JSON.toJSONString(poSchemas);
return poModels;
}
@JSONField(serialize = false)
@JsonIgnore
public String getKeyPropertyName()
......@@ -278,9 +286,11 @@ public class DOModel implements Serializable {
}
public POSchema getPOSchema(String name)
{
name="mysql5";
if(StringUtils.isEmpty(name)&&this.getSchema()!=null)
if(StringUtils.isEmpty(name)&&this.getSchema()!=null&&(!StringUtils.isEmpty(this.getSchema().getDefaultDataSoruce())))
name=this.getSchema().getDefaultDataSoruce();
if(StringUtils.isEmpty(name))
name="mysql";
if(poSchemas==null)
poSchemas=new LinkedHashMap<>();
......@@ -288,12 +298,18 @@ public class DOModel implements Serializable {
{
return poSchemas.get(name);
}
else if(this.getSchema()!=null&&("default".equals(name)||this.getSchema().getDefaultDataSoruce().equals(name)))
String vendorProvider=POSchema.provider.get(name);
if((!StringUtils.isEmpty(vendorProvider))&&(!name.equals(vendorProvider))&&poSchemas.containsKey(vendorProvider))
return poSchemas.get(vendorProvider);
if(this.getSchema()!=null&&("default".equals(name)||this.getSchema().getDefaultDataSoruce().equalsIgnoreCase(name)))
{
POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this.getSchema());
if(defaultPOSchema!=null) {
poSchemas.put("default", defaultPOSchema);
poSchemas.put(this.getSchema().getDefaultDataSoruce(),defaultPOSchema);
if(!StringUtils.isEmpty(this.getSchema().getDefaultDataSoruce()))
poSchemas.put(this.getSchema().getDefaultDataSoruce().toLowerCase(),defaultPOSchema);
return defaultPOSchema;
}
}
......
package cn.ibizlab.core.data.domain;
import java.sql.Timestamp;
import java.util.*;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import cn.ibizlab.core.data.dto.DataObj;
import cn.ibizlab.core.data.lite.MetaEntityModel;
import cn.ibizlab.core.data.lite.Setting;
import cn.ibizlab.core.data.model.DSLinkConfig;
import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.util.ObjectUtils;
import org.springframework.util.DigestUtils;
import java.io.Serializable;
import lombok.*;
import org.springframework.data.annotation.Transient;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;
......@@ -170,14 +160,14 @@ public class DSSetting implements Serializable {
@JSONField(serialize = false)
@JsonIgnore
private DSLinkConfig dsLinkConfig;
private DSLink dsLinkConfig;
@JSONField(serialize = false)
@JsonIgnore
public DSLinkConfig getDSLinkConfig()
public DSLink getDSLinkConfig()
{
if(dsLinkConfig==null)
{
dsLinkConfig = new DSLinkConfig().setName(this.getDsId()).setDescription(this.getDsName()).setDriverClassName(this.getStringValue("driver-class-name"))
dsLinkConfig = new DSLink().setName(this.getDsId()).setDescription(this.getDsName()).setDriverClassName(this.getStringValue("driver-class-name"))
.setUrl(this.getStringValue("url",this.getStringValue("uri")))
.setUsername(this.getStringValue("username")).setPassword(this.getStringValue("password"))
.setSchema(this.getStringValue("defaultSchema",this.getStringValue("schema")));
......@@ -193,7 +183,7 @@ public class DSSetting implements Serializable {
}
return dsLinkConfig;
}
public DSSetting setDSLinkConfig(DSLinkConfig dsLinkConfig)
public DSSetting setDSLinkConfig(DSLink dsLinkConfig)
{
if(dsLinkConfig!=null)
{
......
......@@ -24,7 +24,8 @@ import org.springframework.util.StringUtils;
@Data
public class DSSettingSearchContext extends SearchContextBase {
private String n_dsname_like;//[数据源名称]
private String n_dstype_like;//[数据源名称]
private String n_dsid_like;//[数据源名称]
}
......@@ -206,9 +206,9 @@ public class DynamicModelService {
if(dataEntity.getAllPSDEDBConfigs()!=null)
{
dataEntity.getAllPSDEDBConfigs().forEach(item->{
dsTypes.add(item.getDBType().toLowerCase());
dsTypes.add(item.getDBType().toLowerCase().replace("mysql5","mysql"));
if(!entityModel.getTableName().equalsIgnoreCase(item.getTableName()))
entityModel.getEntity().set("table-"+item.getDBType().toLowerCase(),item.getTableName());
entityModel.getEntity().set("table-"+item.getDBType().toLowerCase().replace("mysql5","mysql"),item.getTableName());
});
}
......@@ -233,7 +233,7 @@ public class DynamicModelService {
{
defield.getAllPSDEFDTColumns().forEach(col->{
if(!metaFieldModel.getFieldName().equalsIgnoreCase(col.getColumnName()))
metaFieldModel.set("column-"+col.getDBType().toLowerCase(),col.getColumnName());
metaFieldModel.set("column-"+col.getDBType().toLowerCase().replace("mysql5","mysql"),col.getColumnName());
if(StringUtils.isEmpty(metaFieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp())))
metaFieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]",""));
});
......@@ -331,7 +331,7 @@ public class DynamicModelService {
String code=getQueryCode(dq);
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase())
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-dq-"+dataQuery.getCodeName()+"-"+dq.getDBType().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(code);
entityModel.addDataSet(dsModel);
......@@ -442,14 +442,14 @@ public class DynamicModelService {
if(dataSet.getMajorSortPSDEField()!=null)
{
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey(),false);
IPSDEFDTColumn column = dataSet.getMajorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(" order by ").concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null)
{
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey(),false);
IPSDEFDTColumn subCol = dataSet.getMinorSortPSDEField().getPSDEFDTColumn(entry.getKey().toLowerCase().replace("mysql5","mysql"),false);
sql=sql.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
......@@ -458,9 +458,9 @@ public class DynamicModelService {
}
}
}
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase())
MetaDataSetModel dsModel=new MetaDataSetModel().setDatasetId(entityModel.getEntityName().toLowerCase()+"-ds-"+dataSet.getCodeName()+"-"+entry.getKey().toLowerCase().replace("mysql5","mysql"))
.setDatasetName(dataSet.getLogicName()).setCodeName(dataSet.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(entry.getValue()).setDsModel(sql);
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(entry.getValue().toLowerCase().replace("mysql5","mysql")).setDsModel(sql);
entityModel.addDataSet(dsModel);
}
......
......@@ -3,11 +3,10 @@ package cn.ibizlab.core.data.mapper;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.core.data.model.POSchema;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
......@@ -52,4 +51,199 @@ public interface DbDataMapper {
@Select("${sql}")
Page<BaseData> queryData(@Param("schema") POSchema schema, @Param("sql") String sql, @Param("srf") FilterData context, @Param("ew") QueryWrapper wrapper, IPage page);
default int insertData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return insertData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int insertBathData(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return insertBathData(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int updateData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return updateData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int updateBathData(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return updateBathData(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int removeData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return removeData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int removeBathData(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return removeBathData(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int save(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return save(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int saveBatch(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return saveBatch(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default int countData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return countData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default List<BaseData> getData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return getData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default List<BaseData> getBatchData(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return getBatchData(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default List<BaseData> getBatchKey(String ds,@Param("schema") POSchema schema, @Param("list") List<BaseData> list){
try
{
DynamicDataSourceContextHolder.push(ds);
return getBatchKey(schema,list);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default List<BaseData> selectData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data){
try
{
DynamicDataSourceContextHolder.push(ds);
return selectData(schema,data);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
default Page<BaseData> selectData(String ds,@Param("schema") POSchema schema, @Param("data") BaseData data, IPage page){
try
{
DynamicDataSourceContextHolder.push(ds);
return selectData(schema,data,page);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
@Update("${sql}")
default boolean executeRaw(String ds,@Param("schema") POSchema schema, @Param("sql") String sql, @Param("param") BaseData param){
try
{
DynamicDataSourceContextHolder.push(ds);
return executeRaw(schema,sql,param);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
@Select("${sql}")
default List<BaseData> queryData(String ds,@Param("schema") POSchema schema, @Param("sql") String sql, @Param("srf") FilterData context, @Param("ew") QueryWrapper wrapper){
try
{
DynamicDataSourceContextHolder.push(ds);
return queryData(schema,sql,context,wrapper);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
@Select("${sql}")
default Page<BaseData> queryData(String ds,@Param("schema") POSchema schema, @Param("sql") String sql, @Param("srf") FilterData context, @Param("ew") QueryWrapper wrapper, IPage page){
try
{
DynamicDataSourceContextHolder.push(ds);
return queryData(schema,sql,context,wrapper,page);
}
finally {
DynamicDataSourceContextHolder.poll();
}
}
}
\ No newline at end of file
package cn.ibizlab.core.data.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
......@@ -12,15 +11,18 @@ import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Set;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DSLinkConfig {
public class DSLink
{
private String name;
private String description;
private String type;
......@@ -59,4 +61,20 @@ public class DSLinkConfig {
return "cassandra".equalsIgnoreCase(this.getType());
}
@JSONField(serialize = false)
@JsonIgnore
public DSLink push()
{
if(this.isDatabase()&&(!StringUtils.isEmpty(name)))
DynamicDataSourceContextHolder.push(name);
return this;
}
private static DSLink defaultLink;
public static DSLink getDefaultLink()
{
if(defaultLink==null)
defaultLink=new DSLink().setName("master").setType("mysql");
return defaultLink;
}
}
......@@ -585,7 +585,7 @@ public class POSchema {
return this;
}
private static Map<String, String> provider = new HashMap<String, String>(){{
public static Map<String, String> provider = new HashMap<String, String>(){{
put("oracle", "oracle");
put("mysql", "mysql");
put("mysql5", "mysql");
......@@ -603,6 +603,8 @@ public class POSchema {
{
if(segments!=null)
{
if(StringUtils.isEmpty(type))
type=this.getDsType();
String vendorProvider=StringUtils.isEmpty(type)?"":provider.get(type.toLowerCase());
for(Segment script:segments)
{
......
......@@ -310,7 +310,7 @@ public class TransUtils {
public static POSchema EntityModelModel2PO(EntityModel entityModel,String dsType) {
final String dataSourceType=dsType.toLowerCase();
POSchema poSchema=new POSchema().setDsType(dsType).setName(entityModel.getTableName(dsType)).setDefaultDataSource(entityModel.getDsName())
POSchema poSchema=new POSchema().setDsType(dataSourceType).setName(entityModel.getTableName(dataSourceType)).setDefaultDataSource(entityModel.getDsName())
.setRemarks(entityModel.getLogicName()).setLogicVal(entityModel.getLogicVal()).setLogicDelVal(entityModel.getLogicDelVal());
......@@ -325,7 +325,6 @@ public class TransUtils {
String colName=fieldModel.getColumnName(dataSourceType);
String dataType=sub.getDataType();
Integer length=sub.getDataLength();
Integer precision=sub.getDataPreci();
......
package cn.ibizlab.core.data.service;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
import java.math.BigInteger;
import cn.ibizlab.core.data.model.DSLink;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async;
import com.alibaba.fastjson.JSONObject;
import org.springframework.cache.annotation.CacheEvict;
import cn.ibizlab.core.data.domain.DSSetting;
import cn.ibizlab.core.data.filter.DSSettingSearchContext;
......@@ -36,7 +27,7 @@ public interface IDSSettingService {
boolean save(DSSetting et);
void saveBatch(List<DSSetting> list);
Page<DSSetting> searchDefault(DSSettingSearchContext context);
DSSetting initDataSource(String tag);
DSLink getDataSource(String tag);
}
......
......@@ -67,6 +67,8 @@ public class ModelService {
{
Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel();
try
{
List<DstSystemModel> liteSystems=liteService.getSysApps();
if(!ObjectUtils.isEmpty(liteSystems))
{
......@@ -78,6 +80,12 @@ public class ModelService {
models.put(system.toLowerCase(), dstSystemModel);
});
}
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
File modelDir=new File(getModelPath());
if(modelDir.exists())
......@@ -115,6 +123,7 @@ public class ModelService {
entities.put(entity.getKey(),id);
});
try{
List<MetaEntityModel> liteEntities=liteService.getEntityModel(system);
if(!ObjectUtils.isEmpty(liteEntities))
{
......@@ -138,6 +147,12 @@ public class ModelService {
});
}
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
File dir=Paths.get(getModelPath(),system,"repo","domain").toFile();
if(dir.exists())
......@@ -154,7 +169,31 @@ public class ModelService {
}
}
return null;
return entities;
}
public EntityModel getEntityModel(String system,String entity)
{
EntityModel entityModel = null;
try {
entityModel = dynamicService.getDynamicEntity(system,entity);
} catch (Exception exception) {
}
try{
if(entityModel==null)
entityModel = liteService.getProxyEntityModel(system,entity);
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
return entityModel;
}
......
......@@ -2,6 +2,8 @@ package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.*;
import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.core.data.service.IDSSettingService;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService;
import lombok.extern.slf4j.Slf4j;
......@@ -39,9 +41,17 @@ public class BaseDataService implements IDataService {
@Autowired
private ModelService modelService;
@Autowired
private IDSSettingService dsSettingService;
public IDataService getProxyService(String datasource)
{
if(datasource.indexOf("mongo")>0)
DSLink dsLink=dsSettingService.getDataSource(datasource);
if(dsLink.isMongodb())
return mongoProxyService;
else if(dsLink.isElasticSearch())
return mongoProxyService;
else if(dsLink.isCassandra())
return mongoProxyService;
else
return dbProxyService;
......@@ -171,7 +181,8 @@ public class BaseDataService implements IDataService {
@Override
public boolean removeByMap(DOModel model, String scope, String datasource, BaseData et)
{
return false;
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).removeByMap(model,scope,datasource,et);
}
@Override
......@@ -184,13 +195,15 @@ public class BaseDataService implements IDataService {
@Override
public List<BaseData> getBatch(DOModel model, String scope, String datasource, List<Serializable> idList)
{
return null;
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).getBatch(model,scope,datasource,idList);
}
@Override
public BaseData getByMap(DOModel model, String scope, String datasource, BaseData et)
{
return null;
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).getByMap(model,scope,datasource,et);
}
@Override
......@@ -239,14 +252,14 @@ public class BaseDataService implements IDataService {
public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).fetch(model,scope,datasource,dataQuery,context);
return getProxyService(datasource).query(model,scope,datasource,dataQuery,context);
}
@Override
public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable)
{
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return getProxyService(datasource).fetch(model,scope,datasource,dataQuery,context,pageable);
return getProxyService(datasource).query(model,scope,datasource,dataQuery,context,pageable);
}
@Override
......
......@@ -11,25 +11,26 @@ import java.util.*;
import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.LiteStorage;
import cn.ibizlab.core.data.model.DSLinkConfig;
import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils;
import cn.ibizlab.core.data.service.ModelService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.filter.DOModelSearchContext;
import cn.ibizlab.core.data.service.IDOModelService;
import org.springframework.util.StringUtils;
/**
......@@ -39,8 +40,8 @@ import cn.ibizlab.core.data.service.IDOModelService;
@Service
public class DOModelServiceImpl implements IDOModelService {
@Value("${ibiz.model.path:/app/file/model/}")
private String modelPath;
@Autowired
private ModelService modelService;
@Override
public boolean create(DOModel et) {
......@@ -68,6 +69,7 @@ public class DOModelServiceImpl implements IDOModelService {
public void removeBatch(Collection<String> idList){
}
@Cacheable( value="domodel",key = "'row:'+#p0")
@Override
public DOModel get(String key) {
DOModel doModel=new DOModel();
......@@ -80,7 +82,26 @@ public class DOModelServiceImpl implements IDOModelService {
Path storePath = Paths.get(LiteStorage.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
if(!Files.exists(storePath))
{
EntityModel entityModel= LiteStorage.getEntityModel(system,entity);
try {
String entityId=modelService.getEntitiyIdsBySystem(system).get(entity);
if(StringUtils.isEmpty(entityId))
throw new BadRequestAlertException("获取模型失败","DOModel",key);
if(!key.equals(entityId))
{
args=entityId.split("[.]");
system=args[0];
entity=args[2];
storePath = Paths.get(LiteStorage.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
}
} catch (Exception exception) {
throw new BadRequestAlertException("获取模型失败","DOModel",key);
}
}
if(!Files.exists(storePath))
{
EntityModel entityModel= modelService.getEntityModel(system,entity);
if(entityModel!=null) {
schema=TransUtils.EntityModelModel2Schema(entityModel);
if(schema!=null)
......@@ -95,7 +116,7 @@ public class DOModelServiceImpl implements IDOModelService {
}
if(doModel.getPoSchemas()!=null)
{
Path poPath = Paths.get(LiteStorage.MODEL_PATH,system,"repo",entity,"repository",entity+".json");
Path poPath = Paths.get(LiteStorage.MODEL_PATH,entityModel.getSystemId(),"repo",entityModel.getEntityName(),"repository",entityModel.getEntityName()+".json");
try {
File dir=poPath.getParent().toFile();
if(!dir.exists())
......@@ -105,7 +126,7 @@ public class DOModelServiceImpl implements IDOModelService {
throw new BadRequestAlertException("保存文件失败","POSchemas",poPath.toString());
}
}
schema.writeTo(storePath);
schema.writeTo(Paths.get(LiteStorage.MODEL_PATH,entityModel.getSystemId(),"repo",entityModel.getEntityName(),"domain",entityModel.getEntityName()+".json"));
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册