audit-regular-time.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <div>
  3. <div :class="$style.addButton"
  4. ><a-button v-if="!readonly" type="primary" @click="showAddTask('add')"
  5. >新建任务</a-button
  6. ></div
  7. >
  8. <a-table
  9. :columns="columns"
  10. :data-source="model.jobName ? [model] : []"
  11. :row-key="(record, index) => index"
  12. :pagination="false"
  13. >
  14. <template slot="lastExecuteStatus" slot-scope="text, record">
  15. <!-- <template v-for="(item, key) in statusList">
  16. <span v-if="text === item.value || text === parseInt(item.value)" :key="key">{{
  17. item.label
  18. }}</span>
  19. </template> -->
  20. <span v-if="record.lastExecuteStatus === 1">执行中</span>
  21. <span v-else-if="record.lastExecuteStatus === 2">执行成功</span>
  22. <span v-else-if="record.lastExecuteStatus === 0">执行失败</span>
  23. <span v-else>暂未执行</span>
  24. </template>
  25. <!-- 时间戳转化成年月日时分秒 -->
  26. <template slot="jobCreationTime" slot-scope="text, record">
  27. <span>{{ new Date(record.jobCreationTime).toLocaleString() }}</span>
  28. </template>
  29. <template slot="jobCreatorName" slot-scope="text, record">
  30. <span>{{ record.jobCreatorName }}</span>
  31. </template>
  32. <template slot="action" slot-scope="text, record">
  33. <!-- 编辑 执行 立即执行 执行记录 查看数据 删除 -->
  34. <a-button v-if="!readonly" type="link" @click="showEditOrData(record.id)">编辑</a-button>
  35. <a-button v-if="record.jobStatus === 1" type="link" @click="execute(record.id, 'stop')"
  36. >暂停任务</a-button
  37. >
  38. <a-button v-else type="link" @click="execute(record.id)">恢复任务</a-button>
  39. <a-button v-if="isShowEmm" type="link" @click="executeNow(record.id)">立即执行</a-button>
  40. <a-button type="link" @click="executeRecord(record.id)">执行记录</a-button>
  41. <a-button type="link" @click="viewData(record.id)">查看数据</a-button>
  42. <a-button v-if="!readonly" type="link" @click="deleteData(record.id)">删除</a-button>
  43. </template>
  44. </a-table>
  45. <!-- 新建任务 -->
  46. <a-modal
  47. v-model="addTask"
  48. :title="(modalTitle === 'add' ? '新增' : '编辑') + '任务'"
  49. width="700px"
  50. :confirm-loading="confirmLoading"
  51. @ok="addJob"
  52. @cancel="cancelAddTask"
  53. >
  54. <div :class="$style.content">
  55. <a-form-model
  56. ref="formValidate"
  57. :model="form"
  58. :label-col="{ span: 3 }"
  59. :wrapper-col="{ span: 12 }"
  60. :rules="rules"
  61. >
  62. <div :class="$style.tip"
  63. >提示:模型新建跑批任务后,将不能修改模型逻辑及参数,修改后取数任务将出现失败,逻辑及参数变化需新建模型。</div
  64. >
  65. <a-form-model-item label="任务名称" prop="jobName">
  66. <!-- <a-input v-model="form.jobName" :disabled="modalTitle !== 'add'" /> -->
  67. <a-input v-model="form.jobName" :disabled="true" />
  68. </a-form-model-item>
  69. <a-tabs v-model="form.jobType" @change="tabscallback">
  70. <a-tab-pane :key="0" tab="全量" :disabled="tabsdisabled">
  71. <!-- 拉取频率 -->
  72. <!-- cron表达式 -->
  73. <a-form-model-item
  74. label="cron表达式"
  75. placeholder="请输入cron表达式"
  76. prop="cronExpression"
  77. >
  78. <a-row :gutter="24">
  79. <a-col :span="14">
  80. <a-input v-model="form.cronExpression"></a-input>
  81. </a-col>
  82. <a-col :span="10">
  83. <a-button
  84. v-show="!cronExpSetting"
  85. :class="$style.formBtn"
  86. @click="
  87. () => {
  88. cronExpSetting = true
  89. }
  90. "
  91. >高级设置</a-button
  92. >
  93. <a-button
  94. v-show="cronExpSetting"
  95. :class="$style.formBtn"
  96. @click="
  97. () => {
  98. cronExpSetting = false
  99. }
  100. "
  101. >收起</a-button
  102. >
  103. </a-col>
  104. </a-row>
  105. <SdCronCreate
  106. v-show="cronExpSetting"
  107. ref="cronCreate"
  108. :scheduler="scheduler"
  109. @setCronExpValue="setCronExpValue"
  110. ></SdCronCreate>
  111. </a-form-model-item>
  112. <!-- 任务有效期 -->
  113. <a-form-model-item label="任务有效期" prop="jobValidSt">
  114. <a-range-picker v-model="form.jobTime" @change="jobTimeChange" />
  115. </a-form-model-item>
  116. </a-tab-pane>
  117. <a-tab-pane :key="1" tab="增量">
  118. <!-- cron表达式 -->
  119. <a-form-model-item
  120. label="cron表达式"
  121. placeholder="请输入cron表达式"
  122. prop="cronExpression"
  123. >
  124. <a-row :gutter="24">
  125. <a-col :span="14">
  126. <a-input v-model="form.cronExpression"></a-input>
  127. </a-col>
  128. <a-col :span="10">
  129. <a-button
  130. v-show="!cronExpSetting"
  131. :class="$style.formBtn"
  132. @click="
  133. () => {
  134. cronExpSetting = true
  135. }
  136. "
  137. >高级设置</a-button
  138. >
  139. <a-button
  140. v-show="cronExpSetting"
  141. :class="$style.formBtn"
  142. @click="
  143. () => {
  144. cronExpSetting = false
  145. }
  146. "
  147. >收起</a-button
  148. >
  149. </a-col>
  150. </a-row>
  151. <SdCronCreate
  152. v-show="cronExpSetting"
  153. ref="cronCreate"
  154. :scheduler="scheduler"
  155. @setCronExpValue="setCronExpValue"
  156. ></SdCronCreate>
  157. </a-form-model-item>
  158. <!-- 任务有效期 -->
  159. <a-form-model-item label="任务有效期" prop="jobValidSt">
  160. <a-range-picker v-model="form.jobTime" @change="jobTimeChange" />
  161. </a-form-model-item>
  162. <!-- 是否开启下发 显示是 1否 0 distributeFlag-->
  163. <a-form-model-item v-if="model.modelType !== '0'" label="是否开启下发">
  164. <a-radio-group v-model="form.distributeFlag">
  165. <a-radio :value="0">否</a-radio>
  166. <a-radio :value="1">是</a-radio>
  167. </a-radio-group>
  168. </a-form-model-item>
  169. <!--添加定时任务那是 distributeSt 传时间戳 -->
  170. <!-- 期初数据判断 distributeSt-->
  171. <a-form-model-item v-if="form.distributeFlag === 1" label="期初数据判断">
  172. <a-date-picker v-model="form.distributeSt" formt="YYYY-MM-DD" />
  173. </a-form-model-item>
  174. </a-tab-pane>
  175. </a-tabs>
  176. </a-form-model>
  177. </div>
  178. </a-modal>
  179. <!-- 执行状态 -->
  180. <a-modal v-model="executeRecordShow" title="执行记录" width="700px">
  181. <div :class="$style.content">
  182. <!-- <a-table
  183. :columns="executeRecordTable.columns"
  184. :data-source="executeRecordTable.dataSource"
  185. ></a-table> -->
  186. <SdDataTableEx
  187. form-id="iamModelJobStatus"
  188. page-id="audit/maintain/iamModelJobStatus"
  189. :filter-expressions="expressions"
  190. :columns="recordColumns"
  191. >
  192. <!-- 执行状态 -->
  193. <template slot="status" slot-scope="text, record">
  194. <span>{{
  195. record.status === 1 ? '执行中' : record.status === 2 ? '执行成功' : '执行失败'
  196. }}</span>
  197. </template>
  198. </SdDataTableEx>
  199. </div>
  200. </a-modal>
  201. </div>
  202. </template>
  203. <script>
  204. import { message, Modal } from 'ant-design-vue'
  205. import AuditMaintainService from './audit-maintain-service'
  206. import SdCronCreate from '@/control-manage/sd-cron-create.vue'
  207. import { scheduler } from '@/control-manage/util'
  208. import moment from 'moment'
  209. import TableColumnTypes from '@/common/services/table-column-types'
  210. import SdDataTableEx from '@/common/components/sd-data-table-ex.vue'
  211. export default {
  212. name: 'AuditRegularTime',
  213. metaInfo: {
  214. title: 'AuditRegularTime',
  215. },
  216. components: {
  217. SdCronCreate,
  218. SdDataTableEx,
  219. },
  220. props: {
  221. model: {
  222. type: Object,
  223. default: () => ({}),
  224. // onreset
  225. },
  226. // 是否只读
  227. readonly: {
  228. type: Boolean,
  229. default: false,
  230. },
  231. },
  232. data() {
  233. return {
  234. isShowEmm: false,
  235. // 任务名称 策略配置 最后一次执行状态 创建时间 创建人 操作(需要插槽)
  236. expressions: [{ dataType: 'str', name: 'modelId', op: 'eq', stringValue: '' }],
  237. recordColumns: [
  238. {
  239. title: '序号',
  240. dataIndex: 'sort',
  241. customRender: (text, record, index) => `${index + 1}`,
  242. },
  243. {
  244. title: '执行时间',
  245. dataIndex: 'creationTime',
  246. sdRender: TableColumnTypes.dateTime,
  247. },
  248. {
  249. title: '执行状态',
  250. dataIndex: 'status',
  251. scopedSlots: { customRender: 'status' },
  252. },
  253. // 失败原因
  254. // errMsg
  255. {
  256. title: '失败原因',
  257. dataIndex: 'errMsg',
  258. },
  259. ],
  260. columns: [
  261. {
  262. title: '任务名称',
  263. dataIndex: 'jobName',
  264. key: 'jobName',
  265. },
  266. {
  267. title: '策略配置',
  268. dataIndex: 'cronExp',
  269. key: 'cronExp',
  270. },
  271. {
  272. title: '最后一次执行状态',
  273. dataIndex: 'lastExecuteStatus',
  274. key: 'lastExecuteStatus',
  275. scopedSlots: { customRender: 'lastExecuteStatus' },
  276. },
  277. {
  278. title: '创建时间',
  279. dataIndex: 'jobCreationTime',
  280. key: 'jobCreationTime',
  281. scopedSlots: { customRender: 'jobCreationTime' },
  282. },
  283. {
  284. title: '创建人',
  285. dataIndex: ' jobCreatorName',
  286. key: ' jobCreatorName',
  287. scopedSlots: { customRender: 'jobCreatorName' },
  288. },
  289. {
  290. title: '操作',
  291. dataIndex: 'action',
  292. key: 'action',
  293. scopedSlots: { customRender: 'action' },
  294. },
  295. ],
  296. dataSource: [],
  297. scheduler,
  298. // 执行状态: 执行中 执行成功 执行失败
  299. statusList: [
  300. { label: '执行中', value: '1' },
  301. { label: '执行成功', value: '2' },
  302. { label: '执行失败', value: '0' },
  303. // 暂未执行
  304. { lable: '暂未执行', value: '10' },
  305. ],
  306. tabsdisabled: false,
  307. modalTitle: 'add',
  308. addTask: false,
  309. rules: {
  310. jobName: [{ required: true, message: '请输入任务名称', trigger: 'blur' }],
  311. cronExpression: [{ required: true, message: '请输入cron表达式', trigger: 'blur' }],
  312. jobValidSt: [{ required: true, message: '请选择任务有效期', trigger: 'blur' }],
  313. // 任务有效期
  314. },
  315. confirmLoading: false,
  316. form: {
  317. // String jobName; // 任务名称 默认为模型名称
  318. jobName: '',
  319. // 任务分组名称 jobGroupName 默认为模型编号
  320. jobGroupName: '',
  321. // 任务类型 0 全 1增 jobType
  322. jobType: 0,
  323. // 任务有效期:
  324. jobTime: [],
  325. // 任务有效开始时间
  326. jobValidSt: '',
  327. // 任务有效结束时间
  328. jobValidEd: '',
  329. // cron 表达式
  330. cronExpression: '',
  331. // 是否下发
  332. distributeFlag: 0,
  333. distributeSt: null,
  334. //
  335. },
  336. cronExpSetting: false,
  337. // 执行记录
  338. executeRecordShow: false,
  339. // 执行记录表格
  340. executeRecordTable: {
  341. columns: [
  342. // 序号
  343. {
  344. title: '序号',
  345. dataIndex: 'sort',
  346. },
  347. {
  348. title: '执行时间',
  349. dataIndex: 'executeTime',
  350. key: 'executeTime',
  351. },
  352. {
  353. title: '执行状态',
  354. dataIndex: 'executeStatus',
  355. key: 'executeStatus',
  356. },
  357. ],
  358. dataSource: [
  359. {
  360. sort: 1,
  361. executeTime: '执行时间',
  362. executeStatus: '执行成功',
  363. },
  364. ],
  365. tableStatus: '',
  366. },
  367. //
  368. }
  369. },
  370. computed: {
  371. comData() {
  372. return this.tableStatus === '正常'
  373. },
  374. },
  375. watch: {
  376. model: {
  377. handler(val) {
  378. this.dataSource = val
  379. },
  380. deep: true,
  381. },
  382. },
  383. created() {
  384. // 查询当前状态
  385. // G_1_EXECUTE_IMMEDIATELY
  386. const roles = this.$store.state.sd.common.userInfo.default.roles
  387. this.isShowEmm = roles.map((val) => val.code).includes('G-1_EXECUTE_IMMEDIATELY')
  388. },
  389. methods: {
  390. // 显示编辑
  391. showEditOrData(id) {
  392. // this.showAddTask('edit')
  393. this.form.cronExpression = this.model.cronExpression
  394. this.form.jobName = this.model.jobName
  395. this.form.jobGroupName = this.model.jobGroupName
  396. this.form.jobValidSt = this.model.jobValidSt
  397. this.form.jobValidEd = this.model.jobValidEd
  398. // moment(this.model.jobValidSt, 'YYYY-MM-DD'),
  399. // moment(this.model.jobValidEd, 'YYYY-MM-DD'),
  400. // 时间戳转moment格式
  401. this.form.jobTime = [moment(this.model.jobValidSt), moment(this.model.jobValidEd)]
  402. this.form.id = this.model.id
  403. this.form.distributeFlag = this.model.distributeFlag
  404. this.form.jobType = parseInt(this.model.jobType)
  405. // 如果有则赋值
  406. this.form.distributeSt = this.model.distributeSt ? moment(this.model.distributeSt) : null
  407. this.modalTitle = 'edit'
  408. this.addTask = true
  409. },
  410. // 新建任务
  411. addJob() {
  412. this.$refs.formValidate.validate((valid) => {
  413. if (valid) {
  414. this.confirmLoading = true
  415. const params = {
  416. jobName: this.form.jobName,
  417. jobGroupName: this.form.jobGroupName,
  418. id: this.model.id,
  419. distributeFlag: this.form.distributeFlag,
  420. jobValidEd: this.form.jobValidEd,
  421. jobValidSt: this.form.jobValidSt,
  422. distributeSt: null,
  423. }
  424. params.distributeSt = this.form.distributeSt ? this.form.distributeSt._d.getTime() : null
  425. params.cronExpression = this.form.cronExpression
  426. if (this.form.jobType === 0) {
  427. params.jobType = 0
  428. } else {
  429. params.jobType = 1
  430. // 增量字段
  431. // 是否下发
  432. }
  433. if (this.modalTitle === 'add') {
  434. AuditMaintainService.addTask(params).then((res) => {
  435. // 新建成功
  436. message.success('新建成功')
  437. setTimeout(() => {
  438. window.location.reload()
  439. }, 500)
  440. this.addTask = false
  441. })
  442. } else {
  443. AuditMaintainService.rescheduleJob(params).then((res) => {
  444. // if (res.code === 200) {
  445. // this.form = res.data
  446. // }
  447. // 更新成功
  448. message.success('更新成功')
  449. this.$emit('onreset')
  450. // 两秒后刷新页面
  451. setTimeout(() => {
  452. window.location.reload()
  453. }, 500)
  454. this.showAddTask('edit')
  455. // 关闭当前
  456. })
  457. }
  458. }
  459. })
  460. },
  461. // 任务有效期变化
  462. jobTimeChange(val) {
  463. // 设置
  464. // 获取时间戳
  465. this.form.jobValidSt = val[0]._d.getTime()
  466. this.form.jobValidEd = val[1]._d.getTime()
  467. },
  468. cancelAddTask() {
  469. this.addTask = false
  470. // 清空表单
  471. this.form = {
  472. jobName: '',
  473. jobGroupName: '',
  474. jobType: 0,
  475. jobTime: null,
  476. jobValidSt: '',
  477. jobValidEd: '',
  478. cronExpression: '',
  479. distributeFlag: 0,
  480. distributeSt: null,
  481. }
  482. },
  483. // 设置cron表达式的值
  484. setCronExpValue(val) {
  485. // this.$refs.createForm.setFieldValue('cronExp', val)
  486. this.form.cronExpression = val
  487. },
  488. execute(id, type) {
  489. const params = {
  490. id,
  491. jobName: this.model.jobName,
  492. }
  493. if (type === 'stop') {
  494. Modal.confirm({
  495. title: '确认停止',
  496. content: '确认停止该任务吗?',
  497. okText: '确认',
  498. cancelText: '取消',
  499. onOk() {
  500. // 停止
  501. AuditMaintainService.pauseJob(params).then((res) => {
  502. message.success('暂停成功')
  503. setTimeout(() => {
  504. window.location.reload()
  505. }, 500)
  506. })
  507. },
  508. })
  509. return
  510. }
  511. AuditMaintainService.resumeJob(params).then((res) => {
  512. message.success('恢复成功')
  513. setTimeout(() => {
  514. window.location.reload()
  515. }, 500)
  516. })
  517. },
  518. executeNow(id) {
  519. const params = {
  520. id,
  521. jobName: this.model.jobName,
  522. }
  523. Modal.confirm({
  524. title: '立即执行',
  525. content: '当前模型存在执行任务,手动执行可能出现重复数据,是否要手动执行?',
  526. okText: '确认',
  527. cancelText: '取消',
  528. onOk() {
  529. AuditMaintainService.executeJob(params).then((res) => {
  530. message.success('立即执行成功')
  531. setTimeout(() => {
  532. // window.location.reload()
  533. }, 500)
  534. })
  535. },
  536. })
  537. },
  538. executeRecord(id) {
  539. // 获取执行记录
  540. this.expressions[0].stringValue = id
  541. this.executeRecordShow = true
  542. },
  543. viewData(id) {
  544. // 如果有且只有一个?号则直接跳转
  545. const url = window.location.href
  546. const urlArr = url.split('?')
  547. if (urlArr.length === 3) {
  548. const baseUrl = urlArr[0]
  549. window.open(baseUrl + `#/audit-sq-record?id=${id}`)
  550. return
  551. }
  552. // const url = window.location.href
  553. // const index = url.indexOf('?')
  554. // const baseUrl = url.substring(0, index)
  555. window.open(`#/audit-sq-record?id=${id}`)
  556. },
  557. deleteData(id) {
  558. const params = {
  559. id,
  560. jobName: this.model.jobName,
  561. }
  562. // 确认删除
  563. Modal.confirm({
  564. title: '确认删除',
  565. content: '确认删除该任务吗?',
  566. okText: '确认',
  567. cancelText: '取消',
  568. onOk() {
  569. // 删除
  570. AuditMaintainService.deleteJob(params).then((res) => {
  571. // 删除成功
  572. message.success('删除成功')
  573. // 刷新页面
  574. window.location.reload()
  575. })
  576. },
  577. })
  578. },
  579. tabscallback(key) {
  580. // 如果key ==0 则保留 corn 和开始结束时间
  581. // 如果key === 0 则下发为0
  582. if (key === '0') {
  583. this.form.distributeFlag = 0
  584. }
  585. },
  586. // 当前的模型类型
  587. showAddTask(type = 'add') {
  588. // 如果已经jobName存在则提示已存在定时任务
  589. if (this.model.jobName && type === 'add') {
  590. message.error('已存在定时任务')
  591. return
  592. }
  593. if (type === 'add') {
  594. this.form.jobName = this.model.modelCode + '-' + this.model.modelName
  595. }
  596. this.modalTitle = type
  597. this.form.jobGroupName = this.model.modelCode
  598. // 请选择模型类型后重试
  599. if (!this.model.modelType) {
  600. message.error('请选择模型类型后重试')
  601. return
  602. }
  603. // 只有分析类可以两者都选
  604. if (this.model.modelType + '' === '0') {
  605. this.tabsdisabled = false
  606. this.form.jobType = 0
  607. this.form.distributeFlag = 0
  608. // 下发标识=0
  609. } else {
  610. this.form.distributeFlag = 0
  611. this.tabsdisabled = true
  612. this.form.jobType = 1
  613. }
  614. this.addTask = !this.addTask
  615. },
  616. },
  617. }
  618. </script>
  619. <style module lang="scss">
  620. @use '@/common/design' as *;
  621. .add-button {
  622. // 居右
  623. text-align: right;
  624. }
  625. .onflex {
  626. display: flex;
  627. align-items: center;
  628. }
  629. .tip {
  630. margin-left: 42px;
  631. color: $alert-error-icon-color;
  632. }
  633. </style>