peng.peng 2 years ago
parent
commit
fc5f4dee3d
  1. 1
      api/.vscode/launch.json
  2. 34
      api/app/lib/controllers/latestMetadata/index.js
  3. 3
      api/app/lib/routes/latestMetadata/index.js
  4. 4
      web/client/src/sections/dataQuality/containers/ruleLibrary.js
  5. 12
      web/client/src/sections/metadataManagement/actions/businessMetadata.js
  6. 237
      web/client/src/sections/metadataManagement/components/releaseModal.js
  7. 31
      web/client/src/sections/metadataManagement/containers/databasesTable.js
  8. 1
      web/client/src/utils/webapi.js

1
api/.vscode/launch.json

@ -16,6 +16,7 @@
"-p 4400", "-p 4400",
// //
"-g postgres://FashionAdmin:123456@10.8.30.39:5432/GovernmentDataResourceCenter", "-g postgres://FashionAdmin:123456@10.8.30.39:5432/GovernmentDataResourceCenter",
// "-g postgres://FashionAdmin:123456@10.8.30.156:5432/gdrcenter",
"-b http://10.8.30.161:31420" "-b http://10.8.30.161:31420"
] ]
}, },

34
api/app/lib/controllers/latestMetadata/index.js

@ -531,6 +531,14 @@ async function postMetadataResourceApplications(ctx) {
if (!resourceName || !applyBy || !resourceType || !resourceId) { if (!resourceName || !applyBy || !resourceType || !resourceId) {
ctx.status = 400; ctx.status = 400;
ctx.body = { message: '参数不全,请重新申请资源' } ctx.body = { message: '参数不全,请重新申请资源' }
} else {
const models = ctx.fs.dc.models;
const postOne = await models.ResourceConsumption.findOne({
where: { applyBy: applyBy, resourceName: resourceName, resourceId, resourceType }
});
if (postOne) {
ctx.status = 400;
ctx.body = { message: '参数不全,请重新申请资源' }
} else { } else {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const postOne = await models.ResourceConsumption.findOne({ const postOne = await models.ResourceConsumption.findOne({
@ -804,6 +812,29 @@ async function delMetadataRestapis(ctx) {
ctx.body = { message: '删除元数据失败' } ctx.body = { message: '删除元数据失败' }
} }
} }
//获取对表的库与字段信息
async function listStructuredData (ctx) {
try {
const models = ctx.fs.dc.models;
const { id, parent } = ctx.query;
let field = await models.MetadataDatabase.findAll({ where: { parent: id } }) || []
let database = await models.MetadataDatabase.findOne({ where: { id: parent } }) || {}
ctx.status = 200;
ctx.body = {
field: field,
database: database
};
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": "获取元数据资源申请记录失败"
}
}
}
module.exports = { module.exports = {
getResourceCatalog, getResourceCatalog,
postResourceCatalog, postResourceCatalog,
@ -826,5 +857,6 @@ module.exports = {
delMetadataFiles, delMetadataFiles,
postMetadataRestapis, postMetadataRestapis,
putMetadataRestapis, putMetadataRestapis,
delMetadataRestapis delMetadataRestapis,
listStructuredData
} }

3
api/app/lib/routes/latestMetadata/index.js

@ -68,4 +68,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/metadata/restapis/:id'] = { content: '删除接口元数据', visible: true }; app.fs.api.logAttr['DEL/metadata/restapis/:id'] = { content: '删除接口元数据', visible: true };
router.delete('/metadata/restapis/:id', latestMetadata.delMetadataRestapis); router.delete('/metadata/restapis/:id', latestMetadata.delMetadataRestapis);
app.fs.api.logAttr['GET/listStructuredData'] = { content: '获取对表的库与字段信息', visible: true };
router.get('/listStructuredData', latestMetadata.listStructuredData);
}; };

4
web/client/src/sections/dataQuality/containers/ruleLibrary.js

@ -97,7 +97,7 @@ function RuleLibrary ({ loading, clientHeight, actions, dispatch, }) {
return <> return <>
<div style={{ display: 'flex', justifyContent: 'space-between' }}> <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 20 }}>
<Button onClick={() => { <Button onClick={() => {
setRuleModal(true); setRuleModal(true);
}}>新建业务规则</Button> }}>新建业务规则</Button>
@ -123,7 +123,7 @@ function RuleLibrary ({ loading, clientHeight, actions, dispatch, }) {
<Table <Table
columns={columns} columns={columns}
dataSource={tableList?.rows || []} dataSource={tableList?.rows || []}
scroll={{ scrollToFirstRowOnChange: true, y: clientHeight - 260 }} scroll={{ scrollToFirstRowOnChange: true, y: clientHeight - 240 }}
pagination={{ pagination={{
current: query?.page + 1, current: query?.page + 1,
pageSize: query?.limit, pageSize: query?.limit,

12
web/client/src/sections/metadataManagement/actions/businessMetadata.js

@ -151,3 +151,15 @@ export function delBusinessMetadataRestapis(id) {
} }
}); });
} }
export function listStructuredData (query = {}) {
return dispatch => basicAction({
type: 'get',
query,
dispatch: dispatch,
actionType: 'GET_LIST_STRUCTURED_DATA',
url: ApiTable.listStructuredData,
msg: { error: '获取对表的库与字段信息失败' },
reducer: {}
});
}

