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

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 лет назад
Родитель
Сommit
55285da0ac

+ 4 - 0
src/main/java/com/template/api/SmartDataSourceControllerAPI.java

@@ -36,6 +36,10 @@ public interface SmartDataSourceControllerAPI {
     @ApiOperation(value = "数据源分页数据", notes = "数据源分页数据", httpMethod = "GET")
     CommonResult queryPageSmartDataSources(@RequestParam int currentPage, @RequestParam int pageCount, SmartDataSource smartDataSource);
 
+    @GetMapping(value = "/querySmartDataSourceById")
+    @ApiOperation(value = "根据ID查询数据源数据", notes = "根据ID查询数据源数据", httpMethod = "GET")
+    CommonResult querySmartDataSourceById(@RequestParam int id);
+
     @GetMapping(value = "/deleteSmartDataSourceById")
     @ApiOperation(value = "根据ID删除指定数据源", notes = "根据ID删除指定数据源", httpMethod = "GET")
     CommonResult deleteSmartDataSourceById(@RequestParam int id, HttpServletRequest httpServletRequest);

+ 5 - 1
src/main/java/com/template/api/SmartDataTaskControllerAPI.java

@@ -65,7 +65,7 @@ public interface SmartDataTaskControllerAPI {
     CommonResult getTables(@RequestBody String json);
 
     @PostMapping(value = "/getViews")
-    @ApiOperation(value = "根据数据源获取所有的表", notes = "根据数据源获取所有的表", httpMethod = "POST")
+    @ApiOperation(value = "根据数据源获取所有的视图", notes = "根据数据源获取所有的视图", httpMethod = "POST")
     CommonResult getViews(@RequestBody String json);
 
     @PostMapping(value = "/insertSmartDataTask1")
@@ -124,6 +124,10 @@ public interface SmartDataTaskControllerAPI {
                                            @RequestParam(required = false) String startTime,
                                            @RequestParam(required = false) String endTime);
 
+    @GetMapping(value = "/queryAllTask")
+    @ApiOperation(value = "获取所有任务名称", notes = "获取所有任务名称", httpMethod = "GET")
+    CommonResult queryAllTask();
+
     @GetMapping(value = "/queryTaskDebugSql")
     @ApiOperation(value = "任务debugSql", notes = "任务debugSql", httpMethod = "GET")
     CommonResult queryTaskDebugSql();

+ 15 - 8
src/main/java/com/template/common/utils/DBUtil.java

@@ -102,16 +102,19 @@ public class DBUtil {
 
     public Map<String, Object> getMetaDataByTable(Connection conn, String tableName) {
         // 获取数据表的列信息
-        DatabaseMetaData dbMetaData;
         ResultSet rs = null;
-        Map<Integer, Object> map = new HashMap<>();
         try {
-            dbMetaData = conn.getMetaData();
+            DatabaseMetaData dbMetaData = conn.getMetaData();
             rs = dbMetaData.getColumns(null, null, tableName, null);
-            List<Map<String, String>> list = new ArrayList<>();
+            List<Map<String, Object>> list = new ArrayList<>();
+            int isHavaNext = 0;
             // 遍历列信息
-            while (rs.next()) {
-                Map<String, String> tmpMap = new HashMap<>();
+            while (true) {
+                if (!rs.next()) {
+                    break;
+                }
+                isHavaNext++;
+                Map<String, Object> tmpMap = new HashMap<>();
                 // 获取列名称
                 String columnName = rs.getString("COLUMN_NAME");
                 // 获取列类型
@@ -120,6 +123,7 @@ public class DBUtil {
                 String columnComment = rs.getString("REMARKS");
                 // 获取是否允许为空
                 String isNullable = rs.getString("IS_NULLABLE");
+//                int isNullable = rs.getInt("NULLABLE");
                 // 获取字段的长度
                 int columnSize = rs.getInt("COLUMN_SIZE");
 
@@ -131,8 +135,11 @@ public class DBUtil {
 
                 list.add(tmpMap);
             }
-
-            return CommonUtil.getReturnMap("0", list);
+            if (isHavaNext > 0) {
+                return CommonUtil.getReturnMap("0", list);
+            } else {
+                return CommonUtil.getReturnMap("1", "没有查询到数据");
+            }
         } catch (SQLException e) {
             return CommonUtil.getReturnMap("1", e.getMessage());
         } finally {

+ 6 - 0
src/main/java/com/template/controller/SmartDataSourceController.java

@@ -130,6 +130,12 @@ public class SmartDataSourceController implements SmartDataSourceControllerAPI {
         return CommonResult.ok(result);
     }
 
+    @Override
+    public CommonResult querySmartDataSourceById(int id) {
+        SmartDataSource smartDataSource = smartDataSourceService.querySmartDataSourceById(id);
+        return CommonResult.ok(smartDataSource);
+    }
+
 
     @Override
     public CommonResult deleteSmartDataSourceById(int id, HttpServletRequest httpServletRequest) {

+ 9 - 0
src/main/java/com/template/controller/SmartDataTaskController.java

@@ -469,6 +469,15 @@ public class SmartDataTaskController implements SmartDataTaskControllerAPI {
     }
 
     @Override
+    public CommonResult queryAllTask() {
+        List<SmartDataTask> result = smartDataTaskService.queryAllTask();
+        if (result.size() > 0) {
+            return CommonResult.ok(result);
+        } else {
+            return CommonResult.fail("没有任何任务");
+        }
+    }
+    @Override
     public CommonResult queryTaskDebugSql() {
         List<SmartDataTaskSetDebugSql> result = smartDataTaskService.queryTaskDebugSql();
         if (result.size() > 0) {

+ 10 - 1
src/main/java/com/template/mapper/SmartDataClassMapper.java

@@ -22,6 +22,15 @@ public interface SmartDataClassMapper extends BaseMapper<SmartDataClass> {
             " FROM " +
             "    smart_data_source " +
             " WHERE " +
-            "    ds_cls_id = #{id}")
+            "    ds_cls_id = #{id}"
+    )
     int checkDataSourceExist(int id);
+
+    @Select(" SELECT " +
+            "    * " +
+            " FROM " +
+            "    smart_data_source " +
+            " WHERE " +
+            "    ds_id = #{id}")
+    SmartDataSource querySmartDataSourceById(int id);
 }

+ 15 - 4
src/main/java/com/template/mapper/SmartDataTaskMapper.java

@@ -61,9 +61,8 @@ public interface SmartDataTaskMapper extends BaseMapper<SmartDataTask> {
             "       <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='tkRepeatTime != null'>tk_repeat_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> ",
@@ -89,14 +88,14 @@ public interface SmartDataTaskMapper extends BaseMapper<SmartDataTask> {
             "      <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='tkRepeatTime != null'>#{tkRepeatTime},</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")
+    @Options(useGeneratedKeys = true, keyProperty = "tkId")
     int insertOne(SmartDataTask smartDataTask);
 
     @Update("UPDATE smart_data_task " +
@@ -437,4 +436,16 @@ public interface SmartDataTaskMapper extends BaseMapper<SmartDataTask> {
             "    tk_id = #{tkId} "
     )
     int queryTaskSetDebugSql(int tkId, int tkDebugSql);
+
+    @Select({
+            "<script>",
+            "   SELECT ",
+            "      * ",
+            "   FROM ",
+            "      smart_data_task ",
+            "   ORDER BY ",
+            "      tk_name ",
+            "</script>"
+    })
+    List<SmartDataTask> queryAllTask();
 }

+ 2 - 0
src/main/java/com/template/services/SmartDataSourceService.java

@@ -28,4 +28,6 @@ public interface SmartDataSourceService extends IService<SmartDataSource> {
     SmartDataSource getSmartById(int id);
 
     Map<String, Object> vcoSmartDataSource(SmartDataSource smartDataSource);
+
+    SmartDataSource querySmartDataSourceById(int id);
 }

+ 2 - 0
src/main/java/com/template/services/SmartDataTaskService.java

@@ -76,4 +76,6 @@ public interface SmartDataTaskService extends IService<SmartDataTask> {
     List<SmartDataTaskSetDebugSql>  queryTaskDebugSql();
 
     int queryTaskSetDebugSql(int tkId, int tkDebugSql);
+
+    List<SmartDataTask> queryAllTask();
 }

+ 6 - 0
src/main/java/com/template/services/impl/SmartDataSourceServiceImpl.java

@@ -243,4 +243,10 @@ public class SmartDataSourceServiceImpl extends ServiceImpl<SmartDataSourceMappe
             }
         }
     }
+
+    @Override
+    public SmartDataSource querySmartDataSourceById(int id) {
+        SmartDataSource smartDataSource = smartDataClassMapper.querySmartDataSourceById(id);
+        return smartDataSource;
+    }
 }

+ 69 - 25
src/main/java/com/template/services/impl/SmartDataTaskServiceImpl.java

@@ -208,21 +208,25 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
             return CommonUtil.getReturnMap("1", "【目标数据源】连接失败!");
         }
         Connection dsDestinationConn = (Connection) dsDestinationMap.get("msg");
+        String tmpString = smartDataTask.getTkDestTable();
         // 目标数据表
-        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");
+        if (tmpString.contains("[")) {
+            Map<String, Object> metaDataByTable = dbDestinationUtil.getMetaDataByTable(dsDestinationConn, tmpString.substring(0, tmpString.indexOf("[")).trim());
+            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);
+            // 组合返回数据
+            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;
+            return returnMap;
+        }
+        return CommonUtil.getReturnMap("1", "【目标数据表】格式错误!");
     }
 
     // 添加任务2-字段配置
@@ -245,12 +249,13 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
                 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", "数据未修改,请修改后再提交!");
-                        }
-                    }
+//                    if (action.equals("编辑")) {
+//                        SmartDataTask smartDataTask = smartDataTaskMapper.selectColRelationship(tkId);
+//                        if (JSONArray.parseArray(smartDataTask.getTkColRelationship()).equals(colRelationshipArray)) {
+//                            return CommonUtil.getReturnMap("1", "数据未修改!");
+//                        }
+//                    }
+                    int hasPrimaryKey = 0;
                     // 检测数据类型和字段长度是否符合要求
                     for (int i = 0; i < colRelationshipArray.size(); i++) {
                         JSONObject colRelationshipObj = colRelationshipArray.getJSONObject(i);
@@ -260,6 +265,9 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
                         String colDestination = colRelationshipObj.getString("colDestination");
                         String colDestinationType = colRelationshipObj.getString("colDestinationType");
                         Integer colDestinationSize = colRelationshipObj.getInteger("colDestinationSize");
+                        if (colRelationshipObj.getInteger("isUpdatePrimaryKey") == 1) {
+                            hasPrimaryKey++;
+                        }
                         // 判断字段类型是否一致
                         if (!colSourceType.equals(colDestinationType)) {
                             return CommonUtil.getReturnMap("1", "来源字段类型【" + colSource + "】与 目标字段类型【" + colDestination + "】不一致!");
@@ -269,12 +277,19 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
                             return CommonUtil.getReturnMap("1", "目标字段长度【" + colSource + "】小于 来源字段长度【" + colDestination + "】!");
                         }
                     }
+                    if (hasPrimaryKey == 0) {
+                        return CommonUtil.getReturnMap("1", "至少需要一个更新主键!");
+                    }
                     // 存数据库中
                     int num = smartDataTaskMapper.insertColRelationship(tkId, colRelationship);
                     if (num > 0) {
                         return CommonUtil.getReturnMap("0", "【" + action + "任务-字段配置】" + action + "成功!");
                     } else {
-                        return CommonUtil.getReturnMap("1", "【" + action + "任务-字段配置】" + action + "失败!");
+                        if (action.equals("编辑")) {
+                            return CommonUtil.getReturnMap("0", "【" + action + "任务-字段配置】数据未修改!");
+                        } else {
+                            return CommonUtil.getReturnMap("1", "【" + action + "任务-字段配置】" + action + "失败!");
+                        }
                     }
                 } else {
                     return CommonUtil.getReturnMap("1", "字段对应关系为空!");
@@ -295,6 +310,9 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
     }
 
     private Map<String, Object> insertOrUpdate3(SmartDataTask smartDataTask, String action) {
+        if (smartDataTask.getTkId() == null) {
+            return CommonUtil.getReturnMap("1", "任务ID为空!");
+        }
         if (smartDataTask.getTkManualOrAuto() == null) {
             return CommonUtil.getReturnMap("1", "【手动或定时执行】不能为空!");
         }
@@ -325,7 +343,7 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         if (action.equals("编辑")) {
             int numSDT = smartDataTaskMapper.isRepeatTask(smartDataTask);
             if (numSDT > 0) {
-                return CommonUtil.getReturnMap("1", "数据未修改,请修改后再提交!");
+                return CommonUtil.getReturnMap("1", "数据未修改!");
             }
         }
         // 入库
@@ -555,7 +573,11 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         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("["));
+            String sql;
+            if (smartDataTask.getTkSql().contains("["))
+                sql = "SELECT * FROM " + smartDataTask.getTkSql().substring(0, smartDataTask.getTkSql().indexOf("["));
+            else
+                sql = "SELECT * FROM " + smartDataTask.getTkSql().trim();
             queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkSql()), "tk_sql", sql);
             smartDataTask.setTkSql(sql);
         }
