Просмотр исходного кода

基本完成数据交换所有接口

soft5566 2 лет назад
Родитель
Сommit
efdd854d81

+ 23 - 6
src/main/java/com/template/api/SmartDataTaskControllerAPI.java

@@ -1,5 +1,6 @@
 package com.template.api;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.template.model.pojo.SmartDataTask;
 import com.template.model.result.CommonResult;
 import io.swagger.annotations.Api;
@@ -68,12 +69,28 @@ public interface SmartDataTaskControllerAPI {
     CommonResult getViews(@RequestBody String json);
 
     @PostMapping(value = "/insertSmartDataTask1")
-    @ApiOperation(value = "添加数据源任务管理数据", notes = "添加数据源任务管理数据", httpMethod = "POST")
-    CommonResult insertSmartDataTask(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
+    @ApiOperation(value = "添加数据源任务管理数据", notes = "添加数据源任务管理数据-任务基本信息", httpMethod = "POST")
+    CommonResult insertSmartDataTask1(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
 
-    @PostMapping(value = "/updateSmartDataTaskById")
-    @ApiOperation(value = "编辑数据源任务管理数据", notes = "编辑数据源任务管理数据", httpMethod = "POST")
-    CommonResult updateSmartDataTaskById(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
+    @PostMapping(value = "/insertSmartDataTask2")
+    @ApiOperation(value = "添加数据源任务管理数据", notes = "添加数据源任务管理数据-字段配置", httpMethod = "POST")
+    CommonResult insertSmartDataTask2(@Validated @RequestBody JSONObject json, HttpServletRequest httpServletRequest, BindingResult bindingResult);
+
+    @PostMapping(value = "/insertSmartDataTask3")
+    @ApiOperation(value = "添加数据源任务管理数据", notes = "添加数据源任务管理数据-定时信息", httpMethod = "POST")
+    CommonResult insertSmartDataTask3(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
+
+    @PostMapping(value = "/updateSmartDataTaskById1")
+    @ApiOperation(value = "编辑数据源任务管理数据", notes = "编辑数据源任务管理数据-任务基本信息", httpMethod = "POST")
+    CommonResult updateSmartDataTaskById1(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
+
+    @PostMapping(value = "/updateSmartDataTaskById2")
+    @ApiOperation(value = "编辑数据源任务管理数据", notes = "编辑数据源任务管理数据-字段配置", httpMethod = "POST")
+    CommonResult updateSmartDataTaskById2(@Validated @RequestBody JSONObject json,  HttpServletRequest httpServletRequest, BindingResult bindingResult);
+
+    @PostMapping(value = "/updateSmartDataTaskById3")
+    @ApiOperation(value = "编辑数据源任务管理数据", notes = "编辑数据源任务管理数据-定时信息", httpMethod = "POST")
+    CommonResult updateSmartDataTaskById3(@Validated @RequestBody SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult);
 
     @GetMapping(value = "/queryPageSmartDataTask")
     @ApiOperation(value = "数据源任务管理分页数据", notes = "数据源任务管理分页数据", httpMethod = "GET")
@@ -81,5 +98,5 @@ public interface SmartDataTaskControllerAPI {
 
     @GetMapping(value = "/deleteSmartDataTaskById")
     @ApiOperation(value = "根据ID删除数据源任务数据", notes = "根据ID删除数据源任务数据", httpMethod = "GET")
-    CommonResult deleteSmartDataTaskById(@RequestParam int id, HttpServletRequest httpServletRequest);
+    CommonResult deleteSmartDataTaskById(@RequestParam int id, @RequestParam int delMethod, HttpServletRequest httpServletRequest);
 }

+ 45 - 24
src/main/java/com/template/common/utils/DBUtil.java

@@ -1,36 +1,41 @@
 package com.template.common.utils;
 
 
-import io.swagger.models.auth.In;
-
 import java.sql.*;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 public class DBUtil {
     private String url;
     private String user;
     private String password;
     private String driver;
-
-    private String str_link = "?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai";
+    private String charset;
+    private String str_link = "?useUnicode=true" +
+            "&useSSL=false" +
+            "&useAffectedRows=true" +
+            "&allowPublicKeyRetrieval=true" +
+            "&allowMultiQueries=true" +
+            "&rewriteBatchedStatements=true" +
+            "&serverTimezone=Asia/Shanghai";
 
 
-    public DBUtil(String url, String user, String password, String driver) {
+    public DBUtil(String url, String user, String password, String driver, String charset) {
         this.url = url;
         this.user = user;
         this.password = password;
         this.driver = driver;
+        if (charset != null && !charset.equals("")) {
+            this.charset = "&characterEncoding=" + charset;
+        }
     }
 
     public Map<String, Object> getConnection() {
         try {
             Class.forName(driver);
-            Connection connection = DriverManager.getConnection(url + str_link, user, password);
+            Connection connection = DriverManager.getConnection(url + str_link + charset, user, password);
             return CommonUtil.getReturnMap("0", connection);
         } catch (SQLException | ClassNotFoundException e) {
             return CommonUtil.getReturnMap("1", e.getMessage());
@@ -69,7 +74,6 @@ public class DBUtil {
             count = stmt.executeUpdate();
         } catch (Exception e) {
             return CommonUtil.getReturnMap("1", e.getMessage());
-
         } finally {
             map.put("count", count);
             map.put("stmt", stmt);
@@ -79,7 +83,24 @@ public class DBUtil {
         return CommonUtil.getReturnMap("0", map);
     }
 
-    public Map<Integer, Object> getMetaDataByTable(Connection conn, String tableName) {
+    public Map<String, Object> update(Connection conn, String sql) {
+        PreparedStatement stmt = null;
+        int count = 0;
+        Map<String, Object> map = new HashMap<>();
+        try {
+            stmt = conn.prepareStatement(sql);
+            count = stmt.executeUpdate();
+        } catch (Exception e) {
+            return CommonUtil.getReturnMap("1", e.getMessage());
+        } finally {
+            map.put("count", count);
+            map.put("stmt", stmt);
+        }
+
+        return CommonUtil.getReturnMap("0", map);
+    }
+
+    public Map<String, Object> getMetaDataByTable(Connection conn, String tableName) {
         // 获取数据表的列信息
         DatabaseMetaData dbMetaData;
         ResultSet rs = null;
@@ -87,38 +108,37 @@ public class DBUtil {
         try {
             dbMetaData = conn.getMetaData();
             rs = dbMetaData.getColumns(null, null, tableName, null);
-            int i = 1;
+            List<Map<String, String>> list = new ArrayList<>();
             // 遍历列信息
             while (rs.next()) {
                 Map<String, String> tmpMap = new HashMap<>();
                 // 获取列名称
                 String columnName = rs.getString("COLUMN_NAME");
-
                 // 获取列类型
                 String columnType = rs.getString("TYPE_NAME");
-
                 // 获取列备注
                 String columnComment = rs.getString("REMARKS");
+                // 获取是否允许为空
+                String isNullable = rs.getString("IS_NULLABLE");
+                // 获取字段的长度
+                int columnSize = rs.getInt("COLUMN_SIZE");
 
                 tmpMap.put("COLUMN_NAME", columnName);
                 tmpMap.put("TYPE_NAME", columnType);
                 tmpMap.put("REMARKS", columnComment);
+                tmpMap.put("IS_NULLABLE", isNullable);
+                tmpMap.put("COLUMN_SIZE", String.valueOf(columnSize));
 
-                map.put(i++, tmpMap);
-
-                // 打印列信息
-                System.out.println("Column name: " + columnName);
-                System.out.println("Column type: " + columnType);
-                System.out.println("Column comment: " + columnComment);
+                list.add(tmpMap);
             }
+
+            return CommonUtil.getReturnMap("0", list);
         } catch (SQLException e) {
-            throw new RuntimeException(e);
+            return CommonUtil.getReturnMap("1", e.getMessage());
         } finally {
             this.closeResultSet(rs);
             this.closeConnection(conn);
         }
-
-        return map;
     }
 
     public Map<String, Object> getTableMetaData(Connection conn) {
@@ -147,7 +167,8 @@ public class DBUtil {
 
     /**
      * 获取表的备注
-     * @param metaData 数据库元数据
+     *
+     * @param metaData  数据库元数据
      * @param tableName 表名
      * @return 表的备注
      * @throws SQLException
@@ -178,7 +199,7 @@ public class DBUtil {
             return CommonUtil.getReturnMap("1", e.getMessage());
         }
 
-        List<Object> list = new ArrayList<>();
+        List<Map<String, String>> list = new ArrayList<>();
         // 遍历字段信息
         for (int i = 1; i <= columnCount; i++) {
             Map<String, String> tmpMap = new HashMap<>();

+ 12 - 3
src/main/java/com/template/common/utils/QuartzJobUtils.java

@@ -34,7 +34,6 @@ public class QuartzJobUtils {
             // 构建定时任务信息
             JobDetail jobDetail = JobBuilder.newJob(jobClass)
                     .withIdentity(smartDataTask.getTkName())
-                    .withDescription(smartDataTask.getTkDescrition())
                     .build();
 
             // 创建一个JobDataMap对象,并设置参数
@@ -44,13 +43,23 @@ public class QuartzJobUtils {
             jobDataMap.put("sourceUrl", dsSourceInfo.getDsUrl());
             jobDataMap.put("sourceUser", dsSourceInfo.getDsUser());
             jobDataMap.put("sourcePassword", dsSourceInfo.getDsPassword());
-            jobDataMap.put("sourceSql", dsSourceInfo.getSql());
+//            jobDataMap.put("exchangeType", dsSourceInfo.getExchangeType());
+            jobDataMap.put("sourceSql", dsSourceInfo.getSourceSql());
             // 目标数据源参数
             jobDataMap.put("destinationDriver", dsDestinationInfo.getDsClsDriver());
             jobDataMap.put("destinationUrl", dsDestinationInfo.getDsUrl());
             jobDataMap.put("destinationUser", dsDestinationInfo.getDsUser());
             jobDataMap.put("destinationPassword", dsDestinationInfo.getDsPassword());
-            jobDataMap.put("destinationSql", dsDestinationInfo.getSql());
+            jobDataMap.put("destinationTable", dsDestinationInfo.getDestinationTable().substring(0, dsDestinationInfo.getDestinationTable().indexOf("[")));
+
+            // 字段对应关系
+            jobDataMap.put("tkId", smartDataTask.getTkId());
+            jobDataMap.put("colRelationship", smartDataTask.getTkColRelationship());
+            jobDataMap.put("rsIncorrectData", smartDataTask.getTkRsIncorrectData());
+            jobDataMap.put("optCfgRsNum", smartDataTask.getTkOptCfgRsNum());
+            jobDataMap.put("optCfgAutoManual", smartDataTask.getTkOptCfgAutoManual());
+            jobDataMap.put("dsSourceCharset", smartDataTask.getTkDsSourceCharset());
+            jobDataMap.put("dsDestinationCharset", smartDataTask.getTkDsDestinationCharset());
 
             // 将JobDataMap对象与JobDetail关联
             jobDetail.getJobDataMap().putAll(jobDataMap);

+ 0 - 1
src/main/java/com/template/controller/ScheduleController.java

@@ -4,7 +4,6 @@ import com.seewo.open.sdk.DefaultSeewoClient;
 import com.seewo.open.sdk.SeewoClient;
 import com.seewo.open.sdk.auth.Account;
 import com.template.common.utils.TimeExchange;
-import com.template.config.ParkConfig;
 import com.template.config.ScheduleConfig;
 import com.template.config.SeewoConfig;
 import com.template.model.pojo.AttendanceServiceListAttendClassRecordsParam;

+ 96 - 16
src/main/java/com/template/controller/SmartDataTaskController.java

@@ -1,9 +1,9 @@
 package com.template.controller;
 
 
+import com.alibaba.fastjson2.JSONObject;
 import com.template.api.SmartDataTaskControllerAPI;
 import com.template.common.utils.CommonUtil;
-import com.template.common.utils.DBUtil;
 import com.template.common.utils.paramUtils;
 import com.template.model.pojo.SmartDataSourceLog;
 import com.template.model.pojo.SmartDataTask;
@@ -13,7 +13,6 @@ import com.template.services.SmartDataSourceLogService;
 import com.template.services.SmartDataTaskService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
@@ -230,15 +229,53 @@ public class SmartDataTaskController implements SmartDataTaskControllerAPI {
      * @return
      */
     @Override
-    public CommonResult insertSmartDataTask(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+    public CommonResult insertSmartDataTask1(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
         if (bindingResult.hasErrors()) {
             String st = paramUtils.getParamError(bindingResult);
             return CommonResult.fail(st);
         }
 
         SmartDataSourceLog smartDataSourceLog =
-                CommonUtil.generateLog("新增数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|新增【数据源数据交换任务】|create", httpServletRequest);
-        Map<String, Object> result = smartDataTaskService.insertSmartDataTask(smartDataTask);
+                CommonUtil.generateLog("新增数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|新增【任务-任务基本信息】|create", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.insertSmartDataTask1(smartDataTask);
+        if (Integer.parseInt((String) result.get("code")) == 0) {
+            smartDataSourceLog.setLogActionStatus(1);
+            smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
+            return CommonResult.ok(result.get("msg"));
+        } else {
+            return CommonResult.fail((String) result.get("msg"));
+        }
+    }
+
+    @Override
+    public CommonResult insertSmartDataTask2(JSONObject json, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            String st = paramUtils.getParamError(bindingResult);
+            return CommonResult.fail(st);
+        }
+
+        SmartDataSourceLog smartDataSourceLog =
+                CommonUtil.generateLog("新增数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|新增【任务-字段配置】|create", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.insertSmartDataTask2(json);
+        if (Integer.parseInt((String) result.get("code")) == 0) {
+            smartDataSourceLog.setLogActionStatus(1);
+            smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
+            return CommonResult.ok(result.get("msg"));
+        } else {
+            return CommonResult.fail((String) result.get("msg"));
+        }
+    }
+
+    @Override
+    public CommonResult insertSmartDataTask3(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            String st = paramUtils.getParamError(bindingResult);
+            return CommonResult.fail(st);
+        }
+
+        SmartDataSourceLog smartDataSourceLog =
+                CommonUtil.generateLog("新增数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|新增【任务-定时信息】|create", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.insertSmartDataTask3(smartDataTask);
         if (Integer.parseInt((String) result.get("code")) == 0) {
             smartDataSourceLog.setLogActionStatus(1);
             smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
@@ -256,7 +293,7 @@ public class SmartDataTaskController implements SmartDataTaskControllerAPI {
      * @return
      */
     @Override
-    public CommonResult updateSmartDataTaskById(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+    public CommonResult updateSmartDataTaskById1(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
         if (bindingResult.hasErrors()) {
             String st = paramUtils.getParamError(bindingResult);
             return CommonResult.fail(st);
@@ -264,8 +301,46 @@ public class SmartDataTaskController implements SmartDataTaskControllerAPI {
 
 
         SmartDataSourceLog smartDataSourceLog =
-                CommonUtil.generateLog("更新数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|更新【数据源数据交换任务】|update", httpServletRequest);
-        Map<String, Object> result = smartDataTaskService.updateSmartDataTaskById(smartDataTask);
+                CommonUtil.generateLog("更新数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|编辑【任务-任务基本信息】|update", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.updateSmartDataTaskById1(smartDataTask);
+        if (Integer.parseInt((String) result.get("code")) == 0) {
+            smartDataSourceLog.setLogActionStatus(1);
+            smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
+            return CommonResult.ok(result.get("msg"));
+        } else {
+            return CommonResult.fail((String) result.get("msg"));
+        }
+    }
+
+    @Override
+    public CommonResult updateSmartDataTaskById2(JSONObject json, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            String st = paramUtils.getParamError(bindingResult);
+            return CommonResult.fail(st);
+        }
+
+        SmartDataSourceLog smartDataSourceLog =
+                CommonUtil.generateLog("更新数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|编辑【任务-字段配置】|update", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.updateSmartDataTaskById2(json);
+        if (Integer.parseInt((String) result.get("code")) == 0) {
+            smartDataSourceLog.setLogActionStatus(1);
+            smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
+            return CommonResult.ok(result.get("msg"));
+        } else {
+            return CommonResult.fail((String) result.get("msg"));
+        }
+    }
+
+    @Override
+    public CommonResult updateSmartDataTaskById3(SmartDataTask smartDataTask, HttpServletRequest httpServletRequest, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            String st = paramUtils.getParamError(bindingResult);
+            return CommonResult.fail(st);
+        }
+
+        SmartDataSourceLog smartDataSourceLog =
+                CommonUtil.generateLog("更新数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|编辑【任务-定时信息】|update", httpServletRequest);
+        Map<String, Object> result = smartDataTaskService.updateSmartDataTaskById3(smartDataTask);
         if (Integer.parseInt((String) result.get("code")) == 0) {
             smartDataSourceLog.setLogActionStatus(1);
             smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
@@ -298,28 +373,33 @@ public class SmartDataTaskController implements SmartDataTaskControllerAPI {
      * @return
      */
     @Override
-    public CommonResult deleteSmartDataTaskById(int id, HttpServletRequest httpServletRequest) {
+    public CommonResult deleteSmartDataTaskById(int id, int delMethod, HttpServletRequest httpServletRequest) {
 
         SmartDataTask smartDataTask = smartDataTaskService.getSmartById(id);
-
         if (smartDataTask == null) {
             return CommonResult.fail("当前数据不存在,删除失败!");
         }
 
-        if (smartDataTask.getTkDeleted() == 1) {
-            return CommonResult.fail("当前数据已是标记为删除状态,删除失败!");
+        if (delMethod == 0) {
+            if (smartDataTask.getTkDeleted() == 1) {
+                return CommonResult.fail("当前数据已是删除状态,无需删除,删除失败!");
+            }
+        } else if (delMethod == 1) {
+            if (smartDataTask.getTkDeleted() == 0) {
+                return CommonResult.fail("当前数据已是正常状态,无需恢复,恢复失败!");
+            }
         }
 
         SmartDataSourceLog smartDataSourceLog =
                 CommonUtil.generateLog("标记为删除数据源数据交换任务|【数据交换中心】→【数据源数据交换任务】|标记为删除【数据源数据交换任务】|delete", httpServletRequest);
         smartDataTask.setTkDeleted(1);
-        int result = smartDataTaskService.deleteSmartDataTaskById(smartDataTask);
-        if (result > 0) {
+        Map<String, Object> result = smartDataTaskService.deleteSmartDataTaskById(id, delMethod);
+        if (result.get("code") == "0") {
             smartDataSourceLog.setLogActionStatus(1);
             smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
-            return CommonResult.ok("标记为删除状态成功");
+            return CommonResult.ok(result.get("msg"));
         } else {
-            return CommonResult.fail("标记为删除状态失败");
+            return CommonResult.fail((String) result.get("msg"));
         }
     }
 }

+ 262 - 35
src/main/java/com/template/controller/Task.java

@@ -1,10 +1,14 @@
 package com.template.controller;
 
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.template.annotation.PassToken;
+import com.template.common.utils.DBUtil;
 import com.template.common.utils.QuartzJobUtils;
 import com.template.mapper.SmartDataTaskMapper;
 import com.template.model.pojo.SmartDataTask;
+import com.template.model.pojo.SmartDataTaskErr;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
@@ -13,8 +17,14 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.quartz.QuartzJobBean;
 import org.springframework.stereotype.Component;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 @Component
 public class Task extends QuartzJobBean {
@@ -26,30 +36,19 @@ public class Task extends QuartzJobBean {
     @PassToken
     protected void executeInternal(JobExecutionContext jobExecutionContext) {
         // 输出当前时间
-//        Date date = new Date();
-//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-//        String dateString = dateFormat.format(date);
-//
-//        System.out.println("定时任务名称:【" + key.getName() + "】,执行时间:" + dateString);
+        Date date = new Date();
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String dateString = dateFormat.format(date);
 
+        // 执行任务
+        executeTask(dateString, jobExecutionContext);
+    }
+
+    // 执行任务的逻辑
+    private void executeTask(String datetime, JobExecutionContext jobExecutionContext) {
+        // 获取任务信息
         JobDetail jobDetail = jobExecutionContext.getJobDetail();
         JobKey key = jobDetail.getKey();
-        // 及时更新下次更新时间
-        QueryWrapper<SmartDataTask> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq(key.getName() != null, "tk_name", key.getName());
-        SmartDataTask smartDataTask = smartDataTaskMapper.selectOne(queryWrapper);
-        if (smartDataTask != null) {
-            // 下次执行的时间
-            String nextExeTime = QuartzJobUtils.getNextExeTime(smartDataTask.getTkCron());
-            smartDataTask.setTkNextExeTime(nextExeTime);
-            try {
-                smartDataTaskMapper.markTaskById(smartDataTask);
-            } catch (Exception e) {
-                System.out.println(e.getMessage());
-            }
-        } else {
-            System.out.println("【下次执行的时间】无法更新至数据库中!");
-        }
 
         // 工作内容
         JobDataMap jobDataMap = jobDetail.getJobDataMap();
@@ -58,26 +57,254 @@ public class Task extends QuartzJobBean {
         String sourceUrl = (String) jobDataMap.get("sourceUrl");
         String sourceUser = (String) jobDataMap.get("sourceUser");
         String sourcePassword = (String) jobDataMap.get("sourcePassword");
+//        Integer exchangeType = (Integer) jobDataMap.get("exchangeType");
         String sourceSql = (String) jobDataMap.get("sourceSql");
         // 目标数据源参数
         String destinationDriver = (String) jobDataMap.get("destinationDriver");
         String destinationUrl = (String) jobDataMap.get("destinationUrl");
         String destinationUser = (String) jobDataMap.get("destinationUser");
         String destinationPassword = (String) jobDataMap.get("destinationPassword");
-        String destinationSql = (String) jobDataMap.get("destinationSql");
-
-        System.out.println("来源库参数:==============================" + "\n" +
-                "    driver:" + sourceDriver + "\n" +
-                "       url:" + sourceUrl + "\n" +
-                "      user:" + sourceUser + "\n" +
-                "  password:" + sourcePassword + "\n" +
-                "       sql:" + sourceSql);
-        System.out.println("目标库参数:==============================" + "\n" +
-                "    driver:" + destinationDriver + "\n" +
-                "       url:" + destinationUrl + "\n" +
-                "      user:" + destinationUser + "\n" +
-                "  password:" + destinationPassword + "\n" +
-                "       sql:" + destinationSql);
+        String destinationTable = (String) jobDataMap.get("destinationTable");
+        // 列关系
+        Integer tkId = (Integer) jobDataMap.get("tkId");
+        String colRelationship = (String) jobDataMap.get("colRelationship");
+        Integer rsIncorrectData = (Integer) jobDataMap.get("rsIncorrectData");
+        Integer optCfgRsNum = (Integer) jobDataMap.get("optCfgRsNum");
+        Integer optCfgAutoManual = (Integer) jobDataMap.get("optCfgAutoManual");
+        String dsSourceCharset = (String) jobDataMap.get("dsSourceCharset");
+        String dsDestinationCharset = (String) jobDataMap.get("dsDestinationCharset");
+        // 获取交换主键
+        SmartDataTask smartDataTask = smartDataTaskMapper.selectColSwappedPrimaryKeys(tkId);
+        String swappedPrimaryKeys = smartDataTask.getTkSwappedPrimaryKeys();
+
+        // 及时更新下次执行时间
+        saveNextExtTime(tkId, datetime, key, rsIncorrectData);
+
+        // 源连接
+        DBUtil sourceDbUtil = new DBUtil(sourceUrl, sourceUser, sourcePassword, sourceDriver, dsSourceCharset);
+        Map<String, Object> sourceConnMap = sourceDbUtil.getConnection();
+        if ("1".equals(sourceConnMap.get("code"))) {
+            if (rsIncorrectData == 0) {
+                // 记录错误信息
+                saveErrorMsg(tkId, datetime, sourceConnMap.get("msg").toString());
+            }
+        }
+
+        // 解析列对应关系
+        JSONArray colRelationshipArray = JSONArray.parseArray(colRelationship);
+        // 源表列名列表
+        Map<String, String> colSourceMap = new HashMap<>();
+        // 目标表列名列表
+        Map<String, String> colDestinationMap = new HashMap<>();
+        int index = 1;
+        for (int i = 0; i < colRelationshipArray.size(); i++) {
+            JSONObject colRelationshipObject = colRelationshipArray.getJSONObject(i);
+            if (colRelationshipObject.getInteger("isUpdatePrimaryKey") == 1) {
+                colSourceMap.put("colPrimaryKey", colRelationshipObject.getString("colSource"));
+                colDestinationMap.put("colPrimaryKey", colRelationshipObject.getString("colDestination"));
+            } else {
+                colSourceMap.put("col" + index, colRelationshipObject.getString("colSource"));
+                colDestinationMap.put("col" + index, colRelationshipObject.getString("colDestination"));
+                index++;
+            }
+        }
+
+        if (optCfgAutoManual == 0) {
+            if (swappedPrimaryKeys == null || swappedPrimaryKeys.equals("")) {
+                sourceSql = sourceSql + " LIMIT 1 ";
+            } else {
+                sourceSql = sourceSql + " WHERE " + colSourceMap.get("colPrimaryKey") + " NOT IN(" + swappedPrimaryKeys + ") LIMIT 1 ";
+            }
+        } else {
+            if (swappedPrimaryKeys == null || swappedPrimaryKeys.equals("")) {
+                sourceSql = sourceSql + " LIMIT " + optCfgRsNum;
+            } else {
+                sourceSql = sourceSql + " WHERE " + colSourceMap.get("colPrimaryKey") + " NOT IN(" + swappedPrimaryKeys + ") LIMIT " + optCfgRsNum;
+            }
+        }
+        Connection sourceConn = (Connection) sourceConnMap.get("msg");
+        // 执行源sql
+        Map<String, Object> sourceQuery = sourceDbUtil.query(sourceConn, sourceSql);
+        if ("1".equals(sourceQuery.get("code"))) {
+            if (rsIncorrectData == 0) {
+                // 记录错误信息
+                saveErrorMsg(tkId, datetime, sourceQuery.get("msg").toString());
+            }
+            // 关闭连接
+            sourceDbUtil.closeConnection(sourceConn);
+            return;
+        }
+        Map<String, Object> sourceMap = (Map<String, Object>) sourceQuery.get("msg");
+        ResultSet sourceRs = (ResultSet) sourceMap.get("rs");
+        PreparedStatement sourceStmt = (PreparedStatement) sourceMap.get("stmt");
 
+        StringBuilder stringInsertData = new StringBuilder();
+        StringBuilder stringInsertCols = new StringBuilder();
+        StringBuilder stringUpdateData = new StringBuilder();
+        String stringPrimaryKeyData;
+        try {
+            // 执行解析操作
+            while (true) {
+                if (!sourceRs.next()) {
+                    if (rsIncorrectData == 0) {
+                        // 记录错误信息
+                        saveErrorMsg(tkId, datetime, "没有需要交换的数据!");
+                    }
+                    break;
+                } else {
+                    // 主键列的值
+                    stringPrimaryKeyData = sourceRs.getString(colSourceMap.get("colPrimaryKey"));
+                    // 拼接插入的值
+                    stringInsertData.append("'").append(sourceRs.getString(colSourceMap.get("colPrimaryKey"))).append("',");
+                    // 拼接插入的列
+                    stringInsertCols.append(colDestinationMap.get("colPrimaryKey")).append(",");
+                    for (int i = 1; i < index; i++) {
+                        stringInsertData.append("'").append(sourceRs.getString(colSourceMap.get("col" + i))).append("',");
+                        stringInsertCols.append(colDestinationMap.get("col" + i)).append(",");
+                        // 拼接更新的列和值
+                        stringUpdateData.append(colDestinationMap.get("col" + i)).append("='").append(sourceRs.getString(colSourceMap.get("col" + i))).append("',");
+                    }
+                    stringInsertData.setLength(stringInsertData.length() - 1);
+                    stringInsertCols.setLength(stringInsertCols.length() - 1);
+                    stringUpdateData.setLength(stringUpdateData.length() - 1);
+                    // 执行插入操作
+                    // 目标连接
+                    DBUtil destinationDbUtil = new DBUtil(destinationUrl, destinationUser, destinationPassword, destinationDriver, dsDestinationCharset);
+                    Map<String, Object> destinationConnMap = destinationDbUtil.getConnection();
+                    if (destinationConnMap.get("code").equals("1")) {
+                        if (rsIncorrectData == 0) {
+                            // 记录错误信息
+                            saveErrorMsg(tkId, datetime, destinationConnMap.get("msg").toString());
+                        }
+                    }
+                    Connection destinationConn = (Connection) destinationConnMap.get("msg");
+                    String destinationQuerySql = "select * from " + destinationTable + " where " + colDestinationMap.get("colPrimaryKey") + " = '" + stringPrimaryKeyData + "'";
+                    Map<String, Object> destinationQuery = destinationDbUtil.query(destinationConn, destinationQuerySql);
+                    if (destinationQuery.get("code").equals("1")) {
+                        if (rsIncorrectData == 0) {
+                            // 记录错误信息
+                            saveErrorMsg(tkId, datetime, destinationQuery.get("msg").toString());
+                        }
+                        // 关闭连接
+                        destinationDbUtil.closeConnection(destinationConn);
+                        return;
+                    }
+                    // 获取查询结果集
+                    Map<String, Object> sourceQueryMap = (Map<String, Object>) destinationQuery.get("msg");
+                    ResultSet destinationRs = (ResultSet) sourceQueryMap.get("rs");
+                    PreparedStatement destinationQueryStmt = (PreparedStatement) sourceQueryMap.get("stmt");
+                    if (destinationRs.next()) {
+                        // 更新操作
+                        String destinationUpdateSql = "UPDATE " + destinationTable + " SET " + stringUpdateData + " WHERE " + colDestinationMap.get("colPrimaryKey") + " = '" + stringPrimaryKeyData + "'";
+                        Map<String, Object> destinationUpdate = destinationDbUtil.update(destinationConn, destinationUpdateSql);
+                        if (destinationUpdate.get("code").equals("1")) {
+                            if (rsIncorrectData == 0) {
+                                // 记录错误信息
+                                saveErrorMsg(tkId, datetime, destinationUpdate.get("msg").toString());
+                            }
+                            // 关闭连接
+                            destinationDbUtil.closeConnection(destinationConn);
+                            return;
+                        }
+                        Map<String, Object> destinationQueryMap = (Map<String, Object>) destinationUpdate.get("msg");
+                        PreparedStatement destinationUpdateStmt = (PreparedStatement) destinationQueryMap.get("stmt");
+                        destinationDbUtil.closeStatement(destinationUpdateStmt);
+                    } else {
+                        // 插入操作
+                        String destinationInsertSql = "INSERT INTO " + destinationTable + " (" + stringInsertCols + ") VALUES (" + stringInsertData + ")";
+                        Map<String, Object> destinationInsert = destinationDbUtil.update(destinationConn, destinationInsertSql);
+                        if (destinationInsert.get("code").equals("1")) {
+                            if (rsIncorrectData == 0) {
+                                // 记录错误信息
+                                saveErrorMsg(tkId, datetime, destinationInsert.get("msg").toString());
+                            }
+                            // 关闭连接
+                            destinationDbUtil.closeConnection(destinationConn);
+                            return;
+                        }
+                        Map<String, Object> destinationQueryMap = (Map<String, Object>) destinationInsert.get("msg");
+                        PreparedStatement destinationInsertStmt = (PreparedStatement) destinationQueryMap.get("stmt");
+                        // 关闭对象 PreparedStatement
+                        destinationDbUtil.closeStatement(destinationInsertStmt);
+
+                        SmartDataTask tempSmartDataTask = new SmartDataTask();
+                        tempSmartDataTask.setTkId(tkId);
+                        if (swappedPrimaryKeys == null || swappedPrimaryKeys.equals("")) {
+                            tempSmartDataTask.setTkSwappedPrimaryKeys(stringPrimaryKeyData);
+                        } else {
+                            swappedPrimaryKeys = swappedPrimaryKeys + "," + stringPrimaryKeyData;
+                            tempSmartDataTask.setTkSwappedPrimaryKeys(swappedPrimaryKeys);
+                        }
+                        // 保存交换后的主键
+                        int returnUpdateCount = smartDataTaskMapper.saveSwappedPrimaryKeys(tempSmartDataTask);
+                        if (returnUpdateCount == 0) {
+                            if (rsIncorrectData == 0) {
+                                // 记录错误信息
+                                saveErrorMsg(tkId, datetime, "记录交换的主键失败!插入语句:" + destinationInsertSql);
+                            }
+                        }
+                    }
+
+                    destinationDbUtil.closeResultSet(destinationRs);
+                    destinationDbUtil.closeStatement(destinationQueryStmt);
+                    destinationDbUtil.closeConnection(destinationConn);
+                }
+            }
+        } catch (SQLException e) {
+            if (rsIncorrectData == 0) {
+                // 记录错误信息
+                saveErrorMsg(tkId, datetime, e.getMessage());
+            }
+        } finally {
+            sourceDbUtil.closeResultSet(sourceRs);
+            sourceDbUtil.closeStatement(sourceStmt);
+        }
+    }
+
+    private void saveErrorMsg(Integer tkId, String datetime, String errorMsg) {
+        // 实现错误信息保存的逻辑
+        SmartDataTaskErr smartDataTaskErr = new SmartDataTaskErr();
+        smartDataTaskErr.setETaskId(tkId);
+        smartDataTaskErr.setEMsg(errorMsg);
+        smartDataTaskErr.setEDateTime(datetime);
+
+        SmartDataTaskErr returnSmartDataTaskErr = smartDataTaskMapper.selectErrorMsg(smartDataTaskErr);
+        if (returnSmartDataTaskErr == null) {
+            // 保存错误信息到数据库
+            int i = smartDataTaskMapper.insertErrorMsg(smartDataTaskErr);
+            if (i == 0) {
+                System.out.println(datetime + ":保存错误信息失败!");
+            }
+        } else {
+            smartDataTaskErr.setEId(returnSmartDataTaskErr.getEId());
+            smartDataTaskErr.setENum(returnSmartDataTaskErr.getENum() + 1);
+            int i = smartDataTaskMapper.updateErrorMsg(smartDataTaskErr);
+            if (i == 0) {
+                System.out.println(datetime + ":更新错误信息失败!");
+            }
+        }
+    }
+
+    // 保存下次执行时间
+    private void saveNextExtTime(Integer tkId, String datetime, JobKey key, int rsIncorrectData) {
+        QueryWrapper<SmartDataTask> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(key.getName() != null, "tk_name", key.getName());
+        SmartDataTask smartDataTask = smartDataTaskMapper.selectOne(queryWrapper);
+        if (smartDataTask != null) {
+            // 下次执行的时间
+            String nextExeTime = QuartzJobUtils.getNextExeTime(smartDataTask.getTkCron());
+            smartDataTask.setTkNextExeTime(nextExeTime);
+            try {
+                smartDataTaskMapper.markTaskById(smartDataTask);
+            } catch (Exception e) {
+                if (rsIncorrectData == 0) {
+                    saveErrorMsg(tkId, datetime, e.getMessage());
+                }
+            }
+        } else {
+            if (rsIncorrectData == 0) {
+                saveErrorMsg(tkId, datetime, "【下次执行的时间】无法更新至数据库中!");
+            }
+        }
     }
 }

+ 1 - 2
src/main/java/com/template/mapper/SmartDataSourceMapper.java

@@ -1,10 +1,9 @@
 package com.template.mapper;
 
-import com.template.model.pojo.SmartDataSource;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.template.model.pojo.SmartDataSource;
 import com.template.model.pojo.SmartDataSourceJobParams;
 import com.template.model.pojo.SmartDepartment;
-import com.template.model.pojo.SmartDsColumnCor;
 import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 

+ 210 - 25
src/main/java/com/template/mapper/SmartDataTaskMapper.java

@@ -2,12 +2,10 @@ package com.template.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.template.model.pojo.SmartDataTask;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
+import com.template.model.pojo.SmartDataTaskErr;
+import org.apache.ibatis.annotations.*;
 import org.springframework.stereotype.Repository;
 
-import java.util.List;
-
 /**
  * <p>
  * 数据源任务 Mapper 接口
@@ -19,32 +17,219 @@ import java.util.List;
 @Repository
 public interface SmartDataTaskMapper extends BaseMapper<SmartDataTask> {
     @Select("SELECT " +
-            "        tk_id " +
-            "        ,tk_name " +
-            "        ,tk_ds_id_source " +
-            "        ,tk_sync_policy " +
-            "        ,tk_sql, " +
-            "        tk_ds_id_destination " +
-            "        ,tk_dest_table " +
-            "        ,tk_manual_or_auto " +
-            "        ,tk_descrition " +
-            "    FROM " +
-            "        smart_data_task  " +
-            "    WHERE " +
-            "        tk_name = #{tkName} " +
-            "        AND tk_id != #{tkId} ")
-    List<SmartDataTask> isRepeatTaskName(SmartDataTask smartDataTask);
+            "    COUNT(tk_id) " +
+            "FROM " +
+            "    smart_data_task  " +
+            "WHERE " +
+            "    tk_name = #{tkName} " +
+            "    AND tk_id != #{tkId} "
+    )
+    int isRepeatTaskName(SmartDataTask smartDataTask);
+
+    @Update("UPDATE smart_data_task " +
+            "SET tk_activation = #{tkActivation} " +
+            "    ,tk_next_exe_time = #{tkNextExeTime} " +
+            "WHERE " +
+            "    tk_id = #{tkId} "
+    )
+    int markTaskById(SmartDataTask smartDataTask);
+
+    @Insert({
+            "<script>",
+            "INSERT INTO smart_data_task ",
+            "   <trim prefix='(' suffix=')' suffixOverrides=','> ",
+            "       <if test='tkName != null'>tk_name,</if> ",
+            "       <if test='tkDtId != null'>tk_dt_id,</if> ",
+            "       <if test='tkDsIdSource != null'>tk_ds_id_source,</if> ",
+            "       <if test='tkSyncPolicy != null'>tk_sync_policy,</if> ",
+            "       <if test='tkExchangeType != null'>tk_exchange_type,</if> ",
+            "       <if test='tkSql != null'>tk_sql,</if> ",
+            "       <if test='tkDsIdDestination != null'>tk_ds_id_destination,</if> ",
+            "       <if test='tkDestTable != null'>tk_dest_table,</if> ",
+            "       <if test='tkExchangeServer != null'>tk_exchange_server,</if> ",
+            "       <if test='tkExchangeServerId != null'>tk_exchange_server_id,</if> ",
+            "       <if test='tkOptCfgAutoManual != null'>tk_opt_cfg_auto_manual,</if> ",
+            "       <if test='tkOptCfgRsNum != null'>tk_opt_cfg_rs_num,</if> ",
+            "       <if test='tkOptCfgThreadsNum != null'>tk_opt_cfg_threads_num,</if> ",
+            "       <if test='tkRsIncorrectData != null'>tk_rs_incorrect_data,</if> ",
+            "       <if test='tkDsSourceCharset != null'>tk_ds_source_charset,</if> ",
+            "       <if test='tkDsDestinationCharset != null'>tk_ds_destination_charset,</if> ",
+            "       <if test='tkCron != null'>tk_cron,</if> ",
+            "       <if test='tkManualOrAuto != null'>tk_manual_or_auto,</if> ",
+            "       <if test='tkExeType != null'>tk_exe_type,</if> ",
+            "       <if test='tkRepetTime != null'>tk_repet_time,</if> ",
+            "       <if test='tkActivation != null'>tk_activation,</if> ",
+            "       <if test='tkDescrition != null'>tk_descrition,</if> ",
+            "       <if test='tkDeleted != null'>tk_deleted,</if> ",
+            "       <if test='tkNextExeTime != null'>tk_next_exe_time,</if> ",
+            "   </trim> ",
+            "VALUES ",
+            "   <trim prefix='(' suffix=')' suffixOverrides=','>",
+            "      <if test='tkName != null'>#{tkName},</if> ",
+            "      <if test='tkDtId != null'>#{tkDtId},</if> ",
+            "      <if test='tkDsIdSource != null'>#{tkDsIdSource},</if> ",
+            "      <if test='tkSyncPolicy != null'>#{tkSyncPolicy},</if> ",
+            "      <if test='tkExchangeType != null'>#{tkExchangeType},</if> ",
+            "      <if test='tkSql != null'>#{tkSql},</if> ",
+            "      <if test='tkDsIdDestination != null'>#{tkDsIdDestination},</if> ",
+            "      <if test='tkDestTable != null'>#{tkDestTable},</if> ",
+            "      <if test='tkExchangeServer != null'>#{tkExchangeServer},</if> ",
+            "      <if test='tkExchangeServerId != null'>#{tkExchangeServerId},</if> ",
+            "      <if test='tkOptCfgAutoManual != null'>#{tkOptCfgAutoManual},</if> ",
+            "      <if test='tkOptCfgRsNum != null'>#{tkOptCfgRsNum},</if> ",
+            "      <if test='tkOptCfgThreadsNum != null'>#{tkOptCfgThreadsNum},</if> ",
+            "      <if test='tkRsIncorrectData != null'>#{tkRsIncorrectData},</if> ",
+            "      <if test='tkDsSourceCharset != null'>#{tkDsSourceCharset},</if> ",
+            "      <if test='tkDsDestinationCharset != null'>#{tkDsDestinationCharset},</if> ",
+            "      <if test='tkColRelationship != null'>#{tkColRelationship},</if> ",
+            "      <if test='tkCron != null'>#{tkCron},</if> ",
+            "      <if test='tkManualOrAuto != null'>#{tkManualOrAuto},</if> ",
+            "      <if test='tkExeType != null'>#{tkExeType},</if> ",
+            "      <if test='tkRepetTime != null'>#{tkRepetTime},</if> ",
+            "      <if test='tkActivation != null'>#{tkActivation},</if> ",
+            "      <if test='tkDeleted != null'>#{tkDeleted},</if> ",
+            "      <if test='tkNextExeTime != null'>#{tkNextExeTime},</if> ",
+            "   </trim>",
+            "</script>"
+    })
+    @Options(useGeneratedKeys = true, keyProperty = "tk_id")
+    int insert(SmartDataTask smartDataTask);
+
+    @Update("UPDATE smart_data_task " +
+            "   SET tk_col_relationship = #{colRelationship} " +
+            "WHERE " +
+            "   tk_id = #{tkId}")
+    int insertColRelationship(int tkId, String colRelationship);
+
+    @Select("SELECT " +
+            "    COUNT(id) " +
+            "FROM " +
+            "    smart_department  " +
+            "WHERE " +
+            "    id = #{tkDtId} ")
+    int isHaveDepartmentById(Integer tkDtId);
+
+    @Select("SELECT " +
+            "    tk_id " +
+            "    ,tk_col_relationship " +
+            "FROM " +
+            "    smart_data_task  " +
+            "WHERE " +
+            "    tk_id = #{tkId} "
+    )
+    SmartDataTask selectColRelationship(int tkId);
+
+    @Select("SELECT " +
+            "    tk_id " +
+            "    ,tk_swapped_primary_keys " +
+            "FROM " +
+            "    smart_data_task  " +
+            "WHERE " +
+            "    tk_id = #{tkId} "
+    )
+    SmartDataTask selectColSwappedPrimaryKeys(int tkId);
+
+    @Select({
+            "<script>",
+            "   SELECT " +
+            "      COUNT(*) " +
+            "   FROM smart_data_task ",
+            "   <where>",
+            "      <if test='tkId != null'>AND tk_id = #{tkId}</if> ",
+            "      <if test='tkName != null'>AND tk_name = #{tkName}</if> ",
+            "      <if test='tkDtId != null'>AND tk_dt_id = #{tkDtId}</if> ",
+            "      <if test='tkDsIdSource != null'>AND tk_ds_id_source = #{tkDsIdSource}</if> ",
+            "      <if test='tkSyncPolicy != null'>AND tk_sync_policy = #{tkSyncPolicy}</if> ",
+            "      <if test='tkExchangeType != null'>AND tk_exchange_type = #{tkExchangeType}</if> ",
+            "      <if test='tkSql != null'>AND tk_sql = #{tkSql}</if> ",
+            "      <if test='tkDsIdDestination != null'>AND tk_ds_id_destination = #{tkDsIdDestination}</if> ",
+            "      <if test='tkDestTable != null'>AND tk_dest_table = #{tkDestTable}</if> ",
+            "      <if test='tkExchangeServer != null'>AND tk_exchange_server = #{tkExchangeServer}</if> ",
+            "      <if test='tkExchangeServerId != null'>AND tk_exchange_server_id = #{tkExchangeServerId}</if> ",
+            "      <if test='tkOptCfgAutoManual != null'>AND tk_opt_cfg_auto_manual = #{tkOptCfgAutoManual}</if> ",
+            "      <if test='tkOptCfgRsNum != null'>AND tk_opt_cfg_rs_num = #{tkOptCfgRsNum}</if> ",
+            "      <if test='tkOptCfgThreadsNum != null'>AND tk_opt_cfg_threads_num = #{tkOptCfgThreadsNum}</if> ",
+            "      <if test='tkRsIncorrectData != null'>AND tk_rs_incorrect_data = #{tkRsIncorrectData}</if> ",
+            "      <if test='tkDsSourceCharset != null'>AND tk_ds_source_charset = #{tkDsSourceCharset}</if> ",
+            "      <if test='tkDsDestinationCharset != null'>AND tk_ds_destination_charset = #{tkDsDestinationCharset}</if> ",
+            "      <if test='tkColRelationship != null'>AND tk_name = #{tkColRelationship}</if> ",
+            "      <if test='tkCron != null'>AND tk_cron = #{tkCron}</if> ",
+            "      <if test='tkManualOrAuto != null'>AND tk_manual_or_auto = #{tkManualOrAuto}</if> ",
+            "      <if test='tkExeType != null'>AND tk_exe_type = #{tkExeType}</if> ",
+            "      <if test='tkRepetTime != null'>AND tk_repet_time = #{tkRepetTime}</if> ",
+            "      <if test='tkActivation != null'>AND tk_activation = #{tkActivation}</if> ",
+            "      <if test='tkDeleted != null'>AND tk_deleted = #{tkDeleted}</if> ",
+            "      <if test='tkNextExeTime != null'>AND tk_next_exe_time = #{tkNextExeTime}</if> ",
+            "   </where>",
+            "</script>"
+    })
+    int isRepeatTask(SmartDataTask smartDataTask);
 
     @Update("UPDATE smart_data_task " +
             "SET tk_deleted = 1 " +
             "WHERE " +
-            "       tk_id = #{tkId} ")
-    Integer deleteMarkTaskById(SmartDataTask smartDataTask);
+            "    tk_id = #{id} "
+    )
+    int logicDeleteMarkTaskById(int id);
+
+    @Delete("DELETE FROM smart_data_task "+
+            "WHERE "+
+            "    tk_id = #{id} "
+    )
+    int physicsDeleteMarkTaskById(int id);
 
     @Update("UPDATE smart_data_task " +
-            "SET tk_activation = #{tkActivation} " +
-            "    ,tk_next_exe_time = #{tkNextExeTime} " +
+            "SET tk_deleted = 0 " +
+            "WHERE " +
+            "    tk_id = #{id} "
+    )
+    int restoreLogicDeleteMarkTaskById(int id);
+
+    @Update("UPDATE smart_data_task " +
+            "SET tk_swapped_primary_keys = #{tkSwappedPrimaryKeys} " +
+            "WHERE " +
+            "    tk_id = #{tkId} "
+    )
+    int saveSwappedPrimaryKeys(SmartDataTask smartDataTask);
+
+    @Insert({
+            "<script>",
+            "INSERT INTO smart_data_task_err ",
+            "   <trim prefix='(' suffix=')' suffixOverrides=','> ",
+            "       <if test='eTaskId != null'>e_task_id,</if> ",
+            "       <if test='eDateTime != null'>e_date_time,</if> ",
+            "       <if test='eMsg != null'>e_msg,</if> ",
+            "   </trim> ",
+            "VALUES ",
+            "   <trim prefix='(' suffix=')' suffixOverrides=','>",
+            "      <if test='eTaskId != null'>#{eTaskId},</if> ",
+            "      <if test='eDateTime != null'>#{eDateTime},</if> ",
+            "      <if test='eMsg != null'>#{eMsg},</if> ",
+            "   </trim>",
+            "</script>"
+    })
+    int insertErrorMsg(SmartDataTaskErr smartDataTaskErr);
+
+    @Select({
+            "<script>",
+            "   SELECT " +
+                    "      * " +
+                    "   FROM smart_data_task_err ",
+            "   <where>",
+            "      <if test='eTaskId != null'>AND e_task_id = #{eTaskId}</if> ",
+            "      <if test='eMsg != null'>AND e_msg = #{eMsg}</if> ",
+            "   </where>",
+            "</script>"
+    })
+    SmartDataTaskErr selectErrorMsg(SmartDataTaskErr smartDataTaskErr);
+
+    @Update("UPDATE smart_data_task_err " +
+            "SET e_task_id = #{eTaskId} " +
+            "    ,e_msg = #{eMsg} " +
+            "    ,e_num = #{eNum} " +
+            "    ,e_date_time = #{eDateTime} " +
             "WHERE " +
-            "       tk_id = #{tkId} ")
-    Integer markTaskById(SmartDataTask smartDataTask);
+            "    e_id = #{eId} "
+    )
+    int updateErrorMsg(SmartDataTaskErr smartDataTaskErr);
 }

+ 7 - 1
src/main/java/com/template/model/pojo/SmartDataSourceJobParams.java

@@ -27,7 +27,13 @@ public class SmartDataSourceJobParams {
 
     private String dsUser;
 
-    private String sql;
+    private Integer exchangeType;
+
+    private String sourceSql;
+
+    private String destinationTable;
+
+    private String colRelationship;
 
     private String dsPassword;
 

+ 5 - 3
src/main/java/com/template/model/pojo/SmartDataTask.java

@@ -10,7 +10,6 @@ import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
-import java.sql.Timestamp;
 import java.util.Date;
 
 /**
@@ -81,6 +80,9 @@ public class SmartDataTask implements Serializable {
     @ApiModelProperty(value = "目的数据源字符集:UTF8 或 GBK")
     private String tkDsDestinationCharset;
 
+    @ApiModelProperty(value = "存储已交换的主键")
+    private String tkSwappedPrimaryKeys;
+
     @ApiModelProperty(value = "任务定时表达式")
     private String tkCron;
 
@@ -96,8 +98,8 @@ public class SmartDataTask implements Serializable {
     @ApiModelProperty(value = "是否激活")
     private Integer tkActivation;
 
-    @ApiModelProperty(value = "任务描述")
-    private String tkDescrition;
+    @ApiModelProperty(value = "字段对应关系")
+    private String tkColRelationship;
 
     @ApiModelProperty(value = "删除标记")
     private Integer tkDeleted;

+ 51 - 0
src/main/java/com/template/model/pojo/SmartDataTaskErr.java

@@ -0,0 +1,51 @@
+package com.template.model.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 数据源操作日志
+ * </p>
+ *
+ * @author ceshi
+ * @since 2023-12-05
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="SmartDataTaskErr对象", description="数据源任务错误管理")
+public class SmartDataTaskErr implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键id")
+    @TableId(value = "e_id", type = IdType.AUTO)
+    private Integer eId;
+
+    @ApiModelProperty(value = "出错的任务id")
+    private Integer eTaskId;
+
+    @ApiModelProperty(value = "错误文本")
+    private String eMsg;
+
+    @ApiModelProperty(value = "发生错误次数")
+    private Integer eNum;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "发生错误时间")
+    private String eDateTime;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date eCreateTime;
+}

+ 8 - 2
src/main/java/com/template/model/pojo/SmartDsColumnCor.java

@@ -4,10 +4,16 @@ import lombok.Data;
 
 @Data
 public class SmartDsColumnCor {
+    // 来源列名
     private String colSource;
+    // 目标列名
     private String colDestination;
-    private int updatePrimaryKey;
+    // 是否是更新主键列
+    private int isUpdatePrimaryKey;
+    // 是否是交换列
     private int isExchange;
+    // 是否是更新列
     private int isUpdate;
-    private int markIncrement;
+    // 是否是增量标记
+    private int isMarkIncrement;
 }

+ 15 - 5
src/main/java/com/template/services/SmartDataTaskService.java

@@ -1,11 +1,10 @@
 package com.template.services;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.template.model.pojo.SmartDataTask;
-import com.template.model.result.CommonResult;
 import com.template.model.result.PageUtils;
 
-import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 /**
@@ -17,13 +16,22 @@ import java.util.Map;
  * @since 2023-12-05
  */
 public interface SmartDataTaskService extends IService<SmartDataTask> {
-    Map<String, Object> insertSmartDataTask(SmartDataTask smartDataTask);
+    Map<String, Object> insertSmartDataTask1(SmartDataTask smartDataTask);
 
-    Map<String, Object> updateSmartDataTaskById(SmartDataTask smartDataTask);
+    // 添加任务2-字段配置
+    Map<String, Object> insertSmartDataTask2(JSONObject requestData);
+
+    Map<String, Object> insertSmartDataTask3(SmartDataTask smartDataTask);
+
+    Map<String, Object> updateSmartDataTaskById1(SmartDataTask smartDataTask);
+
+    Map<String, Object> updateSmartDataTaskById2(JSONObject json);
+
+    Map<String, Object> updateSmartDataTaskById3(SmartDataTask smartDataTask);
 
     PageUtils<SmartDataTask> queryPageSmartDataTasks(int currentPage, int pageCount, SmartDataTask smartDataTask);
 
-    int deleteSmartDataTaskById(SmartDataTask smartDataTask);
+    Map<String, Object> deleteSmartDataTaskById(int id, int delMethod);
 
     SmartDataTask getSmartById(int id);
 
@@ -50,4 +58,6 @@ public interface SmartDataTaskService extends IService<SmartDataTask> {
     Map<String, Object> getTables(String json);
 
     Map<String, Object> getViews(String json);
+
+
 }

+ 337 - 107
src/main/java/com/template/services/impl/SmartDataTaskServiceImpl.java

@@ -1,36 +1,38 @@
 package com.template.services.impl;
 
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
 import com.template.common.utils.CommonUtil;
 import com.template.common.utils.DBUtil;
 import com.template.common.utils.QuartzJobUtils;
 import com.template.mapper.SmartDataSourceMapper;
 import com.template.mapper.SmartDataTaskMapper;
-import com.template.model.pojo.*;
-import com.template.model.result.CommonResult;
+import com.template.model.pojo.SmartDataSourceJobParams;
+import com.template.model.pojo.SmartDataTask;
+import com.template.model.pojo.SmartDepartment;
 import com.template.model.result.PageUtils;
 import com.template.services.SmartDataTaskService;
-import lombok.val;
 import org.quartz.CronExpression;
-import org.quartz.JobKey;
 import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
-import javax.servlet.http.HttpServletRequest;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -54,15 +56,17 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
     @Autowired
     private Scheduler scheduler;
 
+    // 添加任务1-任务基本信息
     @Override
-    public Map<String, Object> insertSmartDataTask(SmartDataTask smartDataTask) {
+    public Map<String, Object> insertSmartDataTask1(SmartDataTask smartDataTask) {
         // 检测参数,还有是否存在重复记录
         // 任务属性
         if (smartDataTask.getTkName() == null) {
             return CommonUtil.getReturnMap("1", "【任务名称】不能为空!");
         }
-        if (!CommonUtil.checkStrByRegx("^[a-zA-Z0-9]{5,32}$", smartDataTask.getTkName())) {
-            return CommonUtil.getReturnMap("1", "【任务名称】只能包含字母、数字,且长度为5-32位!");
+        // 只能包含字母、数字、下划线和中文,且长度为5-32位
+        if (!CommonUtil.checkStrByRegx("^[\\w\\u4e00-\\u9fa5]{4,32}$", smartDataTask.getTkName())) {
+            return CommonUtil.getReturnMap("1", "【任务名称】只能包含字母、数字、下划线和中文,且长度为4-32位!");
         }
         QueryWrapper<SmartDataTask> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq(smartDataTask.getTkName() != null, "tk_name", smartDataTask.getTkName());
@@ -73,6 +77,10 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (smartDataTask.getTkDtId() == null) {
             return CommonUtil.getReturnMap("1", "【部门id】不能为空!");
         }
+        int numOfDepartment = smartDataTaskMapper.isHaveDepartmentById(smartDataTask.getTkDtId());
+        if (numOfDepartment == 0) {
+            return CommonUtil.getReturnMap("1", "【部门】不存在!");
+        }
         if (smartDataTask.getTkSyncPolicy() == null) {
             return CommonUtil.getReturnMap("1", "【同步策略】不能为空!");
         }
@@ -80,8 +88,8 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (smartDataTask.getTkDsIdSource() == null) {
             return CommonUtil.getReturnMap("1", "【来源数据源id】不能为空!");
         }
-        SmartDataSource smartDataSource = smartDataSourceMapper.selectById(smartDataTask.getTkDsIdSource());
-        if (smartDataSource == null) {
+        SmartDataSourceJobParams dsSource = smartDataSourceMapper.getDataSourceInfo(smartDataTask.getTkDsIdSource());
+        if (dsSource == null) {
             return CommonUtil.getReturnMap("1", "选择的【来源数据源】不存在!");
         }
         if (smartDataTask.getTkExchangeType() == null) {
@@ -94,8 +102,8 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (smartDataTask.getTkDsIdDestination() == null) {
             return CommonUtil.getReturnMap("1", "【目标数据源id】不能为空!");
         }
-        smartDataSource = smartDataSourceMapper.selectById(smartDataTask.getTkDsIdDestination());
-        if (smartDataSource == null) {
+        SmartDataSourceJobParams dsDestination = smartDataSourceMapper.getDataSourceInfo(smartDataTask.getTkDsIdDestination());
+        if (dsDestination == null) {
             return CommonUtil.getReturnMap("1", "选择的【目标数据源】不存在!");
         }
         if (smartDataTask.getTkDestTable() == null) {
@@ -110,16 +118,22 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
                 return CommonUtil.getReturnMap("1", "【指定服务器id】不能为空!");
             }
         }
-        if (smartDataTask.getTkOptCfgAutoManual()== null) {
+        if (smartDataTask.getTkOptCfgAutoManual() == null) {
             return CommonUtil.getReturnMap("1", "【运行参数配置】不能为空!");
         }
-        if (smartDataTask.getTkOptCfgAutoManual() == 1){
+        if (smartDataTask.getTkOptCfgAutoManual() == 1) {
             if (smartDataTask.getTkOptCfgRsNum() == null) {
                 return CommonUtil.getReturnMap("1", "【运行参数配置:记录数】不能为空!");
             }
+            if (smartDataTask.getTkOptCfgRsNum() > 100){
+                return CommonUtil.getReturnMap("1", "【运行参数配置:记录数】不能大于100!");
+            }
             if (smartDataTask.getTkOptCfgThreadsNum() == null) {
                 return CommonUtil.getReturnMap("1", "【运行参数配置:线程数】不能为空!");
             }
+            if (smartDataTask.getTkOptCfgThreadsNum() > 10) {
+                return CommonUtil.getReturnMap("1", "【运行参数配置:线程数】不能大于10!");
+            }
         }
         if (smartDataTask.getTkRsIncorrectData() == null) {
             return CommonUtil.getReturnMap("1", "【是否记录错误数据】不能为空!");
@@ -127,25 +141,35 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (smartDataTask.getTkDsSourceCharset() == null) {
             return CommonUtil.getReturnMap("1", "【来源数据源字符集】不能为空!");
         }
+        if (!smartDataTask.getTkDsSourceCharset().equals("UTF8") && !smartDataTask.getTkDsSourceCharset().equals("GBK")) {
+            return CommonUtil.getReturnMap("1", "【来源数据源字符集】只能为UTF8或GBK!");
+        }
         if (smartDataTask.getTkDsDestinationCharset() == null) {
             return CommonUtil.getReturnMap("1", "【目标数据源字符集】不能为空!");
         }
+        if (!smartDataTask.getTkDsDestinationCharset().equals("UTF8") && !smartDataTask.getTkDsDestinationCharset().equals("GBK")) {
+            return CommonUtil.getReturnMap("1", "【目标数据源字符集】只能为UTF8或GBK!");
+        }
 
         queryWrapper.eq(smartDataTask.getTkDtId() != null, "tk_dt_id", smartDataTask.getTkDtId());
         queryWrapper.eq(smartDataTask.getTkDsIdSource() != null, "tk_ds_id_source", smartDataTask.getTkDsIdSource());
         queryWrapper.eq(smartDataTask.getTkSyncPolicy() != null, "tk_sync_policy", smartDataTask.getTkSyncPolicy());
         queryWrapper.eq(smartDataTask.getTkExchangeType() != null, "tk_exchange_type", smartDataTask.getTkExchangeType());
-        queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", smartDataTask.getTkSql());
+        // 交换方式:0自定义SQL语句,1数据视图,2数据表,如果是1或2,tkSql传视图或表格名称即可
+        if (smartDataTask.getTkExchangeType() == 0) {
+            queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", smartDataTask.getTkSql());
+        } else {
+            String sql = "SELECT * FROM " + smartDataTask.getTkSql().substring(0, smartDataTask.getTkSql().indexOf("["));
+            queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", sql);
+            smartDataTask.setTkSql(sql);
+        }
         queryWrapper.eq(smartDataTask.getTkDsIdDestination() != null, "tk_ds_id_destination", smartDataTask.getTkDsIdDestination());
         queryWrapper.eq(smartDataTask.getTkDestTable() != null, "tk_dest_table", smartDataTask.getTkDestTable());
         queryWrapper.eq(smartDataTask.getTkExchangeServer() != null, "tk_exchange_server", smartDataTask.getTkExchangeServer());
-        queryWrapper.eq(smartDataTask.getTkExchangeServer() != null && smartDataTask.getTkExchangeServerId() != null,
-                "tk_exchange_server_id", smartDataTask.getTkExchangeServerId());
+        queryWrapper.eq(smartDataTask.getTkExchangeServer() != null && smartDataTask.getTkExchangeServerId() != null, "tk_exchange_server_id", smartDataTask.getTkExchangeServerId());
         queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null, "tk_opt_cfg_auto_manual", smartDataTask.getTkOptCfgAutoManual());
-        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgRsNum() != null,
-                "tk_opt_cfg_rs_num", smartDataTask.getTkOptCfgRsNum());
-        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgThreadsNum() != null,
-                "tk_opt_cfg_threads_num", smartDataTask.getTkOptCfgThreadsNum());
+        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgRsNum() != null, "tk_opt_cfg_rs_num", smartDataTask.getTkOptCfgRsNum());
+        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgThreadsNum() != null, "tk_opt_cfg_threads_num", smartDataTask.getTkOptCfgThreadsNum());
         queryWrapper.eq(smartDataTask.getTkRsIncorrectData() != null, "tk_rs_incorrect_data", smartDataTask.getTkRsIncorrectData());
         queryWrapper.eq(smartDataTask.getTkDsSourceCharset() != null, "tk_ds_source_charset", smartDataTask.getTkDsSourceCharset());
         queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkDsDestinationCharset()), "tk_ds_destination_charset", smartDataTask.getTkDsDestinationCharset());
@@ -153,42 +177,164 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (sdt != null) {
             return CommonUtil.getReturnMap("1", "有重复记录!");
         }
-
+        // 插入记录,插入成功后获取记录的id返回
         int result = smartDataTaskMapper.insert(smartDataTask);
         if (result > 0) {
-            return CommonUtil.getReturnMap("0", "任务添加成功!");
+            // 获取数据源对应的表、视图、Sql对应的结构
+            return CommonUtil.getReturnMap("0", this.getMetaData(smartDataTask, dsSource, dsDestination, "添加"));
+        } else {
+            return CommonUtil.getReturnMap("1", "【添加任务-任务基本信息】添加失败!");
+        }
+    }
+
+    private Map<String, Object> getMetaData(SmartDataTask smartDataTask, SmartDataSourceJobParams dsSource, SmartDataSourceJobParams dsDestination, String action) {
+        // 源连接
+        DBUtil dsSourceDbUtil = new DBUtil(dsSource.getDsUrl(), dsSource.getDsUser(), dsSource.getDsPassword(), dsSource.getDsClsDriver(), "UTF8");
+        Map<String, Object> dsSourceMap = dsSourceDbUtil.getConnection();
+        if (dsSourceMap.get("code") == "1") {
+            return CommonUtil.getReturnMap("1", "【来源数据源】连接失败!");
+        }
+        Connection dsSourceConn = (Connection) dsSourceMap.get("msg");
+        // 解析字段名称、字段类型、字段大小等
+        Map<String, Object> metaDataBySql = dsSourceDbUtil.getMetaDataBySql(dsSourceConn, smartDataTask.getTkSql());
+        if (metaDataBySql.get("code") == "1") {
+            return CommonUtil.getReturnMap("1", metaDataBySql.get("msg"));
+        }
+        List<Map<String, String>> listSource = (List<Map<String, String>>) metaDataBySql.get("msg");
+        // 目标连接
+        DBUtil dbDestinationUtil = new DBUtil(dsDestination.getDsUrl(), dsDestination.getDsUser(), dsDestination.getDsPassword(), dsDestination.getDsClsDriver(), "UTF8");
+        Map<String, Object> dsDestinationMap = dbDestinationUtil.getConnection();
+        if (dsDestinationMap.get("code") == "1") {
+            return CommonUtil.getReturnMap("1", "【目标数据源】连接失败!");
+        }
+        Connection dsDestinationConn = (Connection) dsDestinationMap.get("msg");
+        // 目标数据表
+        Map<String, Object> metaDataByTable = dbDestinationUtil.getMetaDataByTable(dsDestinationConn, smartDataTask.getTkDestTable().substring(0, smartDataTask.getTkDestTable().indexOf("[")));
+        if (metaDataByTable.get("code") == "1") {
+            return CommonUtil.getReturnMap("1", metaDataByTable.get("msg"));
+        }
+        List<Map<String, String>> listDestination = (List<Map<String, String>>) metaDataByTable.get("msg");
+
+        // 组合返回数据
+        Map<String, Object> returnMap = new HashMap<>();
+        returnMap.put("tkId", smartDataTask.getTkId());
+        returnMap.put("msg", "【" + action + "任务-任务基本信息】" + action + "成功!");
+        returnMap.put("dsSourceMetaData", listSource);
+        returnMap.put("dsDestinationMetaData", listDestination);
+
+        return returnMap;
+    }
+
+    // 添加任务2-字段配置
+    @Override
+    public Map<String, Object> insertSmartDataTask2(JSONObject requestData) {
+        return this.insertOrUpdate2(requestData, "添加");
+    }
+
+    private Map<String, Object> insertOrUpdate2(JSONObject requestData, String action) {
+        // 任务ID
+        if (requestData.containsKey("tkId")) {
+            // tkId 存在
+            int tkId = requestData.getIntValue("tkId");
+            if (tkId <= 0) {
+                return CommonUtil.getReturnMap("1", "任务id错误!");
+            }
+            // 字段对应关系
+            if (requestData.containsKey("colRelationship")) {
+                JSONArray colRelationshipArray = requestData.getJSONArray("colRelationship");
+                if (colRelationshipArray.size() > 0) {
+                    String colRelationship = colRelationshipArray.toString();
+                    // 检测是否有修改
+                    if (action.equals("编辑")) {
+                        SmartDataTask smartDataTask = smartDataTaskMapper.selectColRelationship(tkId);
+                        if (JSONArray.parseArray(smartDataTask.getTkColRelationship()).equals(colRelationshipArray)) {
+                            return CommonUtil.getReturnMap("1", "数据未修改,请修改后再提交!");
+                        }
+                    }
+                    // 检测数据类型和字段长度是否符合要求
+                    for (int i = 0; i < colRelationshipArray.size(); i++) {
+                        JSONObject colRelationshipObj = colRelationshipArray.getJSONObject(i);
+                        String colSource = colRelationshipObj.getString("colSource");
+                        String colSourceType = colRelationshipObj.getString("colSourceType");
+                        Integer colSourceSize = colRelationshipObj.getInteger("colSourceSize");
+                        String colDestination = colRelationshipObj.getString("colDestination");
+                        String colDestinationType = colRelationshipObj.getString("colDestinationType");
+                        Integer colDestinationSize = colRelationshipObj.getInteger("colDestinationSize");
+                        // 判断字段类型是否一致
+                        if (!colSourceType.equals(colDestinationType)) {
+                            return CommonUtil.getReturnMap("1", "来源字段类型【" + colSource + "】与 目标字段类型【" + colDestination + "】不一致!");
+                        }
+                        // 判断目标字段长度是否小于来源字段长度
+                        if (colSourceSize > colDestinationSize) {
+                            return CommonUtil.getReturnMap("1", "目标字段长度【" + colSource + "】小于 来源字段长度【" + colDestination + "】!");
+                        }
+                    }
+                    // 存数据库中
+                    int num = smartDataTaskMapper.insertColRelationship(tkId, colRelationship);
+                    if (num > 0) {
+                        return CommonUtil.getReturnMap("0", "【" + action + "任务-字段配置】" + action + "成功!");
+                    } else {
+                        return CommonUtil.getReturnMap("1", "【" + action + "任务-字段配置】" + action + "失败!");
+                    }
+                } else {
+                    return CommonUtil.getReturnMap("1", "字段对应关系为空!");
+                }
+            } else {
+                return CommonUtil.getReturnMap("1", "字段对应关系为空!");
+            }
+        } else {
+            // tkId 不存在
+            return CommonUtil.getReturnMap("1", "任务ID为空!");
+        }
+    }
+
+    // 添加任务3-定时信息
+    @Override
+    public Map<String, Object> insertSmartDataTask3(SmartDataTask smartDataTask) {
+        return this.insertOrUpdate3(smartDataTask, "添加");
+    }
+
+    private Map<String, Object> insertOrUpdate3(SmartDataTask smartDataTask, String action) {
+        if (smartDataTask.getTkManualOrAuto() == null) {
+            return CommonUtil.getReturnMap("1", "【手动或定时执行】不能为空!");
+        }
+        if (smartDataTask.getTkManualOrAuto() == 0) {
+            if (smartDataTask.getTkExeType() == null) {
+                return CommonUtil.getReturnMap("1", "【执行方式】不能为空!");
+            }
+            if (smartDataTask.getTkRepetTime() == null) {
+                return CommonUtil.getReturnMap("1", "【重复时间】不能为空!");
+            }
+            // 生成cron表达式
+            Map<String, Object> stringObjectMap = generateCron(smartDataTask.getTkExeType(), smartDataTask.getTkRepetTime());
+            if (stringObjectMap.get("code") == "1") {
+                return stringObjectMap;
+            }
+            String cron = (String) stringObjectMap.get("msg");
+            if (CronExpression.isValidExpression(cron)) {
+                smartDataTask.setTkCron(cron);
+            } else {
+                return CommonUtil.getReturnMap("1", "生成的【定时表达式】不正确!请联系管理员!" + cron);
+            }
         } else {
-            return CommonUtil.getReturnMap("1", "任务添加失败!");
-        }
-
-//        if (smartDataTask.getTkManualOrAuto() == null) {
-//            return CommonUtil.getReturnMap("1", "【手动或定时执行】不能为空!");
-//        }
-//        if (smartDataTask.getTkManualOrAuto() == 0) {
-//            if (smartDataTask.getTkExeType() == null) {
-//                return CommonUtil.getReturnMap("1", "【执行方式】不能为空!");
-//            }
-//            if (smartDataTask.getTkRepetTime() == null) {
-//                return CommonUtil.getReturnMap("1", "【重复时间】不能为空!");
-//            }
-//            // 生成cron表达式
-//            Map<String, Object> stringObjectMap = generateCron(smartDataTask.getTkExeType(), smartDataTask.getTkRepetTime());
-//            if (stringObjectMap.get("code") == "1") {
-//                return stringObjectMap;
-//            }
-//            String cron = (String) stringObjectMap.get("msg");
-//            if (CronExpression.isValidExpression(cron)) {
-//                smartDataTask.setTkCron(cron);
-//            } else {
-//                return CommonUtil.getReturnMap("1", "生成的【定时表达式】不正确!请联系管理员!" + cron);
-//            }
-//        } else {
-//            smartDataTask.setTkExeType(-1);
-//            smartDataTask.setTkRepetTime("");
-//        }
-//        if (smartDataTask.getTkDescrition() == null) {
-//            return CommonUtil.getReturnMap("1", "【任务描述】不能为空!");
-//        }
+            smartDataTask.setTkCron("");
+            smartDataTask.setTkExeType(-1);
+            smartDataTask.setTkRepetTime("");
+        }
+        // 检测是否有重复记录
+        if (action.equals("编辑")) {
+            int numSDT = smartDataTaskMapper.isRepeatTask(smartDataTask);
+            if (numSDT > 0) {
+                return CommonUtil.getReturnMap("1", "数据未修改,请修改后再提交!");
+            }
+        }
+        // 入库
+        int num = smartDataTaskMapper.updateById(smartDataTask);
+        if (num > 0) {
+            return CommonUtil.getReturnMap("0", "【" + action + "任务-定时信息】" + action + "成功!");
+        } else {
+            return CommonUtil.getReturnMap("1", "【" + action + "任务-定时信息】" + action + "失败!");
+        }
     }
 
     // 生成cron表达式
@@ -277,8 +423,7 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
             }
 
             int day = Integer.parseInt(split[0]);
-            if (day > 30 || day < 1)
-                CommonUtil.getReturnMap("1", "【重复时间】格式错误2,要求:19 09:40");
+            if (day > 30 || day < 1) CommonUtil.getReturnMap("1", "【重复时间】格式错误2,要求:19 09:40");
 
             if (isOnlyHourAndMinute(split[1])) {
                 String[] hour_minute = split[1].split(":");
@@ -303,81 +448,127 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
     }
 
     @Override
-    public Map<String, Object> updateSmartDataTaskById(SmartDataTask smartDataTask) {
+    public Map<String, Object> updateSmartDataTaskById1(SmartDataTask smartDataTask) {
         if (smartDataTask.getTkId() == null) {
             return CommonUtil.getReturnMap("1", "【任务id】不能为空!");
         }
+        // 任务属性
+        SmartDataTask sdc = smartDataTaskMapper.selectById(smartDataTask.getTkId());
+        if (sdc == null) {
+            return CommonUtil.getReturnMap("1", "要修改的【任务】不存在!");
+        }
         if (smartDataTask.getTkName() == null) {
             return CommonUtil.getReturnMap("1", "【任务名称】不能为空!");
         }
-        // 检测参数,还有是否存在重复记录
-        List<SmartDataTask> smartDataSources = smartDataTaskMapper.isRepeatTaskName(smartDataTask);
-        if (smartDataSources.size() > 0) {
+        // 只能包含字母、数字、下划线和中文,且长度为5-32位
+        if (!CommonUtil.checkStrByRegx("^[\\w\\u4e00-\\u9fa5]{4,32}$", smartDataTask.getTkName())) {
+            return CommonUtil.getReturnMap("1", "【任务名称】只能包含字母、数字、下划线和中文,且长度为4-32位!");
+        }
+        int numOfDataTask = smartDataTaskMapper.isRepeatTaskName(smartDataTask);
+        if (numOfDataTask > 0) {
             return CommonUtil.getReturnMap("1", "任务名有重名!");
         }
-        SmartDataTask sdc = smartDataTaskMapper.selectById(smartDataTask.getTkId());
-        if (sdc == null) {
-            return CommonUtil.getReturnMap("1", "要修改的【任务】不存在!");
+        if (smartDataTask.getTkDtId() == null) {
+            return CommonUtil.getReturnMap("1", "【部门id】不能为空!");
+        }
+        int numOfDepartment = smartDataTaskMapper.isHaveDepartmentById(smartDataTask.getTkDtId());
+        if (numOfDepartment == 0) {
+            return CommonUtil.getReturnMap("1", "【部门】不存在!");
+        }
+        if (smartDataTask.getTkSyncPolicy() == null) {
+            return CommonUtil.getReturnMap("1", "【同步策略】不能为空!");
         }
+        // 来源库设置
         if (smartDataTask.getTkDsIdSource() == null) {
             return CommonUtil.getReturnMap("1", "【来源数据源id】不能为空!");
         }
-        SmartDataSource smartDataSource = smartDataSourceMapper.selectById(smartDataTask.getTkDsIdSource());
-        if (smartDataSource == null) {
+        SmartDataSourceJobParams dsSource = smartDataSourceMapper.getDataSourceInfo(smartDataTask.getTkDsIdSource());
+        if (dsSource == null) {
             return CommonUtil.getReturnMap("1", "选择的【来源数据源】不存在!");
         }
-        if (smartDataTask.getTkSyncPolicy() == null) {
-            return CommonUtil.getReturnMap("1", "【同步策略】不能为空!");
-        }
         if (smartDataTask.getTkExchangeType() == null) {
             return CommonUtil.getReturnMap("1", "【交换方式】不能为空!");
         }
         if (smartDataTask.getTkSql() == null) {
-            return CommonUtil.getReturnMap("1", "【数据来源SQL语句】不能为空!");
+            return CommonUtil.getReturnMap("1", "【自定义SQL语句】不能为空!");
         }
+        // 目的库设置
         if (smartDataTask.getTkDsIdDestination() == null) {
             return CommonUtil.getReturnMap("1", "【目标数据源id】不能为空!");
         }
-        smartDataSource = smartDataSourceMapper.selectById(smartDataTask.getTkDsIdDestination());
-        if (smartDataSource == null) {
+        SmartDataSourceJobParams dsDestination = smartDataSourceMapper.getDataSourceInfo(smartDataTask.getTkDsIdDestination());
+        if (dsDestination == null) {
             return CommonUtil.getReturnMap("1", "选择的【目标数据源】不存在!");
         }
         if (smartDataTask.getTkDestTable() == null) {
             return CommonUtil.getReturnMap("1", "【目标数据表】不能为空!");
         }
-        if (smartDataTask.getTkManualOrAuto() == null) {
-            return CommonUtil.getReturnMap("1", "【手动或定时执行】不能为空!");
+        // 高级设置
+        if (smartDataTask.getTkExchangeServer() == null) {
+            return CommonUtil.getReturnMap("1", "【交换服务器】不能为空!");
         }
-        if (smartDataTask.getTkManualOrAuto() == 0) {
-            if (smartDataTask.getTkExeType() == null) {
-                return CommonUtil.getReturnMap("1", "【执行方式】不能为空!");
+        if (smartDataTask.getTkExchangeServer() == 1) {
+            if (smartDataTask.getTkExchangeServerId() == null) {
+                return CommonUtil.getReturnMap("1", "【指定服务器id】不能为空!");
             }
-            if (smartDataTask.getTkRepetTime() == null) {
-                return CommonUtil.getReturnMap("1", "【重复时间】不能为空!");
+        }
+        if (smartDataTask.getTkOptCfgAutoManual() == null) {
+            return CommonUtil.getReturnMap("1", "【运行参数配置】不能为空!");
+        }
+        if (smartDataTask.getTkOptCfgAutoManual() == 1) {
+            if (smartDataTask.getTkOptCfgRsNum() == null) {
+                return CommonUtil.getReturnMap("1", "【运行参数配置:记录数】不能为空!");
             }
-            // 生成cron表达式
-            Map<String, Object> stringObjectMap = generateCron(smartDataTask.getTkExeType(), smartDataTask.getTkRepetTime());
-            if (stringObjectMap.get("code") == "1") {
-                return stringObjectMap;
+            if (smartDataTask.getTkOptCfgRsNum() > 100){
+                return CommonUtil.getReturnMap("1", "【运行参数配置:记录数】不能大于100!");
             }
-            smartDataTask.setTkCron((String) stringObjectMap.get("msg"));
-        } else {
-            smartDataTask.setTkExeType(0);
-            smartDataTask.setTkRepetTime("");
+            if (smartDataTask.getTkOptCfgThreadsNum() == null) {
+                return CommonUtil.getReturnMap("1", "【运行参数配置:线程数】不能为空!");
+            }
+            if (smartDataTask.getTkOptCfgThreadsNum() > 10) {
+                return CommonUtil.getReturnMap("1", "【运行参数配置:线程数】不能大于10!");
+            }
+        }
+        if (smartDataTask.getTkRsIncorrectData() == null) {
+            return CommonUtil.getReturnMap("1", "【是否记录错误数据】不能为空!");
+        }
+        if (smartDataTask.getTkDsSourceCharset() == null) {
+            return CommonUtil.getReturnMap("1", "【来源数据源字符集】不能为空!");
+        }
+        if (!smartDataTask.getTkDsSourceCharset().equals("UTF8") && !smartDataTask.getTkDsSourceCharset().equals("GBK")) {
+            return CommonUtil.getReturnMap("1", "【来源数据源字符集】只能为UTF8或GBK!");
+        }
+        if (smartDataTask.getTkDsDestinationCharset() == null) {
+            return CommonUtil.getReturnMap("1", "【目标数据源字符集】不能为空!");
         }
-        if (smartDataTask.getTkDescrition() == null) {
-            return CommonUtil.getReturnMap("1", "【任务描述】不能为空!");
+        if (!smartDataTask.getTkDsDestinationCharset().equals("UTF8") && !smartDataTask.getTkDsDestinationCharset().equals("GBK")) {
+            return CommonUtil.getReturnMap("1", "【目标数据源字符集】只能为UTF8或GBK!");
         }
+
         QueryWrapper<SmartDataTask> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq(smartDataTask.getTkName() != null, "tk_name", smartDataTask.getTkName());
+        queryWrapper.eq(smartDataTask.getTkDtId() != null, "tk_dt_id", smartDataTask.getTkDtId());
         queryWrapper.eq(smartDataTask.getTkDsIdSource() != null, "tk_ds_id_source", smartDataTask.getTkDsIdSource());
         queryWrapper.eq(smartDataTask.getTkSyncPolicy() != null, "tk_sync_policy", smartDataTask.getTkSyncPolicy());
         queryWrapper.eq(smartDataTask.getTkExchangeType() != null, "tk_exchange_type", smartDataTask.getTkExchangeType());
-        queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", smartDataTask.getTkSql());
+        // 交换方式:0自定义SQL语句,1数据视图,2数据表,如果是1或2,tkSql传视图或表格名称即可
+        if (smartDataTask.getTkExchangeType() == 0) {
+            queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", smartDataTask.getTkSql());
+        } else {
+            String sql = "SELECT * FROM " + smartDataTask.getTkSql().substring(0, smartDataTask.getTkSql().indexOf("["));
+            queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", sql);
+            smartDataTask.setTkSql(sql);
+        }
         queryWrapper.eq(smartDataTask.getTkDsIdDestination() != null, "tk_ds_id_destination", smartDataTask.getTkDsIdDestination());
         queryWrapper.eq(smartDataTask.getTkDestTable() != null, "tk_dest_table", smartDataTask.getTkDestTable());
-        queryWrapper.eq(smartDataTask.getTkManualOrAuto() != null, "tk_manual_or_auto", smartDataTask.getTkManualOrAuto());
-        queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkDescrition()), "tk_descrition", smartDataTask.getTkDescrition());
+        queryWrapper.eq(smartDataTask.getTkExchangeServer() != null, "tk_exchange_server", smartDataTask.getTkExchangeServer());
+        queryWrapper.eq(smartDataTask.getTkExchangeServer() != null && smartDataTask.getTkExchangeServerId() != null, "tk_exchange_server_id", smartDataTask.getTkExchangeServerId());
+        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null, "tk_opt_cfg_auto_manual", smartDataTask.getTkOptCfgAutoManual());
+        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgRsNum() != null, "tk_opt_cfg_rs_num", smartDataTask.getTkOptCfgRsNum());
+        queryWrapper.eq(smartDataTask.getTkOptCfgAutoManual() != null && smartDataTask.getTkOptCfgThreadsNum() != null, "tk_opt_cfg_threads_num", smartDataTask.getTkOptCfgThreadsNum());
+        queryWrapper.eq(smartDataTask.getTkRsIncorrectData() != null, "tk_rs_incorrect_data", smartDataTask.getTkRsIncorrectData());
+        queryWrapper.eq(smartDataTask.getTkDsSourceCharset() != null, "tk_ds_source_charset", smartDataTask.getTkDsSourceCharset());
+        queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkDsDestinationCharset()), "tk_ds_destination_charset", smartDataTask.getTkDsDestinationCharset());
         SmartDataTask sdt = smartDataTaskMapper.selectOne(queryWrapper);
         if (sdt != null) {
             return CommonUtil.getReturnMap("1", "数据未修改,请修改后再提交!");
@@ -385,12 +576,23 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
 
         int result = smartDataTaskMapper.updateById(smartDataTask);
         if (result > 0) {
-            return CommonUtil.getReturnMap("0", "任务修改成功!");
+            // 获取数据源对应的表、视图、Sql对应的结构
+            return CommonUtil.getReturnMap("0", this.getMetaData(smartDataTask, dsSource, dsDestination, "编辑"));
         } else {
-            return CommonUtil.getReturnMap("1", "任务修改失败!");
+            return CommonUtil.getReturnMap("1", "【编辑任务-任务基本信息】失败!");
         }
     }
 
+    @Override
+    public Map<String, Object> updateSmartDataTaskById2(JSONObject requestData) {
+        return this.insertOrUpdate2(requestData, "编辑");
+    }
+
+    @Override
+    public Map<String, Object> updateSmartDataTaskById3(SmartDataTask smartDataTask) {
+        return this.insertOrUpdate3(smartDataTask, "编辑");
+    }
+
     // 判断之前状态是否启用
     public Map<String, Object> updateSmartDataTaskActivation(SmartDataTask smartDataTask) {
         // 检测参数,还有是否存在重复记录
@@ -428,15 +630,39 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         queryWrapper.eq(smartDataTask.getTkExeType() != null, "tk_exe_type", smartDataTask.getTkExeType());
         queryWrapper.like(smartDataTask.getTkDestTable() != null, "tk_dest_table", smartDataTask.getTkDestTable());
         queryWrapper.eq(smartDataTask.getTkActivation() != null, "tk_activation", smartDataTask.getTkActivation());
-        queryWrapper.like(smartDataTask.getTkDescrition() != null, "tk_descrition", smartDataTask.getTkDescrition());
+        queryWrapper.orderByAsc("tk_deleted");
         queryWrapper.orderByDesc("tk_update_time");
         IPage<SmartDataTask> result = smartDataTaskMapper.selectPage(page, queryWrapper);
         return new PageUtils<>(result);
     }
 
     @Override
-    public int deleteSmartDataTaskById(SmartDataTask smartDataTask) {
-        return smartDataTaskMapper.deleteMarkTaskById(smartDataTask);
+    public Map<String, Object> deleteSmartDataTaskById(int id, int delMethod) {
+        if (delMethod == 0) {
+            // 逻辑删除
+            int num = smartDataTaskMapper.logicDeleteMarkTaskById(id);
+            if (num > 0) {
+                return CommonUtil.getReturnMap("0", "逻辑删除成功");
+            }
+            return CommonUtil.getReturnMap("1", "逻辑删除失败");
+        } else if (delMethod == 1) {
+            // 恢复逻辑删除
+            int num = smartDataTaskMapper.restoreLogicDeleteMarkTaskById(id);
+            if (num > 0) {
+                return CommonUtil.getReturnMap("0", "恢复逻辑删除成功");
+            }
+            return CommonUtil.getReturnMap("1", "恢复逻辑删除失败");
+        } else if (delMethod == 9) {
+            // 物理删除
+            int num = smartDataTaskMapper.physicsDeleteMarkTaskById(id);
+            if (num > 0) {
+                return CommonUtil.getReturnMap("0", "物理删除成功");
+            }
+            return CommonUtil.getReturnMap("1", "物理删除失败");
+        } else {
+            // 错误
+            return CommonUtil.getReturnMap("1", "删除方式错误");
+        }
     }
 
     @Override
@@ -444,6 +670,7 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         return smartDataTaskMapper.selectById(id);
     }
 
+    // 校验任务名是否存在
     public Map<String, Object> TaskNameValidator(SmartDataTask smartDataTask) {
         if (smartDataTask.getTkName() == null) {
             return CommonUtil.getReturnMap(String.valueOf(1), "任务名称为空!");
@@ -460,21 +687,26 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
 
     @Override
     public Map<String, Object> createJob(SmartDataTask smartDataTask) {
+        // 校验任务名是否存在
         Map<String, Object> tmp_map = TaskNameValidator(smartDataTask);
         if ("1".equals(tmp_map.get("code"))) {
             return tmp_map;
         }
 
         SmartDataTask smartDataTask_return = (SmartDataTask) tmp_map.get("msg");
+        if (smartDataTask_return.getTkCron() == null) {
+            return CommonUtil.getReturnMap(String.valueOf(1), "任务调度cron表达式为空!该任务未设置【定时信息】!");
+        }
         // 来源数据源id
         Integer tkDsIdSource = smartDataTask_return.getTkDsIdSource();
         // 目标数据源id
         Integer tkDsIdDestination = smartDataTask_return.getTkDsIdDestination();
         // 根据id,获取数据源url、user、password、driver等
         SmartDataSourceJobParams dsSourceInfo = smartDataSourceMapper.getDataSourceInfo(tkDsIdSource);
-        dsSourceInfo.setSql(smartDataTask_return.getTkSql());
+        dsSourceInfo.setExchangeType(smartDataTask_return.getTkExchangeType());
+        dsSourceInfo.setSourceSql(smartDataTask_return.getTkSql());
         SmartDataSourceJobParams dsDestinationInfo = smartDataSourceMapper.getDataSourceInfo(tkDsIdDestination);
-        dsDestinationInfo.setSql(smartDataTask_return.getTkSql());
+        dsDestinationInfo.setDestinationTable(smartDataTask_return.getTkDestTable());
 
         Map<String, Object> returnMap = QuartzJobUtils.createScheduleJob(scheduler, smartDataTask_return, dsSourceInfo, dsDestinationInfo);
         if ("0".equals(returnMap.get("code"))) {
@@ -652,14 +884,12 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (exchangeType == 0) {
             // sql语句
             if (dataSourceInfo != null) {
-                DBUtil dbUtil = new DBUtil(dataSourceInfo.getDsUrl(), dataSourceInfo.getDsUser(), dataSourceInfo.getDsPassword(), dataSourceInfo.getDsClsDriver());
+                DBUtil dbUtil = new DBUtil(dataSourceInfo.getDsUrl(), dataSourceInfo.getDsUser(), dataSourceInfo.getDsPassword(), dataSourceInfo.getDsClsDriver(), "UTF8");
                 Map<String, Object> map_return = dbUtil.getConnection();
                 if (map_return.get("code") == "0") {
                     Map<String, Object> metaDataBySql = dbUtil.getMetaDataBySql((Connection) map_return.get("msg"), sql);
                     if (metaDataBySql.get("code") == "0") {
                         return CommonUtil.getReturnMap("0", "SQL语句正确");
-                        // 解析字段名称、字段类型、字段大小等
-//                        return CommonUtil.getReturnMap("0", metaDataBySql.get("msg"));
                     } else {
                         return CommonUtil.getReturnMap("1", metaDataBySql.get("msg"));
                     }
@@ -714,7 +944,7 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         SmartDataSourceJobParams dataSourceInfo = smartDataSourceMapper.getDataSourceInfo(dsIdSource);
         if (dataSourceInfo != null) {
             // 创建DBUtil对象
-            DBUtil dbUtil = new DBUtil(dataSourceInfo.getDsUrl(), dataSourceInfo.getDsUser(), dataSourceInfo.getDsPassword(), dataSourceInfo.getDsClsDriver());
+            DBUtil dbUtil = new DBUtil(dataSourceInfo.getDsUrl(), dataSourceInfo.getDsUser(), dataSourceInfo.getDsPassword(), dataSourceInfo.getDsClsDriver(), "UTF8");
             // 获取连接
             Map<String, Object> map_return = dbUtil.getConnection();
             if (map_return.get("code") == "0") {