66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
|
|
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
|
||
|
|
import { BaseEntity } from '@wwjCore/base/BaseEntity';
|
||
|
|
import { ScheduleStatus } from '../enums/schedule-status.enum';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 定时任务实体
|
||
|
|
* 对应数据库表: sys_schedule
|
||
|
|
*/
|
||
|
|
@Entity('sys_schedule')
|
||
|
|
export class Schedule extends BaseEntity {
|
||
|
|
@PrimaryGeneratedColumn()
|
||
|
|
id: number;
|
||
|
|
|
||
|
|
@Column({ name: 'addon', type: 'varchar', length: 255, default: '' })
|
||
|
|
addon: string;
|
||
|
|
|
||
|
|
@Column({ name: 'key', type: 'varchar', length: 255, default: '' })
|
||
|
|
key: string;
|
||
|
|
|
||
|
|
@Column({ name: 'status', type: 'int', default: 1 })
|
||
|
|
status: ScheduleStatus;
|
||
|
|
|
||
|
|
@Column({ name: 'time', type: 'varchar', length: 500, default: '' })
|
||
|
|
time: string;
|
||
|
|
|
||
|
|
@Column({ name: 'count', type: 'int', default: 0 })
|
||
|
|
count: number;
|
||
|
|
|
||
|
|
@Column({ name: 'last_time', type: 'int', default: 0 })
|
||
|
|
last_time: number;
|
||
|
|
|
||
|
|
@Column({ name: 'next_time', type: 'int', default: 0 })
|
||
|
|
next_time: number;
|
||
|
|
|
||
|
|
@Column({ name: 'sort', type: 'int', default: 0 })
|
||
|
|
sort: number;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取状态文本
|
||
|
|
*/
|
||
|
|
getStatusText(): string {
|
||
|
|
const statusMap = {
|
||
|
|
[ScheduleStatus.DISABLED]: '禁用',
|
||
|
|
[ScheduleStatus.ENABLED]: '启用',
|
||
|
|
[ScheduleStatus.RUNNING]: '执行中',
|
||
|
|
[ScheduleStatus.ERROR]: '错误',
|
||
|
|
[ScheduleStatus.PAUSED]: '暂停',
|
||
|
|
};
|
||
|
|
return statusMap[this.status] || '未知';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 检查任务是否启用
|
||
|
|
*/
|
||
|
|
isEnabled(): boolean {
|
||
|
|
return this.status === ScheduleStatus.ENABLED;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 检查任务是否正在执行
|
||
|
|
*/
|
||
|
|
isRunning(): boolean {
|
||
|
|
return this.status === ScheduleStatus.RUNNING;
|
||
|
|
}
|
||
|
|
}
|