提交 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,22 +14,31 @@
<description>Ibzdata Core</description>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<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,7 +83,24 @@
</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>
<groupId>org.jbpm</groupId>
......@@ -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,18 +67,26 @@ public class ModelService {
{
Map<String,DstSystemModel> models=dynamicService.findAllDynamicModel();
List<DstSystemModel> liteSystems=liteService.getSysApps();
if(!ObjectUtils.isEmpty(liteSystems))
try
{
liteSystems.forEach(dstSystemModel->{
String system=dstSystemModel.getPssystemid();
if(!models.containsKey(system))
models.put(system, dstSystemModel);
if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase())))
models.put(system.toLowerCase(), dstSystemModel);
});
List<DstSystemModel> liteSystems=liteService.getSysApps();
if(!ObjectUtils.isEmpty(liteSystems))
{
liteSystems.forEach(dstSystemModel->{
String system=dstSystemModel.getPssystemid();
if(!models.containsKey(system))
models.put(system, dstSystemModel);
if ((!system.toLowerCase().equals(system))&&(!models.containsKey(system.toLowerCase())))
models.put(system.toLowerCase(), dstSystemModel);
});
}
}
catch (Exception ex)
{
log.error("dst接口访问异常",ex);
}
File modelDir=new File(getModelPath());
if(modelDir.exists())
{
......@@ -115,30 +123,37 @@ public class ModelService {
entities.put(entity.getKey(),id);
});
List<MetaEntityModel> liteEntities=liteService.getEntityModel(system);
if(!ObjectUtils.isEmpty(liteEntities))
try{
List<MetaEntityModel> liteEntities=liteService.getEntityModel(system);
if(!ObjectUtils.isEmpty(liteEntities))
{
liteEntities.forEach(metaEntityModel->{
String id=metaEntityModel.getSystemId().concat(".domain.").concat(metaEntityModel.getEntityName());
if(!entities.containsKey(metaEntityModel.getCodeName()))
entities.put(metaEntityModel.getCodeName(),id);
if(!entities.containsKey(metaEntityModel.getCodeName().toLowerCase()))
entities.put(metaEntityModel.getCodeName().toLowerCase(),id);
if(!entities.containsKey(metaEntityModel.getEntityName())) {
entities.put(metaEntityModel.getEntityName(), id);
}
if(!entities.containsKey(metaEntityModel.getEntityName().toLowerCase())) {
entities.put(metaEntityModel.getEntityName().toLowerCase(), id);
}
String pluralize= Inflector.getInstance().pluralize(metaEntityModel.getCodeName()).toLowerCase();
if(!entities.containsKey(pluralize)) {
entities.put(pluralize, id);
}
});
}
}
catch (Exception ex)
{
liteEntities.forEach(metaEntityModel->{
String id=metaEntityModel.getSystemId().concat(".domain.").concat(metaEntityModel.getEntityName());
if(!entities.containsKey(metaEntityModel.getCodeName()))
entities.put(metaEntityModel.getCodeName(),id);
if(!entities.containsKey(metaEntityModel.getCodeName().toLowerCase()))
entities.put(metaEntityModel.getCodeName().toLowerCase(),id);
if(!entities.containsKey(metaEntityModel.getEntityName())) {
entities.put(metaEntityModel.getEntityName(), id);
}
if(!entities.containsKey(metaEntityModel.getEntityName().toLowerCase())) {
entities.put(metaEntityModel.getEntityName().toLowerCase(), id);
}
String pluralize= Inflector.getInstance().pluralize(metaEntityModel.getCodeName()).toLowerCase();
if(!entities.containsKey(pluralize)) {
entities.put(pluralize, id);
}
});
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"));
}
......
package cn.ibizlab.core.data.service.impl;
import java.io.File;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.math.BigInteger;
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.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.creator.DataSourceCreator;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
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;
......@@ -53,23 +45,23 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Lazy
private DSSettingServiceImpl proxy;
public Map<String,DSLinkConfig> getAllConfigs()
public Map<String, DSLink> getAllConfigs()
{
Path path = Paths.get(LiteStorage.MODEL_PATH,"DATASOURCE.json");
try {
Map<String,DSLinkConfig> all=new HashMap<>();
Map<String, DSLink> all=new LinkedHashMap<>();
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
{
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->{
String id=item.getKey();
DSLinkConfig config=item.getValue();
DSLink config=item.getValue();
config.setName(id);
if(!all.containsKey(id))
all.put(id,config);
......@@ -96,23 +88,29 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Override
public boolean create(DSSetting et) {
//代码实现
return true;
return this.save(et);
}
public void createBatch(List<DSSetting> list){
list.forEach(et->create(et));
}
@Override
public boolean update(DSSetting et) {
//代码实现
this.save(et);
synchronized (lock)
{
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
if (check.containsKey(et.getDsId()))
{
if(et.isDatabase())
if(et.isDatabase()) {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
ds.removeDataSource(et.getDsId());
}
check.remove(et.getDsId());
}
if (!et.getDsId().equals(et.getDsId().toLowerCase()))
......@@ -130,29 +128,80 @@ public class DSSettingServiceImpl implements IDSSettingService {
}
buildDS(et);
return true;
}
public void updateBatch(List<DSSetting> list){
list.forEach(et->update(et));
}
@Override
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;
}
public void removeBatch(Collection<String> idList){
idList.forEach(id->{
remove(id);
});
}
@Override
public DSSetting get(String key) {
DSSetting et = new DSSetting();
Map<String,DSLinkConfig> allConfigs=proxy.getAllConfigs();
Map<String, DSLink> allConfigs=proxy.getAllConfigs();
if(allConfigs.containsKey(key))
et.setDSLinkConfig(allConfigs.get(key));
else
throw new BadRequestAlertException("未找到数据源配置信息","DSSetting",key);
return null;
return et;
}
......@@ -169,19 +218,41 @@ public class DSSettingServiceImpl implements IDSSettingService {
@Transactional
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;
}
@Override
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();
public DSSetting initDataSource(String tag)
public DSLink getDataSource(String tag)
{
if(StringUtils.isEmpty(tag))
return DSLink.getDefaultLink();
if (check.containsKey(tag))
return check.get(tag);
......@@ -191,11 +262,16 @@ public class DSSettingServiceImpl implements IDSSettingService {
if (check.containsKey(tag))
return check.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()))
return check.get(dstDataSource.getDsId());
}
return buildDS(dstDataSource);
return buildDS(dstDataSource).getDSLinkConfig();
}
public DSSetting buildDS(DSSetting dstDataSource) {
......@@ -210,15 +286,15 @@ public class DSSettingServiceImpl implements IDSSettingService {
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dstDataSource.getDsId(), dataSource);
}
check.put(dstDataSource.getDsId(), dstDataSource);
check.put(dstDataSource.getDsId(), dstDataSource.getDSLinkConfig());
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()))
{
dstDataSource.getUsings().forEach(using->{
check.put(using, dstDataSource);
check.put(using, dstDataSource.getDSLinkConfig());
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 {
*/
@Override
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;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.*;
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.service.IDSSettingService;
import cn.ibizlab.core.data.service.IDataService;
import cn.ibizlab.core.data.service.ModelService;
import cn.ibizlab.util.errors.BadRequestAlertException;
......@@ -15,6 +17,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.*;
......@@ -32,6 +35,10 @@ public class DbDataServiceImpl implements IDataService {
@Autowired
private DbDataMapper dbDataMapper;
@Autowired
private IDSSettingService dsSettingService;
@Override
public ResponseData call(DOModel model, String scope, String datasource, String method, RequestData requestData)
{
......@@ -44,7 +51,12 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
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));
return true;
}
......@@ -53,7 +65,9 @@ public class DbDataServiceImpl implements IDataService {
public void createBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{
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->{
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
......@@ -61,13 +75,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.insertBathData(poSchema,batch);
dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.insertBathData(poSchema,batch);
dbDataMapper.insertBathData(link.getName(),poSchema,batch);
batch.clear();
}
}
......@@ -78,7 +92,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
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));
return true;
}
......@@ -87,7 +104,9 @@ public class DbDataServiceImpl implements IDataService {
public void updateBatch(DOModel model, String scope, String datasource, List<BaseData> list)
{
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->{
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
......@@ -95,13 +114,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.updateBathData(poSchema,batch);
dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.updateBathData(poSchema,batch);
dbDataMapper.updateBathData(link.getName(),poSchema,batch);
batch.clear();
}
}
......@@ -114,7 +133,10 @@ public class DbDataServiceImpl implements IDataService {
BaseData et = model.newData(key);
if(et==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;
}
......@@ -122,7 +144,9 @@ public class DbDataServiceImpl implements IDataService {
public void removeBatch(DOModel model, String scope, String datasource, List<Serializable> idList)
{
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->{
BaseData et = model.newData(key);
if(et==null)
......@@ -130,13 +154,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
dbDataMapper.removeBathData(poSchema,batch);
dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear();
}
});
if(batch.size()>=0)
{
dbDataMapper.removeBathData(poSchema,batch);
dbDataMapper.removeBathData(link.getName(),poSchema,batch);
batch.clear();
}
}
......@@ -147,8 +171,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource);
dbDataMapper.removeData(poSchema,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;
}
......@@ -160,8 +186,10 @@ public class DbDataServiceImpl implements IDataService {
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource);
List<BaseData> list=dbDataMapper.getData(poSchema,et);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
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)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0));
......@@ -172,7 +200,9 @@ public class DbDataServiceImpl implements IDataService {
{
List<BaseData> rt=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->{
BaseData et = model.newData(key);
if(et==null)
......@@ -180,13 +210,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
rt.addAll(dbDataMapper.getBatchData(poSchema,batch));
rt.addAll(dbDataMapper.getBatchData(link.getName(),poSchema,batch));
batch.clear();
}
return rt;
......@@ -198,8 +228,10 @@ public class DbDataServiceImpl implements IDataService {
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
POSchema poSchema=model.getPOSchema(datasource);
List<BaseData> list=dbDataMapper.getData(poSchema,et);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
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)
throw new BadRequestAlertException("未找到数据",model.getName(),key.toString());
return poSchema.trans(list.get(0));
......@@ -218,7 +250,10 @@ public class DbDataServiceImpl implements IDataService {
if(ObjectUtils.isEmpty(key))
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;
}
......@@ -237,7 +272,9 @@ public class DbDataServiceImpl implements IDataService {
List<BaseData> rt=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->{
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
......@@ -245,13 +282,13 @@ public class DbDataServiceImpl implements IDataService {
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
rt.addAll(dbDataMapper.getBatchKey(poSchema,batch));
rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear();
}
});
if(batch.size()>=0)
{
rt.addAll(dbDataMapper.getBatchKey(poSchema,batch));
rt.addAll(dbDataMapper.getBatchKey(link.getName(),poSchema,batch));
batch.clear();
}
Map<Serializable,Integer> keys=new LinkedHashMap<>();
......@@ -281,73 +318,89 @@ public class DbDataServiceImpl implements IDataService {
@Override
public List<BaseData> select(DOModel model, String scope, String datasource, BaseData et)
{
POSchema poSchema=model.getPOSchema(datasource);
return dbDataMapper.selectData(poSchema,et);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.selectData(link.getName(),poSchema,et);
}
@Override
public Page<BaseData> select(DOModel model, String scope, String datasource, BaseData et, Pageable pageable)
{
POSchema poSchema=model.getPOSchema(datasource);
com.baomidou.mybatisplus.extension.plugins.pagination.Page<BaseData> pages=dbDataMapper.selectData(poSchema,et,FilterData.getPages(poSchema,pageable));
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
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());
}
@Override
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);
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
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);
if(pageable!=null)
context.setPageable(pageable);
else
pageable=context.getPageable();
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());
}
@Override
public List<BaseData> selectRaw(DOModel model, String scope, String datasource, String sql, FilterData context)
{
POSchema poSchema=model.getPOSchema(datasource);
return dbDataMapper.queryData(poSchema,sql,context,context.getSearchCond());
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.queryData(link.getName(),poSchema,sql,context,context.getSearchCond());
}
@Override
public boolean execRaw(DOModel model, String scope, String datasource, String sql, BaseData param)
{
POSchema poSchema=model.getPOSchema(datasource);
return dbDataMapper.executeRaw(poSchema,sql,param);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink link=dsSettingService.getDataSource(datasource);
POSchema poSchema=model.getPOSchema(link.getType());
return dbDataMapper.executeRaw(link.getName(),poSchema,sql,param);
}
@Override
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);
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
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);
if(pageable!=null)
context.setPageable(pageable);
else
pageable=context.getPageable();
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());
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册