feat: 自动化执行逻辑开发
This commit is contained in:
@@ -14,25 +14,26 @@ export function runTaskOperationService() {
|
||||
try {
|
||||
await launchLocalChrome(options)
|
||||
|
||||
const channels = ['fz', 'mt', 'dy', 'xc']
|
||||
// 从options.roomList列表中找到对应的名称
|
||||
const roomType = options.roomList.find((item: any) => item.id === options.roomType);
|
||||
|
||||
const scriptMap: Record<string, string> = {
|
||||
fz: 'fg_trace.mjs',
|
||||
mt: 'mt_trace.mjs',
|
||||
dy: 'dy_trace.mjs',
|
||||
xc: 'xc_trace.mjs',
|
||||
}
|
||||
// 从roomType找fzName、mtName、dyHotelName、dyHotSpringName、xcName属性,判断是否有值
|
||||
// 如果有值,就找出对应的脚本
|
||||
// 如果没有值,就跳过
|
||||
const pairs: Array<[string, string]> = [
|
||||
['fzName', 'fg_trace.mjs'],
|
||||
['mtName', 'mt_trace.mjs'],
|
||||
['dyHotelName', 'dy_hotel_trace.mjs'],
|
||||
['dyHotSpringName', 'dy_hot_spring_trace.mjs'],
|
||||
['xcName', 'xc_trace.mjs'],
|
||||
]
|
||||
const scriptEntries = pairs.filter(([prop]) => roomType?.[prop])
|
||||
|
||||
const scriptsDir = app.isPackaged
|
||||
? path.join(process.resourcesPath, 'scripts')
|
||||
: path.join(process.cwd(), 'src/main/scripts')
|
||||
|
||||
const scriptPaths = channels.map((channel: string) => {
|
||||
const fileName = scriptMap[channel]
|
||||
if (!fileName) {
|
||||
throw new Error(`Unknown channel: ${channel}`)
|
||||
}
|
||||
|
||||
const scriptPaths = scriptEntries.map(([channel, fileName]) => {
|
||||
const p = path.join(scriptsDir, fileName)
|
||||
if (!fs.existsSync(p)) {
|
||||
throw new Error(`Script not found for channel ${channel}: ${p}`)
|
||||
@@ -43,7 +44,12 @@ export function runTaskOperationService() {
|
||||
const results: any[] = []
|
||||
for (const item of scriptPaths) {
|
||||
log.info(`Launching script for channel ${item.channel}: ${item.scriptPath}`)
|
||||
const result = await executeScriptServiceInstance.executeScript(item.scriptPath, options)
|
||||
const result = await executeScriptServiceInstance.executeScript(item.scriptPath, {
|
||||
roomType: roomType[item.channel],
|
||||
startTime: options.startTime,
|
||||
endTime: options.endTime,
|
||||
operation: options.operation,
|
||||
})
|
||||
results.push({
|
||||
channel: item.channel,
|
||||
scriptPath: item.scriptPath,
|
||||
|
||||
Reference in New Issue
Block a user