65 lines
1.8 KiB
Java
65 lines
1.8 KiB
Java
|
|
package com.mini.capi.job;
|
||
|
|
|
||
|
|
import com.mini.capi.biz.domain.DbConfig;
|
||
|
|
import com.mini.capi.biz.domain.SyncTask;
|
||
|
|
import com.mini.capi.biz.service.DbConfigService;
|
||
|
|
import com.mini.capi.biz.service.SyncTaskService;
|
||
|
|
import com.mini.capi.config.DataSourceConfig;
|
||
|
|
import com.mini.capi.model.ApiResult;
|
||
|
|
import com.mini.capi.utils.vToken;
|
||
|
|
import jakarta.annotation.Resource;
|
||
|
|
|
||
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
import java.time.LocalDate;
|
||
|
|
import java.time.format.DateTimeFormatter;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/Sys/dbs")
|
||
|
|
public class taskDbSync {
|
||
|
|
|
||
|
|
|
||
|
|
@Resource
|
||
|
|
private SyncTaskService syncTaskService;
|
||
|
|
|
||
|
|
@Resource
|
||
|
|
private DbConfigService dbConfigService;
|
||
|
|
|
||
|
|
|
||
|
|
private static final int BATCH_SIZE = 1000;
|
||
|
|
|
||
|
|
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||
|
|
|
||
|
|
|
||
|
|
@GetMapping("/getTaskSyncDbInfo")
|
||
|
|
public ApiResult<?> jobSyncTask(String token) {
|
||
|
|
if (vToken.isValidToken(token)) {
|
||
|
|
String dsValue = LocalDate.now().format(DATE_FORMATTER);
|
||
|
|
List<SyncTask> syncTasks = syncTaskService.list();
|
||
|
|
for (SyncTask task : syncTasks) {
|
||
|
|
DbConfig sourceDbConfig = dbConfigService.getById(task.getSourceDbId());
|
||
|
|
DbConfig targetDbConfig = dbConfigService.getById(task.getTargetDbId());
|
||
|
|
JdbcTemplate sourceJdbc = DataSourceConfig.createJdbcTemplate(sourceDbConfig);
|
||
|
|
JdbcTemplate targetJdbc = DataSourceConfig.createJdbcTemplate(targetDbConfig);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
return ApiResult.success();
|
||
|
|
}
|
||
|
|
return ApiResult.error();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|