Commit 911a23a3 by zhaochengxiang

服务导入

parent cefdd8e6
...@@ -149,7 +149,7 @@ const ImportAssetDrawer = (props) => { ...@@ -149,7 +149,7 @@ const ImportAssetDrawer = (props) => {
const handleOk = () => { const handleOk = () => {
if ((fileList||[]).length === 0) { if ((fileList||[]).length === 0) {
showMessage('info', '请先选择模板上传'); showMessage('info', '请先选择文件上传');
return; return;
} }
......
...@@ -36,7 +36,7 @@ const ImportElement = (props) => { ...@@ -36,7 +36,7 @@ const ImportElement = (props) => {
const handleOk = () => { const handleOk = () => {
if ((fileList||[]).length === 0) { if ((fileList||[]).length === 0) {
showMessage('info', '请先选择模板上传'); showMessage('info', '请先选择文件上传');
return; return;
} }
......
import React from 'react' import React from 'react'
import { Drawer, Form, Table, Pagination, Divider, Upload, Button, Typography } from 'antd' import { Drawer, Form, Pagination, Divider, Upload, Button, Typography, Modal, Spin } from 'antd'
import { UploadOutlined, DownloadOutlined } from '@ant-design/icons'; import { UploadOutlined, DownloadOutlined } from '@ant-design/icons'
import { dispatch } from '../../../../model'
import { AppContext } from '../../../../App'
import { showMessage } from '../../../../util'
import Table from '../../ResizeableTable'
const FC = (props) => { const FC = (props) => {
const { onCancel, onSuccess, visible } = props const { onCancel, onSuccess, visible } = props
...@@ -9,12 +14,16 @@ const FC = (props) => { ...@@ -9,12 +14,16 @@ const FC = (props) => {
const [confirmLoading, setConfirmLoading] = React.useState(false) const [confirmLoading, setConfirmLoading] = React.useState(false)
const [loading, setLoading] = React.useState(false) const [loading, setLoading] = React.useState(false)
const [logs, setLogs] = React.useState([]) const [logs, setLogs] = React.useState([])
const [ pagination, setPagination ] = useState( { pageNum: 1, pageSize: 20 } ); const [pagination, setPagination] = React.useState({ pageNum: 1, pageSize: 20 })
const { pageNum, pageSize } = pagination; const [total, setTotal] = React.useState(0)
const [ total, setTotal ] = useState(0); const [users, setUsers] = React.useState([])
const [ users, setUsers ] = useState([]); const [confirmParams, setConfirmParams] = React.useState({
visible: false,
message: undefined,
fileId: undefined,
})
const app = useContext(AppContext); const app = React.useContext(AppContext)
const columns = [ const columns = [
{ {
...@@ -30,18 +39,14 @@ const FC = (props) => { ...@@ -30,18 +39,14 @@ const FC = (props) => {
dataIndex: 'startTime', dataIndex: 'startTime',
width: 200, width: 200,
ellipsis: true, ellipsis: true,
render: (_, record, __) => { render: (_, record) => record.startTime ? new Date(record.startTime).toLocaleString() : ''
return formatDate(record.startTime);
}
}, },
{ {
title: '结束时间', title: '结束时间',
dataIndex: 'endTime', dataIndex: 'endTime',
width: 200, width: 200,
ellipsis: true, ellipsis: true,
render: (_, record, __) => { render: (_, record) => record.endTime ? new Date(record.endTime).toLocaleString() : ''
return formatDate(record.endTime);
}
}, },
{ {
title: '耗时', title: '耗时',
...@@ -57,56 +62,34 @@ const FC = (props) => { ...@@ -57,56 +62,34 @@ const FC = (props) => {
dataIndex: 'operator', dataIndex: 'operator',
width: 100, width: 100,
ellipsis: true, ellipsis: true,
render: (text, record) => { render: (_, record) => {
const user = users?.filter((user)=>user.pernr===text); const temp = (record.operator??'').split(':')
if (user && user.length > 0) { if ((temp??[]).length >= 3) {
return user[0].nachn?`${user[0].nachn}(${user[0].pernr})`:user[0].pernr; const user = (users??[]).filter((user)=>user.pernr === temp[2])
} if (user && user.length > 0) {
return user[0].nachn?`${user[0].nachn}(${user[0].pernr})`:user[0].pernr
}
return temp[2]
}
return text; return ''
} }
}, },
{ {
title: '导入状态', title: '导入状态',
dataIndex: 'state', dataIndex: 'state',
ellipsis: true, ellipsis: true,
} },
] ]
useEffect(() => { React.useEffect(() => {
if (visible) { if (visible) {
setPagination({ pageNum: 1, pageSize: 20 }); getLogs()
getUsers(); getUsers()
getLogs();
} }
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible]) }, [visible])
const downloadTemplate = () => {
window.open(`/api/dataassetmanager/dataAssetApi/getImportTemplate?templateType=${getTemplateType()}`);
}
const getLogs = (p = 1, s = 20) => {
setLoading(true);
dispatch({
type: 'assetmanage.importLogs',
payload: {
page: p,
pageSize: s
},
callback: data => {
setLoading(false);
setTotal(data.total);
setLogs(data.data||[]);
},
error: () => {
setLoading(false);
}
})
}
const getUsers = () => { const getUsers = () => {
dispatch({ dispatch({
type: 'pds.getOwners', type: 'pds.getOwners',
...@@ -116,9 +99,35 @@ const FC = (props) => { ...@@ -116,9 +99,35 @@ const FC = (props) => {
}) })
} }
const downloadTemplate = () => {
window.open('/api/pdataservice/pdsCURD/exportPDSDataServiceTemplate?model=DataService')
}
const getLogs = () => {
setLoading(true)
setPagination(prev => {
dispatch({
type: 'pds.getImportLogs',
payload: {
page: prev.pageNum,
size: prev.pageSize
},
callback: data => {
setLoading(false)
setTotal(data.totalElements)
setLogs(data.content||[])
},
error: () => {
setLoading(false)
}
})
return prev
})
}
const uploadProps = { const uploadProps = {
onRemove: file => { onRemove: file => {
const index = fileList.indexOf(file); const index = fileList.indexOf(file);
const newFileList = fileList.slice(); const newFileList = fileList.slice();
newFileList.splice(index, 1); newFileList.splice(index, 1);
...@@ -142,32 +151,43 @@ const FC = (props) => { ...@@ -142,32 +151,43 @@ const FC = (props) => {
}; };
const handleOk = () => { const handleOk = () => {
if ((fileList||[]).length === 0) { if ((fileList||[]).length === 0) {
showMessage('info', '请先选择模板上传'); showMessage('info', '请先选择文件上传')
return; return
} }
setConfirmLoading(true); setConfirmLoading(true)
dispatch({ dispatch({
type: 'assetmanage.assetImport', type: 'pds.addImportWithConfirm',
payload: { fileList: fileList, params: { env: `${app?.env?.domainId}`, saveAsDraft: true } }, payload: {
fileList: fileList,
params: {
namespace: app?.env?.domainId
},
},
callback: data => { callback: data => {
setConfirmLoading(false); setConfirmLoading(false)
setFileList([]); setFileList([])
getLogs(pageNum, pageSize); if (data?.fileId) {
showMessage('success', '导入动作完成,详情查看日志'); setConfirmParams({
onSuccess && onSuccess(data||''); visible: true,
message: data?.message,
fileId: data?.fileId,
})
} else {
showMessage('error', '上传文件失败')
}
}, },
error: () => { error: () => {
setConfirmLoading(false); setConfirmLoading(false)
} }
}); })
} }
const reset = () => { const reset = () => {
setConfirmLoading(false); setConfirmLoading(false)
setFileList([]); setPagination({ pageNum: 1, pageSize: 20 })
setFileList([])
} }
return ( return (
...@@ -179,7 +199,8 @@ const FC = (props) => { ...@@ -179,7 +199,8 @@ const FC = (props) => {
closable closable
destroyOnClose destroyOnClose
onClose={() => { onClose={() => {
reset()
onCancel?.()
}} }}
> >
<div className='mt-3'> <div className='mt-3'>
...@@ -197,7 +218,7 @@ const FC = (props) => { ...@@ -197,7 +218,7 @@ const FC = (props) => {
<Form.Item> <Form.Item>
<Button type='primary' onClick={handleOk} loading={confirmLoading}>确定导入</Button> <Button type='primary' onClick={handleOk} loading={confirmLoading}>确定导入</Button>
</Form.Item> </Form.Item>
<Button onClick={() => getLogs()} style={{ marginLeft: 'auto' }}>刷新日志</Button> <Button onClick={() => getLogs()} style={{ marginLeft: 'auto' }}>刷新日志</Button>
</Form> </Form>
</div> </div>
<Divider orientation="left">导入日志</Divider> <Divider orientation="left">导入日志</Divider>
...@@ -210,7 +231,7 @@ const FC = (props) => { ...@@ -210,7 +231,7 @@ const FC = (props) => {
loading={loading} loading={loading}
expandable={{ expandable={{
expandedRowRender: record => <React.Fragment> expandedRowRender: record => <React.Fragment>
{record.message?.split('<br/>').map((info, index) => { {record.message?.split('\n').map((info, index) => {
return <Typography.Paragraph key={index}>{info}</Typography.Paragraph> return <Typography.Paragraph key={index}>{info}</Typography.Paragraph>
})} })}
</React.Fragment> </React.Fragment>
...@@ -223,21 +244,117 @@ const FC = (props) => { ...@@ -223,21 +244,117 @@ const FC = (props) => {
showQuickJumper showQuickJumper
onChange={(_pageNum, _pageSize) => { onChange={(_pageNum, _pageSize) => {
setPagination({ pageNum: _pageNum||1, pageSize: _pageSize || 20 }); setPagination({ pageNum: _pageNum||1, pageSize: _pageSize || 20 });
getLogs(_pageNum||1, _pageSize||20); getLogs();
}} }}
onShowSizeChange={(_pageNum, _pageSize) => { onShowSizeChange={(_pageNum, _pageSize) => {
setPagination({ pageNum: _pageNum || 1, pageSize: _pageSize || 20 }); setPagination({ pageNum: _pageNum || 1, pageSize: _pageSize || 20 });
getLogs(_pageNum||1, _pageSize||20); getLogs();
}} }}
current={pageNum} current={pagination.pageNum}
pageSize={pageSize} pageSize={pagination.pageSize}
defaultCurrent={1} defaultCurrent={1}
total={total} total={total}
pageSizeOptions={[10,20]}
showTotal={total => `共 ${total} 条`} showTotal={total => `共 ${total} 条`}
/> />
<Confirm
{...confirmParams}
onCancel={(refresh) => {
setConfirmParams({
visible: false,
message: undefined,
fileId: undefined,
})
getLogs()
refresh && onSuccess?.()
}}
/>
</Drawer> </Drawer>
) )
} }
export default FC export default FC
\ No newline at end of file
const Confirm = ({ visible, message, fileId, onCancel }) => {
const [waiting, setWaiting] = React.useState(false)
const close = () => {
setWaiting(true)
dispatch({
type: 'pds.importConfirm',
payload: {
params: {
fileId,
isContinued: false,
},
},
callback: data => {
showMessage('success', '取消导入成功')
setWaiting(false)
onCancel?.()
},
error: () => {
setWaiting(false)
}
})
}
const save = () => {
setWaiting(true)
dispatch({
type: 'pds.importConfirm',
payload: {
params: {
fileId,
isContinued: true,
},
},
callback: data => {
showMessage('success', '上传文件成功,正在导入。。。')
setWaiting(false)
onCancel?.(true)
},
error: () => {
setWaiting(false)
}
})
}
const footer = React.useMemo(() => {
return [
<Button key={'cancel'}
onClick={() => close()}
>取消导入</Button>,
<Button key={'save'} type='primary'
disabled={waiting}
onClick={() => save()}
>继续导入</Button>
]
}, [close, save, waiting])
return (
<Modal
title='导入确认'
width={600}
visible={visible}
footer={footer}
destroyOnClose
maskClosable={false}
onCancel={() => {
close()
}}
bodyStyle={{
height: 400,
overflow: 'auto'
}}
>
<Spin spinning={waiting}>
{
(message??'').split('\n').map((info, index) => {
return <Typography.Paragraph key={index}>{info}</Typography.Paragraph>
})
}
</Spin>
</Modal>
)
}
\ No newline at end of file
...@@ -24,6 +24,7 @@ import ColSettingModal from './Component/ColSettingModal'; ...@@ -24,6 +24,7 @@ import ColSettingModal from './Component/ColSettingModal';
import StartAuthorize from './Component/StartAuthorize'; import StartAuthorize from './Component/StartAuthorize';
import StartRelease from './Component/StartRelease'; import StartRelease from './Component/StartRelease';
import Offline from './Component/Offline'; import Offline from './Component/Offline';
import ImportServices from './Component/ImportServices';
import './index.less'; import './index.less';
...@@ -72,6 +73,7 @@ class Model extends React.Component { ...@@ -72,6 +73,7 @@ class Model extends React.Component {
offlineVisible: false, offlineVisible: false,
jdbcInformationVisible: false, jdbcInformationVisible: false,
isRoot: false, isRoot: false,
importServicesVisible: false,
} }
} }
...@@ -347,7 +349,7 @@ class Model extends React.Component { ...@@ -347,7 +349,7 @@ class Model extends React.Component {
} }
onImportClick = () => { onImportClick = () => {
this.setState({ importServicesVisible: true });
} }
onSubscribeBtnClick = () => { onSubscribeBtnClick = () => {
...@@ -725,7 +727,7 @@ class Model extends React.Component { ...@@ -725,7 +727,7 @@ class Model extends React.Component {
<Button onClick={() => { this.setState({jdbcInformationVisible: true}); }}>JDBC信息</Button> <Button onClick={() => { this.setState({jdbcInformationVisible: true}); }}>JDBC信息</Button>
</Space> </Space>
{ {
(getDataModelerRole(app?.user)!==DataModelerRoleReader) && isOnlyEnding && <Button onClick={this.onImportClick}>导入</Button> (getDataModelerRole(app?.user)!==DataModelerRoleReader) && !isOnlyEnding && <Button onClick={this.onImportClick}>导入</Button>
} }
{ {
(getDataModelerRole(app?.user)!==DataModelerRoleReader) && isOnlyEnding && (getDataModelerRole(app?.user)!==DataModelerRoleReader) && isOnlyEnding &&
...@@ -853,7 +855,15 @@ class Model extends React.Component { ...@@ -853,7 +855,15 @@ class Model extends React.Component {
<JDBCInformation <JDBCInformation
visible={this.state.jdbcInformationVisible} visible={this.state.jdbcInformationVisible}
onCancel={() => { this.setState({ jdbcInformationVisible: false }) }} onCancel={() => { this.setState({ jdbcInformationVisible: false }) }}
/> />
<ImportServices
visible={this.state.importServicesVisible}
onCancel={() => { this.setState({ importServicesVisible: false }) }}
onSuccess={() => {
this.onTableChange()
}}
/>
</div> </div>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment