feat:fileLog.ets修改
This commit is contained in:
parent
94cf59b607
commit
3ac39b383b
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import { GetCurrentTime } from '../../../utils/Common'
|
import { GetCurrentTime } from '../../../utils/Common'
|
||||||
import FileUtils from '../../../utils/FileUtils'
|
import FileUtils from '../../../utils/FileUtils'
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
|
||||||
interface StuInfo {
|
interface StuInfo {
|
||||||
name: string
|
name: string
|
||||||
@ -24,56 +25,46 @@ export default class FileLog {
|
|||||||
public examLineDataFd: number = undefined
|
public examLineDataFd: number = undefined
|
||||||
// 过程文件数据
|
// 过程文件数据
|
||||||
public setExamProgressData = async (str: Object) => {
|
public setExamProgressData = async (str: Object) => {
|
||||||
const { fileUtil, folderPath, progressDataFd } = this;
|
|
||||||
this.progressDataFd =
|
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) => {
|
public setExamJudgeWuxiData = async (str:string) => {
|
||||||
const { fileUtil, folderPath, examJudgeWuxiDataFd } = this;
|
this.examJudgeWuxiDataFd = await this.fileUtil.editFile(`${this.folderPath}/wuxi_exam_data.txt`, str, this.examJudgeWuxiDataFd);
|
||||||
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`, str, examJudgeWuxiDataFd);
|
|
||||||
}
|
}
|
||||||
// 无锡所过程数据
|
// 无锡所过程数据
|
||||||
public setExamJudgeWuxiProgressData = async (str) => {
|
public setExamJudgeWuxiProgressData = async (str:string) => {
|
||||||
const { fileUtil, folderPath, examJudgeWuxiProgressDataFd } = this;
|
|
||||||
this.examJudgeWuxiProgressDataFd =
|
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文件数据
|
// plc文件数据
|
||||||
public setPlcProgressData = async (str: Object) => {
|
public setPlcProgressData = async (str: Object) => {
|
||||||
const { fileUtil, folderPath, plcDataFd } = this;
|
this.plcDataFd = await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str), this.plcDataFd);
|
||||||
this.plcDataFd = await fileUtil.editFile(`${folderPath}/plc_data.txt`, JSON.stringify(str), plcDataFd);
|
|
||||||
}
|
}
|
||||||
// 过程评判json数据
|
// 过程评判json数据
|
||||||
public setExamJudgeData = async (str: Object) => {
|
public setExamJudgeData = async (str: Object) => {
|
||||||
const { fileUtil, folderPath, examJudgeDataFd } = this;
|
|
||||||
this.examJudgeDataFd =
|
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) => {
|
public setExamJudgeCallbackData = async (str: string) => {
|
||||||
const { fileUtil, folderPath, examJudgeCallbackDataFd } = this;
|
|
||||||
this.examJudgeCallbackDataFd =
|
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) => {
|
public setExamJudgeLogData = async (str: string) => {
|
||||||
const { fileUtil, folderPath, examJudgeLogDataFd } = this;
|
this.examJudgeLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str, this.examJudgeLogDataFd);
|
||||||
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`, str, examJudgeLogDataFd);
|
|
||||||
}
|
}
|
||||||
// 设置四合一画面数据
|
// 设置四合一画面数据
|
||||||
public setFourAndOneLogData = async (str: string) => {
|
public setFourAndOneLogData = async (str: string) => {
|
||||||
const { fileUtil, folderPath, fourAndOneLogDataFd } = this;
|
this.fourAndOneLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/four_one_log_data.txt`, str, this.fourAndOneLogDataFd);
|
||||||
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`, str, fourAndOneLogDataFd);
|
|
||||||
}
|
}
|
||||||
public setFourAndOneLogDataBytes = async (str: string) => {
|
public setFourAndOneLogDataBytes = async (str: string) => {
|
||||||
const { fileUtil, folderPath, fourAndOneLogDataBytesFd } = this;
|
|
||||||
this.fourAndOneLogDataBytesFd =
|
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) => {
|
public setExamLineData = async (plcStr:string) => {
|
||||||
const { fileUtil, folderPath, examLineDataFd } = this;
|
|
||||||
const plcData = plcStr.split(',');
|
const plcData = plcStr.split(',');
|
||||||
const time = await GetCurrentTime();
|
const time = await GetCurrentTime();
|
||||||
const lineData = [
|
const lineData = [
|
||||||
@ -103,25 +94,23 @@ export default class FileLog {
|
|||||||
/*结束符*/ time,
|
/*结束符*/ time,
|
||||||
];
|
];
|
||||||
this.examLineDataFd =
|
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 fileUtil: FileUtils
|
||||||
private stuInfo: StuInfo
|
private stuInfo: StuInfo
|
||||||
// 设置文件夹
|
// 设置文件夹
|
||||||
public initFileLogo = async (stuInfo: StuInfo) => {
|
public initFileLogo = async (stuInfo: StuInfo) => {
|
||||||
const { fileUtil, setExamLineData } = this
|
|
||||||
const { name, lsh, idCard } = stuInfo;
|
|
||||||
this.stuInfo = stuInfo;
|
this.stuInfo = stuInfo;
|
||||||
const time = await GetCurrentTime()
|
const time = await GetCurrentTime()
|
||||||
const date = time.split(' ')[0].split('-').join('_')
|
const date = time.split(' ')[0].split('-').join('_')
|
||||||
const hourTime = time.split(' ')[1].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;
|
this.folderPath = folderPath;
|
||||||
return folderPath
|
return folderPath
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(context) {
|
constructor(context:common.UIAbilityContext) {
|
||||||
const fileUtil = new FileUtils(context)
|
const fileUtil = new FileUtils(context)
|
||||||
this.fileUtil = fileUtil
|
this.fileUtil = fileUtil
|
||||||
|
|
||||||
@ -129,10 +118,9 @@ export default class FileLog {
|
|||||||
|
|
||||||
//关闭所有文件写入
|
//关闭所有文件写入
|
||||||
public closeAllFiles = async () => {
|
public closeAllFiles = async () => {
|
||||||
const { fileUtil, folderPath, fourAndOneLogDataFd } = this;
|
|
||||||
['exam_progress_data', 'wuxi_exam_data', 'wuxi_progress_data', 'plc_data', 'judge_exam_data',
|
['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 => {
|
'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`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user