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

提交

上级 2cc4ed8f
...@@ -14,11 +14,6 @@ ...@@ -14,11 +14,6 @@
<description>Ibzdata Boot</description> <description>Ibzdata Boot</description>
<dependencies> <dependencies>
<dependency>
<groupId>cn.ibizlab</groupId>
<artifactId>ibzdata-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>cn.ibizlab</groupId> <groupId>cn.ibizlab</groupId>
<artifactId>ibzdata-core</artifactId> <artifactId>ibzdata-core</artifactId>
......
...@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@EnableTransactionManagement @EnableTransactionManagement
@EnableFeignClients(basePackages = {"cn.ibizlab" }) @EnableFeignClients(basePackages = {"cn.ibizlab" })
@SpringBootApplication(exclude = { @SpringBootApplication(exclude = {
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
}) })
@ComponentScan(basePackages = {"cn.ibizlab"} @ComponentScan(basePackages = {"cn.ibizlab"}
// ,excludeFilters = { // ,excludeFilters = {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<description>Ibzdata Core</description> <description>Ibzdata Core</description>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId> <artifactId>spring-data-commons</artifactId>
...@@ -29,7 +30,15 @@ ...@@ -29,7 +30,15 @@
<artifactId>logstash-logback-encoder</artifactId> <artifactId>logstash-logback-encoder</artifactId>
</dependency> </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> <dependency>
<groupId>io.jsonwebtoken</groupId> <groupId>io.jsonwebtoken</groupId>
...@@ -42,6 +51,22 @@ ...@@ -42,6 +51,22 @@
</dependency> </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 --> <!-- Swagger2 -->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
...@@ -58,6 +83,23 @@ ...@@ -58,6 +83,23 @@
</dependency> </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 --> <!-- JBPM -->
<dependency> <dependency>
...@@ -86,7 +128,6 @@ ...@@ -86,7 +128,6 @@
<groupId>org.kie</groupId> <groupId>org.kie</groupId>
<artifactId>kie-api</artifactId> <artifactId>kie-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>
...@@ -104,6 +145,15 @@ ...@@ -104,6 +145,15 @@
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>
<!--MongoDB--> <!--MongoDB-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -126,6 +176,12 @@ ...@@ -126,6 +176,12 @@
<groupId>net.ibizsys.model</groupId> <groupId>net.ibizsys.model</groupId>
<artifactId>ibizlab-model</artifactId> <artifactId>ibizlab-model</artifactId>
<version>1.2.7</version> <version>1.2.7</version>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -6,6 +6,7 @@ import cn.ibizlab.core.data.dto.BaseData; ...@@ -6,6 +6,7 @@ import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.model.POSchema; 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 cn.ibizlab.core.data.model.TransUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
...@@ -123,6 +124,13 @@ public class DOModel implements Serializable { ...@@ -123,6 +124,13 @@ public class DOModel implements Serializable {
@ApiModelProperty("存储") @ApiModelProperty("存储")
private String poModels; private String poModels;
public String getPoModels()
{
if(StringUtils.isEmpty(poModels)&&this.poSchemas!=null)
poModels= JSON.toJSONString(poSchemas);
return poModels;
}
@JSONField(serialize = false) @JSONField(serialize = false)
@JsonIgnore @JsonIgnore
public String getKeyPropertyName() public String getKeyPropertyName()
...@@ -278,9 +286,11 @@ public class DOModel implements Serializable { ...@@ -278,9 +286,11 @@ public class DOModel implements Serializable {
} }
public POSchema getPOSchema(String name) 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(); name=this.getSchema().getDefaultDataSoruce();
if(StringUtils.isEmpty(name))
name="mysql";
if(poSchemas==null) if(poSchemas==null)
poSchemas=new LinkedHashMap<>(); poSchemas=new LinkedHashMap<>();
...@@ -288,12 +298,18 @@ public class DOModel implements Serializable { ...@@ -288,12 +298,18 @@ public class DOModel implements Serializable {
{ {
return poSchemas.get(name); 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()); POSchema defaultPOSchema= TransUtils.PojoSchema2PO(this.getSchema());
if(defaultPOSchema!=null) { if(defaultPOSchema!=null) {
poSchemas.put("default", defaultPOSchema); 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; return defaultPOSchema;
} }
} }
......
package cn.ibizlab.core.data.domain; package cn.ibizlab.core.data.domain;
import java.sql.Timestamp;
import java.util.*; 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.lite.Setting;
import cn.ibizlab.core.data.model.DSLinkConfig; import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.DigestUtils;
import java.io.Serializable; import java.io.Serializable;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.Transient;
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; import org.springframework.util.StringUtils;
...@@ -170,14 +160,14 @@ public class DSSetting implements Serializable { ...@@ -170,14 +160,14 @@ public class DSSetting implements Serializable {
@JSONField(serialize = false) @JSONField(serialize = false)
@JsonIgnore @JsonIgnore
private DSLinkConfig dsLinkConfig; private DSLink dsLinkConfig;
@JSONField(serialize = false) @JSONField(serialize = false)
@JsonIgnore @JsonIgnore
public DSLinkConfig getDSLinkConfig() public DSLink getDSLinkConfig()
{ {
if(dsLinkConfig==null) 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"))) .setUrl(this.getStringValue("url",this.getStringValue("uri")))
.setUsername(this.getStringValue("username")).setPassword(this.getStringValue("password")) .setUsername(this.getStringValue("username")).setPassword(this.getStringValue("password"))
.setSchema(this.getStringValue("defaultSchema",this.getStringValue("schema"))); .setSchema(this.getStringValue("defaultSchema",this.getStringValue("schema")));
...@@ -193,7 +183,7 @@ public class DSSetting implements Serializable { ...@@ -193,7 +183,7 @@ public class DSSetting implements Serializable {
} }
return dsLinkConfig; return dsLinkConfig;
} }
public DSSetting setDSLinkConfig(DSLinkConfig dsLinkConfig) public DSSetting setDSLinkConfig(DSLink dsLinkConfig)
{ {
if(dsLinkConfig!=null) if(dsLinkConfig!=null)
{ {
......
...@@ -24,7 +24,8 @@ import org.springframework.util.StringUtils; ...@@ -24,7 +24,8 @@ import org.springframework.util.StringUtils;
@Data @Data
public class DSSettingSearchContext extends SearchContextBase { public class DSSettingSearchContext extends SearchContextBase {
private String n_dsname_like;//[数据源名称] private String n_dsname_like;//[数据源名称]
private String n_dstype_like;//[数据源名称]
private String n_dsid_like;//[数据源名称]
} }
...@@ -206,9 +206,9 @@ public class DynamicModelService { ...@@ -206,9 +206,9 @@ public class DynamicModelService {
if(dataEntity.getAllPSDEDBConfigs()!=null) if(dataEntity.getAllPSDEDBConfigs()!=null)
{ {
dataEntity.getAllPSDEDBConfigs().forEach(item->{ dataEntity.getAllPSDEDBConfigs().forEach(item->{
dsTypes.add(item.getDBType().toLowerCase()); dsTypes.add(item.getDBType().toLowerCase().replace("mysql5","mysql"));
if(!entityModel.getTableName().equalsIgnoreCase(item.getTableName())) 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 { ...@@ -233,7 +233,7 @@ public class DynamicModelService {
{ {
defield.getAllPSDEFDTColumns().forEach(col->{ defield.getAllPSDEFDTColumns().forEach(col->{
if(!metaFieldModel.getFieldName().equalsIgnoreCase(col.getColumnName())) 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()))) if(StringUtils.isEmpty(metaFieldModel)&&defield.isFormulaDEField()&&(!StringUtils.isEmpty(col.getQueryCodeExp())))
metaFieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]","")); metaFieldModel.setExpression(col.getQueryCodeExp().replace("`","").replace("[","").replace("]",""));
}); });
...@@ -331,7 +331,7 @@ public class DynamicModelService { ...@@ -331,7 +331,7 @@ public class DynamicModelService {
String code=getQueryCode(dq); 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()) .setDatasetName(dataQuery.getLogicName()).setCodeName(dataQuery.getCodeName())
.setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(code); .setEntityId(entityModel.getEntityId()).setEntityName(entityModel.getEntityName()).setDsCode(code);
entityModel.addDataSet(dsModel); entityModel.addDataSet(dsModel);
...@@ -442,14 +442,14 @@ public class DynamicModelService { ...@@ -442,14 +442,14 @@ public class DynamicModelService {
if(dataSet.getMajorSortPSDEField()!=null) 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()); sql=sql.concat(" order by ").concat(column==null?dataSet.getMajorSortPSDEField().getName():column.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMajorSortDir())) if(!StringUtils.isEmpty(dataSet.getMajorSortDir()))
sql=sql.concat(" ").concat(dataSet.getMajorSortDir()); sql=sql.concat(" ").concat(dataSet.getMajorSortDir());
if(dataSet.getMinorSortPSDEField()!=null) 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()); sql=sql.concat(",").concat(subCol==null?dataSet.getMinorSortPSDEField().getName():subCol.getColumnName());
if(!StringUtils.isEmpty(dataSet.getMinorSortDir())) if(!StringUtils.isEmpty(dataSet.getMinorSortDir()))
...@@ -458,9 +458,9 @@ public class DynamicModelService { ...@@ -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()) .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); entityModel.addDataSet(dsModel);
} }
......
...@@ -3,11 +3,10 @@ package cn.ibizlab.core.data.mapper; ...@@ -3,11 +3,10 @@ package cn.ibizlab.core.data.mapper;
import cn.ibizlab.core.data.dto.BaseData; import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.FilterData; import cn.ibizlab.core.data.dto.FilterData;
import cn.ibizlab.core.data.model.POSchema; 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.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
...@@ -52,4 +51,199 @@ public interface DbDataMapper { ...@@ -52,4 +51,199 @@ public interface DbDataMapper {
@Select("${sql}") @Select("${sql}")
Page<BaseData> queryData(@Param("schema") POSchema schema, @Param("sql") String sql, @Param("srf") FilterData context, @Param("ew") QueryWrapper wrapper, IPage page); 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; package cn.ibizlab.core.data.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
...@@ -12,15 +11,18 @@ import lombok.Setter; ...@@ -12,15 +11,18 @@ import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Set; import java.util.Set;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class DSLinkConfig { public class DSLink
{
private String name; private String name;
private String description; private String description;
private String type; private String type;
...@@ -59,4 +61,20 @@ public class DSLinkConfig { ...@@ -59,4 +61,20 @@ public class DSLinkConfig {
return "cassandra".equalsIgnoreCase(this.getType()); 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 { ...@@ -585,7 +585,7 @@ public class POSchema {
return this; 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("oracle", "oracle");
put("mysql", "mysql"); put("mysql", "mysql");
put("mysql5", "mysql"); put("mysql5", "mysql");
...@@ -603,6 +603,8 @@ public class POSchema { ...@@ -603,6 +603,8 @@ public class POSchema {
{ {
if(segments!=null) if(segments!=null)
{ {
if(StringUtils.isEmpty(type))
type=this.getDsType();
String vendorProvider=StringUtils.isEmpty(type)?"":provider.get(type.toLowerCase()); String vendorProvider=StringUtils.isEmpty(type)?"":provider.get(type.toLowerCase());
for(Segment script:segments) for(Segment script:segments)
{ {
......
...@@ -310,7 +310,7 @@ public class TransUtils { ...@@ -310,7 +310,7 @@ public class TransUtils {
public static POSchema EntityModelModel2PO(EntityModel entityModel,String dsType) { public static POSchema EntityModelModel2PO(EntityModel entityModel,String dsType) {
final String dataSourceType=dsType.toLowerCase(); 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()); .setRemarks(entityModel.getLogicName()).setLogicVal(entityModel.getLogicVal()).setLogicDelVal(entityModel.getLogicDelVal());
...@@ -325,7 +325,6 @@ public class TransUtils { ...@@ -325,7 +325,6 @@ public class TransUtils {
String colName=fieldModel.getColumnName(dataSourceType); String colName=fieldModel.getColumnName(dataSourceType);
String dataType=sub.getDataType();
Integer length=sub.getDataLength(); Integer length=sub.getDataLength();
Integer precision=sub.getDataPreci(); Integer precision=sub.getDataPreci();
......
package cn.ibizlab.core.data.service; 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.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection; 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.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.domain.DSSetting;
import cn.ibizlab.core.data.filter.DSSettingSearchContext; import cn.ibizlab.core.data.filter.DSSettingSearchContext;
...@@ -36,7 +27,7 @@ public interface IDSSettingService { ...@@ -36,7 +27,7 @@ public interface IDSSettingService {
boolean save(DSSetting et); boolean save(DSSetting et);
void saveBatch(List<DSSetting> list); void saveBatch(List<DSSetting> list);
Page<DSSetting> searchDefault(DSSettingSearchContext context); Page<DSSetting> searchDefault(DSSettingSearchContext context);
DSSetting initDataSource(String tag); DSLink getDataSource(String tag);
} }
......
...@@ -67,6 +67,8 @@ public class ModelService { ...@@ -67,6 +67,8 @@ public class ModelService {
{ {
Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel(); Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel();
try
{
List<DstSystemModel> liteSystems=liteService.getSysApps(); List<DstSystemModel> liteSystems=liteService.getSysApps();
if(!ObjectUtils.isEmpty(liteSystems)) if(!ObjectUtils.isEmpty(liteSystems))
{ {
...@@ -78,6 +80,12 @@ public class ModelService { ...@@ -78,6 +80,12 @@ public class ModelService {
models.put(system.toLowerCase(), dstSystemModel); models.put(system.toLowerCase(), dstSystemModel);
}); });
} }
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
File modelDir=new File(getModelPath()); File modelDir=new File(getModelPath());
if(modelDir.exists()) if(modelDir.exists())
...@@ -115,6 +123,7 @@ public class ModelService { ...@@ -115,6 +123,7 @@ public class ModelService {
entities.put(entity.getKey(),id); entities.put(entity.getKey(),id);
}); });
try{
List<MetaEntityModel> liteEntities=liteService.getEntityModel(system); List<MetaEntityModel> liteEntities=liteService.getEntityModel(system);
if(!ObjectUtils.isEmpty(liteEntities)) if(!ObjectUtils.isEmpty(liteEntities))
{ {
...@@ -138,6 +147,12 @@ public class ModelService { ...@@ -138,6 +147,12 @@ public class ModelService {
}); });
} }
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
File dir=Paths.get(getModelPath(),system,"repo","domain").toFile(); File dir=Paths.get(getModelPath(),system,"repo","domain").toFile();
if(dir.exists()) if(dir.exists())
...@@ -154,7 +169,31 @@ public class ModelService { ...@@ -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; ...@@ -2,6 +2,8 @@ package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel; import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.*; 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.IDataService;
import cn.ibizlab.core.data.service.ModelService; import cn.ibizlab.core.data.service.ModelService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -39,9 +41,17 @@ public class BaseDataService implements IDataService { ...@@ -39,9 +41,17 @@ public class BaseDataService implements IDataService {
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@Autowired
private IDSSettingService dsSettingService;
public IDataService getProxyService(String datasource) 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; return mongoProxyService;
else else
return dbProxyService; return dbProxyService;
...@@ -171,7 +181,8 @@ public class BaseDataService implements IDataService { ...@@ -171,7 +181,8 @@ public class BaseDataService implements IDataService {
@Override @Override
public boolean removeByMap(DOModel model, String scope, String datasource, BaseData et) 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 @Override
...@@ -184,13 +195,15 @@ public class BaseDataService implements IDataService { ...@@ -184,13 +195,15 @@ public class BaseDataService implements IDataService {
@Override @Override
public List<BaseData> getBatch(DOModel model, String scope, String datasource, List<Serializable> idList) 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 @Override
public BaseData getByMap(DOModel model, String scope, String datasource, BaseData et) 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 @Override
...@@ -239,14 +252,14 @@ public class BaseDataService implements IDataService { ...@@ -239,14 +252,14 @@ public class BaseDataService implements IDataService {
public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context) public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context)
{ {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource(); 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 @Override
public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable) public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable)
{ {
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource(); 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 @Override
......
...@@ -11,25 +11,26 @@ import java.util.*; ...@@ -11,25 +11,26 @@ import java.util.*;
import cn.ibizlab.core.data.lite.EntityModel; import cn.ibizlab.core.data.lite.EntityModel;
import cn.ibizlab.core.data.lite.LiteStorage; 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.POSchema;
import cn.ibizlab.core.data.model.PojoSchema; import cn.ibizlab.core.data.model.PojoSchema;
import cn.ibizlab.core.data.model.TransUtils; import cn.ibizlab.core.data.model.TransUtils;
import cn.ibizlab.core.data.service.ModelService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import lombok.extern.slf4j.Slf4j; 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.stereotype.Service;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.core.data.domain.DOModel; import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.filter.DOModelSearchContext; import cn.ibizlab.core.data.filter.DOModelSearchContext;
import cn.ibizlab.core.data.service.IDOModelService; import cn.ibizlab.core.data.service.IDOModelService;
import org.springframework.util.StringUtils;
/** /**
...@@ -39,8 +40,8 @@ import cn.ibizlab.core.data.service.IDOModelService; ...@@ -39,8 +40,8 @@ import cn.ibizlab.core.data.service.IDOModelService;
@Service @Service
public class DOModelServiceImpl implements IDOModelService { public class DOModelServiceImpl implements IDOModelService {
@Value("${ibiz.model.path:/app/file/model/}") @Autowired
private String modelPath; private ModelService modelService;
@Override @Override
public boolean create(DOModel et) { public boolean create(DOModel et) {
...@@ -68,6 +69,7 @@ public class DOModelServiceImpl implements IDOModelService { ...@@ -68,6 +69,7 @@ public class DOModelServiceImpl implements IDOModelService {
public void removeBatch(Collection<String> idList){ public void removeBatch(Collection<String> idList){
} }
@Cacheable( value="domodel",key = "'row:'+#p0")
@Override @Override
public DOModel get(String key) { public DOModel get(String key) {
DOModel doModel=new DOModel(); DOModel doModel=new DOModel();
...@@ -80,7 +82,26 @@ public class DOModelServiceImpl implements IDOModelService { ...@@ -80,7 +82,26 @@ public class DOModelServiceImpl implements IDOModelService {
Path storePath = Paths.get(LiteStorage.MODEL_PATH,system,"repo",entity,"domain",entity+".json"); Path storePath = Paths.get(LiteStorage.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
if(!Files.exists(storePath)) 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) { if(entityModel!=null) {
schema=TransUtils.EntityModelModel2Schema(entityModel); schema=TransUtils.EntityModelModel2Schema(entityModel);
if(schema!=null) if(schema!=null)
...@@ -95,7 +116,7 @@ public class DOModelServiceImpl implements IDOModelService { ...@@ -95,7 +116,7 @@ public class DOModelServiceImpl implements IDOModelService {
} }
if(doModel.getPoSchemas()!=null) 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 { try {
File dir=poPath.getParent().toFile(); File dir=poPath.getParent().toFile();
if(!dir.exists()) if(!dir.exists())
...@@ -105,7 +126,7 @@ public class DOModelServiceImpl implements IDOModelService { ...@@ -105,7 +126,7 @@ public class DOModelServiceImpl implements IDOModelService {
throw new BadRequestAlertException("保存文件失败","POSchemas",poPath.toString()); 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"));
} }
......
package cn.ibizlab.core.data.service.impl; package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.Serializable;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.*; import java.util.*;
import java.math.BigInteger;
import cn.ibizlab.core.data.lite.LiteStorage; import cn.ibizlab.core.data.lite.LiteStorage;
import cn.ibizlab.core.data.model.DSLinkConfig; import cn.ibizlab.core.data.model.DSLink;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.creator.DataSourceCreator; import com.baomidou.dynamic.datasource.creator.DataSourceCreator;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
...@@ -53,23 +45,23 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -53,23 +45,23 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Lazy @Lazy
private DSSettingServiceImpl proxy; private DSSettingServiceImpl proxy;
public Map<String,DSLinkConfig> getAllConfigs() public Map<String, DSLink> getAllConfigs()
{ {
Path path = Paths.get(LiteStorage.MODEL_PATH,"DATASOURCE.json"); Path path = Paths.get(LiteStorage.MODEL_PATH,"DATASOURCE.json");
try { try {
Map<String,DSLinkConfig> all=new HashMap<>(); Map<String, DSLink> all=new LinkedHashMap<>();
if(!Files.exists(path)) if(!Files.exists(path))
{ {
Files.write(path, JSON.toJSONBytes(new LinkedHashMap<String, DSLinkConfig>()), StandardOpenOption.CREATE); Files.write(path, JSON.toJSONBytes(new LinkedHashMap<String, DSLink>()), StandardOpenOption.CREATE);
} }
else else
{ {
LinkedHashMap<String,DSLinkConfig> map = JSON.parseObject(new String(Files.readAllBytes(path), StandardCharsets.UTF_8), new TypeReference<LinkedHashMap<String,DSLinkConfig>>(){}); LinkedHashMap<String, DSLink> map = JSON.parseObject(new String(Files.readAllBytes(path), StandardCharsets.UTF_8), new TypeReference<LinkedHashMap<String, DSLink>>(){});
map.entrySet().forEach(item->{ map.entrySet().forEach(item->{
String id=item.getKey(); String id=item.getKey();
DSLinkConfig config=item.getValue(); DSLink config=item.getValue();
config.setName(id); config.setName(id);
if(!all.containsKey(id)) if(!all.containsKey(id))
all.put(id,config); all.put(id,config);
...@@ -96,23 +88,29 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -96,23 +88,29 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Override @Override
public boolean create(DSSetting et) { public boolean create(DSSetting et) {
//代码实现 //代码实现
return true;
return this.save(et);
} }
public void createBatch(List<DSSetting> list){ public void createBatch(List<DSSetting> list){
list.forEach(et->create(et));
} }
@Override @Override
public boolean update(DSSetting et) { public boolean update(DSSetting et) {
//代码实现 //代码实现
this.save(et);
synchronized (lock) synchronized (lock)
{ {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
if (check.containsKey(et.getDsId())) if (check.containsKey(et.getDsId()))
{ {
if(et.isDatabase()) if(et.isDatabase()) {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
ds.removeDataSource(et.getDsId()); ds.removeDataSource(et.getDsId());
}
check.remove(et.getDsId()); check.remove(et.getDsId());
} }
if (!et.getDsId().equals(et.getDsId().toLowerCase())) if (!et.getDsId().equals(et.getDsId().toLowerCase()))
...@@ -130,29 +128,80 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -130,29 +128,80 @@ public class DSSettingServiceImpl implements IDSSettingService {
} }
buildDS(et); buildDS(et);
return true; return true;
} }
public void updateBatch(List<DSSetting> list){ public void updateBatch(List<DSSetting> list){
list.forEach(et->update(et));
} }
@Override @Override
public boolean remove(String key) { public boolean remove(String key) {
DSSetting et = new DSSetting();
synchronized (lock) {
LinkedHashMap<String, DSLink> newConfigs = new LinkedHashMap<>();
proxy.getAllConfigs().values().forEach(config -> {
if (!newConfigs.containsKey(config.getName())) {
if (!config.getName().equals(key))
newConfigs.put(config.getName(), config);
else
et.setDSLinkConfig(config);
}
});
Path path = Paths.get(LiteStorage.MODEL_PATH, "DATASOURCE.json");
try {
Files.write(path, JSON.toJSONBytes(newConfigs));
} catch (Exception e) {
throw new BadRequestAlertException("读写文件失败", "DSLinkConfig", path.toString());
}
if (!StringUtils.isEmpty(et.getDsId()))
{
if (check.containsKey(et.getDsId()))
{
if(et.isDatabase()) {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
ds.removeDataSource(et.getDsId());
}
check.remove(et.getDsId());
}
if (!et.getDsId().equals(et.getDsId().toLowerCase()))
{
check.remove(et.getDsId().toLowerCase());
}
if(!ObjectUtils.isEmpty(et.getUsings()))
{
et.getUsings().forEach(using->{
check.remove(using);
if(!using.equals(using.toLowerCase()))
check.remove(using.toLowerCase());
});
}
}
}
return true; return true;
} }
public void removeBatch(Collection<String> idList){ public void removeBatch(Collection<String> idList){
idList.forEach(id->{
remove(id);
});
} }
@Override @Override
public DSSetting get(String key) { public DSSetting get(String key) {
DSSetting et = new DSSetting(); DSSetting et = new DSSetting();
Map<String,DSLinkConfig> allConfigs=proxy.getAllConfigs(); Map<String, DSLink> allConfigs=proxy.getAllConfigs();
if(allConfigs.containsKey(key)) if(allConfigs.containsKey(key))
et.setDSLinkConfig(allConfigs.get(key)); et.setDSLinkConfig(allConfigs.get(key));
else else
throw new BadRequestAlertException("未找到数据源配置信息","DSSetting",key); return null;
return et; return et;
} }
...@@ -169,19 +218,41 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -169,19 +218,41 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Transactional @Transactional
public boolean save(DSSetting et) { public boolean save(DSSetting et) {
//代码实现 //代码实现
synchronized (lock) {
LinkedHashMap<String, DSLink> newConfigs = new LinkedHashMap<>();
proxy.getAllConfigs().values().forEach(config -> {
if (!newConfigs.containsKey(config.getName())) {
if (!config.getName().equals(et.getDsId()))
newConfigs.put(config.getName(), config);
else
newConfigs.put(config.getName(), et.getDSLinkConfig());
}
});
Path path = Paths.get(LiteStorage.MODEL_PATH, "DATASOURCE.json");
try {
Files.write(path, JSON.toJSONBytes(newConfigs));
} catch (Exception e) {
throw new BadRequestAlertException("读写文件失败", "DSLinkConfig", path.toString());
}
}
return true; return true;
} }
@Override @Override
public void saveBatch(List<DSSetting> list) { public void saveBatch(List<DSSetting> list) {
list.forEach(et->save(et));
} }
private HashMap<String,DSSetting> check=new HashMap<>(); private HashMap<String, DSLink> check=new HashMap<>();
private Object lock=new Object(); private Object lock=new Object();
public DSSetting initDataSource(String tag) public DSLink getDataSource(String tag)
{ {
if(StringUtils.isEmpty(tag))
return DSLink.getDefaultLink();
if (check.containsKey(tag)) if (check.containsKey(tag))
return check.get(tag); return check.get(tag);
...@@ -191,11 +262,16 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -191,11 +262,16 @@ public class DSSettingServiceImpl implements IDSSettingService {
if (check.containsKey(tag)) if (check.containsKey(tag))
return check.get(tag); return check.get(tag);
dstDataSource=this.get(tag); dstDataSource=this.get(tag);
if(dstDataSource==null) {
DSLink defaultLink=DSLink.getDefaultLink();
check.put(tag,defaultLink);
return defaultLink;
}
if ((!tag.equalsIgnoreCase(dstDataSource.getDsId()))&&check.containsKey(dstDataSource.getDsId())) if ((!tag.equalsIgnoreCase(dstDataSource.getDsId()))&&check.containsKey(dstDataSource.getDsId()))
return check.get(dstDataSource.getDsId()); return check.get(dstDataSource.getDsId());
} }
return buildDS(dstDataSource); return buildDS(dstDataSource).getDSLinkConfig();
} }
public DSSetting buildDS(DSSetting dstDataSource) { public DSSetting buildDS(DSSetting dstDataSource) {
...@@ -210,15 +286,15 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -210,15 +286,15 @@ public class DSSettingServiceImpl implements IDSSettingService {
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty); DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dstDataSource.getDsId(), dataSource); ds.addDataSource(dstDataSource.getDsId(), dataSource);
} }
check.put(dstDataSource.getDsId(), dstDataSource); check.put(dstDataSource.getDsId(), dstDataSource.getDSLinkConfig());
if(!dstDataSource.getDsId().equals(dstDataSource.getDsId().toLowerCase())) if(!dstDataSource.getDsId().equals(dstDataSource.getDsId().toLowerCase()))
check.put(dstDataSource.getDsId().toLowerCase(), dstDataSource); check.put(dstDataSource.getDsId().toLowerCase(), dstDataSource.getDSLinkConfig());
if(!ObjectUtils.isEmpty(dstDataSource.getUsings())) if(!ObjectUtils.isEmpty(dstDataSource.getUsings()))
{ {
dstDataSource.getUsings().forEach(using->{ dstDataSource.getUsings().forEach(using->{
check.put(using, dstDataSource); check.put(using, dstDataSource.getDSLinkConfig());
if(!using.equals(using.toLowerCase())) if(!using.equals(using.toLowerCase()))
check.put(using.toLowerCase(), dstDataSource); check.put(using.toLowerCase(), dstDataSource.getDSLinkConfig());
}); });
} }
} }
...@@ -241,7 +317,24 @@ public class DSSettingServiceImpl implements IDSSettingService { ...@@ -241,7 +317,24 @@ public class DSSettingServiceImpl implements IDSSettingService {
*/ */
@Override @Override
public Page<DSSetting> searchDefault(DSSettingSearchContext context) { public Page<DSSetting> searchDefault(DSSettingSearchContext context) {
return new PageImpl<DSSetting>(new ArrayList(),context.getPageable(),0);
LinkedHashMap<String, DSLink> newConfigs = new LinkedHashMap<>();
proxy.getAllConfigs().values().forEach(config -> {
if (!newConfigs.containsKey(config.getName())) {
newConfigs.put(config.getName(),config);
}
});
List<DSSetting> list=new ArrayList<>();
newConfigs.values().forEach(config->{
if((!StringUtils.isEmpty(context.getN_dsid_like())&&(StringUtils.isEmpty(config.getName())||config.getName().indexOf(context.getN_dsid_like())<0)))
return;
if((!StringUtils.isEmpty(context.getN_dsname_like())&&(StringUtils.isEmpty(config.getName())||config.getDescription().indexOf(context.getN_dsname_like())<0)))
return;
if((!StringUtils.isEmpty(context.getN_dstype_like())&&(StringUtils.isEmpty(config.getName())||config.getType().indexOf(context.getN_dstype_like())<0)))
return;
list.add(new DSSetting().setDSLinkConfig(config));
});
return new PageImpl<DSSetting>(list,context.getPageable(),list.size());
} }
} }
......
...@@ -3,7 +3,9 @@ package cn.ibizlab.core.data.service.impl; ...@@ -3,7 +3,9 @@ package cn.ibizlab.core.data.service.impl;
import cn.ibizlab.core.data.domain.DOModel; import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.*; import cn.ibizlab.core.data.dto.*;
import cn.ibizlab.core.data.mapper.DbDataMapper; import cn.ibizlab.core.data.mapper.DbDataMapper;
import cn.ibizlab.core.data.model.DSLink;
import cn.ibizlab.core.data.model.POSchema; import cn.ibizlab.core.data.model.POSchema;
import cn.ibizlab.core.data.service.IDSSettingService;
import cn.ibizlab.core.data.service.IDataService; import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService; import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
...@@ -15,6 +17,7 @@ import org.springframework.data.domain.PageImpl; ...@@ -15,6 +17,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
...@@ -32,6 +35,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -32,6 +35,10 @@ public class DbDataServiceImpl implements IDataService {
@Autowired @Autowired
private DbDataMapper dbDataMapper; private DbDataMapper dbDataMapper;
@Autowired
private IDSSettingService dsSettingService;
@Override @Override
public ResponseData call(DOModel model, String scope, String datasource, String method, RequestData requestData) public ResponseData call(DOModel model, String scope, String datasource, String method, RequestData requestData)
{ {
...@@ -44,7 +51,12 @@ public class DbDataServiceImpl implements IDataService { ...@@ -44,7 +51,12 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,true); Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
if(dbDataMapper.insertData(model.getPOSchema(datasource),et)==1)
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
if(dbDataMapper.insertData(link.getName(),poSchema,et)==1)
et.setAll(get(model,scope,datasource,key)); et.setAll(get(model,scope,datasource,key));
return true; return true;
} }
...@@ -53,7 +65,9 @@ public class DbDataServiceImpl implements IDataService { ...@@ -53,7 +65,9 @@ public class DbDataServiceImpl implements IDataService {
public void createBatch(DOModel model, String scope, String datasource, List<BaseData> list) public void createBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{ {
List<BaseData> batch=new ArrayList<>(); List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
list.forEach(et->{ list.forEach(et->{
Serializable key=model.getKeyValue(et,true); Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
...@@ -61,13 +75,13 @@ public class DbDataServiceImpl implements IDataService { ...@@ -61,13 +75,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et); batch.add(et);
if(batch.size()>=BATCH_SIZE) if(batch.size()>=BATCH_SIZE)
{ {
dbDataMapper.insertBathData(poSchema,batch); dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
}); });
if(batch.size()>=0) if(batch.size()>=0)
{ {
dbDataMapper.insertBathData(poSchema,batch); dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
} }
...@@ -78,7 +92,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -78,7 +92,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false); Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
dbDataMapper.updateData(model.getPOSchema(datasource),et); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.updateData(link.getName(),poSchema,et);
et.setAll(get(model,scope,datasource,(Serializable)key)); et.setAll(get(model,scope,datasource,(Serializable)key));
return true; return true;
} }
...@@ -87,7 +104,9 @@ public class DbDataServiceImpl implements IDataService { ...@@ -87,7 +104,9 @@ public class DbDataServiceImpl implements IDataService {
public void updateBatch(DOModel model, String scope, String datasource, List<BaseData> list) public void updateBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{ {
List<BaseData> batch=new ArrayList<>(); List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
list.forEach(et->{ list.forEach(et->{
Serializable key=model.getKeyValue(et,false); Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
...@@ -95,13 +114,13 @@ public class DbDataServiceImpl implements IDataService { ...@@ -95,13 +114,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et); batch.add(et);
if(batch.size()>=BATCH_SIZE) if(batch.size()>=BATCH_SIZE)
{ {
dbDataMapper.updateBathData(poSchema,batch); dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
}); });
if(batch.size()>=0) if(batch.size()>=0)
{ {
dbDataMapper.updateBathData(poSchema,batch); dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
} }
...@@ -114,7 +133,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -114,7 +133,10 @@ public class DbDataServiceImpl implements IDataService {
BaseData et = model.newData(key); BaseData et = model.newData(key);
if(et==null) if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
dbDataMapper.removeData(model.getPOSchema(datasource),et); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.removeData(link.getName(),poSchema,et);
return true; return true;
} }
...@@ -122,7 +144,9 @@ public class DbDataServiceImpl implements IDataService { ...@@ -122,7 +144,9 @@ public class DbDataServiceImpl implements IDataService {
public void removeBatch(DOModel model, String scope, String datasource, List<Serializable> idList) public void removeBatch(DOModel model, String scope, String datasource, List<Serializable> idList)
{ {
List<BaseData> batch=new ArrayList<>(); List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
idList.forEach(key->{ idList.forEach(key->{
BaseData et = model.newData(key); BaseData et = model.newData(key);
if(et==null) if(et==null)
...@@ -130,13 +154,13 @@ public class DbDataServiceImpl implements IDataService { ...@@ -130,13 +154,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et); batch.add(et);
if(batch.size()>=BATCH_SIZE) if(batch.size()>=BATCH_SIZE)
{ {
dbDataMapper.removeBathData(poSchema,batch); dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
}); });
if(batch.size()>=0) if(batch.size()>=0)
{ {
dbDataMapper.removeBathData(poSchema,batch); dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear(); batch.clear();
} }
} }
...@@ -147,8 +171,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -147,8 +171,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false); Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
dbDataMapper.removeData(poSchema,et); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
dbDataMapper.removeData(link.getName(),poSchema,et);
return true; return true;
} }
...@@ -160,8 +186,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -160,8 +186,10 @@ public class DbDataServiceImpl implements IDataService {
BaseData et = model.newData(key); BaseData et = model.newData(key);
if(et==null) if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
List<BaseData> list=dbDataMapper.getData(poSchema,et); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1) if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString()); throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0)); return poSchema.trans(list.get(0));
...@@ -172,7 +200,9 @@ public class DbDataServiceImpl implements IDataService { ...@@ -172,7 +200,9 @@ public class DbDataServiceImpl implements IDataService {
{ {
List<BaseData> rt=new ArrayList<>(); List<BaseData> rt=new ArrayList<>();
List<BaseData> batch=new ArrayList<>(); List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
idList.forEach(key->{ idList.forEach(key->{
BaseData et = model.newData(key); BaseData et = model.newData(key);
if(et==null) if(et==null)
...@@ -180,13 +210,13 @@ public class DbDataServiceImpl implements IDataService { ...@@ -180,13 +210,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et); batch.add(et);
if(batch.size()>=BATCH_SIZE) if(batch.size()>=BATCH_SIZE)
{ {
rt.addAll(dbDataMapper.getBatchData(poSchema,batch)); rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear(); batch.clear();
} }
}); });
if(batch.size()>=0) if(batch.size()>=0)
{ {
rt.addAll(dbDataMapper.getBatchData(poSchema,batch)); rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear(); batch.clear();
} }
return rt; return rt;
...@@ -198,8 +228,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -198,8 +228,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false); Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null); throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
List<BaseData> list=dbDataMapper.getData(poSchema,et); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
List<BaseData> list=dbDataMapper.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1) if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString()); throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0)); return poSchema.trans(list.get(0));
...@@ -218,7 +250,10 @@ public class DbDataServiceImpl implements IDataService { ...@@ -218,7 +250,10 @@ public class DbDataServiceImpl implements IDataService {
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
return false; return false;
int cnt=dbDataMapper.countData(model.getPOSchema(datasource),et); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
int cnt=dbDataMapper.countData(link.getName(),poSchema,et);
return cnt==1; return cnt==1;
} }
...@@ -237,7 +272,9 @@ public class DbDataServiceImpl implements IDataService { ...@@ -237,7 +272,9 @@ public class DbDataServiceImpl implements IDataService {
List<BaseData> rt=new ArrayList<>(); List<BaseData> rt=new ArrayList<>();
List<BaseData> batch=new ArrayList<>(); List<BaseData> batch=new ArrayList<>();
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
list.forEach(et->{ list.forEach(et->{
Serializable key=model.getKeyValue(et,true); Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key)) if(ObjectUtils.isEmpty(key))
...@@ -245,13 +282,13 @@ public class DbDataServiceImpl implements IDataService { ...@@ -245,13 +282,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et); batch.add(et);
if(batch.size()>=BATCH_SIZE) if(batch.size()>=BATCH_SIZE)
{ {
rt.addAll(dbDataMapper.getBatchKey(poSchema,batch)); rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear(); batch.clear();
} }
}); });
if(batch.size()>=0) if(batch.size()>=0)
{ {
rt.addAll(dbDataMapper.getBatchKey(poSchema,batch)); rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear(); batch.clear();
} }
Map<Serializable,Integer> keys=new LinkedHashMap<>(); Map<Serializable,Integer> keys=new LinkedHashMap<>();
...@@ -281,73 +318,89 @@ public class DbDataServiceImpl implements IDataService { ...@@ -281,73 +318,89 @@ public class DbDataServiceImpl implements IDataService {
@Override @Override
public List<BaseData> select(DOModel model, String scope, String datasource, BaseData et) public List<BaseData> select(DOModel model, String scope, String datasource, BaseData et)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return dbDataMapper.selectData(poSchema,et); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.selectData(link.getName(),poSchema,et);
} }
@Override @Override
public Page<BaseData> select(DOModel model, String scope, String datasource, BaseData et, Pageable pageable) public Page<BaseData> select(DOModel model, String scope, String datasource, BaseData et, Pageable pageable)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=dbDataMapper.selectData(poSchema,et,FilterData.getPages(poSchema,pageable)); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=dbDataMapper.selectData(link.getName(),poSchema,et,FilterData.getPages(poSchema,pageable));
return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal()); return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal());
} }
@Override @Override
public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context) public List<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
context.setPOSchema(poSchema); context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond()); return dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond());
} }
@Override @Override
public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable) public Page<BaseData> query(DOModel model, String scope, String datasource, String dataQuery, FilterData context, Pageable pageable)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
context.setPOSchema(poSchema); context.setPOSchema(poSchema);
if(pageable!=null) if(pageable!=null)
context.setPageable(pageable); context.setPageable(pageable);
else else
pageable=context.getPageable(); pageable=context.getPageable();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages= com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=
dbDataMapper.queryData(poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond(),context.getPages()); dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-dq-"+dataQuery+"-"),context,context.getSearchCond(),context.getPages());
return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal()); return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal());
} }
@Override @Override
public List<BaseData> selectRaw(DOModel model, String scope, String datasource, String sql, FilterData context) public List<BaseData> selectRaw(DOModel model, String scope, String datasource, String sql, FilterData context)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return dbDataMapper.queryData(poSchema,sql,context,context.getSearchCond()); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.queryData(link.getName(),poSchema,sql,context,context.getSearchCond());
} }
@Override @Override
public boolean execRaw(DOModel model, String scope, String datasource, String sql, BaseData param) public boolean execRaw(DOModel model, String scope, String datasource, String sql, BaseData param)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
return dbDataMapper.executeRaw(poSchema,sql,param); DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.executeRaw(link.getName(),poSchema,sql,param);
} }
@Override @Override
public List<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context) public List<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
context.setPOSchema(poSchema); context.setPOSchema(poSchema);
return dbDataMapper.queryData(poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond()); return dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond());
} }
@Override @Override
public Page<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context, Pageable pageable) public Page<BaseData> fetch(DOModel model, String scope, String datasource, String dataSet, FilterData context, Pageable pageable)
{ {
POSchema poSchema=model.getPOSchema(datasource); if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
context.setPOSchema(poSchema); context.setPOSchema(poSchema);
if(pageable!=null) if(pageable!=null)
context.setPageable(pageable); context.setPageable(pageable);
else else
pageable=context.getPageable(); pageable=context.getPageable();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages= com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=
dbDataMapper.queryData(poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond(),context.getPages()); dbDataMapper.queryData(link.getName(),poSchema,context.getSql("-ds-"+dataSet+"-"),context,context.getSearchCond(),context.getPages());
return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal()); return new PageImpl<BaseData>(pages.getRecords(), pageable, pages.getTotal());
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册