From 1016b32873768f41b67c5f3f918e22352fd3a15b Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Tue, 19 Aug 2025 15:26:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=A4=8D=E8=BD=A8=E8=BF=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/Judge/JudgeBusiness.ets | 8 +-- entry/src/main/ets/pages/Judge/JudgeIng.ets | 70 +++++++++++-------- .../main/ets/pages/Judge/JudgeVariable.ets | 28 ++++++++ .../ets/pages/Judge/ProcessDataTaskPool.ets | 26 +++---- entry/src/main/ets/pages/Judge/utils.ets | 27 ------- 5 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 entry/src/main/ets/pages/Judge/JudgeVariable.ets diff --git a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets index 528dd48..b24bafb 100644 --- a/entry/src/main/ets/pages/Judge/JudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/JudgeBusiness.ets @@ -1,9 +1,7 @@ import { JudgeConfigObjKmItems, - JudgeKSJS, JudgePerformInfo, JudgeUI, - LANE, MarkRule, PLCType, ProcessDataEnumType, @@ -43,9 +41,6 @@ export default class JudgeBusiness { //所有的科目考试项目(大车&小车) public kmItems: JudgeConfigObjKmItems public xmmcStr: string = "" - public lane: LANE = { - road: '', num: 0, count: 0 - } public xmmcCode: string = "" public xmmcSingleCode: string = "" public xmmcEndCode?: string @@ -53,13 +48,12 @@ export default class JudgeBusiness { public xmxh: string = "" public kfArr?: MarkRule[] public carztStr: string - public ksjs?: JudgeKSJS - public mndgStr: string | undefined private judgeUI: JudgeUI private tempData?: PLCType private plcData?: PLCType // 是否发送udp private isUdpEnd: boolean = false + private mndgStr: string | undefined constructor(judgeUI: JudgeUI) { this.judgeUI = judgeUI diff --git a/entry/src/main/ets/pages/Judge/JudgeIng.ets b/entry/src/main/ets/pages/Judge/JudgeIng.ets index 0ee9a29..a4a8329 100644 --- a/entry/src/main/ets/pages/Judge/JudgeIng.ets +++ b/entry/src/main/ets/pages/Judge/JudgeIng.ets @@ -3,7 +3,7 @@ import { JudgeCallBackData, JudgeUI, KmItem, MarkRule, ProcessDataEnumType, Proj import { dConsole } from '../../utils/LogWorker'; import JudgeBusiness from './JudgeBusiness'; import { examJudgeArtificialItem } from './JudgeSDKUtils'; -import { CurrentProjectConversion, DeductionProjectConversion, GetCarStatus } from './utils'; +import { CurrentProjectConversion, DeductionProjectConversion } from './utils'; export const JudgingFn = async (strData: string, callBack: Function, judgeUI: JudgeUI, that: JudgeBusiness) => { let examData: JudgeCallBackData = JSON.parse(strData); @@ -26,9 +26,13 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju const isManualProjectIn = artSubject3ProjectsCodesArr.includes(xmdm); const examSubject = judgeUI.examSubject const judgeConfigObj = judgeUI.judgeConfigObj + let project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm) + const xmmcCode = project.projectCodeCenter || ""; + const kmItem: KmItem = Reflect.get(that.kmItems, xmmcCode) + switch (event) { - case 1: { - const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm) + // 项目开始 + case 1: project.type = '2'; if (isManualProjectIn) { //手动项目是否在进行中 @@ -39,9 +43,7 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju } judgeUI.currentXmdm = xmdm; const xmmcStr = project.name || ""; - const xmmcCode = project.projectCodeCenter || ""; const xmmcSingleCode = project.projectCode || ""; - const kmItem: KmItem = Reflect.get(that.kmItems, xmmcCode) kmItem.status = 2; that.xmmcStr = xmmcStr; that.xmmcCode = xmmcCode; @@ -53,11 +55,10 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju Reflect.set(judgeUI.projectsObj, xmdm, project) Reflect.set(that.kmItems, xmmcCode || 0, kmItem) break; - } - case 2: { - const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm) - const xmmcCode = project.projectCodeCenter || ""; + // 项目结束 + case 2: project.type = (xmjs.xmhg === 0 ? '4' : '3') + //计算项目是否全部结束 judgeUI.isProjectIn = (Reflect.ownKeys(judgeUI.projectsObj).filter((projectKey) => { const fillProject: ProjectInfo = Reflect.get(judgeUI.projectsObj, projectKey) return fillProject.type == '2' @@ -65,9 +66,8 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju if (isManualProjectIn) { judgeUI.isManualProjectIn = false } - const kmItem: KmItem = Reflect.get(that.kmItems, xmmcCode) kmItem.status = 3; - //统计必考项目数量 + //统计必考项目数量 that.xmmcStr = '无'; that.xmmcCode = ''; that.xmdm = ''; @@ -75,8 +75,8 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju Reflect.set(judgeUI.projectsObj, xmdm, project) Reflect.set(that.kmItems, xmmcCode, kmItem) break; - } - case 3: { + // 扣分 + case 3: const thisKf = DeductionProjectConversion(`${kf.xmdm}_${kf.kfdm}`, judgeUI.markRuleListObj) const kfObj: MarkRule = { //扣分项目名称 @@ -103,24 +103,34 @@ export const JudgingFn = async (strData: string, callBack: Function, judgeUI: Ju project.type = (type == '3' || type == '4') ? '4' : '5' Reflect.set(judgeUI.projectsObj, kf.xmdm, project) } - } - case 4: { - that.carztStr = GetCarStatus(carzt); break; - } - case 5: { - - } - case 6: { - - } - case 7: { - - } - } - - // 考车状态 - if (event === 4) { + // 考试状态 + case 4: + break; + // 考试结束 + case 5: + break; + // 项目取消 + case 6: + break; + // 语音播报和提示 + case 7: + break; + // 模拟灯光事件 + case 8: + break; + // 车道和路段变化 + case 9: + break; + // 预进项目事件 + case 10: + break; + // 差分事件 + case 11: + break; + default: + 83 + break; } await callBack({ //项目名称 考车状态 扣分arr diff --git a/entry/src/main/ets/pages/Judge/JudgeVariable.ets b/entry/src/main/ets/pages/Judge/JudgeVariable.ets new file mode 100644 index 0000000..fb241fa --- /dev/null +++ b/entry/src/main/ets/pages/Judge/JudgeVariable.ets @@ -0,0 +1,28 @@ +import { testKm2Items, testKm3Items } from '../../mock'; +import { JudgeConfigObjKmItems, ProjectInfo, ProjectInfos } from '../../model'; + +class judgeVariable { + public rmndg: 0 | 1 = 0 + public kmItems: JudgeConfigObjKmItems = {} + public xmmcStr: string = "" + public xmmcEndCode?: string = "" + public xmxh: string = "" + public status: string = "开始" + + constructor() { + + } + + public initKmItems(examSubject: string, projectsCenterObj: ProjectInfos) { + (examSubject == '2' ? testKm2Items : testKm3Items).forEach(item => { + const projectCenterObj: ProjectInfo = Reflect.get(projectsCenterObj, item.code) + Reflect.set(this.kmItems, item.code, { + code: item.code, + status: projectCenterObj === undefined ? 0 : (projectCenterObj.isEnd ? 3 : 1) + }) + }) + + } +} + +export const JudgeVariable = new judgeVariable(); \ No newline at end of file diff --git a/entry/src/main/ets/pages/Judge/ProcessDataTaskPool.ets b/entry/src/main/ets/pages/Judge/ProcessDataTaskPool.ets index a7ac838..a9ced7b 100644 --- a/entry/src/main/ets/pages/Judge/ProcessDataTaskPool.ets +++ b/entry/src/main/ets/pages/Judge/ProcessDataTaskPool.ets @@ -11,7 +11,7 @@ export class ProcessDataTaskPool { private readonly maxRetries = 5; public addTask(dataItem: RegulatoryInterfaceParams): void { - dConsole.log(`[Queue] 新任务已添加: ${JSON.stringify(dataItem)},当前队列长度: ${this.queue.length + 1}`); + console.info(`[Queue] 新任务已添加: ${JSON.stringify(dataItem)},当前队列长度: ${this.queue.length + 1}`); this.queue.push(dataItem); // 将任务添加到队尾 this.triggerProcessing(); // 尝试启动处理流程 } @@ -22,7 +22,7 @@ export class ProcessDataTaskPool { */ private triggerProcessing(): void { if (this.isProcessing) { - dConsole.log('[Queue] 处理器正在运行中,新任务将在稍后被处理。'); + console.log('[Queue] 处理器正在运行中,新任务将在稍后被处理。'); return; // 如果已经在处理,则直接返回,新任务会被正在运行的循环消费掉 } // 使用 Promise.resolve().then() 来确保 processQueue 在下一个事件循环中异步执行 @@ -32,13 +32,13 @@ export class ProcessDataTaskPool { private async processQueue(): Promise { this.isProcessing = true; - dConsole.log(`[Queue] 启动处理器... 待处理任务数: ${this.queue.length}`); + console.log(`[Queue] 启动处理器... 待处理任务数: ${this.queue.length}`); while (this.queue.length > 0) { const taskData = this.queue[0]; // 查看队首任务 try { - dConsole.log(`[Queue] 开始处理任务: ${JSON.stringify(taskData)}`); + console.log(`[Queue] 开始处理任务: ${JSON.stringify(taskData)}`); // 此方法若成功则正常返回,若永久失败则会抛出错误 let obj: WuxiExamType = { xtlb: taskData.xtlb, @@ -52,11 +52,11 @@ export class ProcessDataTaskPool { await this.processSingleTaskWithRetries(taskData); // 任务成功,将其从队列中移除 this.queue.shift(); - dConsole.log(`[Queue] ✅ 任务处理成功,已从队列移除。剩余任务: ${this.queue.length}`); + console.log(`[Queue] ✅ 任务处理成功,已从队列移除。剩余任务: ${this.queue.length}`); } catch (error) { // 捕获到永久失败的错误 - dConsole.error(`[Queue] 🔥 致命错误: ${(error as Error).message}`); - dConsole.error('[Queue] 队列已停止,后续任务将不会被处理。'); + console.error(`[Queue] 🔥 致命错误: ${(error as Error).message}`); + console.error('[Queue] 队列已停止,后续任务将不会被处理。'); // (可选)可以在此处清空队列,防止下次意外启动时处理旧任务 this.queue = []; @@ -67,7 +67,7 @@ export class ProcessDataTaskPool { } this.isProcessing = false; - dConsole.log('[Queue] 处理器已停止。'); + console.log('[Queue] 处理器已停止。'); } private async processSingleTaskWithRetries(taskData: RegulatoryInterfaceParams): Promise { @@ -76,16 +76,16 @@ export class ProcessDataTaskPool { const attemptNum = attempt + 1; try { const attemptType = attempt === 0 ? '初次尝试' : `重试 ${attempt}`; - dConsole.log(`[Queue] 开始上传 (${attemptType}, 总共第 ${attemptNum} 次): ${JSON.stringify(taskData)}`); + console.log(`[Queue] 开始上传 (${attemptType}, 总共第 ${attemptNum} 次): ${JSON.stringify(taskData)}`); const result: WR = await taskpool.execute(uploadWorkerTask, taskData); dConsole.writeProcessData(ProcessDataEnumType.WuxiExam, JSON.stringify(result)) if (result.code === 1) { - dConsole.log(`[Queue] ✔️ 上传成功 (在第 ${attemptNum} 次尝试)`); + console.log(`[Queue] ✔️ 上传成功 (在第 ${attemptNum} 次尝试)`); return; // 成功,立即返回 } - dConsole.log(`[Queue] ❌ 上传失败 (第 ${attemptNum} 次)。响应: ${result.message}`); + console.warn(`[Queue] ❌ 上传失败 (第 ${attemptNum} 次)。响应: ${result.message}`); } catch (e) { - dConsole.error(`[Queue] ❌ TaskPool 执行错误 (第 ${attemptNum} 次): ${e}`); + console.error(`[Queue] ❌ TaskPool 执行错误 (第 ${attemptNum} 次): ${e}`); } // 如果这是最后一次尝试且依然失败,则不再等待,直接跳出循环去抛出错误 @@ -117,7 +117,7 @@ export async function uploadWorkerTask(data: RegulatoryInterfaceParams): Promise } catch (err) { // 捕获请求过程中可能出现的异常 const error = err as Error; - dConsole.error(`[Worker] 上传时发生异常: ${error.message}`); + console.error(`[Worker] 上传时发生异常: ${error.message}`); return { code: 20038 }; } } diff --git a/entry/src/main/ets/pages/Judge/utils.ets b/entry/src/main/ets/pages/Judge/utils.ets index 73e27c1..dfb88e2 100644 --- a/entry/src/main/ets/pages/Judge/utils.ets +++ b/entry/src/main/ets/pages/Judge/utils.ets @@ -6,11 +6,9 @@ import { DefaultJudgeConfigObj, ExtendType, Gps, - JudgeSound, LANE, MarkRule, PLCType, - ProcessDataEnumType, ProjectInfo, ProjectInfos, ProjectRoads, @@ -20,8 +18,6 @@ import { import { ArrayToByteArray, NumberToByteArray } from '../../utils/Common'; import dayTs from '../../utils/Date'; import { dConsole } from '../../utils/LogWorker'; -import VoiceAnnounce from '../judgeSDK/utils/voiceAnnouncements'; -import { examJudgeSoundEnd } from './JudgeSDKUtils'; // 中心信号转换 @@ -856,27 +852,4 @@ export const DeductionProjectConversion = (code: string, markRuleListObj: object export const CurrentProjectConversion = (code: number, projectsObj: object): string => { const project: ProjectInfo = Reflect.get(projectsObj, code) return project?.abbreviation || '通用评判' -} - -/** - * 获取评判语音 - * @param sound - 评判音频对象 - * @param avPlayer - 语音播放器实例 - */ -export const PlayJudgeVoice = (sound: JudgeSound, avPlayer: VoiceAnnounce) => { - if (sound.type == 1) { - avPlayer?.playAudio([`voice/${sound.code[0]}.mp3`], false, () => { - examJudgeSoundEnd({ - xmdm: sound.xmdm, code: sound.code[0], type: sound.type - }) - dConsole.writeProcessData(ProcessDataEnumType.JudgeExamData, JSON.stringify({ - method: 'examJudgeSoundEnd', - itemno: sound.xmdm, - code: sound.code[0], - type: sound.type, - })) - }) - } else { - avPlayer?.playAudio([`voice/${sound.code[0]}.mp3`]) - } } \ No newline at end of file