|
@@ -1,6 +1,7 @@
|
|
|
package org.springblade.resouces;
|
|
|
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.cube.model.*;
|
|
@@ -59,34 +60,40 @@ public class AppCopyService {
|
|
|
@Resource
|
|
|
private AppClient appClient;
|
|
|
@Async
|
|
|
- public boolean copy(List<Integer> cubeIds, List<Integer> dsIds, String appId, PlatomixAppCopyLogModel platomixAppCopyLogModel) {
|
|
|
+ public void copy(List<Integer> cubeIds, List<Integer> dsIds, String appId, PlatomixAppCopyLogModel platomixAppCopyLogModel) {
|
|
|
|
|
|
try {
|
|
|
long start = System.currentTimeMillis();
|
|
|
copyCube(cubeIds, appId);
|
|
|
+ platomixAppCopyLogModel.setCubeResult(0);
|
|
|
+ appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
System.out.println("copyCube 时长=" + (start - System.currentTimeMillis()));
|
|
|
} catch (Exception e) {
|
|
|
platomixAppCopyLogModel.setCubeResult(1);
|
|
|
platomixAppCopyLogModel.setErrorInfo(ExceptionUtil.stacktraceToString(e));
|
|
|
appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
- return false;
|
|
|
+ log.error("copyCube复制失败:"+ExceptionUtil.stacktraceToString(e));
|
|
|
}
|
|
|
try {
|
|
|
long start1 = System.currentTimeMillis();
|
|
|
copyDs(dsIds, appId, platomixAppCopyLogModel);
|
|
|
+ platomixAppCopyLogModel.setDsResult(0);
|
|
|
+ appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
System.out.println("start1 时长=" + (start1 - System.currentTimeMillis()));
|
|
|
} catch (Exception e) {
|
|
|
platomixAppCopyLogModel.setDsResult(1);
|
|
|
platomixAppCopyLogModel.setErrorInfo(ExceptionUtil.stacktraceToString(e));
|
|
|
appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
- return false;
|
|
|
+ log.error("数据源 复制失败:"+ExceptionUtil.stacktraceToString(e));
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
private void copyDs(List<Integer> dsIds, String appId, PlatomixAppCopyLogModel platomixAppCopyLogModel) {
|
|
|
- List<ReportDatasource> list = reportDatasourceService.lambdaQuery().in(ReportDatasource::getDsId, dsIds).list();
|
|
|
+ List<ReportDatasource> list = reportDatasourceService.lambdaQuery()
|
|
|
+ .in(ReportDatasource::getDsId, dsIds)
|
|
|
+ .eq(ReportDatasource::getAppId,appId)
|
|
|
+ .list();
|
|
|
List<Integer> collect = list.stream().map(ReportDatasource::getDsId).collect(Collectors.toList());
|
|
|
if (!list.isEmpty()) {
|
|
|
List<Integer> newIds = new ArrayList<>();
|
|
@@ -98,7 +105,13 @@ public class AppCopyService {
|
|
|
}
|
|
|
dsIds = newIds;
|
|
|
}
|
|
|
+
|
|
|
long start1 = System.currentTimeMillis();
|
|
|
+ if (dsIds.isEmpty()){
|
|
|
+ platomixAppCopyLogModel.setDbResult(0);
|
|
|
+ appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!reportDatasourceService(dsIds, appId, platomixAppCopyLogModel)) {
|
|
|
return;
|
|
|
}
|
|
@@ -184,11 +197,16 @@ public class AppCopyService {
|
|
|
List<ReportDatasource> list = reportDatasourceService.lambdaQuery().in(ReportDatasource::getDsId, dsIds).list();
|
|
|
List<ReportDatasource> copy = null;
|
|
|
try {
|
|
|
+ String jsonStr = JSONUtil.toJsonStr(list);
|
|
|
+ System.out.println("数据库复制参数"+jsonStr);
|
|
|
copy = dsHandler.copy(list);
|
|
|
+ platomixAppCopyLogModel.setDbResult(0);
|
|
|
+ appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
} catch (Exception e) {
|
|
|
- platomixAppCopyLogModel.setDsResult(1);
|
|
|
+ platomixAppCopyLogModel.setDbResult(1);
|
|
|
platomixAppCopyLogModel.setErrorInfo(ExceptionUtil.stacktraceToString(e));
|
|
|
appClient.taskInfo(platomixAppCopyLogModel);
|
|
|
+ log.error("数据库 复制失败:"+ExceptionUtil.stacktraceToString(e));
|
|
|
return false;
|
|
|
}
|
|
|
for (ReportDatasource obj : copy) {
|
|
@@ -203,7 +221,10 @@ public class AppCopyService {
|
|
|
}
|
|
|
|
|
|
private void copyCube(List<Integer> ids, String appId) {
|
|
|
- List<CubeData> list = cubeDataService.lambdaQuery().in(CubeData::getCubeId, ids).eq(CubeData::getAppId, appId).list();
|
|
|
+ List<CubeData> list = cubeDataService.lambdaQuery()
|
|
|
+ .in(CubeData::getCubeId, ids)
|
|
|
+ .eq(CubeData::getAppId, appId)
|
|
|
+ .list();
|
|
|
List<Integer> collect = list.stream().map(CubeData::getCubeId).collect(Collectors.toList());
|
|
|
if (!list.isEmpty()) {
|
|
|
List<Integer> newIds = new ArrayList<>();
|
|
@@ -215,6 +236,9 @@ public class AppCopyService {
|
|
|
}
|
|
|
ids = newIds;
|
|
|
}
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
cubeDataService(ids, appId);
|
|
|
cubeDataPermissionService(ids, appId);
|
|
|
cubeTableColumnService(ids, appId);
|
|
@@ -237,6 +261,7 @@ public class AppCopyService {
|
|
|
for (CubeTableColumn obj : list) {
|
|
|
obj.setId(null);
|
|
|
obj.setAppId(appId);
|
|
|
+ obj.setCubeTableColumnId(SnowFlowIntUtil.nextId());
|
|
|
cubeTableColumnService.save(obj);
|
|
|
}
|
|
|
}
|