index.tsx 12 KB

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