|
|
@@ -3,6 +3,7 @@ package com.usoftchina.saas.dc.snapshot.support;
|
|
|
import com.usoftchina.saas.dc.mapper.CommonMapper;
|
|
|
import com.usoftchina.saas.dc.mapper.SchemaMapper;
|
|
|
import com.usoftchina.saas.dc.po.DataSourceInfo;
|
|
|
+import com.usoftchina.saas.dc.po.SchemaInfo;
|
|
|
import com.usoftchina.saas.dc.po.Snapshot;
|
|
|
import com.usoftchina.saas.dc.po.SnapshotData;
|
|
|
import com.usoftchina.saas.dc.repository.SnapshotDataRepository;
|
|
|
@@ -41,14 +42,20 @@ public class MysqlStrategy implements CompanyStrategy {
|
|
|
DynamicDataSourceContextHolder.set(ds);
|
|
|
try {
|
|
|
// 查找所有与公司相关表
|
|
|
- List<String> tables = schemaMapper.selectTableNameBySchema(ds.getDbRealName(), COMPANY_ID_COLUMN);
|
|
|
- if (!CollectionUtils.isEmpty(tables)) {
|
|
|
- tables.parallelStream().forEach(table -> {
|
|
|
- // 查找指定表的所有数据
|
|
|
- List<LinkedHashMap<String, Object>> data = commonMapper.select(String.format("select * from %s where %s=%s", table, COMPANY_ID_COLUMN, companyId));
|
|
|
- if (!CollectionUtils.isEmpty(data)) {
|
|
|
- SnapshotData snapshotData = new SnapshotData(snapshot, ds, table, data);
|
|
|
- snapshotDataRepository.save(snapshotData);
|
|
|
+ List<SchemaInfo> schemas = schemaMapper.selectSchemaInfoByColumns(ds.getDbRealName(), COMPANY_ID_COLUMNS);
|
|
|
+ if (!CollectionUtils.isEmpty(schemas)) {
|
|
|
+ schemas.parallelStream().forEach(schema -> {
|
|
|
+ DynamicDataSourceContextHolder.set(ds);
|
|
|
+ try {
|
|
|
+ // 查找指定表的所有数据
|
|
|
+ List<LinkedHashMap<String, Object>> data = commonMapper.selectByTableAndColumnAndValue(
|
|
|
+ schema.getTableName(), schema.getColumnName(), companyId);
|
|
|
+ if (!CollectionUtils.isEmpty(data)) {
|
|
|
+ SnapshotData snapshotData = new SnapshotData(snapshot, ds, schema, data);
|
|
|
+ snapshotDataRepository.save(snapshotData);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ DynamicDataSourceContextHolder.clear();
|
|
|
}
|
|
|
});
|
|
|
}
|