|
@@ -1,12 +1,17 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
|
|
|
+import com.ruoyi.common.constant.HttpStatus;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.domain.entity.DataSource;
|
|
|
import com.ruoyi.common.core.domain.entity.SysTenant;
|
|
|
import com.ruoyi.system.mapper.DataSourceMapper;
|
|
|
import com.ruoyi.system.service.IDataSourceService;
|
|
|
import com.ruoyi.system.service.ISysTenantService;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -19,19 +24,35 @@ public class DataSourceServiceImpl implements IDataSourceService {
|
|
|
@Resource
|
|
|
private ISysTenantService sysTenantService;
|
|
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+ @Value("${parameter.ip.DATA_ENGINE_INITDATABASE_IP}")
|
|
|
+ public String DATA_ENGINE_INITDATABASE_IP;
|
|
|
+
|
|
|
@Override
|
|
|
- public int selectDatabaseExist(String databaseIp, String databaseName, Long portNumber) {
|
|
|
- return dataSourceMapper.selectDatabaseExist(databaseIp,databaseName,portNumber);
|
|
|
+ public int selectDatabaseExist(DataSource dataSource) {
|
|
|
+ return dataSourceMapper.selectDatabaseExist(dataSource);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insertDataSource(DataSource dataSource,Long tenantId) {
|
|
|
+ public AjaxResult insertDataSource(DataSource dataSource,Long tenantId) {
|
|
|
+
|
|
|
+ //调用数据引擎服务初始化数据库接口
|
|
|
+ ResponseEntity<AjaxResult> dataSourceResponseEntity = restTemplate.postForEntity(DATA_ENGINE_INITDATABASE_IP, dataSource, AjaxResult.class);
|
|
|
+ //获取请求状态码
|
|
|
+ int code = (int)dataSourceResponseEntity.getBody().get("code");
|
|
|
+ String msg = (String) dataSourceResponseEntity.getBody().get("msg");
|
|
|
+ if(code == HttpStatus.WARN){
|
|
|
+ return AjaxResult.warn(msg);
|
|
|
+ }
|
|
|
+
|
|
|
dataSourceMapper.insertDataSource(dataSource);
|
|
|
//租户绑定数据源
|
|
|
SysTenant sysTenant = new SysTenant();
|
|
|
sysTenant.setTenantId(tenantId);
|
|
|
sysTenant.setDatasourceId(dataSource.getId());
|
|
|
- return sysTenantService.updateSysTenant(sysTenant);
|
|
|
+ sysTenantService.updateSysTenant(sysTenant);
|
|
|
+ return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
@Override
|