import { QuartzJobQueryDto, QuartzJobDto } from './../../../../syc-models'; import { RhSycService } from './../../../../syc.service'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; import { MsgHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-my-information-cycle', templateUrl: './my-information-cycle.component.html', styleUrls: ['./my-information-cycle.component.css'] }) export class MyInformationCycleComponent implements OnInit { @ViewChild('cycleQueryForm', { static: false }) cycleQueryFormCmt!: DynamicFormComponent; dataLoading = false; cycleDataResult: RhSafeAny; cycleLogCollapseQueryDto: RhSafeAny = {}; cycleQueryDto!: QuartzJobQueryDto; isShowDetail = false; selectedIndex = 0; detailData!: RhBaseDto | RhSafeAny; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'play-circle', '运行一次', 'primary', false, 'play-circle', false, null, (data) => this.redoBtnFun(data as RhBaseDto), true, false, 'blue' ), new RhTableButtonInfoDto( 'delete', '删除', 'primary', false, 'delete', false, null, (data) => this.deleteBtnFun(data as RhBaseDto), true, false, 'red' ) ]; TitleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('add', '添加定时任务', 'primary', false, 'file', false, null, () => this.openAddModal(), true) ]; addModalShow = false; addDto: RhBaseDto | null = null; addBeforeSubmit = (data: RhBaseDto) => { if (data['url']) { data['data'] = JSON.stringify({ url: data['url'] }); } return true; }; isEverySecond = false; CronStr = ''; constructor(private sycService: RhSycService) {} ngOnInit(): void { // this.getDatas(); } getDatas() { setTimeout(() => { this.cycleQueryFormCmt.submitDefaultForm(null); }); // this.sycService.GetQuartzJobs(this.cycleQueryDto).subscribe((result) => { // if (result.Success) { // this.cycleDataResult = result; // } else { // this.cycleDataResult = {}; // MsgHelper.ShowWarningMessage('查询失败!' + result.Message); // } // }); } redoBtnFun(data: RhBaseDto) { MsgHelper.ShowQuestionConfirm( '提示', `是否立即执行一次(后台工作名:${data['Name']})?`, () => { this.sycService.RequeueQuartzJob(data as QuartzJobDto).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('启动成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage('启动失败!' + result.Message); } }); }, () => {} ); } deleteBtnFun(data: RhBaseDto) { MsgHelper.ShowDeleteConfirm(`是否删除(后台工作名:${data['Name']})?`, () => { this.sycService.RemoveQuartzJob(data as QuartzJobDto).subscribe((result) => { if (result.Success) { MsgHelper.ShowInfoMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage('删除失败!' + result.Message); } }); }); } /** * * @param status */ dataLoadingChange(status: boolean) { this.dataLoading = status; } /** * 数据查询到赋值 * @param data * @param status */ resultDataChange(data: RhSafeAny) { this.cycleDataResult = data; } /** * 刷新表格 * @param data * @param status */ refreshDatas(option: RhTableQueryOptionDto) { setTimeout(() => { // this.cycleQueryFormCmt.submitDefaultForm(null); this.cycleQueryFormCmt.submitDefaultForm(null, option); }, 10); } /** * 打开详情 * @param event */ openDetailsBtnFun(event: RhSafeAny) { this.isShowDetail = false; setTimeout(() => { // this.detailData = new TransactOperationLogQueryDto(null, null, null, null, null, null, null); this.detailData = event.data; this.detailData['MethodName'] = event?.data?.Name + event?.data?.BackgroundWorkType; this.isShowDetail = true; this.selectedIndex = 1; }, 20); } // //关闭tab closeEntryTab() { this.selectedIndex = 0; this.isShowDetail = false; this.getDatas(); } initDefaultQueryDto(dto: RhSafeAny) { this.cycleLogCollapseQueryDto = dto; this.cycleQueryDto = { ...this.cycleQueryDto, ...this.cycleLogCollapseQueryDto }; } getValueChange() { this.cycleQueryDto = { ...this.cycleQueryDto, ...this.cycleLogCollapseQueryDto }; setTimeout(() => { this.getDatas(); }); } openAddModal() { this.addModalShow = true; } CloseAddModal() { this.addModalShow = false; this.addDto = null; this.CronStr = ''; } onStoreData(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`新增任务数据成功!`); this.selectedIndex = 0; this.addDto = null; this.CloseAddModal(); this.getDatas(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } setMsgCornExpressions(event: string, form: UntypedFormGroup) { this.getCronExpressionsExplain(event, form); } getCronExpressionsExplain(crons: string, form: UntypedFormGroup) { const cronList = crons.split(' '); if (cronList[0] === '*') { this.isEverySecond = true; } else { this.isEverySecond = false; } const unitList = ['秒', '分钟', '小时', '天', '月', '周', '年']; const explainList: RhSafeAny[] = []; let regResults: RhSafeAny = []; let explain = ''; let dayIndex = 0; if (crons === '* * * * * ? *') { explain = '每秒触发;'; } else { cronList.forEach((cron, index) => { let cronExpain = ''; switch (true) { case cron === '*': if (unitList[index] === '周') { cronExpain = '每天'; } else { cronExpain = `每${unitList[index]}`; } break; case cron === '?': dayIndex = index; break; case /\d+\/\d+/.test(cron): regResults = /(\d+)\/(\d+)/.exec(cron); cronExpain = `每隔${regResults[2]}${unitList[index]}执行,从第${regResults[1]}${unitList[index]}开始`; break; case /L\-\d+/.test(cron): regResults = /L\-(\d+)/.exec(cron); cronExpain = `距本月底前${regResults[1]}${unitList[index]}`; break; case /\d+W/.test(cron): regResults = /(\d+)W/.exec(cron); cronExpain = `距离${regResults[1]}日最近的工作日`; break; case /\d+L/.test(cron): regResults = /(\d+)L/.exec(cron); cronExpain = `本月最后一个星期${regResults[1]}`; break; case /\d+#\d+/.test(cron): regResults = /(\d+)#(\d+)/.exec(cron); cronExpain = `本月第${regResults[2]}个星期${regResults[1]}`; break; case /\d+\-\d+/.test(cron): regResults = /(\d+)\-(\d+)/.exec(cron); if (unitList[index] === '周') { cronExpain = `周期从星期${regResults[1]}到星期${regResults[2]}`; } else { cronExpain = `周期从${regResults[1]}到${regResults[2]}${unitList[index]}`; } break; case /\d+(\,\d+)*/.test(cron): if (unitList[index] === '周') { const dayList = (/(\d+)(,\d+)*/.exec(cron) as RhSafeAny)[0]; cronExpain = `具体天数为星期${dayList}`; } else { cronExpain = `具体${unitList[index]}数为${cron}`; } break; default: break; } if (cronExpain !== '') { explainList.push(cronExpain); } }); explainList.reverse(); if (dayIndex === 3) { const t = explainList[1]; explainList[1] = explainList[2]; explainList[2] = t; } explain = explainList.join(';') + '触发;'; } // form.get('Cron').setValue(explain); this.CronStr = explain; } }