index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. } catch (err) {
  239. if (err?.response?.data?.header?.msg) {
  240. message.error({ content: err?.response?.data?.header?.msg })
  241. }
  242. console.log(err)
  243. } finally {
  244. setSCLoading(false)
  245. }
  246. }
  247. const queryClassifications = async () => {
  248. try {
  249. setTreeLoading(true)
  250. const data = await request(api.getAuditClassification, { method: 'GET' })
  251. // @ts-ignore
  252. setClassifications(data?.payload ?? [])
  253. // @ts-ignore
  254. setSelectedKey(data?.payload?.[0]?.id)
  255. } finally {
  256. setTreeLoading(false)
  257. }
  258. }
  259. const queryQualityTasks = async () => {
  260. try {
  261. setTableLoading(true)
  262. const data = await request(
  263. `${api.getQualityTaskByPid}?pId=${selectedKey}`,
  264. {
  265. method: 'GET'
  266. }
  267. )
  268. // @ts-ignore
  269. setQualityTasks(data?.payload ?? [])
  270. } finally {
  271. setTableLoading(false)
  272. }
  273. }
  274. const handleSaveCfForm = async (form: IClassification) => {
  275. try {
  276. setCfLoading(true)
  277. const url = cfForm.id
  278. ? api.updateAuditClassification + cfForm.id
  279. : api.createAuditClassification
  280. const result = await request(url, {
  281. method: cfForm.id ? 'PUT' : 'POST',
  282. data: { ...cfForm, ...form }
  283. })
  284. // @ts-ignore
  285. if (result?.header?.code === 200) {
  286. setCfVisible(false)
  287. await queryClassifications()
  288. }
  289. } finally {
  290. setCfLoading(false)
  291. }
  292. }
  293. const handleSaveQtForm = async (view) => {
  294. try {
  295. setQtLoading(true)
  296. const url = qtForm?.id
  297. ? api.updateQualityTask + qtForm?.id
  298. : api.createQualityTask
  299. const result = await request(url, {
  300. method: qtForm?.id ? 'PUT' : 'POST',
  301. data: { ...qtForm, ...view }
  302. })
  303. // @ts-ignore
  304. if (result?.header?.code === 200) {
  305. setQtVisible(false)
  306. await queryQualityTasks()
  307. }
  308. } finally {
  309. setQtLoading(false)
  310. }
  311. }
  312. const handleDeleteTask = async (id: number) => {
  313. try {
  314. setTableLoading(true)
  315. const data = await request(`${api.deleteQualityTask}${id}`, {
  316. method: 'DELETE'
  317. })
  318. // @ts-ignore
  319. if (data.header.code === 200) {
  320. message.success({ content: '删除成功' })
  321. queryQualityTasks()
  322. }
  323. } finally {
  324. setTableLoading(false)
  325. }
  326. }
  327. useEffect(() => {
  328. queryClassifications()
  329. }, [])
  330. useEffect(() => {
  331. if (selectedKey) {
  332. queryQualityTasks()
  333. }
  334. // eslint-disable-next-line react-hooks/exhaustive-deps
  335. }, [selectedKey])
  336. return (
  337. <Container>
  338. <Helmet title="质量稽核" />
  339. <ContainerBody>
  340. <Box>
  341. <Box.Header>
  342. <Box.Title>质量稽核</Box.Title>
  343. </Box.Header>
  344. <Box.Body>
  345. <div className={styles.treeTableContainer}>
  346. <div className={styles.treeContainer}>
  347. <div className={styles.treeTitle}>
  348. <h6>数据质量</h6>
  349. <div
  350. className={styles.treePlusNode}
  351. onClick={() => {
  352. setCfForm({})
  353. setCfVisible(true)
  354. }}
  355. >
  356. <Icon type="plus" />
  357. </div>
  358. </div>
  359. <div className={styles.treeContent}>
  360. <Spin spinning={treeLoading}>
  361. {renderTree(classifications)}
  362. </Spin>
  363. </div>
  364. </div>
  365. <div style={{ flex: 1 }}>
  366. <div style={{ padding: '0 0 20px' }}>
  367. <Button
  368. type="primary"
  369. icon="plus"
  370. onClick={() => {
  371. setQtVisible(true)
  372. setQtForm(null)
  373. }}
  374. >
  375. 新增
  376. </Button>
  377. </div>
  378. <Table
  379. style={{ flex: 1 }}
  380. bordered
  381. rowKey="id"
  382. loading={tableLoading}
  383. dataSource={qualityTasks}
  384. columns={tableColumns}
  385. pagination={false}
  386. // onChange={this.tableChange}
  387. />
  388. </div>
  389. </div>
  390. <br />
  391. </Box.Body>
  392. </Box>
  393. </ContainerBody>
  394. <ClassificationsFormModal
  395. visible={cfVisible}
  396. formView={cfForm}
  397. onSave={handleSaveCfForm}
  398. loading={cfLoading}
  399. onCancel={() => setCfVisible(false)}
  400. />
  401. <QualityTaskFormModal
  402. pId={selectedKey}
  403. visible={qtVisible}
  404. formView={qtForm}
  405. onSave={handleSaveQtForm}
  406. loading={qtLoading}
  407. onCancel={() => {
  408. setQtVisible(false)
  409. setQtForm(null)
  410. }}
  411. />
  412. <ScheduleFormModal
  413. visible={scVisible}
  414. loading={scLoading}
  415. formView={qtForm}
  416. onSave={handleDispatch}
  417. onCancel={() => setScVisible(false)}
  418. />
  419. </Container>
  420. )
  421. }
  422. export default withRouter(DataGovernanceQualityAudit)