@@ -5,7 +5,18 @@
*/
import { api } from '@/apis/index' ;
import type { CrontabTask , CrontabLog , DataCollectionItem , CrontabItem , ResultDomain , PageParam } from '@/types' ;
import type {
CrontabTask ,
CrontabLog ,
DataCollectionItem ,
CrontabItem ,
TaskMeta ,
EmailDefault ,
EmailRecipient ,
CreateTaskRequest ,
ResultDomain ,
PageParam
} from '@/types' ;
/**
* 定时任务API服务
@@ -16,11 +27,11 @@ export const crontabApi = {
// ==================== 定时任务管理 ====================
/**
* 获取可创建的定时任务模板 列表
* @returns Promise<ResultDomain<CrontabItem >>
* 获取可创建的定时任务列表(从数据库获取任务元数据)
* @returns Promise<ResultDomain<TaskMeta >>
*/
async getEnabledCrontabList ( ) : Promise < ResultDomain < CrontabItem > > {
const response = await api . get < CrontabItem > ( ` ${ this . baseUrl } /getEnabledCrontabList ` ) ;
async getEnabledCrontabList ( ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . get < TaskMeta > ( ` ${ this . baseUrl } /getEnabledCrontabList ` ) ;
return response . data ;
} ,
@@ -29,18 +40,18 @@ export const crontabApi = {
* @param task 任务对象
* @returns Promise<ResultDomain<CrontabTask>>
*/
async createTask ( task : CrontabTask ) : Promise < ResultDomain < CrontabTask > > {
async createTask ( task : CreateTaskRequest ) : Promise < ResultDomain < CrontabTask > > {
const response = await api . post < CrontabTask > ( ` ${ this . baseUrl } /crontabTask ` , task ) ;
return response . data ;
} ,
/**
* 更新定时任务
* @param task 任务对象
* @param request 更新任务请求( 包含任务信息、元数据ID等)
* @returns Promise<ResultDomain<CrontabTask>>
*/
async updateTask ( task : CrontabTask ) : Promise < ResultDomain < CrontabTask > > {
const response = await api . put < CrontabTask > ( ` ${ this . baseUrl } /crontabTask ` , task ) ;
async updateTask ( request : CreateTaskRequest ) : Promise < ResultDomain < CrontabTask > > {
const response = await api . put < CrontabTask > ( ` ${ this . baseUrl } /crontabTask ` , request ) ;
return response . data ;
} ,
@@ -255,5 +266,254 @@ export const crontabApi = {
const response = await api . put < string > ( ` ${ this . baseUrl } /collection/item/ ${ itemId } /status/ ${ status } ` ) ;
return response . data ;
} ,
// ==================== 任务元数据管理 ====================
/**
* 创建任务元数据
* @param taskMeta 任务元数据
* @returns Promise<ResultDomain<TaskMeta>>
*/
async createTaskMeta ( taskMeta : TaskMeta ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . post < TaskMeta > ( ` ${ this . baseUrl } /meta ` , taskMeta ) ;
return response . data ;
} ,
/**
* 更新任务元数据
* @param taskMeta 任务元数据
* @returns Promise<ResultDomain<TaskMeta>>
*/
async updateTaskMeta ( taskMeta : TaskMeta ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . put < TaskMeta > ( ` ${ this . baseUrl } /meta ` , taskMeta ) ;
return response . data ;
} ,
/**
* 删除任务元数据
* @param metaId 元数据ID
* @returns Promise<ResultDomain<boolean>>
*/
async deleteTaskMeta ( metaId : string ) : Promise < ResultDomain < boolean > > {
const response = await api . delete < boolean > ( ` ${ this . baseUrl } /meta/ ${ metaId } ` ) ;
return response . data ;
} ,
/**
* 根据ID查询任务元数据
* @param metaId 元数据ID
* @returns Promise<ResultDomain<TaskMeta>>
*/
async getTaskMetaById ( metaId : string ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . get < TaskMeta > ( ` ${ this . baseUrl } /meta/ ${ metaId } ` ) ;
return response . data ;
} ,
/**
* 查询所有任务元数据
* @returns Promise<ResultDomain<TaskMeta>>
*/
async getAllTaskMeta ( ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . get < TaskMeta > ( ` ${ this . baseUrl } /meta/all ` ) ;
return response . data ;
} ,
/**
* 根据分类查询任务元数据
* @param category 分类
* @returns Promise<ResultDomain<TaskMeta>>
*/
async getTaskMetaByCategory ( category : string ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . get < TaskMeta > ( ` ${ this . baseUrl } /meta/category/ ${ category } ` ) ;
return response . data ;
} ,
/**
* 分页查询任务元数据
* @param filter 过滤条件
* @param pageParam 分页参数
* @returns Promise<ResultDomain<TaskMeta>>
*/
async getTaskMetaPage ( filter? : Partial < TaskMeta > , pageParam? : PageParam ) : Promise < ResultDomain < TaskMeta > > {
const response = await api . post < TaskMeta > ( ` ${ this . baseUrl } /meta/page ` , {
filter ,
pageParam : {
pageNumber : pageParam?.pageNumber || 1 ,
pageSize : pageParam?.pageSize || 10
}
} ) ;
return response . data ;
} ,
// ==================== 邮件默认接收人管理 ====================
/**
* 创建默认接收人
* @param emailDefault 默认接收人
* @returns Promise<ResultDomain<EmailDefault>>
*/
async createEmailDefault ( emailDefault : EmailDefault ) : Promise < ResultDomain < EmailDefault > > {
const response = await api . post < EmailDefault > ( ` ${ this . baseUrl } /email/default ` , emailDefault ) ;
return response . data ;
} ,
/**
* 更新默认接收人
* @param emailDefault 默认接收人
* @returns Promise<ResultDomain<EmailDefault>>
*/
async updateEmailDefault ( emailDefault : EmailDefault ) : Promise < ResultDomain < EmailDefault > > {
const response = await api . put < EmailDefault > ( ` ${ this . baseUrl } /email/default ` , emailDefault ) ;
return response . data ;
} ,
/**
* 删除默认接收人
* @param defaultId 默认ID
* @returns Promise<ResultDomain<boolean>>
*/
async deleteEmailDefault ( defaultId : string ) : Promise < ResultDomain < boolean > > {
const response = await api . delete < boolean > ( ` ${ this . baseUrl } /email/default/ ${ defaultId } ` ) ;
return response . data ;
} ,
/**
* 根据defaultId查询
* @param defaultId 默认ID
* @returns Promise<ResultDomain<EmailDefault>>
*/
async getEmailDefaultById ( defaultId : string ) : Promise < ResultDomain < EmailDefault > > {
const response = await api . get < EmailDefault > ( ` ${ this . baseUrl } /email/default/ ${ defaultId } ` ) ;
return response . data ;
} ,
/**
* 根据metaId查询默认接收人
* @param metaId 元数据ID
* @returns Promise<ResultDomain<EmailDefault>>
*/
async getEmailDefaultByMetaId ( metaId : string ) : Promise < ResultDomain < EmailDefault > > {
const response = await api . get < EmailDefault > ( ` ${ this . baseUrl } /email/default/meta/ ${ metaId } ` ) ;
return response . data ;
} ,
// ==================== 邮件接收人管理 ====================
/**
* 创建邮件接收人
* @param recipient 邮件接收人
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async createEmailRecipient ( recipient : EmailRecipient ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . post < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient ` , recipient ) ;
return response . data ;
} ,
/**
* 批量创建邮件接收人
* @param recipients 邮件接收人列表
* @returns Promise<ResultDomain<boolean>>
*/
async batchCreateEmailRecipient ( recipients : EmailRecipient [ ] ) : Promise < ResultDomain < boolean > > {
const response = await api . post < boolean > ( ` ${ this . baseUrl } /email/recipient/batch ` , recipients ) ;
return response . data ;
} ,
/**
* 更新邮件接收人
* @param recipient 邮件接收人
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async updateEmailRecipient ( recipient : EmailRecipient ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . put < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient ` , recipient ) ;
return response . data ;
} ,
/**
* 删除邮件接收人
* @param recipientId 接收人ID
* @returns Promise<ResultDomain<boolean>>
*/
async deleteEmailRecipient ( recipientId : string ) : Promise < ResultDomain < boolean > > {
const response = await api . delete < boolean > ( ` ${ this . baseUrl } /email/recipient/ ${ recipientId } ` ) ;
return response . data ;
} ,
/**
* 根据ID查询接收人
* @param recipientId 接收人ID
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async getEmailRecipientById ( recipientId : string ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . get < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient/ ${ recipientId } ` ) ;
return response . data ;
} ,
/**
* 根据default_id查询接收人列表
* @param defaultId 默认ID
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async getRecipientsByDefaultId ( defaultId : string ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . get < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient/default/ ${ defaultId } ` ) ;
return response . data ;
} ,
/**
* 根据任务ID查询接收人列表
* @param taskId 任务ID
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async getRecipientsByTaskId ( taskId : string ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . get < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient/task/ ${ taskId } ` ) ;
return response . data ;
} ,
/**
* 查询所有启用的接收人
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async getAllEnabledRecipients ( ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . get < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient/enabled ` ) ;
return response . data ;
} ,
/**
* 分页查询邮件接收人
* @param filter 过滤条件
* @param pageParam 分页参数
* @returns Promise<ResultDomain<EmailRecipient>>
*/
async getEmailRecipientPage ( filter? : Partial < EmailRecipient > , pageParam? : PageParam ) : Promise < ResultDomain < EmailRecipient > > {
const response = await api . post < EmailRecipient > ( ` ${ this . baseUrl } /email/recipient/page ` , {
filter ,
pageParam : {
pageNumber : pageParam?.pageNumber || 1 ,
pageSize : pageParam?.pageSize || 10
}
} ) ;
return response . data ;
} ,
/**
* 删除default_id的所有接收人
* @param defaultId 默认ID
* @returns Promise<ResultDomain<boolean>>
*/
async deleteRecipientsByDefaultId ( defaultId : string ) : Promise < ResultDomain < boolean > > {
const response = await api . delete < boolean > ( ` ${ this . baseUrl } /email/recipient/default/ ${ defaultId } ` ) ;
return response . data ;
} ,
/**
* 删除任务的所有接收人
* @param taskId 任务ID
* @returns Promise<ResultDomain<boolean>>
*/
async deleteRecipientsByTaskId ( taskId : string ) : Promise < ResultDomain < boolean > > {
const response = await api . delete < boolean > ( ` ${ this . baseUrl } /email/recipient/task/ ${ taskId } ` ) ;
return response . data ;
} ,
} ;