|
@@ -3,8 +3,6 @@ package com.nokia.task;
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
import com.jcraft.jsch.SftpException;
|
|
|
import com.nokia.common.exception.MyRuntimeException;
|
|
|
-import com.nokia.common.gpload.GploadUtil;
|
|
|
-import com.nokia.common.gpload.entity.GploadResult;
|
|
|
import com.nokia.common.psql.PsqlUtil;
|
|
|
import com.nokia.common.ssh.SSHUtil;
|
|
|
import com.nokia.config.TaskConfig;
|
|
@@ -268,26 +266,21 @@ public class SyncTask {
|
|
|
* 回滚
|
|
|
*/
|
|
|
public void rollback() {
|
|
|
- String sql = "drop table if exists sqmdb_rpt.acl_top_user";
|
|
|
+ String sql = "select exists (select from pg_tables where schemaname = 'sqmdb_rpt' and tablename = 'acl_top_user_bak')";
|
|
|
+ Boolean backupExists = jdbcTemplate.queryForObject(sql, Boolean.class);
|
|
|
log.warn(sql);
|
|
|
XxlJobHelper.log(sql);
|
|
|
- jdbcTemplate.execute(sql);
|
|
|
- sql = "alter table sqmdb_rpt.acl_top_user_bak rename to acl_top_user";
|
|
|
- log.warn(sql);
|
|
|
- XxlJobHelper.log(sql);
|
|
|
- jdbcTemplate.execute(sql);
|
|
|
- }
|
|
|
-
|
|
|
- public void gpload() throws IOException {
|
|
|
- String gploadCommand = "sh gpload/gpload.sh";
|
|
|
- GploadResult gpload = GploadUtil.gpload(gploadCommand);
|
|
|
- if (Boolean.TRUE.equals(gpload.getTaskStatus())) {
|
|
|
- log.info("gpload完成: {}", gpload);
|
|
|
- XxlJobHelper.log("gpload完成: {}", gpload);
|
|
|
- // 删除文件
|
|
|
- Files.deleteIfExists(Paths.get(taskConfig.getDistinctFilename()));
|
|
|
- } else {
|
|
|
- throw new MyRuntimeException("gpload失败: " + gpload.getMessage());
|
|
|
+ if (Boolean.TRUE.equals(backupExists)) {
|
|
|
+ sql = "truncate table sqmdb_rpt.acl_top_user";
|
|
|
+ log.warn(sql);
|
|
|
+ XxlJobHelper.log(sql);
|
|
|
+ jdbcTemplate.execute(sql);
|
|
|
+ sql = "insert into sqmdb_rpt.acl_top_user\n"
|
|
|
+ + "(login_name, org_id, org_name, user_id, user_name, phone, employee_code, province_id, city_id, area_id)\n"
|
|
|
+ + "select * from sqmdb_rpt.acl_top_user_bak";
|
|
|
+ log.warn(sql);
|
|
|
+ XxlJobHelper.log(sql);
|
|
|
+ jdbcTemplate.execute(sql);
|
|
|
}
|
|
|
}
|
|
|
}
|