Browse Source

(+)采集任务配置新增修改查询完善

master
peng.peng 2 years ago
parent
commit
d9dfdbd096
  1. 15
      api/app/lib/controllers/metadataAcquisition/task.js
  2. 1
      api/app/lib/index.js
  3. 2
      web/client/src/sections/metadataAcquisition/components/dataSourceManagementModal.js
  4. 20
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js
  5. 3
      web/client/src/sections/metadataAcquisition/components/taskModal.js
  6. 134
      web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js
  7. 11
      web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js

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

@ -38,14 +38,19 @@ function getAcquisitionTask(opts) {
let option = { let option = {
where: searchWhere, where: searchWhere,
order: [["id", "desc"]], order: [["id", "desc"]],
include: [{ model: models.DataSource }] include: [{
model: models.DataSource,
include: [{
model: models.Adapter,
}]
}]
} }
if (taskName) { if (taskName) {
searchWhere.taskName = { searchWhere.$or = [
// 模糊查询 { taskName: { $iLike: `%${taskName}%` } },
[Op.like]: '%' + taskName + '%', { '$dataSource.name$': { $iLike: `%${taskName}%` } },
}; ]
} }
option.where = searchWhere option.where = searchWhere

1
api/app/lib/index.js

@ -64,5 +64,6 @@ module.exports.models = function (dc) {
DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' }); DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' });
Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' }); Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' });
}; };

2
web/client/src/sections/metadataAcquisition/components/dataSourceManagementModal.js

