2024-09-12 14:13:09 +08:00
|
|
|
|
import { ipcMain } from "electron"
|
|
|
|
|
|
import { BookServiceBasic } from "../Service/ServiceBasic/bookServiceBasic"
|
|
|
|
|
|
import { DEFINE_STRING } from "../../define/define_string";
|
|
|
|
|
|
import { errorMessage, successMessage } from "../Public/generalTools";
|
2024-10-15 19:33:37 +08:00
|
|
|
|
import { BookBackTaskStatus, BookBackTaskType, TaskExecuteType } from "../../define/enum/bookEnum";
|
2024-09-12 14:13:09 +08:00
|
|
|
|
|
|
|
|
|
|
let bookServiceBasic = new BookServiceBasic();
|
2024-10-15 19:33:37 +08:00
|
|
|
|
import BackTaskService from '../Service/task/backTaskService'
|
2024-11-02 18:18:55 +08:00
|
|
|
|
import { TaskModal } from "@/model/task";
|
2025-05-08 20:30:50 +08:00
|
|
|
|
import { Book } from "@/model/book/book";
|
2024-10-15 19:33:37 +08:00
|
|
|
|
const backTaskService = new BackTaskService()
|
2024-09-12 14:13:09 +08:00
|
|
|
|
|
|
|
|
|
|
function TaskIpc() {
|
|
|
|
|
|
|
2024-10-15 19:33:37 +08:00
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.START_BACK_TASK, async (event, isGiveUp: boolean) => await backTaskService.StartBackTask(isGiveUp))
|
|
|
|
|
|
|
2024-09-12 14:13:09 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加后台任务,单个
|
|
|
|
|
|
*/
|
|
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.ADD_BOOK_BACK_TASK, async (event, bookId: string, taskType: BookBackTaskType, executeType: TaskExecuteType, bookTaskId: string, bookTaskDetailId: string, responseMessageName: string) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let res = await bookServiceBasic.AddBookBackTask(bookId, taskType, executeType, bookTaskId, bookTaskDetailId, responseMessageName)
|
|
|
|
|
|
return successMessage(res, `添加 ${taskType} 任务成功`, 'TaskIpc_AddBookBackTask');
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return errorMessage(`添加 ${taskType} 任务失败,错误信息如下:${error.toString()} `, 'TaskIpc_AddBookBackTask')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 添加多个后台任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.ADD_MULTI_BOOK_BACK_TASK, async (event, tasks: TaskModal.Task[]) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
for (let i = 0; i < tasks.length; i++) {
|
|
|
|
|
|
const element = tasks[i];
|
|
|
|
|
|
let res = await bookServiceBasic.AddBookBackTask(element.bookId, element.type, element.executeType, element.bookTaskId, element.bookTaskDetailId, element.messageName)
|
|
|
|
|
|
}
|
|
|
|
|
|
return successMessage(null, `添加多个任务成功`, 'TaskIpc_AddMultiBookBackTask');
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return errorMessage(`添加多个任务失败,错误信息如下:${error.toString()} `, 'TaskIpc_AddMultiBookBackTask')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-11-02 18:18:55 +08:00
|
|
|
|
|
2024-10-15 19:33:37 +08:00
|
|
|
|
/** 获取指定状态的任务数量 */
|
|
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.GET_ALL_STATUS_TASK_COUNT, async (event, value: BookBackTaskStatus[]) => await backTaskService.GetAllStatusTaskCount(value))
|
2024-11-02 18:18:55 +08:00
|
|
|
|
|
|
|
|
|
|
/** 获取后台任务的集合,分页 */
|
|
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.GET_BACK_TASK_COLLECTION, async (event, queryTaskCondition: TaskModal.QueryTaskCondition) => await backTaskService.GetBackTaskCollection(queryTaskCondition))
|
2025-05-08 20:30:50 +08:00
|
|
|
|
|
|
|
|
|
|
/** 修改后台队列的状态 */
|
|
|
|
|
|
ipcMain.handle(DEFINE_STRING.TASK.UPDATE_TASK_STATUS, async (event, bookBackTask: Book.UpdateBookTaskListStatus) => await backTaskService.UpdateTaskStatus(bookBackTask))
|
2024-09-12 14:13:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { TaskIpc }
|