index.tsx 12 KB

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