fix: 过程数据完善
This commit is contained in:
parent
797b785721
commit
f0653c0c92
@ -31,7 +31,8 @@ export enum WorkerBackMessageType {
|
||||
export interface LogWorkerMessage {
|
||||
type: WorkerMessageType;
|
||||
data?: string;
|
||||
studentDirName?: string
|
||||
studentDirName?: string;
|
||||
processDataType?:ProcessDataEnumType
|
||||
}
|
||||
|
||||
//枚举
|
||||
@ -45,7 +46,31 @@ export enum WorkerMessageType {
|
||||
// 初始化过程数据,初始化到人员以及人员里面各个目录
|
||||
ProcessDataInit = 'processDataInit',
|
||||
// 初始化考试过程
|
||||
ExamProcessInit = 'examProcessInit'
|
||||
ExamProcessInit = 'examProcessInit',
|
||||
// 写过程数据
|
||||
WriteProcessData = 'writeProcessData',
|
||||
// 关闭过程数据
|
||||
CloseProcessData='closeProcessData'
|
||||
}
|
||||
|
||||
// 过程数据枚举
|
||||
export enum ProcessDataEnumType {
|
||||
//four_one_log_byte_data
|
||||
FourOneLogByteData = 0,
|
||||
//four_one_log_data
|
||||
FourOneLogData = 1,
|
||||
//judge_exam_data
|
||||
JudgeExamData = 2,
|
||||
//judge_log_data
|
||||
JudgeLogData = 3,
|
||||
// judge_progress_callback_data
|
||||
JudgeProgressCallbackData = 4,
|
||||
//plc_data
|
||||
PlcData = 5,
|
||||
//wuxi_exam_data
|
||||
WuxiExam = 6,
|
||||
//wuxi_progress_data
|
||||
WuxiProgressData = 7
|
||||
}
|
||||
|
||||
export interface LogPathType {
|
||||
|
||||
@ -37,7 +37,8 @@ import {
|
||||
SYSSET,
|
||||
SyssetConfig,
|
||||
SYSTEMPARMARR,
|
||||
User
|
||||
User,
|
||||
ProcessDataEnumType
|
||||
} from '../model';
|
||||
import { GetSyncData } from '../utils/table/Operation';
|
||||
import dayTs from '../utils/Date';
|
||||
|
||||
@ -44,6 +44,7 @@ import {
|
||||
LANE,
|
||||
MarkRule,
|
||||
PLCType,
|
||||
ProcessDataEnumType,
|
||||
ProjectInfo,
|
||||
RecordHandleType,
|
||||
RegulatoryInterfaceParams,
|
||||
@ -1967,6 +1968,7 @@ export default class Judge {
|
||||
const result: WorkerBackMessage = JSON.parse(data)
|
||||
if (result.type === WorkerBackMessageType.ObtainUdpData) {
|
||||
handleUdp(result.data as string)
|
||||
dConsole.writeProcessData(ProcessDataEnumType.PlcData, result.data as string)
|
||||
}
|
||||
//TODO UDP修改
|
||||
// const udpIndex = globalThis.udpIndex;
|
||||
|
||||
@ -34,28 +34,28 @@ export default class FileLog {
|
||||
}
|
||||
// 无锡所过程数据
|
||||
public setExamJudgeWuxiProgressData = async (str: string) => {
|
||||
this.examJudgeWuxiProgressDataFd =
|
||||
await this.fileUtil.editFile(`${this.folderPath}/wuxi_progress_data.txt`, str);
|
||||
// this.examJudgeWuxiProgressDataFd =
|
||||
// await this.fileUtil.editFile(`${this.folderPath}/wuxi_progress_data.txt`, str);
|
||||
}
|
||||
// plc文件数据
|
||||
public setPlcProgressData = async (str: Object) => {
|
||||
this.plcDataFd =
|
||||
await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str));
|
||||
// this.plcDataFd =
|
||||
// await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str));
|
||||
}
|
||||
// 过程评判json数据
|
||||
public setExamJudgeData = async (str: string) => {
|
||||
this.examJudgeDataFd =
|
||||
await this.fileUtil.editFile(`${this.folderPath}/judge_exam_data.txt`, str);
|
||||
// this.examJudgeDataFd =
|
||||
// await this.fileUtil.editFile(`${this.folderPath}/judge_exam_data.txt`, str);
|
||||
}
|
||||
// 过程评判回调数据
|
||||
public setExamJudgeCallbackData = async (str: string) => {
|
||||
this.examJudgeCallbackDataFd =
|
||||
await this.fileUtil.editFile(`${this.folderPath}/judge_progress_callback_data.txt`, str);
|
||||
// this.examJudgeCallbackDataFd =
|
||||
// await this.fileUtil.editFile(`${this.folderPath}/judge_progress_callback_data.txt`, str);
|
||||
}
|
||||
// 过程评判日志调数据
|
||||
public setExamJudgeLogData = async (str: string) => {
|
||||
this.examJudgeLogDataFd =
|
||||
await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str);
|
||||
// this.examJudgeLogDataFd =
|
||||
// await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str);
|
||||
}
|
||||
// 设置四合一画面数据
|
||||
public setFourAndOneLogData = async (str: string) => {
|
||||
@ -103,13 +103,13 @@ export default class FileLog {
|
||||
// 设置文件夹
|
||||
public initFileLogo = async (stuInfo: StuInfo) => {
|
||||
// this.stuInfo = stuInfo;
|
||||
const time = GetCurrentTime()
|
||||
const date = time.split(' ')[0].split('-').join('_')
|
||||
const hourTime = time.split(' ')[1].split(':').join('_')
|
||||
const folderPath =
|
||||
await this.fileUtil.initFolder(`/logs/${date}/${date}_${hourTime}_${stuInfo.lsh}_${stuInfo.idCard}_${stuInfo.name}`);
|
||||
this.folderPath = folderPath;
|
||||
return folderPath
|
||||
// const time = GetCurrentTime()
|
||||
// const date = time.split(' ')[0].split('-').join('_')
|
||||
// const hourTime = time.split(' ')[1].split(':').join('_')
|
||||
// const folderPath =
|
||||
// await this.fileUtil.initFolder(`/logs/${date}/${date}_${hourTime}_${stuInfo.lsh}_${stuInfo.idCard}_${stuInfo.name}`);
|
||||
// this.folderPath = folderPath;
|
||||
return "folderPath"
|
||||
}
|
||||
|
||||
constructor(context: common.UIAbilityContext) {
|
||||
|
||||
@ -217,6 +217,22 @@ export function CreateDir(path: string): Promise<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 写文件
|
||||
*/
|
||||
export function EditFile(fd: number, data: string): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
let result = fs.writeSync(fd, data + "\n")
|
||||
console.log("创建文件之写文件成功", result.toString())
|
||||
resolve(true)
|
||||
} catch (e) {
|
||||
console.log("创建文件之写文件失败")
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
* @params path 文件具体路径
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// 日志向外暴露的方法
|
||||
import dayTs from './Date';
|
||||
import worker from '@ohos.worker';
|
||||
import { LogWorkerMessage, WorkerMessageType } from '../model/index';
|
||||
import { LogWorkerMessage, ProcessDataEnumType, WorkerMessageType } from '../model/index';
|
||||
|
||||
const MAX_MESSAGE_LENGTH = 300;
|
||||
const LOG_CHUNK_PREFIX = '[切割消息序号';
|
||||
@ -63,12 +63,16 @@ class logWorker {
|
||||
}
|
||||
}
|
||||
|
||||
// 过程数据初始化
|
||||
processDataInit(carNo: string, name: string) {
|
||||
let date = dayTs().format("YYYY_MM_DD_HH_mm_ss");
|
||||
// 组装文件夹名 2025_06_18_09_14_36_2506474075216_371427200311275216_王宏伟
|
||||
let folderName = `${date}_${carNo}_${name}`;
|
||||
// 内部包含文件
|
||||
// 过程数据写入
|
||||
writeProcessData(type: ProcessDataEnumType, data: string) {
|
||||
let params: LogWorkerMessage = {
|
||||
type: WorkerMessageType.WriteProcessData,
|
||||
data,
|
||||
processDataType: type
|
||||
}
|
||||
if (this.isLogEnabled === "1") {
|
||||
this.workerInstance?.postMessage(JSON.stringify(params))
|
||||
}
|
||||
}
|
||||
|
||||
// 通用日志方法
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import { GlobalConfig } from '../config';
|
||||
import { LogFileFd, LogPathType, LogWorkerMessage, WorkerMessageType } from '../model';
|
||||
import { CreateDir, CreateFile, IsExit } from '../utils/Common';
|
||||
import { LogFileFd, LogPathType, LogWorkerMessage, ProcessDataEnumType, WorkerMessageType } from '../model';
|
||||
import { CreateDir, CreateFile, EditFile, IsExit } from '../utils/Common';
|
||||
import dayTs from '../utils/Date';
|
||||
import fs from '@ohos.file.fs';
|
||||
|
||||
const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
|
||||
const fileNameArr: string[] = ["four_one_log_byte_data.text", "four_one_log_data.txt", "judge_exam_data.txt", "judge_log_data.txt", "judge_progress_callback_data.txt", "plc_data.txt", "wuxi_exam_data.txt", "wuxi_progress_data.txt"]
|
||||
@ -19,9 +20,18 @@ workerPort.onmessage = (e: MessageEvents) => {
|
||||
if (result.type === WorkerMessageType.Init) {
|
||||
InitLog()
|
||||
}
|
||||
// 初始化过程数据
|
||||
if (result.type === WorkerMessageType.ExamProcessInit && result.studentDirName) {
|
||||
InitExam(result.studentDirName)
|
||||
}
|
||||
// 写过程数据
|
||||
if (result.type === WorkerMessageType.WriteProcessData&&result.processDataType) {
|
||||
WriteProcessData(result.processDataType, result.data||"")
|
||||
}
|
||||
// 关闭过程数据
|
||||
if (result.type === WorkerMessageType.CloseProcessData) {
|
||||
CloseProcessData()
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化日志
|
||||
@ -60,6 +70,7 @@ async function InitLog() {
|
||||
|
||||
// 初始化学员过程数据目录
|
||||
async function InitExam(dirName: string) {
|
||||
console.log("初始化过程",dirName)
|
||||
let date = dayTs().format("YYYY_MM_DD")
|
||||
const path = `${GlobalConfig.commonFileWriteAddress}/logs/${date}/${dirName}`
|
||||
const nameDirIsExit = await IsExit(path)
|
||||
@ -75,6 +86,24 @@ async function InitExam(dirName: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// 写过程数据
|
||||
async function WriteProcessData(type: ProcessDataEnumType, data: string) {
|
||||
let index = Number(type)
|
||||
console.log("创建文件",type,index.toString(),data)
|
||||
let result=await EditFile(fileFdArr[index], data)
|
||||
if(result){
|
||||
// 写文件成功
|
||||
}else{
|
||||
// 写文件失败
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭过程数据
|
||||
function CloseProcessData() {
|
||||
fileFdArr.forEach((item: number) => {
|
||||
fs.closeSync(item)
|
||||
})
|
||||
}
|
||||
|
||||
workerPort.onmessageerror = (e: MessageEvents) => {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user