feat:fileLog.ets修改

This commit is contained in:
Surenjun 2025-03-26 14:44:44 +08:00
parent 94cf59b607
commit 3ac39b383b

View File

@ -1,6 +1,7 @@
import { GetCurrentTime } from '../../../utils/Common'
import FileUtils from '../../../utils/FileUtils'
import common from '@ohos.app.ability.common';
interface StuInfo {
name: string
@ -24,56 +25,46 @@ export default class FileLog {
public examLineDataFd: number = undefined
// 过程文件数据
public setExamProgressData = async (str: Object) => {
const { fileUtil, folderPath, progressDataFd } = this;
this.progressDataFd =
await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`, JSON.stringify(str), progressDataFd);
await this.fileUtil.editFile(`${this.folderPath}/exam_progress_data.txt`, JSON.stringify(str), this.progressDataFd);
}
// 无锡所接口数据
public setExamJudgeWuxiData = async (str) => {
const { fileUtil, folderPath, examJudgeWuxiDataFd } = this;
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`, str, examJudgeWuxiDataFd);
public setExamJudgeWuxiData = async (str:string) => {
this.examJudgeWuxiDataFd = await this.fileUtil.editFile(`${this.folderPath}/wuxi_exam_data.txt`, str, this.examJudgeWuxiDataFd);
}
// 无锡所过程数据
public setExamJudgeWuxiProgressData = async (str) => {
const { fileUtil, folderPath, examJudgeWuxiProgressDataFd } = this;
public setExamJudgeWuxiProgressData = async (str:string) => {
this.examJudgeWuxiProgressDataFd =
await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`, str, examJudgeWuxiProgressDataFd);
await this.fileUtil.editFile(`${this.folderPath}/wuxi_progress_data.txt`, str, this.examJudgeWuxiProgressDataFd);
}
// plc文件数据
public setPlcProgressData = async (str: Object) => {
const { fileUtil, folderPath, plcDataFd } = this;
this.plcDataFd = await fileUtil.editFile(`${folderPath}/plc_data.txt`, JSON.stringify(str), plcDataFd);
this.plcDataFd = await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str), this.plcDataFd);
}
// 过程评判json数据
public setExamJudgeData = async (str: Object) => {
const { fileUtil, folderPath, examJudgeDataFd } = this;
this.examJudgeDataFd =
await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`, JSON.stringify(str), examJudgeDataFd);
await this.fileUtil.editFile(`${this.folderPath}/judge_exam_data.txt`, JSON.stringify(str), this.examJudgeDataFd);
}
// 过程评判回调数据
public setExamJudgeCallbackData = async (str: string) => {
const { fileUtil, folderPath, examJudgeCallbackDataFd } = this;
this.examJudgeCallbackDataFd =
await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`, str, examJudgeCallbackDataFd);
await this.fileUtil.editFile(`${this.folderPath}/judge_progress_callback_data.txt`, str, this.examJudgeCallbackDataFd);
}
// 过程评判日志调数据
public setExamJudgeLogData = async (str: string) => {
const { fileUtil, folderPath, examJudgeLogDataFd } = this;
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`, str, examJudgeLogDataFd);
this.examJudgeLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str, this.examJudgeLogDataFd);
}
// 设置四合一画面数据
public setFourAndOneLogData = async (str: string) => {
const { fileUtil, folderPath, fourAndOneLogDataFd } = this;
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`, str, fourAndOneLogDataFd);
this.fourAndOneLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/four_one_log_data.txt`, str, this.fourAndOneLogDataFd);
}
public setFourAndOneLogDataBytes = async (str: string) => {
const { fileUtil, folderPath, fourAndOneLogDataBytesFd } = this;
this.fourAndOneLogDataBytesFd =
await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`, str, fourAndOneLogDataBytesFd);
await this.fileUtil.editFile(`${this.folderPath}/four_one_log_byte_data.txt`, str, this.fourAndOneLogDataBytesFd);
}
// 无锡所轨迹数据
public setExamLineData = async (plcStr) => {
const { fileUtil, folderPath, examLineDataFd } = this;
public setExamLineData = async (plcStr:string) => {
const plcData = plcStr.split(',');
const time = await GetCurrentTime();
const lineData = [
@ -103,25 +94,23 @@ export default class FileLog {
/*结束符*/ time,
];
this.examLineDataFd =
await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData), examLineDataFd);
await this.fileUtil.editFile(`${this.folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData),this.examLineDataFd);
};
//后续文件路径待替换
private fileUtil: FileUtils
private stuInfo: StuInfo
// 设置文件夹
public initFileLogo = async (stuInfo: StuInfo) => {
const { fileUtil, setExamLineData } = this
const { name, lsh, idCard } = stuInfo;
this.stuInfo = stuInfo;
const time = await GetCurrentTime()
const date = time.split(' ')[0].split('-').join('_')
const hourTime = time.split(' ')[1].split(':').join('_')
const folderPath = await fileUtil.initFolder(`/logs/${date}/${date}_${hourTime}_${lsh}_${idCard}_${name}`);
const folderPath = await this.fileUtil.initFolder(`/logs/${date}/${date}_${hourTime}_${stuInfo.lsh}_${stuInfo.idCard}_${stuInfo.name}`);
this.folderPath = folderPath;
return folderPath
}
constructor(context) {
constructor(context:common.UIAbilityContext) {
const fileUtil = new FileUtils(context)
this.fileUtil = fileUtil
@ -129,10 +118,9 @@ export default class FileLog {
//关闭所有文件写入
public closeAllFiles = async () => {
const { fileUtil, folderPath, fourAndOneLogDataFd } = this;
['exam_progress_data', 'wuxi_exam_data', 'wuxi_progress_data', 'plc_data', 'judge_exam_data',
'judge_progress_callback_data', 'judge_log_data', 'four_one_log_data', 'four_one_log_byte_data'].forEach(path => {
fileUtil.closeFile(`${folderPath}/${path}.txt`);
this.fileUtil.closeFile(`${this.folderPath}/${path}.txt`);
})
}
}