@@ -571,7 +593,15 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
         queryWrapper.eq(StringUtils.hasText(smartDataTask.getTkDsDestinationCharset()), "tk_ds_destination_charset", smartDataTask.getTkDsDestinationCharset());
         SmartDataTask sdt = smartDataTaskMapper.selectOne(queryWrapper);
         if (sdt != null) {
-            return CommonUtil.getReturnMap("1", "数据未修改,请修改后再提交!");
+            // 获取数据源对应的表、视图、Sql对应的结构
+            Map<String, Object> returnMap = this.getMetaData(smartDataTask, dsSource, dsDestination, "编辑");
+            if (returnMap.get("code") == null) {
+                // 获取字段对应关系
+                String colRelationship = smartDataTaskMapper.getColRelationship(smartDataTask);
+                JSONArray jsonArray = JSONArray.parseArray(colRelationship);
+                returnMap.put("colRelationship", jsonArray);
+            }
+            return CommonUtil.getReturnMap("0", returnMap);
         }
 
         int result = smartDataTaskMapper.updateById(smartDataTask);
@@ -630,12 +660,20 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
     public PageUtils<SmartDataTask> queryPageSmartDataTasks(int currentPage, int pageCount, SmartDataTask smartDataTask) {
         Page<SmartDataTask> page = new Page<>(currentPage, pageCount);
         QueryWrapper<SmartDataTask> queryWrapper = new QueryWrapper<>();
-        queryWrapper.like(smartDataTask.getTkName() != null, "tk_name", smartDataTask.getTkName());
+        queryWrapper.like(smartDataTask.getTkName() != null && !smartDataTask.getTkName().equals("") && !smartDataTask.getTkName().equals("null"),
+                "tk_name", smartDataTask.getTkName());
         queryWrapper.eq(smartDataTask.getTkDsIdSource() != null, "tk_ds_id_source", smartDataTask.getTkDsIdSource());
         queryWrapper.eq(smartDataTask.getTkDsIdDestination() != null, "tk_ds_id_destination", smartDataTask.getTkDsIdDestination());
         queryWrapper.eq(smartDataTask.getTkExchangeType() != null, "tk_exchange_type", smartDataTask.getTkExchangeType());
-        queryWrapper.eq(smartDataTask.getTkExeType() != null, "tk_exe_type", smartDataTask.getTkExeType());
-        queryWrapper.like(smartDataTask.getTkDestTable() != null, "tk_dest_table", smartDataTask.getTkDestTable());
+        if (smartDataTask.getTkExeType() != null) {
+            if (smartDataTask.getTkExeType() == -2) {
+                queryWrapper.isNull("tk_exe_type");
+            } else {
+                queryWrapper.eq(true, "tk_exe_type", smartDataTask.getTkExeType());
+            }
+        }
+        queryWrapper.like(smartDataTask.getTkDestTable() != null && !smartDataTask.getTkDestTable().equals("") && !smartDataTask.getTkDestTable().equals("null"),
+                "tk_dest_table", smartDataTask.getTkDestTable());
         queryWrapper.eq(smartDataTask.getTkActivation() != null, "tk_activation", smartDataTask.getTkActivation());
         queryWrapper.orderByAsc("tk_deleted");
         queryWrapper.orderByDesc("tk_update_time");
@@ -991,6 +1029,12 @@ public class SmartDataTaskServiceImpl extends ServiceImpl<SmartDataTaskMapper, S
     }
 
     @Override
+    public List<SmartDataTask> queryAllTask() {
+        List<SmartDataTask> smartDataTask = smartDataTaskMapper.queryAllTask();
+        return smartDataTask;
+    }
+
+    @Override
     public List<SmartDataTaskSetDebugSql> queryTaskDebugSql() {
         List<SmartDataTaskSetDebugSql> smartDataTaskSetDebugSqls = smartDataTaskMapper.queryTaskDebugSql();
         return smartDataTaskSetDebugSqls;