index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /* eslint-disable space-before-function-paren */
  2. import React, { useEffect, useState } from 'react'
  3. import Container, { ContainerBody } from 'components/Container'
  4. import Helmet from 'react-helmet'
  5. import Box from 'components/Box'
  6. import styles from 'containers/DataManagerView/index.less'
  7. import {
  8. Button,
  9. Divider,
  10. Dropdown,
  11. Icon,
  12. Menu,
  13. message,
  14. Popconfirm,
  15. Spin,
  16. Table
  17. } from 'antd'
  18. import classnames from 'classnames'
  19. import request from 'utils/request'
  20. import api from 'utils/api'
  21. import { ColumnProps } from 'antd/lib/table'
  22. import {
  23. IClassification,
  24. IQualityTask
  25. } from 'containers/DataGovernanceQualityAudit/types'
  26. import ClassificationsFormModal from 'containers/DataGovernanceQualityAudit/components/ClassificationsFormModal'
  27. import QualityTaskFormModal from 'containers/DataGovernanceQualityAudit/components/QualityTaskFormModal'
  28. import ScheduleFormModal from 'containers/DataGovernanceQualityAudit/components/ScheduleFormModal'
  29. // import header from 'containers/Display/Editor/Header'
  30. import { RouteComponentProps, withRouter } from 'react-router-dom'
  31. function DataGovernanceQualityAudit(
  32. props: RouteComponentProps<{ projectId: string }>
  33. ) {
  34. const { history, match } = props
  35. const [tableLoading, setTableLoading] = useState(false)
  36. const [treeLoading, setTreeLoading] = useState(false)
  37. const [selectedKey, setSelectedKey] = useState<number>()
  38. const [qualityTasks, setQualityTasks] = useState<IQualityTask[]>([])
  39. const [qtVisible, setQtVisible] = useState(false)
  40. const [qtLoading, setQtLoading] = useState(false)
  41. // eslint-disable-next-line no-undef
  42. const [qtForm, setQtForm] = useState<Partial<IQualityTask>>({})
  43. const [classifications, setClassifications] = useState<IClassification[]>([])
  44. const [cfVisible, setCfVisible] = useState(false)
  45. const [cfLoading, setCfLoading] = useState(false)
  46. const [cfForm, setCfForm] = useState<IClassification>({})
  47. const [scVisible, setScVisible] = useState(false)
  48. const [scLoading, setSCLoading] = useState(false)
  49. const [scForm] = useState<IClassification>({})
  50. const tableColumns: Array<ColumnProps<IQualityTask>> = [
  51. {
  52. title: '任务名称',
  53. dataIndex: 'taskName'
  54. },
  55. {
  56. title: '元数据名称',
  57. dataIndex: 'metadataName'
  58. },
  59. {
  60. title: '稽核字段个数',
  61. dataIndex: 'auditorCount'
  62. },
  63. {
  64. title: '操作',
  65. render: (_, data) => (
  66. <>
  67. <a
  68. onClick={() => {
  69. setQtVisible(true)
  70. setQtForm(data)
  71. }}
  72. >
  73. 编辑
  74. </a>
  75. <Divider type="vertical" />
  76. <Dropdown
  77. overlay={
  78. <Menu>
  79. <Menu.Item
  80. key="00"
  81. onClick={() => {
  82. // eslint-disable-next-line react/prop-types
  83. history.push(
  84. // eslint-disable-next-line react/prop-types
  85. `/project/${match.params.projectId}/dataGovernance/auditAnalysiss?systemId=${data.pId}&starTime=${data.startTime}&endTime=${data.endTime}&taskId=${data.id}`
  86. )
  87. }}
  88. >
  89. 稽查历史
  90. </Menu.Item>
  91. <Menu.Item
  92. key="0"
  93. onClick={() => {
  94. setQtForm(data)
  95. setScVisible(true)
  96. }}
  97. >
  98. 设置调度
  99. </Menu.Item>
  100. <Menu.Item key="1">
  101. <Popconfirm
  102. title="确定立即稽查吗?"
  103. placement="bottom"
  104. onConfirm={() => handleSetDispatchRightNow(data)}
  105. >
  106. <a>立即稽查</a>
  107. </Popconfirm>
  108. </Menu.Item>
  109. <Menu.Item key="3">
  110. <Popconfirm
  111. title="确定删除?"
  112. placement="bottom"
  113. onConfirm={() => handleDeleteTask(data.id)}
  114. >
  115. <a>删除</a>
  116. </Popconfirm>
  117. </Menu.Item>
  118. </Menu>
  119. }
  120. >
  121. <a>
  122. {' '}
  123. 更多 <Icon type="down" />
  124. </a>
  125. </Dropdown>
  126. </>
  127. )
  128. }
  129. ]
  130. const handleEditTreeItem = (form: IClassification) => {
  131. setCfForm(form)
  132. setCfVisible(true)
  133. }
  134. const handleDeleteTreeItem = async (c: IClassification) => {
  135. try {
  136. setTreeLoading(true)
  137. const data = await request(`${api.deleteDataRules}${c.id}`, {
  138. method: 'DELETE'
  139. })
  140. // @ts-ignore
  141. if (data?.header?.code === 200) {
  142. message.success({ content: '删除成功' })
  143. await queryClassifications()
  144. } else {
  145. // @ts-ignore
  146. // tslint:disable-next-line:no-unused-expression
  147. data?.header?.msg && message.error({ content: data?.header?.msg })
  148. }
  149. } finally {
  150. setTreeLoading(false)
  151. }
  152. }
  153. const renderTree = (catalogues: IClassification[]) => (
  154. <>
  155. {catalogues.map((c, idx) => (
  156. <div
  157. key={c.id ?? idx}
  158. className={classnames(styles.treeNode, {
  159. [styles.treeNodeSelected]: selectedKey === c.id
  160. })}
  161. >
  162. <span
  163. className={styles.treeNodeLeft}
  164. onClick={() => {
  165. setSelectedKey(c.id)
  166. }}
  167. >
  168. <Icon type="file" />
  169. {c.name}
  170. </span>
  171. <Dropdown
  172. overlay={() => (
  173. <Menu>
  174. <Menu.Item key="0" onClick={() => handleEditTreeItem(c)}>
  175. 编辑
  176. </Menu.Item>
  177. <Menu.Item key="1">
  178. <Popconfirm
  179. title="确定删除?"
  180. placement="bottom"
  181. onConfirm={() => handleDeleteTreeItem(c)}
  182. >
  183. <a>删除</a>
  184. </Popconfirm>
  185. </Menu.Item>
  186. </Menu>
  187. )}
  188. trigger={['click']}
  189. >
  190. <Icon type="more" />
  191. </Dropdown>
  192. </div>
  193. ))}
  194. </>
  195. )
  196. const handleSetDispatchRightNow = async (data: IQualityTask) => {
  197. try {
  198. setTableLoading(true)
  199. const result = await request(`${api.setDispatchRightNow}${data.id}`, {
  200. method: 'GET'
  201. }).catch((err) => {
  202. if (err?.response?.data?.header?.msg) {
  203. message.error({ content: err?.response?.data?.header?.msg })
  204. }
  205. })
  206. // @ts-ignore
  207. if (result?.header?.code === 200) {
  208. message.success({ content: '立即稽核完成' })
  209. }
  210. } finally {
  211. setTableLoading(false)
  212. }
  213. }
  214. const handleDispatch = async (form) => {
  215. try {
  216. setSCLoading(true)
  217. const result = await request(`${api.setDispatch}${qtForm.id}`, {
  218. method: 'PUT',
  219. data: {
  220. // @ts-ignore
  221. projectId: match.params?.projectId,
  222. name: qtForm.taskName,
  223. // taskName: qtForm.taskName,
  224. cronExpression: form.cronExpression,
  225. startDate: form.startDate[0].format('YYYY-MM-DD hh:mm:ss'),
  226. endDate: form.startDate[1].format('YYYY-MM-DD hh:mm:ss'),
  227. periodUnit: form.periodUnit,
  228. jobStatus: form.jobStatus ? 'started' : 'new',
  229. jobType: 'auditor'
  230. }
  231. })
  232. // @ts-ignore
  233. if (result.header.code === 200) {
  234. setScVisible(false)
  235. message.success({ content: '设置调度成功' })
  236. queryQualityTasks()
  237. }
  238. } finally {
  239. setSCLoading(false)
  240. }
  241. }
  242. const queryClassifications = async () => {
  243. try {
  244. setTreeLoading(true)
  245. const data = await request(api.getAuditClassification, { method: 'GET' })
  246. // @ts-ignore
  247. setClassifications(data?.payload ?? [])
  248. // @ts-ignore
  249. setSelectedKey(data?.payload?.[0]?.id)
  250. } finally {
  251. setTreeLoading(false)
  252. }
  253. }
  254. const queryQualityTasks = async () => {
  255. try {
  256. setTableLoading(true)
  257. const data = await request(`${api.getQualityTask}?pId=${selectedKey}`, {
  258. method: 'GET'
  259. })
  260. // @ts-ignore
  261. setQualityTasks(data?.payload ?? [])
  262. } finally {
  263. setTableLoading(false)
  264. }
  265. }
  266. const handleSaveCfForm = async (form: IClassification) => {
  267. try {
  268. setCfLoading(true)
  269. const url = cfForm.id
  270. ? api.updateAuditClassification + cfForm.id
  271. : api.createAuditClassification
  272. const result = await request(url, {
  273. method: cfForm.id ? 'PUT' : 'POST',
  274. data: { ...cfForm, ...form }
  275. })
  276. // @ts-ignore
  277. if (result?.header?.code === 200) {
  278. setCfVisible(false)
  279. await queryClassifications()
  280. }
  281. } finally {
  282. setCfLoading(false)
  283. }
  284. }
  285. const handleSaveQtForm = async (view) => {
  286. try {
  287. setQtLoading(true)
  288. const url = qtForm?.id
  289. ? api.updateQualityTask + qtForm?.id
  290. : api.createQualityTask
  291. const result = await request(url, {
  292. method: qtForm?.id ? 'PUT' : 'POST',
  293. data: { ...qtForm, ...view }
  294. })
  295. // @ts-ignore
  296. if (result?.header?.code === 200) {
  297. setQtVisible(false)
  298. await queryQualityTasks()
  299. }
  300. } finally {
  301. setQtLoading(false)
  302. }
  303. }
  304. const handleDeleteTask = async (id: number) => {
  305. try {
  306. setTableLoading(true)
  307. const data = await request(`${api.deleteQualityTask}${id}`, {
  308. method: 'DELETE'
  309. })
  310. // @ts-ignore
  311. if (data.header.code === 200) {
  312. message.success({ content: '删除成功' })
  313. queryQualityTasks()
  314. }
  315. } finally {
  316. setTableLoading(false)
  317. }
  318. }
  319. useEffect(() => {
  320. queryClassifications()
  321. }, [])
  322. useEffect(() => {
  323. if (selectedKey) {
  324. queryQualityTasks()
  325. }
  326. // eslint-disable-next-line react-hooks/exhaustive-deps
  327. }, [selectedKey])
  328. return (
  329. <Container>
  330. <Helmet title="质量稽核" />
  331. <ContainerBody>
  332. <Box>
  333. <Box.Header>
  334. <Box.Title>质量稽核</Box.Title>
  335. </Box.Header>
  336. <Box.Body>
  337. <div className={styles.treeTableContainer}>
  338. <div className={styles.treeContainer}>
  339. <div className={styles.treeTitle}>
  340. <h6>数据质量</h6>
  341. <div
  342. className={styles.treePlusNode}
  343. onClick={() => {
  344. setCfForm({})
  345. setCfVisible(true)
  346. }}
  347. >
  348. <Icon type="plus" />
  349. </div>
  350. </div>
  351. <div className={styles.treeContent}>
  352. <Spin spinning={treeLoading}>
  353. {renderTree(classifications)}
  354. </Spin>
  355. </div>
  356. </div>
  357. <div style={{ flex: 1 }}>
  358. <div style={{ padding: '0 0 20px' }}>
  359. <Button
  360. type="primary"
  361. icon="plus"
  362. onClick={() => {
  363. setQtVisible(true)
  364. setQtForm(null)
  365. }}
  366. >
  367. 新增
  368. </Button>
  369. </div>
  370. <Table
  371. style={{ flex: 1 }}
  372. bordered
  373. rowKey="id"
  374. loading={tableLoading}
  375. dataSource={qualityTasks}
  376. columns={tableColumns}
  377. pagination={false}
  378. // onChange={this.tableChange}
  379. />
  380. </div>
  381. </div>
  382. <br />
  383. </Box.Body>
  384. </Box>
  385. </ContainerBody>
  386. <ClassificationsFormModal
  387. visible={cfVisible}
  388. formView={cfForm}
  389. onSave={handleSaveCfForm}
  390. loading={cfLoading}
  391. onCancel={() => setCfVisible(false)}
  392. />
  393. <QualityTaskFormModal
  394. pId={selectedKey}
  395. visible={qtVisible}
  396. formView={qtForm}
  397. onSave={handleSaveQtForm}
  398. loading={qtLoading}
  399. onCancel={() => {
  400. setQtVisible(false)
  401. setQtForm(null)
  402. }}
  403. />
  404. <ScheduleFormModal
  405. visible={scVisible}
  406. loading={scLoading}
  407. formView={scForm}
  408. onSave={handleDispatch}
  409. onCancel={() => setScVisible(false)}
  410. />
  411. </Container>
  412. )
  413. }
  414. export default withRouter(DataGovernanceQualityAudit)