fix: 过程数据问题
This commit is contained in:
		
							parent
							
								
									0f400c7467
								
							
						
					
					
						commit
						8cf68ea6fb
					
				| @ -226,9 +226,10 @@ export struct JudgePage { | ||||
|   async aboutToDisappear() { | ||||
|     this.generateExamRecordsDialogController.close() | ||||
|     this.signalTrajectoryDialogController.close() | ||||
|     // this.judgeBusiness.close() | ||||
|     this.judgeBusiness.close() | ||||
|     clearInterval(this.mileageTimer) | ||||
|     DifferentialAndSignal.offMsg(this.onCenterMsg) | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   //初始化相关数据库表 | ||||
| @ -802,19 +803,19 @@ export struct JudgePage { | ||||
|   private onCenterMsg = (msg: string) => { | ||||
|     let result: WorkerBackMessage = JSON.parse(msg) | ||||
|     if (result.type === WorkerBackMessageType.RemoteEndExam) { | ||||
|       dConsole.info("lixiao", msg) | ||||
|       dConsole.info(JudgeTag, msg) | ||||
|       this.judgeBusiness.JudgeEnd(true) | ||||
|     } else if (result.type === WorkerBackMessageType.RemoteKf) { | ||||
|       let data = result.data as number[] | ||||
|       const config810 = this.judgeConfigObj.param_810 | ||||
|       dConsole.info("lixiao", '评判收到远程扣分项目内容:' + `kfxh=>${data[1]}; directives=>${data[0]}`) | ||||
|       dConsole.info(JudgeTag, '评判收到远程扣分项目内容:' + `kfxh=>${data[1]}; directives=>${data[0]}`) | ||||
|       let currentKf = this.markRules.filter(item => { | ||||
|         return item.kfxh === data[1].toString() && (config810 === "1" || Number(item.markserial) > 99) | ||||
|       })[0] | ||||
|       if (!currentKf) { | ||||
|         return | ||||
|       } | ||||
|       dConsole.info("lixiao", '远程扣分项目:', currentKf) | ||||
|       dConsole.info(JudgeTag, '远程扣分项目:', currentKf) | ||||
|       this.judgeBusiness.setJudgeMark(currentKf.itemno!, currentKf.markserial!, 2) | ||||
|       DifferentialAndSignal.sendMsg({ | ||||
|         type: WorkerMessageDataType.JudgeSend, | ||||
|  | ||||
| @ -519,7 +519,7 @@ export class BaseJudge { | ||||
|     } | ||||
|     //日志回调 | ||||
|     dConsole.info(JudgeTag, '1.进入评判入口') | ||||
|     await examJudgeSetLogCallback(1, async (level: number, info: string, len: number) => { | ||||
|     await examJudgeSetLogCallback(3, async (level: number, info: string, len: number) => { | ||||
|       dConsole.log(JudgeTag, '评判日志:' + info) | ||||
|       dConsole.writeProcessData(ProcessDataEnumType.JudgeLogData, info) | ||||
|     }) | ||||
|  | ||||
| @ -4,7 +4,6 @@ import { | ||||
|   JudgeKSJS, | ||||
|   JudgePerformInfo, | ||||
|   LANE, | ||||
|   MarkRule, | ||||
|   PLCType, | ||||
|   ProcessDataEnumType, | ||||
|   RecordHandleType, | ||||
| @ -121,7 +120,7 @@ export default class JudgeBusiness { | ||||
|   } | ||||
| 
 | ||||
|   // 人工扣分 | ||||
|   public async setJudgeMark(itemno: number,markserial: string, type: number) { | ||||
|   public async setJudgeMark(itemno: number, markserial: string, type: number) { | ||||
|     await examJudgeArtificialMark(itemno, markserial, type) | ||||
|     //   TODO 写扣分轨迹日志 | ||||
|   } | ||||
| @ -133,7 +132,7 @@ export default class JudgeBusiness { | ||||
| 
 | ||||
|   // 结束考试 | ||||
|   public JudgeEnd(isManual?: boolean) { | ||||
|     dConsole.info("lixiao", '收到远程结束考试消息1') | ||||
|     dConsole.info(JudgeTag, '收到远程结束考试消息1') | ||||
|     this.judgeBusiness.JudgeEnd(this.judgeUI, this, isManual) | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -101,6 +101,7 @@ export class ProcessDataTaskPool { | ||||
|           jkid: taskData.jkid, | ||||
|           drvexam: drvexam, | ||||
|         }; | ||||
|          | ||||
|         dConsole.writeProcessData(ProcessDataEnumType.WuxiExam, JSON.stringify(obj)); | ||||
| 
 | ||||
|         await this.processSingleTaskWithRetries(taskData, callback); | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| import dayTs from './Date'; | ||||
| import fs from '@ohos.file.fs'; | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| import { CommonFileTag, JudgeConfig, JudgeTag } from '../config'; | ||||
| import { CommonFileTag, JudgeConfig, JudgeTag, LogTag } from '../config'; | ||||
| import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; | ||||
| import Prompt from '@system.prompt'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| @ -272,9 +272,11 @@ export function CloseFile(fd: number): Promise<boolean> { | ||||
| export function EditFile(fd: number, data: string): Promise<boolean> { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     try { | ||||
|       console.log(LogTag, "写入数据:" + data) | ||||
|       fs.writeSync(fd, data + "\n") | ||||
|       resolve(true) | ||||
|     } catch (e) { | ||||
|       console.error(LogTag, "写入数据失败", data) | ||||
|       reject(false) | ||||
|     } | ||||
|   }) | ||||
|  | ||||
| @ -75,6 +75,7 @@ class logWorker { | ||||
| 
 | ||||
|   // 过程数据写入 | ||||
|   writeProcessData(type: ProcessDataEnumType, data: string) { | ||||
|     dConsole.log(LogTag, "传入过程数据", data) | ||||
|     let params: LogWorkerMessage = { | ||||
|       type: WorkerMessageType.WriteProcessData, | ||||
|       data, | ||||
|  | ||||
| @ -94,7 +94,7 @@ class differentialAndSignal { | ||||
|   getMessage() { | ||||
|     this.workerInstance.onmessage = (e: MessageEvents): void => { | ||||
|       if (e.data) { | ||||
|         console.log(WorkerTag, "lixiao", "Worker 收到消息: " + e.data); | ||||
|         // console.log(WorkerTag, "Worker 收到消息: " + e.data); | ||||
|         this.events.forEach((callback) => { | ||||
|           callback(e.data); | ||||
|         }); | ||||
|  | ||||
| @ -13,7 +13,7 @@ import { | ||||
|   UDPParamType | ||||
| } from '../../model'; | ||||
| 
 | ||||
| import { JudgeConfig } from '../../config'; | ||||
| import { JudgeConfig, JudgeTag } from '../../config'; | ||||
| import { FillZero, NumberToByteArray, StringToASCII } from '../Common'; | ||||
| import UdpClient, { MsgExt } from '../UdpUtils'; | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| @ -46,7 +46,7 @@ class JudgeUdpBusiness { | ||||
|   } | ||||
| 
 | ||||
|   async getMessageHeartbeat(msg: string): Promise<number[]> { | ||||
|     dConsole.info(Tag, msg, this.lsh) | ||||
|     // dConsole.info(Tag, msg, this.lsh) | ||||
|     if (!this.business || !this.performInfo) { | ||||
|       return this.getOBDMessageHeart(msg) | ||||
|     } | ||||
| @ -238,7 +238,7 @@ class JudgeUdpBusiness { | ||||
|       carNo: this.carInfo.carNo!, | ||||
|       placeId: this.carInfo!.examinationRoomId!, | ||||
|     } | ||||
|     dConsole.info(Tag, "发送小红球数据", data) | ||||
|     // dConsole.info(Tag, "发送小红球数据", data) | ||||
|     this.udp.sendMsgExt(data, udpLsh) | ||||
|   } | ||||
| 
 | ||||
| @ -284,7 +284,7 @@ class JudgeUdpBusiness { | ||||
|     this.carInfo = carInfo | ||||
|     return new Promise((resolve, reject) => { | ||||
|       try { | ||||
|         dConsole.info("lixiao udp", config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!) | ||||
|         dConsole.info(JudgeTag, "udp", config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!) | ||||
|         this.udp.create(config.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject) | ||||
|       } catch (e) { | ||||
|         reject(e) | ||||
|  | ||||
| @ -19,7 +19,6 @@ import { DifferentialSignal } from '../utils/business/DifferentialSignal'; | ||||
| import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness'; | ||||
| import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; | ||||
| import { SerialPortService } from '../utils/business/SerialPortService'; | ||||
| import { dConsole } from '../utils/LogWorker'; | ||||
| import dayTs from '../utils/Date'; | ||||
| import { NumberToByteArray } from '../utils/Common'; | ||||
| 
 | ||||
| @ -141,7 +140,7 @@ function getDataFn(config: EnvironmentConfigurationType) { | ||||
|         JudgeUdpBusinessInstance.sendData(byte, udpLsh) | ||||
|       } | ||||
|       udpIndex++ | ||||
|       console.log(SerialPortTag, "后置机消息", data) | ||||
|       // console.log(SerialPortTag, "后置机消息", data) | ||||
|       workerPort.postMessage( | ||||
|         JSON.stringify({ | ||||
|           type: WorkerBackMessageType.ObtainUdpData, | ||||
| @ -154,7 +153,6 @@ function getDataFn(config: EnvironmentConfigurationType) { | ||||
|     // TODO | ||||
|     // 需要观察 | ||||
|     checkLsh() | ||||
|     dConsole.info("lixiao", data) | ||||
|     switch (Number(data.id)) { | ||||
|       case 32: | ||||
|         signNum = data.body![1] | ||||
| @ -170,7 +168,6 @@ function getDataFn(config: EnvironmentConfigurationType) { | ||||
|             } as WorkerBackMessage) | ||||
|           ) | ||||
|         } else if (Number(data.body![0]) === 12) { | ||||
|           dConsole.info("lixiao", 12, data) | ||||
|           workerPort.postMessage( | ||||
|             JSON.stringify({ | ||||
|               type: WorkerBackMessageType.RemoteEndExam | ||||
|  | ||||
| @ -29,6 +29,7 @@ workerPort.onmessage = (e: MessageEvents) => { | ||||
|   } | ||||
|   // 写过程数据 | ||||
|   if (result.type === WorkerMessageType.WriteProcessData && result.processDataType) { | ||||
|     console.log(LogTag, "work收到过程数据") | ||||
|     WriteProcessData(result.processDataType, result.data || "") | ||||
|   } | ||||
|   //   关闭过程数据 | ||||
| @ -82,21 +83,23 @@ async function InitExam(dirName: string) { | ||||
|     await CreateDir(path); | ||||
|   } | ||||
|   //   创建几个文件 | ||||
|   fileNameArr.forEach(async (item: string, index: number) => { | ||||
|   fileNameArr.forEach(async (item: string) => { | ||||
|     let filePath = path + "/" + item | ||||
|     console.log(LogTag, "创建文件", filePath) | ||||
|     let result = await CreateFile(filePath) | ||||
|     fileFdArr[index] = result | ||||
|     // fileFdArr[index] = result | ||||
|     fileFdArr.push(result) | ||||
|   }) | ||||
| } | ||||
| 
 | ||||
| // 写过程数据 | ||||
| async function WriteProcessData(type: ProcessDataEnumType, data: string) { | ||||
|   // if (type === ProcessDataEnumType.WuxiExam) { | ||||
|   //   writeQueue.push({ type, data }); | ||||
|   // } else { | ||||
|   console.log(LogTag, "推入过程数据", type, data) | ||||
|   if (fileFdArr.length === 0) { | ||||
|     return | ||||
|   } | ||||
|   writeQueue.push({ type, data }); | ||||
|   // } | ||||
| 
 | ||||
|   if (!isProcessing) { | ||||
|     processQueue(); | ||||
|   } | ||||
| @ -104,23 +107,34 @@ async function WriteProcessData(type: ProcessDataEnumType, data: string) { | ||||
| 
 | ||||
| async function processQueue() { | ||||
|   isProcessing = true; | ||||
|   while (writeQueue.length > 0) { | ||||
|   while (writeQueue.length > 0 && isProcessing) { | ||||
|     console.log(LogTag, "处理过程数据") | ||||
|     const item = writeQueue.shift()!; | ||||
|     const index = Number(item.type); | ||||
|     await EditFile(fileFdArr[index], item.data); | ||||
|     try { | ||||
|       await EditFile(fileFdArr[index], item.data); | ||||
|     } catch (e) { | ||||
|       console.error(LogTag, "写过程数据错误", JSON.stringify(e)) | ||||
|     } | ||||
|   } | ||||
|   isProcessing = false; | ||||
| } | ||||
| 
 | ||||
| // 关闭过程数据 | ||||
| function CloseProcessData() { | ||||
|   writeQueue = [] | ||||
|   isProcessing = false | ||||
|   if (fileFdArr.length > 0) { | ||||
|     console.log(LogTag, "有文件需要 关闭过程数据") | ||||
|     console.log(LogTag, "有文件需要 关闭过程数据", fileFdArr) | ||||
|     fileFdArr.forEach((item: number) => { | ||||
|       fs.closeSync(item) | ||||
|       try { | ||||
|         fs.closeSync(item) | ||||
|       } catch (e) { | ||||
|         console.error(LogTag, JSON.stringify(e)) | ||||
|       } | ||||
|     }) | ||||
|     fileFdArr = [] | ||||
|   } | ||||
|   fileFdArr = [] | ||||
| } | ||||
| 
 | ||||
| workerPort.onmessageerror = (e: MessageEvents) => { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user