|
@@ -3,7 +3,6 @@ package com.fs.tenant.dict.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
import com.fs.common.core.domain.entity.SysDictData;
|
|
|
import com.fs.common.core.domain.entity.SysDictType;
|
|
import com.fs.common.core.domain.entity.SysDictType;
|
|
|
-import com.fs.common.enums.DataSourceType;
|
|
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.system.mapper.SysDictDataMapper;
|
|
import com.fs.system.mapper.SysDictDataMapper;
|
|
@@ -15,6 +14,7 @@ import com.fs.tenant.dict.domain.TenantDictTemplateType;
|
|
|
import com.fs.tenant.dict.dto.TenantDictSyncRunReq;
|
|
import com.fs.tenant.dict.dto.TenantDictSyncRunReq;
|
|
|
import com.fs.tenant.dict.service.TenantDictSyncService;
|
|
import com.fs.tenant.dict.service.TenantDictSyncService;
|
|
|
import com.fs.tenant.dict.service.TenantDictTemplateService;
|
|
import com.fs.tenant.dict.service.TenantDictTemplateService;
|
|
|
|
|
+import com.fs.tenant.dict.vo.TenantDictSyncInitVo;
|
|
|
import com.fs.tenant.dict.vo.TenantDictSyncResultVo;
|
|
import com.fs.tenant.dict.vo.TenantDictSyncResultVo;
|
|
|
import com.fs.tenant.dict.vo.TenantDictSyncTaskDetailVo;
|
|
import com.fs.tenant.dict.vo.TenantDictSyncTaskDetailVo;
|
|
|
import com.fs.tenant.dict.vo.TenantDictSyncTaskVo;
|
|
import com.fs.tenant.dict.vo.TenantDictSyncTaskVo;
|
|
@@ -28,11 +28,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 租户字典同步引擎:模板 → 租户库,支持 APPEND / MERGE / OVERWRITE。
|
|
* 租户字典同步引擎:模板 → 租户库,支持 APPEND / MERGE / OVERWRITE。
|
|
|
|
|
+ * 数据源切换由接口层负责。
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
@@ -53,181 +53,126 @@ public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Map<String, Object> runSync(TenantDictSyncRunReq req, String triggerBy) {
|
|
|
|
|
-// validateSyncReq(req);
|
|
|
|
|
-// List<TenantDictTemplateType> templateTypes = resolveTemplateTypes(req.getDictTypes());
|
|
|
|
|
-// if (templateTypes.isEmpty()) {
|
|
|
|
|
-// throw new CustomException("没有可同步的模板字典类型,请先在平台模板中维护");
|
|
|
|
|
-// }
|
|
|
|
|
-// List<TenantInfo> tenants = resolveTenants(req);
|
|
|
|
|
-// if (tenants.isEmpty()) {
|
|
|
|
|
-// throw new CustomException("未匹配到可同步租户");
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// if (Boolean.TRUE.equals(req.getDryRun())) {
|
|
|
|
|
-// List<TenantDictSyncResultVo> preview = new ArrayList<>();
|
|
|
|
|
-// for (TenantInfo tenant : tenants) {
|
|
|
|
|
-// preview.add(previewOneTenant(tenant, templateTypes, req.getSyncMode()));
|
|
|
|
|
-// }
|
|
|
|
|
-// Map<String, Object> resp = new HashMap<>();
|
|
|
|
|
-// resp.put("dryRun", true);
|
|
|
|
|
-// resp.put("preview", preview);
|
|
|
|
|
-// return resp;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// String taskNo = buildTaskNo();
|
|
|
|
|
-// contextHelper.runInMaster(() -> {
|
|
|
|
|
-// initMasterTaskTables();
|
|
|
|
|
-// insertTask(taskNo, req, tenants.size(), triggerBy);
|
|
|
|
|
-// });
|
|
|
|
|
-//
|
|
|
|
|
-// CompletableFuture.runAsync(() -> executeSyncTask(taskNo, req, tenants, templateTypes));
|
|
|
|
|
-//
|
|
|
|
|
-// Map<String, Object> resp = new HashMap<>();
|
|
|
|
|
-// resp.put("taskNo", taskNo);
|
|
|
|
|
-// resp.put("status", TenantDictConstants.TASK_RUNNING);
|
|
|
|
|
-// resp.put("totalTenants", tenants.size());
|
|
|
|
|
-// resp.put("syncMode", req.getSyncMode());
|
|
|
|
|
-// return resp;
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public TenantDictSyncInitVo initSync(TenantDictSyncRunReq req, String triggerBy) {
|
|
|
|
|
+ validateSyncReq(req);
|
|
|
|
|
+ List<TenantDictTemplateType> templateTypes = resolveTemplateTypes(req.getDictTypes());
|
|
|
|
|
+ if (templateTypes.isEmpty()) {
|
|
|
|
|
+ throw new CustomException("没有可同步的模板字典类型,请先在平台模板中维护");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<TenantInfo> tenants = resolveTenants(req);
|
|
|
|
|
+ if (tenants.isEmpty()) {
|
|
|
|
|
+ throw new CustomException("未匹配到可同步租户");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public TenantDictSyncTaskVo getTask(String taskNo) {
|
|
|
|
|
-// return contextHelper.executeInMaster(() -> {
|
|
|
|
|
-// initMasterTaskTables();
|
|
|
|
|
-// List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
|
|
|
|
-// "SELECT task_no,sync_mode,scope_type,dict_types,total_tenants,success_tenants,failed_tenants,status,trigger_by,started_at,finished_at " +
|
|
|
|
|
-// "FROM tenant_dict_sync_task WHERE task_no=?", taskNo);
|
|
|
|
|
-// if (rows.isEmpty()) {
|
|
|
|
|
-// return null;
|
|
|
|
|
-// }
|
|
|
|
|
-// Map<String, Object> row = rows.get(0);
|
|
|
|
|
-// TenantDictSyncTaskVo vo = new TenantDictSyncTaskVo();
|
|
|
|
|
-// vo.setTaskNo(str(row.get("task_no")));
|
|
|
|
|
-// vo.setSyncMode(str(row.get("sync_mode")));
|
|
|
|
|
-// vo.setScopeType(str(row.get("scope_type")));
|
|
|
|
|
-// vo.setDictTypes(str(row.get("dict_types")));
|
|
|
|
|
-// vo.setTotalTenants(intVal(row.get("total_tenants")));
|
|
|
|
|
-// vo.setSuccessTenants(intVal(row.get("success_tenants")));
|
|
|
|
|
-// vo.setFailedTenants(intVal(row.get("failed_tenants")));
|
|
|
|
|
-// vo.setStatus(str(row.get("status")));
|
|
|
|
|
-// vo.setTriggerBy(str(row.get("trigger_by")));
|
|
|
|
|
-// vo.setStartedAt(str(row.get("started_at")));
|
|
|
|
|
-// vo.setFinishedAt(str(row.get("finished_at")));
|
|
|
|
|
-// vo.setDetails(queryTaskDetails(taskNo));
|
|
|
|
|
-// return vo;
|
|
|
|
|
-// });
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ Map<String, List<TenantDictTemplateData>> dataCache = loadTemplateDataCache(templateTypes);
|
|
|
|
|
+
|
|
|
|
|
+ TenantDictSyncInitVo init = new TenantDictSyncInitVo();
|
|
|
|
|
+ init.setDryRun(Boolean.TRUE.equals(req.getDryRun()));
|
|
|
|
|
+ init.setSyncMode(req.getSyncMode());
|
|
|
|
|
+ init.setTenants(tenants);
|
|
|
|
|
+ init.setTemplateTypes(templateTypes);
|
|
|
|
|
+ init.setDataCache(dataCache);
|
|
|
|
|
+
|
|
|
|
|
+ if (!init.isDryRun()) {
|
|
|
|
|
+ initMasterTaskTables();
|
|
|
|
|
+ String taskNo = buildTaskNo();
|
|
|
|
|
+ insertTask(taskNo, req, tenants.size(), triggerBy);
|
|
|
|
|
+ init.setTaskNo(taskNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return init;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<TenantDictSyncResultVo> previewDiff(Long tenantId, List<String> dictTypes) {
|
|
|
|
|
-// TenantInfo tenant = contextHelper.loadActiveTenant(tenantId);
|
|
|
|
|
-// List<TenantDictTemplateType> templateTypes = resolveTemplateTypes(dictTypes);
|
|
|
|
|
-// TenantDictSyncResultVo result = previewOneTenant(tenant, templateTypes, TenantDictConstants.SYNC_MERGE);
|
|
|
|
|
-// return Collections.singletonList(result);
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void executeSyncTask(String taskNo, TenantDictSyncRunReq req, List<TenantInfo> tenants,
|
|
|
|
|
- List<TenantDictTemplateType> templateTypes) {
|
|
|
|
|
- int success = 0;
|
|
|
|
|
- int failed = 0;
|
|
|
|
|
- Map<String, List<TenantDictTemplateData>> dataCache = loadTemplateDataCache(templateTypes);
|
|
|
|
|
-
|
|
|
|
|
- if (Boolean.TRUE.equals(req.getParallel())) {
|
|
|
|
|
- int threads = req.getThreads() == null || req.getThreads() <= 0 ? 4 : req.getThreads();
|
|
|
|
|
- ExecutorService pool = Executors.newFixedThreadPool(threads);
|
|
|
|
|
- try {
|
|
|
|
|
- List<Future<Boolean>> futures = new ArrayList<>();
|
|
|
|
|
- for (TenantInfo tenant : tenants) {
|
|
|
|
|
- futures.add(pool.submit(() -> syncOneTenant(taskNo, tenant, templateTypes, dataCache, req.getSyncMode())));
|
|
|
|
|
- }
|
|
|
|
|
- for (Future<Boolean> f : futures) {
|
|
|
|
|
- try {
|
|
|
|
|
- if (Boolean.TRUE.equals(f.get())) success++;
|
|
|
|
|
- else failed++;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- failed++;
|
|
|
|
|
- log.error("[TenantDictSync] 并行任务异常", e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public TenantDictSyncResultVo previewOneTenant(TenantInfo tenant,
|
|
|
|
|
+ List<TenantDictTemplateType> templateTypes,
|
|
|
|
|
+ Map<String, List<TenantDictTemplateData>> dataCache,
|
|
|
|
|
+ String syncMode) {
|
|
|
|
|
+ TenantDictSyncResultVo stats = new TenantDictSyncResultVo();
|
|
|
|
|
+ stats.setTenantId(tenant.getId());
|
|
|
|
|
+ stats.setTenantCode(tenant.getTenantCode());
|
|
|
|
|
+ stats.setTenantName(tenant.getTenantName());
|
|
|
|
|
+ for (TenantDictTemplateType templateType : templateTypes) {
|
|
|
|
|
+ String mode = resolveMode(syncMode, templateType);
|
|
|
|
|
+ previewType(templateType, mode, stats);
|
|
|
|
|
+ List<TenantDictTemplateData> templateDataList =
|
|
|
|
|
+ dataCache.getOrDefault(templateType.getDictType(), Collections.emptyList());
|
|
|
|
|
+ if (TenantDictConstants.SYNC_OVERWRITE.equals(mode)) {
|
|
|
|
|
+ previewOverwriteData(templateType.getDictType(), templateDataList, stats);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (TenantDictTemplateData templateData : templateDataList) {
|
|
|
|
|
+ previewData(templateData, mode, stats);
|
|
|
}
|
|
}
|
|
|
- } finally {
|
|
|
|
|
- pool.shutdown();
|
|
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- for (TenantInfo tenant : tenants) {
|
|
|
|
|
- if (syncOneTenant(taskNo, tenant, templateTypes, dataCache, req.getSyncMode())) {
|
|
|
|
|
- success++;
|
|
|
|
|
- } else {
|
|
|
|
|
- failed++;
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ stats.setMessage("预览完成(未写入)");
|
|
|
|
|
+ return stats;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TenantDictSyncResultVo syncOneTenant(TenantInfo tenant,
|
|
|
|
|
+ List<TenantDictTemplateType> templateTypes,
|
|
|
|
|
+ Map<String, List<TenantDictTemplateData>> dataCache,
|
|
|
|
|
+ String syncMode) {
|
|
|
|
|
+ TenantDictSyncResultVo stats = new TenantDictSyncResultVo();
|
|
|
|
|
+ stats.setTenantId(tenant.getId());
|
|
|
|
|
+ stats.setTenantCode(tenant.getTenantCode());
|
|
|
|
|
+ stats.setTenantName(tenant.getTenantName());
|
|
|
|
|
+ for (TenantDictTemplateType templateType : templateTypes) {
|
|
|
|
|
+ String mode = resolveMode(syncMode, templateType);
|
|
|
|
|
+ syncType(templateType, mode, stats);
|
|
|
|
|
+ List<TenantDictTemplateData> templateDataList =
|
|
|
|
|
+ dataCache.getOrDefault(templateType.getDictType(), Collections.emptyList());
|
|
|
|
|
+ if (TenantDictConstants.SYNC_OVERWRITE.equals(mode)) {
|
|
|
|
|
+ overwriteData(templateType.getDictType(), templateDataList, stats);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (TenantDictTemplateData templateData : templateDataList) {
|
|
|
|
|
+ syncData(templateData, mode, stats);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- finalizeTask(taskNo, success, failed);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private boolean syncOneTenant(String taskNo, TenantInfo tenant, List<TenantDictTemplateType> templateTypes,
|
|
|
|
|
- Map<String, List<TenantDictTemplateData>> dataCache, String syncMode) {
|
|
|
|
|
-// Date start = new Date();
|
|
|
|
|
-// TenantDictSyncResultVo stats = new TenantDictSyncResultVo();
|
|
|
|
|
-// stats.setTenantId(tenant.getId());
|
|
|
|
|
-// stats.setTenantCode(tenant.getTenantCode());
|
|
|
|
|
-// stats.setTenantName(tenant.getTenantName());
|
|
|
|
|
-// String status = TenantDictConstants.DETAIL_SUCCESS;
|
|
|
|
|
-// String errorMsg = null;
|
|
|
|
|
-// try {
|
|
|
|
|
-// contextHelper.executeInTenant(tenant.getId(), () -> {
|
|
|
|
|
-// for (TenantDictTemplateType templateType : templateTypes) {
|
|
|
|
|
-// String mode = resolveMode(syncMode, templateType);
|
|
|
|
|
-// syncType(templateType, mode, stats);
|
|
|
|
|
-// List<TenantDictTemplateData> templateDataList = dataCache.getOrDefault(templateType.getDictType(), Collections.emptyList());
|
|
|
|
|
-// if (TenantDictConstants.SYNC_OVERWRITE.equals(mode)) {
|
|
|
|
|
-// overwriteData(templateType.getDictType(), templateDataList, stats);
|
|
|
|
|
-// } else {
|
|
|
|
|
-// for (TenantDictTemplateData templateData : templateDataList) {
|
|
|
|
|
-// syncData(templateData, mode, stats);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// dictTypeService.resetDictCache();
|
|
|
|
|
-// return null;
|
|
|
|
|
-// });
|
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
|
-// status = TenantDictConstants.DETAIL_FAILED;
|
|
|
|
|
-// errorMsg = e.getMessage();
|
|
|
|
|
-// log.error("[TenantDictSync] tenantId={} 同步失败", tenant.getId(), e);
|
|
|
|
|
-// }
|
|
|
|
|
-// insertTaskDetail(taskNo, tenant, stats, status, errorMsg, start, new Date());
|
|
|
|
|
-// return TenantDictConstants.DETAIL_SUCCESS.equals(status);
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private TenantDictSyncResultVo previewOneTenant(TenantInfo tenant, List<TenantDictTemplateType> templateTypes, String syncMode) {
|
|
|
|
|
-// Map<String, List<TenantDictTemplateData>> dataCache = loadTemplateDataCache(templateTypes);
|
|
|
|
|
-// TenantDictSyncResultVo stats = new TenantDictSyncResultVo();
|
|
|
|
|
-// stats.setTenantId(tenant.getId());
|
|
|
|
|
-// stats.setTenantCode(tenant.getTenantCode());
|
|
|
|
|
-// stats.setTenantName(tenant.getTenantName());
|
|
|
|
|
-// contextHelper.executeInTenant(tenant.getId(), () -> {
|
|
|
|
|
-// for (TenantDictTemplateType templateType : templateTypes) {
|
|
|
|
|
-// String mode = resolveMode(syncMode, templateType);
|
|
|
|
|
-// previewType(templateType, mode, stats);
|
|
|
|
|
-// List<TenantDictTemplateData> templateDataList = dataCache.getOrDefault(templateType.getDictType(), Collections.emptyList());
|
|
|
|
|
-// if (TenantDictConstants.SYNC_OVERWRITE.equals(mode)) {
|
|
|
|
|
-// previewOverwriteData(templateType.getDictType(), templateDataList, stats);
|
|
|
|
|
-// } else {
|
|
|
|
|
-// for (TenantDictTemplateData templateData : templateDataList) {
|
|
|
|
|
-// previewData(templateData, mode, stats);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// return null;
|
|
|
|
|
-// });
|
|
|
|
|
-// stats.setMessage("预览完成(未写入)");
|
|
|
|
|
-// return stats;
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ dictTypeService.resetDictCache();
|
|
|
|
|
+ return stats;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void recordTaskDetail(String taskNo, TenantInfo tenant, TenantDictSyncResultVo stats,
|
|
|
|
|
+ String status, String errorMsg, Date start, Date end) {
|
|
|
|
|
+ insertTaskDetail(taskNo, tenant, stats, status, errorMsg, start, end);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void finalizeTask(String taskNo, int success, int failed) {
|
|
|
|
|
+ String status = failed == 0 ? TenantDictConstants.TASK_SUCCESS
|
|
|
|
|
+ : (success == 0 ? TenantDictConstants.TASK_FAILED : TenantDictConstants.TASK_PARTIAL);
|
|
|
|
|
+ jdbcTemplate.update(
|
|
|
|
|
+ "UPDATE tenant_dict_sync_task SET success_tenants=?, failed_tenants=?, status=?, finished_at=NOW() WHERE task_no=?",
|
|
|
|
|
+ success, failed, status, taskNo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TenantDictSyncTaskVo getTask(String taskNo) {
|
|
|
|
|
+ initMasterTaskTables();
|
|
|
|
|
+ List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
|
|
|
|
+ "SELECT task_no,sync_mode,scope_type,dict_types,total_tenants,success_tenants,failed_tenants,status,trigger_by,started_at,finished_at " +
|
|
|
|
|
+ "FROM tenant_dict_sync_task WHERE task_no=?", taskNo);
|
|
|
|
|
+ if (rows.isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> row = rows.get(0);
|
|
|
|
|
+ TenantDictSyncTaskVo vo = new TenantDictSyncTaskVo();
|
|
|
|
|
+ vo.setTaskNo(str(row.get("task_no")));
|
|
|
|
|
+ vo.setSyncMode(str(row.get("sync_mode")));
|
|
|
|
|
+ vo.setScopeType(str(row.get("scope_type")));
|
|
|
|
|
+ vo.setDictTypes(str(row.get("dict_types")));
|
|
|
|
|
+ vo.setTotalTenants(intVal(row.get("total_tenants")));
|
|
|
|
|
+ vo.setSuccessTenants(intVal(row.get("success_tenants")));
|
|
|
|
|
+ vo.setFailedTenants(intVal(row.get("failed_tenants")));
|
|
|
|
|
+ vo.setStatus(str(row.get("status")));
|
|
|
|
|
+ vo.setTriggerBy(str(row.get("trigger_by")));
|
|
|
|
|
+ vo.setStartedAt(str(row.get("started_at")));
|
|
|
|
|
+ vo.setFinishedAt(str(row.get("finished_at")));
|
|
|
|
|
+ vo.setDetails(queryTaskDetails(taskNo));
|
|
|
|
|
+ return vo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void syncType(TenantDictTemplateType template, String mode, TenantDictSyncResultVo stats) {
|
|
private void syncType(TenantDictTemplateType template, String mode, TenantDictSyncResultVo stats) {
|
|
@@ -344,11 +289,7 @@ public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean canUpdateType(SysDictType existing, String mode) {
|
|
private boolean canUpdateType(SysDictType existing, String mode) {
|
|
|
- if (TenantDictConstants.SYNC_APPEND.equals(mode)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- // MERGE / OVERWRITE:模板中的类型均写入平台溯源字段,便于租户侧锁定
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ return !TenantDictConstants.SYNC_APPEND.equals(mode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean canUpdateData(SysDictData existing, TenantDictTemplateData template, String mode) {
|
|
private boolean canUpdateData(SysDictData existing, TenantDictTemplateData template, String mode) {
|
|
@@ -435,23 +376,17 @@ public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<TenantInfo> resolveTenants(TenantDictSyncRunReq req) {
|
|
private List<TenantInfo> resolveTenants(TenantDictSyncRunReq req) {
|
|
|
-// DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
|
|
|
|
|
-// try {
|
|
|
|
|
-// List<TenantInfo> all = tenantInfoService.selectTenantInfoList(new TenantInfo());
|
|
|
|
|
-// all.removeIf(t -> t.getStatus() == null || t.getStatus() != 1);
|
|
|
|
|
-// String scope = req.getScopeType() == null ? TenantDictConstants.SCOPE_ALL : req.getScopeType().toUpperCase();
|
|
|
|
|
-// List<Long> ids = req.getTenantIds() == null ? Collections.emptyList() : req.getTenantIds();
|
|
|
|
|
-// if (TenantDictConstants.SCOPE_INCLUDE.equals(scope)) {
|
|
|
|
|
-// return all.stream().filter(t -> ids.contains(t.getId())).collect(Collectors.toList());
|
|
|
|
|
-// }
|
|
|
|
|
-// if (TenantDictConstants.SCOPE_EXCLUDE.equals(scope)) {
|
|
|
|
|
-// return all.stream().filter(t -> !ids.contains(t.getId())).collect(Collectors.toList());
|
|
|
|
|
-// }
|
|
|
|
|
-// return all;
|
|
|
|
|
-// } finally {
|
|
|
|
|
-// DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
|
|
|
|
|
-// }
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ List<TenantInfo> all = tenantInfoService.selectTenantInfoList(new TenantInfo());
|
|
|
|
|
+ all.removeIf(t -> t.getStatus() == null || t.getStatus() != 1);
|
|
|
|
|
+ String scope = req.getScopeType() == null ? TenantDictConstants.SCOPE_ALL : req.getScopeType().toUpperCase();
|
|
|
|
|
+ List<Long> ids = req.getTenantIds() == null ? Collections.emptyList() : req.getTenantIds();
|
|
|
|
|
+ if (TenantDictConstants.SCOPE_INCLUDE.equals(scope)) {
|
|
|
|
|
+ return all.stream().filter(t -> ids.contains(t.getId())).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TenantDictConstants.SCOPE_EXCLUDE.equals(scope)) {
|
|
|
|
|
+ return all.stream().filter(t -> !ids.contains(t.getId())).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ return all;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void validateSyncReq(TenantDictSyncRunReq req) {
|
|
private void validateSyncReq(TenantDictSyncRunReq req) {
|
|
@@ -490,58 +425,44 @@ public class TenantDictSyncServiceImpl implements TenantDictSyncService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void insertTask(String taskNo, TenantDictSyncRunReq req, int total, String triggerBy) {
|
|
private void insertTask(String taskNo, TenantDictSyncRunReq req, int total, String triggerBy) {
|
|
|
-// contextHelper.runInMaster(() -> jdbcTemplate.update(
|
|
|
|
|
-// "INSERT INTO tenant_dict_sync_task(task_no,sync_mode,scope_type,dict_types,total_tenants,status,trigger_by,started_at) VALUES(?,?,?,?,?,?,?,NOW())",
|
|
|
|
|
-// taskNo, req.getSyncMode(), req.getScopeType(), JSON.toJSONString(req.getDictTypes()), total,
|
|
|
|
|
-// TenantDictConstants.TASK_RUNNING, triggerBy));
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ jdbcTemplate.update(
|
|
|
|
|
+ "INSERT INTO tenant_dict_sync_task(task_no,sync_mode,scope_type,dict_types,total_tenants,status,trigger_by,started_at) VALUES(?,?,?,?,?,?,?,NOW())",
|
|
|
|
|
+ taskNo, req.getSyncMode(), req.getScopeType(), JSON.toJSONString(req.getDictTypes()), total,
|
|
|
|
|
+ TenantDictConstants.TASK_RUNNING, triggerBy);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void insertTaskDetail(String taskNo, TenantInfo tenant, TenantDictSyncResultVo stats,
|
|
private void insertTaskDetail(String taskNo, TenantInfo tenant, TenantDictSyncResultVo stats,
|
|
|
- String status, String errorMsg, Date start, Date end) {
|
|
|
|
|
-// contextHelper.runInMaster(() -> jdbcTemplate.update(
|
|
|
|
|
-// "INSERT INTO tenant_dict_sync_task_detail(task_no,tenant_id,tenant_code,tenant_name,status,type_added,type_updated,data_added,data_updated,data_skipped,error_msg,started_at,finished_at) " +
|
|
|
|
|
-// "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
|
|
|
-// taskNo, tenant.getId(), tenant.getTenantCode(), tenant.getTenantName(), status,
|
|
|
|
|
-// stats.getTypeAdded(), stats.getTypeUpdated(), stats.getDataAdded(), stats.getDataUpdated(),
|
|
|
|
|
-// stats.getDataSkipped(), errorMsg, start, end));
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void finalizeTask(String taskNo, int success, int failed) {
|
|
|
|
|
-// contextHelper.runInMaster(() -> {
|
|
|
|
|
-// String status = failed == 0 ? TenantDictConstants.TASK_SUCCESS
|
|
|
|
|
-// : (success == 0 ? TenantDictConstants.TASK_FAILED : TenantDictConstants.TASK_PARTIAL);
|
|
|
|
|
-// jdbcTemplate.update(
|
|
|
|
|
-// "UPDATE tenant_dict_sync_task SET success_tenants=?, failed_tenants=?, status=?, finished_at=NOW() WHERE task_no=?",
|
|
|
|
|
-// success, failed, status, taskNo);
|
|
|
|
|
-// });
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ String status, String errorMsg, Date start, Date end) {
|
|
|
|
|
+ jdbcTemplate.update(
|
|
|
|
|
+ "INSERT INTO tenant_dict_sync_task_detail(task_no,tenant_id,tenant_code,tenant_name,status,type_added,type_updated,data_added,data_updated,data_skipped,error_msg,started_at,finished_at) " +
|
|
|
|
|
+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
|
|
|
+ taskNo, tenant.getId(), tenant.getTenantCode(), tenant.getTenantName(), status,
|
|
|
|
|
+ stats.getTypeAdded(), stats.getTypeUpdated(), stats.getDataAdded(), stats.getDataUpdated(),
|
|
|
|
|
+ stats.getDataSkipped(), errorMsg, start, end);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<TenantDictSyncTaskDetailVo> queryTaskDetails(String taskNo) {
|
|
private List<TenantDictSyncTaskDetailVo> queryTaskDetails(String taskNo) {
|
|
|
-// List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
|
|
|
|
-// "SELECT tenant_id,tenant_code,tenant_name,status,type_added,type_updated,data_added,data_updated,data_skipped,error_msg,started_at,finished_at " +
|
|
|
|
|
-// "FROM tenant_dict_sync_task_detail WHERE task_no=? ORDER BY id ASC", taskNo);
|
|
|
|
|
-// List<TenantDictSyncTaskDetailVo> list = new ArrayList<>();
|
|
|
|
|
-// for (Map<String, Object> row : rows) {
|
|
|
|
|
-// TenantDictSyncTaskDetailVo vo = new TenantDictSyncTaskDetailVo();
|
|
|
|
|
-// vo.setTenantId(longVal(row.get("tenant_id")));
|
|
|
|
|
-// vo.setTenantCode(str(row.get("tenant_code")));
|
|
|
|
|
-// vo.setTenantName(str(row.get("tenant_name")));
|
|
|
|
|
-// vo.setStatus(str(row.get("status")));
|
|
|
|
|
-// vo.setTypeAdded(intVal(row.get("type_added")));
|
|
|
|
|
-// vo.setTypeUpdated(intVal(row.get("type_updated")));
|
|
|
|
|
-// vo.setDataAdded(intVal(row.get("data_added")));
|
|
|
|
|
-// vo.setDataUpdated(intVal(row.get("data_updated")));
|
|
|
|
|
-// vo.setDataSkipped(intVal(row.get("data_skipped")));
|
|
|
|
|
-// vo.setErrorMsg(str(row.get("error_msg")));
|
|
|
|
|
-// vo.setStartedAt(str(row.get("started_at")));
|
|
|
|
|
-// vo.setFinishedAt(str(row.get("finished_at")));
|
|
|
|
|
-// list.add(vo);
|
|
|
|
|
-// }
|
|
|
|
|
-// return list;
|
|
|
|
|
- throw new CustomException("Not implemented");
|
|
|
|
|
|
|
+ List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
|
|
|
|
+ "SELECT tenant_id,tenant_code,tenant_name,status,type_added,type_updated,data_added,data_updated,data_skipped,error_msg,started_at,finished_at " +
|
|
|
|
|
+ "FROM tenant_dict_sync_task_detail WHERE task_no=? ORDER BY id ASC", taskNo);
|
|
|
|
|
+ List<TenantDictSyncTaskDetailVo> list = new ArrayList<>();
|
|
|
|
|
+ for (Map<String, Object> row : rows) {
|
|
|
|
|
+ TenantDictSyncTaskDetailVo vo = new TenantDictSyncTaskDetailVo();
|
|
|
|
|
+ vo.setTenantId(longVal(row.get("tenant_id")));
|
|
|
|
|
+ vo.setTenantCode(str(row.get("tenant_code")));
|
|
|
|
|
+ vo.setTenantName(str(row.get("tenant_name")));
|
|
|
|
|
+ vo.setStatus(str(row.get("status")));
|
|
|
|
|
+ vo.setTypeAdded(intVal(row.get("type_added")));
|
|
|
|
|
+ vo.setTypeUpdated(intVal(row.get("type_updated")));
|
|
|
|
|
+ vo.setDataAdded(intVal(row.get("data_added")));
|
|
|
|
|
+ vo.setDataUpdated(intVal(row.get("data_updated")));
|
|
|
|
|
+ vo.setDataSkipped(intVal(row.get("data_skipped")));
|
|
|
|
|
+ vo.setErrorMsg(str(row.get("error_msg")));
|
|
|
|
|
+ vo.setStartedAt(str(row.get("started_at")));
|
|
|
|
|
+ vo.setFinishedAt(str(row.get("finished_at")));
|
|
|
|
|
+ list.add(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String str(Object o) {
|
|
private String str(Object o) {
|