@ -24,7 +24,7 @@ function DataSourceModal(props) {
onFinish={onFinish} onFinish={onFinish}
stepProps={2} stepProps={2}
currentChange={c => { setCurrent(c) }} currentChange={c => { setCurrent(c) }}
stepOneInitValue={{ ...editData, ...editData?.adapterInfo, description: editData?.description }} stepOneInitValue={{ ...editData, ...editData?.adapter, description: editData?.description }}
stepTwoInitValue={{ ...editData?.config }} stepTwoInitValue={{ ...editData?.config }}
{...props} {...props}
/> />

20
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js

@ -13,9 +13,9 @@ import { BellOutlined } from '@ant-design/icons'
import '../../style.less'; import '../../style.less';
function StepThree(props) { function StepThree(props) {
const { prev, next, } = props; const { prev, next, dataSourceFilter, editData } = props;
const formRef = React.createRef(); const formRef = React.createRef();
const initialValues = { const initialValues = editData ? editData : {
} }
const formItemLayout = { labelCol: { span: 4 }, wrapperCol: { span: 16 } }; const formItemLayout = { labelCol: { span: 4 }, wrapperCol: { span: 16 } };
@ -33,7 +33,7 @@ function StepThree(props) {
onCancel: () => { }, onCancel: () => { },
}} }}
onFinish={async (values) => { onFinish={async (values) => {
next() next(values)
// return true; // return true;
}} }}
style={{ marginTop: 20 }} style={{ marginTop: 20 }}
@ -44,6 +44,20 @@ function StepThree(props) {
}} }}
> >
{dataSourceFilter && < ProFormSelect
width={'md'}
rules={[{ required: true, message: '请选择数据源' }]}
options={dataSourceFilter?.map(s => {
return { label: s?.name, value: s?.id, disabled: s?.disabled }
})}
disabled={editData}
name="dataSourceId"
label="数据源"
fieldProps={{
showSearch: true
}}
/>
}
<ProFormText <ProFormText
width={'md'} width={'md'}
rules={[{ required: true, message: '请输入数据源名称' }, rules={[{ required: true, message: '请输入数据源名称' },

3
web/client/src/sections/metadataAcquisition/components/taskModal.js

@ -5,6 +5,7 @@ import { STEP_CONFIG } from './steps/index'
function DataSourceModal(props) { function DataSourceModal(props) {
const { visible, editData, onFinish, onCancel, const { visible, editData, onFinish, onCancel,
type = 'postgre',//当前卡片的key (目前只有postgre,支持后续扩展) type = 'postgre',//当前卡片的key (目前只有postgre,支持后续扩展)
dataSourceFilter,
} = props; } = props;
const { StepThree } = STEP_CONFIG[type]; const { StepThree } = STEP_CONFIG[type];
// const onFinish = () => { } // const onFinish = () => { }
@ -17,7 +18,7 @@ function DataSourceModal(props) {
width={1200} width={1200}
destroyOnClose={true} destroyOnClose={true}
> >
<StepThree next={onFinish} /> <StepThree next={onFinish} dataSourceFilter={dataSourceFilter} editData={editData} />
</Modal> </Modal>
</> </>
} }

134
web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js

@ -16,8 +16,8 @@ function AcquisitionTask(props) {
const [editData, setEditData] = useState(null);//模态框编辑数据 const [editData, setEditData] = useState(null);//模态框编辑数据
const queryData = (search) => { const queryData = (search) => {
const query = { const query = {
limit: search ? 10 : pageSize || 10, // limit: search ? 10 : pageSize || 10,
page: search ? 1 : currentPage || 1, // page: search ? 1 : currentPage || 1,
taskName: searchValue taskName: searchValue
} }
dispatch(actions.metadataAcquisition.getTasks(query)); dispatch(actions.metadataAcquisition.getTasks(query));
@ -30,29 +30,28 @@ function AcquisitionTask(props) {
}, [pageSize, currentPage]); }, [pageSize, currentPage]);
const handleDelete = (id) => { const handleDelete = (id) => {
dispatch(actions.metadataAcquisition.deleteDataSource(id)).then(() => { dispatch(actions.metadataAcquisition.deleteTask(id)).then(() => {
queryData(); queryData();
}); });
}; };
const columns = [ const columns = [
{ {
title: '数据源名称', title: '任务名称',
dataIndex: 'taskName', dataIndex: 'taskName',
}, },
{ {
title: '数据源名称', title: '数据源名称',
dataIndex: 'name', dataIndex: 'dataSourceName',
}, render: (text, record) => {
{ return record?.dataSource?.name
title: '挂载点', }
dataIndex: 'mountPath',
}, },
{ {
title: '适配器类型', title: '适配器类型',
dataIndex: 'adapter', dataIndex: 'adapter',
render: (text, record) => { render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter) const adapterInfo = record?.dataSource?.adapter
return adapterInfo?.adapterName return adapterInfo?.adapterName
} }
}, },
@ -60,29 +59,23 @@ function AcquisitionTask(props) {
title: '采集方式', title: '采集方式',
dataIndex: 'control', dataIndex: 'control',
render: (text, record) => { render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter) const adapterInfo = record?.dataSource?.adapter
return adapterInfo?.mode return adapterInfo?.mode
} }
}, },
{ {
title: '工具版本', title: '执行周期',
dataIndex: 'length', dataIndex: 'dataSourceName',
render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.adapterVersion
}
}, },
{ {
title: '修改时间', title: '重复次数',
dataIndex: 'time', dataIndex: 'retryCount',
render: (text, record) => moment(record?.time).format('YYYY-MM-DD HH:mm:ss')
}, },
{ {
title: '描述', title: '时间间隔',
dataIndex: 'description', dataIndex: 'retryTime',
ellipsis: true,
search: false,
}, },
{ {
title: '操作', title: '操作',
width: 160, width: 160,
@ -115,36 +108,35 @@ function AcquisitionTask(props) {
]; ];
const onFinish = (values) => { const onFinish = (values) => {
const { stepOneValues, stepTwoValues } = values; const dataToSave = {
const adapterInfo = adapters?.find(x => x.adapterName == stepOneValues?.adapterName) taskName: values?.taskName,
if (adapterInfo) { retryCount: values?.retryCount,
const dataToSave = { retryTime: values?.retryTime,
name: stepOneValues?.name, retried: values?.retried ? true : false,
audited: true, dataSourceId: values?.dataSourceId,
adapter: adapterInfo?.id, cron: values?.cron,
mountPath: 1,
description: stepOneValues?.description,
config: stepTwoValues,
time: moment()
}
if (editData) {
dispatch(actions.metadataAcquisition.modifyTask(editData?.id, dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
} else {
dispatch(actions.metadataAcquisition.addTask(dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
}
} }
if (editData) {
dispatch(actions.metadataAcquisition.modifyTask(editData?.id, dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
} else {
dataToSave.enabled = true;
dataToSave.autoReleased = true;
dataToSave.storageStrategy = "增量";
dispatch(actions.metadataAcquisition.addTask(dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
}
} }
return <Spin spinning={loading}> return <Spin spinning={loading}>
@ -169,22 +161,22 @@ function AcquisitionTask(props) {
total: tasks?.count, total: tasks?.count,
showSizeChanger: true, showSizeChanger: true,
// showQuickJumper: true, // showQuickJumper: true,
current: currentPage, // current: currentPage,
pageSize: pageSize || 10, // pageSize: pageSize || 10,
pageSizeOptions: [10, 20, 50], // pageSizeOptions: [10, 20, 50],
showTotal: (total) => { // showTotal: (total) => {
return <span style={{ fontSize: 15 }}>{`${Math.ceil(total / pageSize)}页,${total}`}</span> // return <span style={{ fontSize: 15 }}>{`共${Math.ceil(total / pageSize)}页,${total}项`}</span>
}, // },
onShowSizeChange: (currentPage, pageSize) => { // onShowSizeChange: (currentPage, pageSize) => {
setCurrentPage(currentPage); // setCurrentPage(currentPage);
setPageSize(pageSize); // setPageSize(pageSize);
}, // },
onChange: (page, pageSize) => { // onChange: (page, pageSize) => {
setCurrentPage(page); // setCurrentPage(page);
setPageSize(pageSize); // setPageSize(pageSize);
} // }
}} }}
dataSource={tasks?.rows || []} dataSource={tasks?.rows || []}
options={false} options={false}
@ -201,6 +193,10 @@ function AcquisitionTask(props) {
editData={editData} editData={editData}
visible={visible} visible={visible}
onFinish={onFinish} onFinish={onFinish}
dataSourceFilter={dataSources?.rows?.map(s => {
s.disabled = !!tasks?.rows?.find(x => x.dataSourceId == s.id);
return s;
})}
{...props} {...props}
/> />
} }

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

@ -87,9 +87,7 @@ function DataSourceManagement(props) {
render: (text, record) => { render: (text, record) => {
const options = []; const options = [];
options.push(<a onClick={() => { options.push(<a onClick={() => {
const adapterInfo = adapters?.find(x => x.id == record?.adapter)
setVisible(true) setVisible(true)
record.adapterInfo = adapterInfo
setEditData(record) setEditData(record)
}} style={{ marginRight: 8 }}>编辑</a>) }} style={{ marginRight: 8 }}>编辑</a>)
options.push( options.push(
@ -103,7 +101,6 @@ function DataSourceManagement(props) {
> >
<a>删除</a> <a>删除</a>
</Popconfirm>) </Popconfirm>)
return options; return options;
}, },
@ -117,7 +114,7 @@ function DataSourceManagement(props) {
const dataToSave = { const dataToSave = {
name: stepOneValues?.name, name: stepOneValues?.name,
audited: true, audited: true,
adapter: adapterInfo?.id, adapterId: adapterInfo?.id,
mountPath: 1, mountPath: 1,
description: stepOneValues?.description, description: stepOneValues?.description,
config: stepTwoValues, config: stepTwoValues,
@ -148,7 +145,11 @@ function DataSourceManagement(props) {
<Col span={12}><Button type='primary' onClick={() => { setVisible(true) }}>新建</Button></Col> <Col span={12}><Button type='primary' onClick={() => { setVisible(true) }}>新建</Button></Col>
<Col span={12} style={{ textAlign: 'right' }}><Input <Col span={12} style={{ textAlign: 'right' }}><Input
value={searchValue} onChange={e => { setSearchValue(e.target.value) }} value={searchValue} onChange={e => { setSearchValue(e.target.value) }}
style={{ width: 220, marginRight: 15 }} placeholder="数据源名称" /><Button onClick={() => { queryData() }} type='primary'>查询</Button></Col> style={{ width: 220, marginRight: 15 }} placeholder="数据源名称" /><Button onClick={() => {
setCurrentPage(1)
setPageSize(10)
queryData(true)
}} type='primary'>查询</Button></Col>
</Row> </Row>
<ProTable <ProTable
columns={columns} columns={columns}

Loading…
Cancel
Save