237
web/client/src/sections/metadataManagement/components/releaseModal.js

@ -0,0 +1,237 @@
import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import { Modal, Input, Form, Tabs, Avatar, Checkbox, Button, Select } from 'antd';
import { PlusCircleOutlined, MinusCircleOutlined } from '@ant-design/icons';
const { TabPane } = Tabs;
const { TextArea } = Input;
const CheckboxGroup = Checkbox.Group;
const ReleaseModal = ({ actions, dispatch, onConfirm, onCancel, editData = {} }) => {
const { metadataManagement } = actions;
const [activeKey, setActiveKeyl] = useState("field")
const [fieldList, setFiedList] = useState([])
const [fieldData, setFiedData] = useState([])
const [database, setDatabase] = useState({})
const [fieldValue, setFiedValue] = useState([])
const [indeterminate, setIndeterminate] = useState(false)
const [fromData, setFromData] = useState([{ value1: '', value2: '', value3: '' }])
const [sql, setSql] = useState()
const [form] = Form.useForm();
useEffect(() => {
dispatch(metadataManagement.listStructuredData({ id: editData?.id, parent: editData?.parent })).then(res => {
if (res.success) {
setFiedData(res.payload.data?.field || [])
setFiedList(res.payload.data?.field?.map(v => v.code) || [])
setDatabase(res.payload.data?.database || {})
}
})
}, []);
let operator = [{ value: '=', label: '=' },
{ value: '!=', label: '!=' },
{ value: '>', label: '>' },
{ value: '<', label: '<' },
{ value: '>=', label: '>=' },
{ value: '<=', label: '<=' },
{ value: 'BETWEEN', label: 'BETWEEN' },
{ value: 'LIKE', label: 'LIKE' },
{ value: 'IN', label: 'IN' }]
return (
<Modal title={'发布REST服务'} open={true} destroyOnClose
width={800}
// onOk={() => handleOk(null)}
onCancel={onCancel}
footer={null}
>
<div style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-around' }}>
{[{ name: '选择字段', key: "field" },
{ name: '配置条件', key: "condition" },
{ name: '预览SQL', key: "SQL" },
{ name: '服务发布', key: "release" }].map((v, index) => {
let title = []
if (index > 0) {
title.push(<div style={{ width: '14%', border: '1px solid #0000004a' }}></div>)
}
title.push(<div style={{ width: '14%', color: activeKey == v.key ? '#1e6ee5' : "", }}>
<Avatar style={{
backgroundColor: activeKey == v.key ? "rgb(30 110 229 / 74%)" : 'rgb(200 192 185)'
}}
size="large" icon={index + 1} />
{v.name}
</div>)
return title
})}
</div>
<Tabs activeKey={activeKey} onChange={v => {
setActiveKeyl(v)
}} >
<TabPane key="field">
<div style={{ fontSize: 20, fontWeight: 600 }}>选择字段</div>
{/* <div style={{ marginLeft: 20 }}> */}
<Checkbox indeterminate={indeterminate} style={{ margin: '20px 40px' }} onChange={e => {
setFiedValue(e.target.checked ? fieldList : []);
setIndeterminate(e.target.checked);
}}>
全选
</Checkbox>
<div style={{ display: 'flex', marginLeft: 40 }}>
<div style={{ marginRight: 8 }}>字段:</div>
<CheckboxGroup options={fieldList} value={fieldValue} onChange={v => {
setFiedValue(v)
if (v?.length == fieldList?.length) {
setIndeterminate(true)
} else {
setIndeterminate(false)
}
}} />
</div>
</TabPane>
<TabPane key="condition">
<div style={{ fontSize: 20, margin: '20px 0', fontWeight: 600 }}>配置条件</div>
{fromData?.map((f, index) => {
return <div key={'key' + index} style={{ display: 'flex', marginBottom: 16 }}>
<Select
style={{ width: 200, marginRight: 10 }} value={f.value1 || null}
placeholder="请选择字段"
onChange={v => {
fromData?.splice(index, 1, { value1: v, value2: f.value2, value3: f.value3 })
setFromData([...fromData])
}}
options={fieldValue?.map(d => ({ value: d, label: d })) || []}
allowClear
/>
<Select
style={{ width: 200, marginRight: 10 }} value={f.value2 || null}
placeholder="请选择条件"
onChange={v => {
fromData?.splice(index, 1, { value1: f.value1, value2: v, value3: f.value3 })
setFromData([...fromData])
}}
options={operator}
allowClear
/>
<Input
style={{ width: 200, marginRight: 10 }} value={f.value3}
placeholder="请输入值"
onChange={v => {
fromData?.splice(index, 1, { value1: f.value1, value2: f.value2, value3: v?.target?.value })
setFromData([...fromData])
}}
allowClear
/>
{index == 0 ?
<PlusCircleOutlined style={{ fontSize: 20, marginTop: 6 }} onClick={() => {
fromData?.splice(index, 0, { value1: '', value2: '', value3: '' })
setFromData([...fromData])
}} />
: <MinusCircleOutlined style={{ fontSize: 20, marginTop: 6 }} onClick={() => {
fromData?.splice(index, 1)
setFromData([...fromData])
}} />
}
</div>
})}
</TabPane>
<TabPane key="SQL">
<div style={{ fontSize: 20, marginBottom: 20, fontWeight: 600, display: 'flex', justifyContent: 'space-between' }}>预览SQL<Button onClick={() => {
console.log(editData);
console.log(database);
console.log(fromData);
let whereOption = []
fromData.map(s => {
whereOption.push(`${editData?.code}.${s.value1} ${s.value2} ${s.value3}`);
})
let sqlData = `SELECT * FROM ${editData?.code} ${fromData.length ? 'WHERE ' + whereOption.join(' AND ') : ''}`
setSql(sqlData)
}}>生成SQL</Button></div>
<TextArea value={sql} autoSize={{ minRows: 5 }} disabled={true} />
</TabPane>
<TabPane key="release">
<div style={{ fontSize: 20, marginBottom: 10, fontWeight: 600 }}>服务发布</div>
<div style={{ display: 'flex' }}>接口名称<Input style={{ width: 180 }} placeholder='请输入' /></div>
<div style={{ display: 'flex', margin: '10px 0 10px 30px' }}>URL <Select
style={{ width: 200, marginRight: 10 }}
onChange={v => {
}}
defaultValue={"GET"}
options={[{ value: "GET", label: "GET" },
{ value: "POST", label: "POST" },
{ value: "PUT", label: "PUT" },
{ value: "DEL", label: "DEL" },]}
allowClear
/>
<Input style={{ width: 180, marginLeft: 20 }} placeholder='请输入' />
</div>
<div style={{ display: 'flex', marginLeft: 20 }}>返回值
<div style={{ display: 'flex', width: 250, flexDirection: 'column', alignItems: 'center' }}>
<div key={'fieldData' + index} style={{ display: 'flex' }}>
<div style={{ width: 80, border: '1px solid #dcc' }}>名称</div>
<div style={{ width: 80, border: '1px solid #dcc' }}>意义</div>
<div style={{ width: 80, border: '1px solid #dcc' }}>说明</div>
</div>
{fieldData?.map((s, index) => {
return <div key={'fieldData' + index} style={{ display: 'flex' }}>
<div style={{ width: 80, border: '1px solid #dcc' }}>{s.code}</div>
<div style={{ width: 80, border: '1px solid #dcc' }}>{s.name}</div>
<div style={{ width: 80, border: '1px solid #dcc' }}>{s.type}</div>
</div>
})}
</div>
</div>
</TabPane>
</Tabs >
<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: 20 }}>
{activeKey == 'condition' || activeKey == 'SQL' || activeKey == 'release' ? <Button type="primary" onClick={() => {
if (activeKey == 'condition') {
setActiveKeyl('field')
} else if (activeKey == 'SQL') {
setActiveKeyl('condition')
} else if (activeKey == 'release') {
setActiveKeyl('SQL')
}
}}>上一步</Button> : ""}
{activeKey == 'condition' || activeKey == 'SQL' || activeKey == 'field' ? <Button style={{ marginLeft: 10 }} type="primary" onClick={() => {
if (activeKey == 'field') {
setActiveKeyl('condition')
} else if (activeKey == 'condition') {
setActiveKeyl('SQL')
} else if (activeKey == 'SQL') {
setActiveKeyl('release')
}
}}>下一步</Button> : ""}
{activeKey == 'release' ? <Button type="primary" style={{ marginLeft: 10 }} onClick={() => {
}}>完成 </Button> : ""}
<Button style={{ marginLeft: 10 }} onClick={() => onCancel()}>取消</Button>
</div>
</Modal >
)
}
function mapStateToProps (state) {
const { global, auth, } = state;
return {
user: auth.user,
actions: global.actions,
clientHeight: global.clientHeight,
};
}
export default connect(mapStateToProps)(ReleaseModal)

31
web/client/src/sections/metadataManagement/containers/databasesTable.js

@ -8,6 +8,7 @@ import MetadataDatabaseModal from '../components/metadataDatabaseModal';
import { ModelTypes } from '../constants/index'; import { ModelTypes } from '../constants/index';
import MetadataTagModal from '../components/metadataTagModal'; import MetadataTagModal from '../components/metadataTagModal';
import MetadataResourceModal from '../components/metadataResourceModal'; import MetadataResourceModal from '../components/metadataResourceModal';
import ReleaseModal from '../components/releaseModal';
const DatabaseTable = (props) => { const DatabaseTable = (props) => {
const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey, const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey,
@ -28,6 +29,7 @@ const DatabaseTable = (props) => {
const [editTagData, setEditTagData] = useState({}); const [editTagData, setEditTagData] = useState({});
const [resourceModalVisible, setResourceModalVisible] = useState(false); const [resourceModalVisible, setResourceModalVisible] = useState(false);
const [editResourceData, setEditResourceData] = useState({}); const [editResourceData, setEditResourceData] = useState({});
const [releaseModal, setReleaseModal] = useState(false);
useEffect(() => { useEffect(() => {
dispatch(metadataManagement.getTagList()); dispatch(metadataManagement.getTagList());
@ -73,7 +75,7 @@ const DatabaseTable = (props) => {
const marking = (id) => { const marking = (id) => {
dispatch(metadataManagement.getTagMetadata(id, 'database')).then(res => { dispatch(metadataManagement.getTagMetadata(id, 'database')).then(res => {
if (res.success) { if (res.success) {
const obj = { tagSet: [], tags: [], id: id }; const obj = { tagSet: [], tags: [], id: id }
if (res.payload.data.length) { if (res.payload.data.length) {
const tagSetIds = res.payload.data.map(d => d.tagSet) const tagSetIds = res.payload.data.map(d => d.tagSet)
obj.tagSet = [...new Set(tagSetIds)]; obj.tagSet = [...new Set(tagSetIds)];
@ -96,6 +98,13 @@ const DatabaseTable = (props) => {
setResourceModalVisible(true); setResourceModalVisible(true);
} }
const servicePublication = (record) => {
console.log(record);
setEditData(record)
setReleaseModal(true)
}
const onConfirmResource = (values) => { const onConfirmResource = (values) => {
dispatch(metadataManagement.postMetadataResourceApplications(values)).then(res => { dispatch(metadataManagement.postMetadataResourceApplications(values)).then(res => {
if (res.success) { if (res.success) {
@ -170,7 +179,7 @@ const DatabaseTable = (props) => {
width: '8%', width: '8%',
render: (text, record) => { render: (text, record) => {
let resourceApplicationsRecords = metadataResourceApplications.filter(ra => let resourceApplicationsRecords = metadataResourceApplications.filter(ra =>
ra.applyBy == user.id && ra.resourceName === record.name && ra.resourceId == record.id && !!record.token); ra.applyBy == user.id && ra.resourceName === record.name && ra.resourceId == record.id);
return <ButtonGroup> return <ButtonGroup>
<a onClick={() => onView(record)}>查看</a> <a onClick={() => onView(record)}>查看</a>
{user.role == '数据消费者' ? null : {user.role == '数据消费者' ? null :
@ -187,6 +196,10 @@ const DatabaseTable = (props) => {
{user.role !== '数据消费者' ? null : record.type === '表' ? resourceApplicationsRecords.length === 0 ? {user.role !== '数据消费者' ? null : record.type === '表' ? resourceApplicationsRecords.length === 0 ?
<a style={{ marginLeft: 10 }} onClick={() => applyResources(record)}>申请资源</a> : <a style={{ marginLeft: 10 }} onClick={() => applyResources(record)}>申请资源</a> :
<span style={{ marginLeft: 10, color: "#c0c0c0" }} title='已存在资源申请'>申请资源</span> : null} <span style={{ marginLeft: 10, color: "#c0c0c0" }} title='已存在资源申请'>申请资源</span> : null}
{user.role == '数据消费者' ? null :
record.type === '表' ?
<a style={{ marginLeft: 10 }} onClick={() => servicePublication(record)}>REST服务发布</a> : null
}
</ButtonGroup> </ButtonGroup>
} }
}]; }];
@ -332,6 +345,20 @@ const DatabaseTable = (props) => {
onCancel={() => setResourceModalVisible(false)} onCancel={() => setResourceModalVisible(false)}
onConfirm={onConfirmResource} /> : '' onConfirm={onConfirmResource} /> : ''
} }
{
releaseModal ?
<ReleaseModal
editData={editData}
onCancel={() => {
setReleaseModal(false)
setEditData({})
}}
onConfirm={() => {
}}
/>
: ''
}
</Spin > </Spin >
} }
function mapStateToProps (state) { function mapStateToProps (state) {

1
web/client/src/utils/webapi.js

@ -22,6 +22,7 @@ export const ApiTable = {
postResourceCatalog: 'resource-catalog', postResourceCatalog: 'resource-catalog',
putResourceCatalog: 'resource-catalog/{id}', putResourceCatalog: 'resource-catalog/{id}',
delResourceCatalog: 'resource-catalog/{id}', delResourceCatalog: 'resource-catalog/{id}',
listStructuredData: 'listStructuredData',
//最新元数据-元数据列表查询 //最新元数据-元数据列表查询
getMetadataDatabases: 'metadata/databases', getMetadataDatabases: 'metadata/databases',
getMetadataFiles: 'metadata/files', getMetadataFiles: 'metadata/files',

Loading…
Cancel
Save