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

提交

上级 2bf598b3
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.domain.DstDataSource;
import cn.ibizlab.util.helper.Setting;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.extensions.service.LiteCoreService;
import cn.ibizlab.core.lite.service.DstLiquibaseService;
import cn.ibizlab.core.lite.service.impl.DstDataSourceServiceImpl;
import cn.ibizlab.util.domain.LiquibaseProp;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.Setting;
import com.alibaba.fastjson.JSONArray;
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 cn.ibizlab.core.lite.domain.DstDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.*;
/**
* 实体[数据源] 自定义服务对象
......@@ -32,6 +39,12 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
@Resource
public LiteCoreService liteCoreService;
@Resource
public DstLiquibaseService dstLiquibaseService;
/**
* [BuildDS:buildDS] 行为扩展
......@@ -135,5 +148,50 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
return true;
}
@Override
@Transactional
public DstDataSource initDS(DstDataSource et) {
DstDataSource ds = getById(et.getDsId());
if(ObjectUtils.isEmpty(ds)){
throw new BadRequestAlertException("数据源不存在,请检查是否填写正确","","ibzInit");
}
buildDS(ds);
String datasourceMessage = ds.getDsCfg();
if(ObjectUtils.isEmpty(datasourceMessage)){
throw new BadRequestAlertException("数据源不能为空","","ibzInit");
}
List<Setting> settings = JSONArray.parseArray(ds.getDsCfg(), Setting.class);
Map datasourceMap = new HashMap();
settings.forEach(setting -> datasourceMap.put(setting.getProperty(),setting.getValue()));
if(ObjectUtils.isEmpty(datasourceMap.get("username"))){
throw new BadRequestAlertException("数据源用户名不能为空","","ibzInit");
}
if(ObjectUtils.isEmpty(datasourceMap.get("password"))){
throw new BadRequestAlertException("数据源密码不能为空","","ibzInit");
}
if(ObjectUtils.isEmpty(datasourceMap.get("url"))){
throw new BadRequestAlertException("数据源地址不能为空","","ibzInit");
}
if(ObjectUtils.isEmpty(datasourceMap.get("defaultSchema"))){
throw new BadRequestAlertException("数据源默认数据库不能为空","","ibzInit");
}
if(ObjectUtils.isEmpty(datasourceMap.get("defaultSystemId"))){
throw new BadRequestAlertException("逆向工程归属系统为空","","ibzInit");
}
LiquibaseProp lp = new LiquibaseProp();
lp.setUsername(datasourceMap.get("username").toString());
lp.setPassword(datasourceMap.get("password").toString());
lp.setUrl(datasourceMap.get("url").toString());
lp.setDefaultSchema(datasourceMap.get("defaultSchema").toString());
// 调用liquibase逆向工程的逻辑,生成一个xml,并返回一个SysModel对象
SysModel sysModel = dstLiquibaseService.generateLiquibase(lp,datasourceMap.get("defaultSystemId").toString());
liteCoreService.syncSysModel(sysModel,1);
return et;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册