Browse Source

(*)适配器集成最新元数据目录 定时任务 模型功能完善

master
peng.peng 2 years ago
parent
commit
941a816ca6
  1. 19
      api/app/lib/controllers/metadataAcquisition/dataSource.js
  2. 12
      api/app/lib/controllers/metadataAcquisition/task.js
  3. 2
      api/app/lib/routes/metadataAcquisition/task.js
  4. 53
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepOne.js
  5. 2
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js
  6. 4
      web/client/src/sections/metadataAcquisition/containers/adapter.js
  7. 7
      web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js
  8. 37
      web/client/src/sections/metadataManagement/components/modelModal.js

19
api/app/lib/controllers/metadataAcquisition/dataSource.js

@ -106,13 +106,24 @@ function deleteDataSource(opts) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.DataSource.destroy({
const task = await models.AcquisitionTask.findOne({
where: {
id: id
dataSourceId: id
}
})
ctx.status = 204;
ctx.body = { message: '删除数据源成功' }
if (task) {
ctx.status = 400;
ctx.body = { message: '数据源下存在采集任务,请删除任务后再删除数据源!' }
} else {
await models.DataSource.destroy({
where: {
id: id
}
})
ctx.status = 204;
ctx.body = { message: '删除数据源成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;

12
api/app/lib/controllers/metadataAcquisition/task.js

@ -3,7 +3,7 @@ const schedule = require('node-schedule')
const moment = require('moment');
const initJob = require('./initJob');
// 新增采集任务
function addAcquisitionTask(opts) {
function addAcquisitionTask(app) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
@ -16,9 +16,15 @@ function addAcquisitionTask(opts) {
} else {
let rslt = ctx.request.body;
await models.AcquisitionTask.create(Object.assign({}, rslt))
let datasource = await models.AcquisitionTask.findOne({ where: { taskName } })
let task = await models.AcquisitionTask.findOne({ where: { taskName } })
//新增采集任务 更新采集定时任务状态
const job = await initJob(app, task)
if (app.fs.schedule['taskJobs'][task.id]) schedule.cancelJob(app.fs.schedule['taskJobs'][task.id])
app.fs.schedule['taskJobs'][task.id] = job
ctx.status = 200;
ctx.body = { message: '新建采集任务成功', id: datasource.id }
ctx.body = { message: '新建采集任务成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);

2
api/app/lib/routes/metadataAcquisition/task.js

@ -5,7 +5,7 @@ const task = require('../../controllers/metadataAcquisition/task');
module.exports = function (app, router, opts, AuthCode) {
app.fs.api.logAttr['POST/meta/acq/task'] = { content: '增加采集任务信息', visible: true };
router.post('/meta/acq/task', task.addAcquisitionTask(opts))
router.post('/meta/acq/task', task.addAcquisitionTask(app))
//获取采集任务列表
app.fs.api.logAttr['GET/meta/acq/tasks'] = { content: '获取采集任务列表', visible: true };

53
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepOne.js

@ -4,21 +4,40 @@ import {
ProForm,
ProFormSelect,
ProFormTextArea,
ProFormText
ProFormText,
ProFormTreeSelect
} from '@ant-design/pro-form';
import '../../style.less';
function StepOne(props) {
const { next, stepOneValues, stepOneValuesFinish, readOnly, dataSources, stepOneInitValue } = props;
const { next, stepOneValues, stepOneValuesFinish, readOnly, treeData } = props;
const formRef = React.createRef();
const initialValues = stepOneValues ? stepOneValues : {
adapterName: 'PostgreSQL采集适配器',
adapterVersion: '9.x',
mode: '数据库连接',
mountPath: 1,
// mountPath: 1,
}
const formItemLayout = { labelCol: { span: 3 }, wrapperCol: { span: 10 } };
const getTreeNodeData = (dataSource, parent, key) => {
let treeData = [];
let data = [];
if (!parent) {
data = dataSource.filter(ds => !ds.parent);
} else {
data = dataSource.filter(ds => ds.parent == parent);
}
treeData = data.map(ds => {
return { title: ds.name, key: ds?.id, id: ds.id, value: ds?.id }
});
for (let d of treeData) {
d.children = getTreeNodeData(dataSource, d.id, d.key);
}
return treeData
}
const treeDataFilter = treeData ? getTreeNodeData(treeData, null, 'rc') : []
return <>
<ProForm
title={''}
@ -80,7 +99,7 @@ function StepOne(props) {
label="采集模式"
disabled={readOnly}
/>
<ProFormSelect
{/* <ProFormSelect
rules={[{ required: true, message: '请选择输入控件' }]}
options={[
{ label: '库表/目录1', value: 1 },
@ -88,6 +107,32 @@ function StepOne(props) {
name="mountPath"
label="数据源挂载路径"
// disabled={true}
/> */}
<ProFormTreeSelect
name="mountPath"
label="数据源挂载路径"
placeholder="请选择数据源挂载路径"
rules={[{ required: true, message: '请选择数据源挂载路径' }]}
allowClear
// width={330}
secondary
request={async () => {
return treeDataFilter || [];
}}
// tree-select args
fieldProps={{
showArrow: false,
filterTreeNode: true,
showSearch: true,
dropdownMatchSelectWidth: false,
labelInValue: false,
autoClearSearchValue: true,
multiple: false,
treeNodeFilterProp: 'title',
fieldNames: {
label: 'title',
},
}}
/>
<ProFormTextArea

2
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js

@ -117,7 +117,7 @@ function StepTwo(props) {
<div className='step-footer'>
<Button style={{ margin: '0 8px', }} onClick={() => prev()}>上一步</Button>
<Button
// disabled={connect !== '连接成功'}
disabled={connect !== '连接成功'}
type="primary" onClick={() => {
if (checkNext() === true) {
stepTwoValuesFinish(params)

4
web/client/src/sections/metadataAcquisition/containers/adapter.js

@ -5,11 +5,12 @@ import { DatabaseOutlined } from '@ant-design/icons'
import AdapterStep from '../components/adapterStep';
import moment from 'moment';
import { RELATION_DATABASE_TOOL_CONFIG } from '../constants/adapter';
import { useFsRequest, ApiTable } from '$utils';
const LatestMetadata = (props) => {
const { history, actions, dispatch, adapters } = props;
const [isModalOpen, setIsModalOpen] = useState(false);
const { data: treeData = [] } = useFsRequest({ url: ApiTable.getResourceCatalog });
useEffect(() => {
dispatch(actions.metadataAcquisition.getAdapters())
}, [])
@ -82,6 +83,7 @@ const LatestMetadata = (props) => {
<AdapterStep
type={isModalOpen} //当前卡片的key (目前只有postgre,支持后续扩展)
onFinish={onFinish}
treeData={treeData}
{...props}
/>
</Modal>

7
web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js

@ -4,8 +4,7 @@ import { connect } from 'react-redux';
import ProTable from '@ant-design/pro-table';
import moment from 'moment';
import DataSourceModal from '../components/dataSourceManagementModal';
import { RELATION_DATABASE_TOOL_CONFIG } from '../constants/adapter';
import { useFsRequest, ApiTable } from '$utils';
import './style.less';
function DataSourceManagement(props) {
const { loading, clientHeight, actions, dispatch, dataSources, adapters } = props;
@ -23,6 +22,7 @@ function DataSourceManagement(props) {
dispatch(actions.metadataAcquisition.getDataSources(query));
}
const { data: treeData = [] } = useFsRequest({ url: ApiTable.getResourceCatalog });
useEffect(() => {
dispatch(actions.metadataAcquisition.getAdapters())
@ -115,7 +115,7 @@ function DataSourceManagement(props) {
name: stepOneValues?.name,
audited: true,
adapterId: adapterInfo?.id,
mountPath: 1,
mountPath: stepOneValues?.mountPath,
description: stepOneValues?.description,
config: stepTwoValues,
time: moment()
@ -198,6 +198,7 @@ function DataSourceManagement(props) {
editData={editData}
visible={visible}
onFinish={onFinish}
treeData={treeData}
{...props}
/>
}

37
web/client/src/sections/metadataManagement/components/modelModal.js

@ -74,8 +74,10 @@ export default (props) => {
fieldProps={{
showSearch: true,
onChange: value => {
value == '布尔型' && formRef?.current?.validateFields(['length']); //布尔型 长度可以为空
formRef?.current?.setFieldsValue({
control: DATA_TYPES[value]
control: DATA_TYPES[value],
length: null
})
}
}}
@ -91,21 +93,28 @@ export default (props) => {
]}
name="control"
label="输入控件"
fieldProps={{
showSearch: true,
onChange: value => {
formRef?.current?.setFieldsValue({
dataType: DATA_TYPES[value]
})
}
}}
/>
<ProFormDigit
name="length"
label="长度"
fieldProps={{ precision: 0, max: 99999999, }}
/>
<ProFormDependency name={['dataType']}>
{({ dataType }) => {
return dataType == '整型' || dataType == '字符型' ?
<ProFormDigit
rules={[{ required: true, message: '请输入长度' }]}
name="length"
label="长度"
fieldProps={{ min: 1, precision: 0, max: 99999999, }}
/>
: <ProFormDigit
name="length"
label="长度"
fieldProps={{ precision: 0, max: 99999999, }}
/>
}}
</ProFormDependency>
<ProFormSelect
rules={[{ required: true, message: '请选择是否允许为空' }]}
options={[

Loading…
Cancel
Save