Explorar o código

feat: 路径带出

Leo hai 1 ano
pai
achega
a1dbc8d343

+ 52 - 7
src/module/datasource/component/StepOne.jsx

@@ -1,6 +1,11 @@
 import React, { useState, useEffect } from 'react'
 import { Form, Select, Input, message } from 'antd'
-import { getTableNamesList, getAilabList, getLakeTable } from '../services'
+import {
+  getTableNamesList,
+  getAilabList,
+  getLakeTable,
+  getDataPath,
+} from '../services'
 import PropTypes from 'prop-types'
 
 const { TextArea } = Input
@@ -22,6 +27,8 @@ export default function StepOne({
 
   const [dsType, setDsType] = useState(null)
 
+  const [ailabDb, setAilabDb] = useState(null)
+
   // 获取数据源列表
   useEffect(() => {
     if (dataSourceList.length !== 0) {
@@ -78,6 +85,7 @@ export default function StepOne({
         }
       })
       setTableList(list)
+      setAilabDb(data.data.database_name)
     } else {
       message.error(data.msg)
     }
@@ -92,6 +100,7 @@ export default function StepOne({
           label: item.table_name,
           value: item.table_name,
           table_path: item.table_path,
+          database_name: item.database_name,
         }
       })
       setTableList(list)
@@ -100,24 +109,58 @@ export default function StepOne({
     }
   }
 
+  const fetchDataPath = async () => {
+    const { datasource_name, datasource_table } = drawDataForm.getFieldsValue()
+    if (dsType === 'datasource') {
+      const { datasource, database } = dataSourceList.find(
+        item => item.key === datasource_name
+      )
+      if (datasource_name && datasource_table && datasource === 'hive') {
+        const { data } = await getDataPath({
+          ds_id: datasource_name,
+          table_name: datasource_table,
+          db_name: database,
+        })
+        if (data.code === 200) {
+          drawDataForm.setFieldsValue({ reader_path: data.data.location })
+        }
+      }
+    } else {
+      if (datasource_table) {
+        const { data } = await getDataPath({
+          ds_id: datasource_name,
+          table_name: datasource_table,
+          db_name: ailabDb,
+        })
+        if (data.code === 200) {
+          drawDataForm.setFieldsValue({ reader_path: data.data.location })
+        }
+      }
+    }
+  }
+
   // 选择表
   const selectTable = val => {
     const currentTable = drawDataForm.getFieldValue('datasource_table')
     switch (dsType) {
       case 'datasource':
         const ds_id = drawDataForm.getFieldValue('datasource_name')
+        fetchDataPath()
         updateTableStruct(ds_id, val)
         break
       case 'datalake':
-        drawDataForm.setFieldValue(
-          'reader_path',
-          tableList.find(item => item.value === currentTable).table_path
+        const { database_name, value, table_path } = tableList.find(
+          item => item.value === currentTable
         )
-        updateDrawLakeStruct(currentTable)
+        drawDataForm.setFieldValue('reader_path', table_path)
+        updateDrawLakeStruct({ db_name: database_name, table_name: value })
         break
-      default:
+      case 'ailab':
+        fetchDataPath()
         updateDrawAilabStruct(currentTable)
         break
+      default:
+        break
     }
   }
 
@@ -134,10 +177,12 @@ export default function StepOne({
         setDatasourceType('hive')
         selectLake()
         break
-      default:
+      case 'ailab':
         setDatasourceType('hive')
         selectAilab()
         break
+      default:
+        break
     }
   }
 

+ 41 - 7
src/module/datasource/component/StepThree.jsx

@@ -5,8 +5,13 @@ import arrowImgUrl from '../style/img/arrow.png'
 import syncImgUrl from '../style/img/sync.png'
 import warningImgUrl from '../style/img/warning.png'
 import deleteImgUrl from '../style/img/delete.png'
-import { getTableSchema, ailabSchema, lakeSchema } from '../services'
-import { Button, Space, Tooltip } from 'antd'
+import {
+  getTableSchema,
+  ailabSchema,
+  lakeSchema,
+  getLakeTable,
+} from '../services'
+import { Button, message, Space, Tooltip } from 'antd'
 import PropTypes from 'prop-types'
 
 const StepThreeDiv = styled.div`
@@ -98,6 +103,8 @@ export default function StepThree({
   // 映射管理
   const [syncMappings, setSyncMappings] = useState([])
 
+  const [lakeList, setLakeList] = useState([])
+
   // 暴露同步map
   useImperativeHandle(onRef, () => {
     return {
@@ -105,12 +112,31 @@ export default function StepThree({
     }
   })
 
+  const getLakeList = async () => {
+    const { data } = await getLakeTable()
+    if (data.code === 200) {
+      const list = data.data.map(item => {
+        return {
+          tb_name: item.table_name,
+          db_name: item.database_name,
+        }
+      })
+      setLakeList(list)
+    } else {
+      message.error(data.msg)
+    }
+  }
+
   const fetchDatasource = async (id, table_name, ds_type) => {
+    const lake = lakeList.find(item => item.tb_name === table_name)
     const { data } =
       ds_type === 'datasource'
         ? await getTableSchema({ id, table_name })
         : ds_type === 'datalake'
-        ? await lakeSchema(table_name)
+        ? await lakeSchema({
+            table_name: lake?.tb_name,
+            db_name: lake?.db_name,
+          })
         : await ailabSchema(table_name)
     if (data.code === 200) {
       const list = formatData(data.data)
@@ -119,11 +145,15 @@ export default function StepThree({
   }
 
   const fetchSyncData = async (id, table_name, ds_type) => {
+    const lake = lakeList.find(item => item.tb_name === table_name)
     const { data } =
       ds_type === 'datasource'
         ? await getTableSchema({ id, table_name })
         : ds_type === 'datalake'
-        ? await lakeSchema(table_name)
+        ? await lakeSchema({
+            table_name: lake?.tb_name,
+            db_name: lake?.db_name,
+          })
         : await ailabSchema(table_name)
     if (data.code === 200) {
       const list = formatData(data.data)
@@ -144,6 +174,10 @@ export default function StepThree({
     return list
   }
 
+  useEffect(() => {
+    getLakeList()
+  }, [])
+
   useEffect(() => {
     const ds_id = drawDataForm.getFieldValue('datasource_name')
     const table_name = drawDataForm.getFieldValue('datasource_table')
@@ -151,7 +185,7 @@ export default function StepThree({
     if (table_name && ds_type) {
       fetchDatasource(ds_id, table_name, ds_type)
     }
-  }, [drawDataForm])
+  }, [drawDataForm, lakeList])
 
   useEffect(() => {
     const ds_id = loadDataForm.getFieldValue('datasource_name')
@@ -160,7 +194,7 @@ export default function StepThree({
     if (table_name && ds_type) {
       fetchSyncData(ds_id, table_name, ds_type)
     }
-  }, [loadDataForm])
+  }, [loadDataForm, lakeList])
 
   useEffect(() => {
     setSyncMappings(syncMapSaving)
@@ -362,7 +396,7 @@ export default function StepThree({
 }
 
 StepThree.propTypes = {
-  onRef: PropTypes.func,
+  onRef: PropTypes.object,
   drawDataForm: PropTypes.object,
   loadDataForm: PropTypes.object,
   syncMapSaving: PropTypes.array,

+ 42 - 3
src/module/datasource/component/StepTwo.jsx

@@ -1,6 +1,6 @@
 import React, { useState, useEffect } from 'react'
 import { Form, Select, Input, message, Tooltip } from 'antd'
-import { getTableNamesList, getAilabList } from '../services'
+import { getTableNamesList, getAilabList, getDataPath } from '../services'
 import PropTypes from 'prop-types'
 
 const { Option } = Select
@@ -21,6 +21,8 @@ export default function StepTwo({
 
   const [dsType, setDsType] = useState(null)
 
+  const [ailabDb, setAilabDb] = useState(null)
+
   // 获取数据源列表
   useEffect(() => {
     if (dataSourceList.length !== 0) {
@@ -77,22 +79,57 @@ export default function StepTwo({
         }
       })
       setTableList(list)
+      setAilabDb(data.data.database_name)
     } else {
       message.error(data.msg)
     }
   }
 
+  const fetchDataPath = async () => {
+    const { datasource_name, datasource_table } = loadDataForm.getFieldsValue()
+    if (dsType === 'datasource') {
+      const { datasource, database } = dataSourceList.find(
+        item => item.key === datasource_name
+      )
+      if (datasource_name && datasource_table && datasource === 'hive') {
+        const { data } = await getDataPath({
+          ds_id: datasource_name,
+          table_name: datasource_table,
+          db_name: database,
+        })
+        if (data.code === 200) {
+          loadDataForm.setFieldsValue({ writer_path: data.data.location })
+        }
+      }
+    } else {
+      if (datasource_table) {
+        const { data } = await getDataPath({
+          ds_id: datasource_name,
+          table_name: datasource_table,
+          db_name: ailabDb,
+        })
+        if (data.code === 200) {
+          loadDataForm.setFieldsValue({ writer_path: data.data.location })
+        }
+      }
+    }
+  }
+
   // 选择表
   const selectTable = val => {
     const currentTable = loadDataForm.getFieldValue('datasource_table')
     switch (dsType) {
       case 'datasource':
         const ds_id = loadDataForm.getFieldValue('datasource_name')
+        fetchDataPath()
         updateTableStruct(ds_id, val)
         break
-      default:
+      case 'ailab':
+        fetchDataPath()
         updateLoadAilabStruct(currentTable)
         break
+      default:
+        break
     }
   }
 
@@ -105,10 +142,12 @@ export default function StepTwo({
           selectDatasource(ds_id)
         }
         break
-      default:
+      case 'ailab':
         setDatasourceType('hive')
         selectAilab()
         break
+      default:
+        break
     }
   }
 

+ 5 - 4
src/module/datasource/component/SyncTaskAdd.jsx

@@ -70,8 +70,8 @@ export default function SyncTaskAdd() {
   const updateDrawAilabStruct = async table_name => {
     await updateAilabStruct(table_name, setDrawDataStruct)
   }
-  const updateDrawLakeStruct = async table_name => {
-    await updateLakeStruct(table_name, setDrawDataStruct)
+  const updateDrawLakeStruct = async params => {
+    await updateLakeStruct(params, setDrawDataStruct)
   }
 
   // 加载源表单表结构
@@ -120,8 +120,8 @@ export default function SyncTaskAdd() {
     }
   }
 
-  const updateLakeStruct = async (table_name, setFunc) => {
-    const { data } = await lakeSchema(table_name)
+  const updateLakeStruct = async (params, setFunc) => {
+    const { data } = await lakeSchema(params)
     if (data.code === 200) {
       const tableList = data.data.map(item => {
         const splitData = item.split(':')
@@ -210,6 +210,7 @@ export default function SyncTaskAdd() {
           key: item.id,
           datasource_name: item.datasource_name,
           datasource: item.datasource,
+          database: item.database_name,
         }
       })
       setDataSourceList(list)

+ 16 - 2
src/module/datasource/page/DatasourceView.jsx

@@ -6,7 +6,7 @@ import DatasourceLog from '../component/DatasourceLog'
 import React, { useState, useEffect } from 'react'
 import { Link, useNavigate, useLocation } from 'react-router-dom'
 import styled from 'styled-components'
-import { importDatalake, craeteAilab } from '../services'
+import { importDatalake, craeteAilab, getDataPath } from '../services'
 import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
 
 const { TabPane } = Tabs
@@ -105,6 +105,20 @@ export default function DatasourceView() {
         message.error('请检查表单数据是否完整')
       })
   }
+
+  const fetchDataPath = async () => {
+    const { database_name, datatable_name } = datatableForm.getFieldsValue()
+    if (database_name && datatable_name) {
+      const { data } = await getDataPath({
+        db_name: database_name,
+        table_name: datatable_name,
+      })
+      if (data.code === 200) {
+        datatableForm.setFieldsValue({ datatable_path: data.data.location })
+      }
+    }
+  }
+
   const importModal = (
     <Modal
       title="导入数据表"
@@ -147,7 +161,7 @@ export default function DatasourceView() {
               message: '请输入数据表路径!',
             },
           ]}>
-          <Input placeholder="输入数据表路径" />
+          <Input placeholder="输入数据表路径" onFocus={fetchDataPath} />
         </FormItem>
       </Form>
     </Modal>

+ 6 - 0
src/module/datasource/services/index.js

@@ -230,3 +230,9 @@ export const getDataLakeInfo = (dl_id) =>
     method: 'get',
   })
 
+export const getDataPath = (params) =>
+  request({
+    url: `jpt/datasource/table_location?db_name=${params.db_name}&table_name=${params.table_name}${params.ds_id ? `&ds_id=${params.ds_id}` : ''}`,
+    method: 'get',
+  })
+