surenjun 4f1a4f894c 1. 新增623参数控制联网模式实施轨迹显示
2. 新增监管结束考试异常,错误提示弹窗显示
3. 优化文件系统:考试结束关闭文件读写
2025-01-09 20:56:36 +08:00

149 lines
5.8 KiB
TypeScript

import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
import promptAction from '@ohos.promptAction'
import fileAccess from '@ohos.file.fileAccess'
import common from '@ohos.app.ability.common'
import Want from '@ohos.app.ability.Want'
import fs from '@ohos.file.fs'
import FileUtil from '../../../common/utils/File'
import { getCurrentTime } from '../../../common/utils/tools'
interface StuInfo {
name: string
lsh: string
idCard: string
}
const LOGTAG = 'LOGTAG'
export default class FileLog {
//后续文件路径待替换
private fileUtil: FileUtil
private stuInfo: StuInfo
public folderPath: string
public progressDataFd: number = undefined
public examJudgeWuxiDataFd: number = undefined
public examJudgeWuxiProgressDataFd: number = undefined
public plcDataFd: number = undefined
public examJudgeDataFd: number = undefined
public examJudgeCallbackDataFd: number = undefined
public examJudgeLogDataFd: number = undefined
public fourAndOneLogDataFd: number = undefined
public fourAndOneLogDataBytesFd: number = undefined
public examLineDataFd: number = undefined
constructor(context) {
const fileUtil = new FileUtil(context)
this.fileUtil = fileUtil
}
// 设置文件夹
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}`);
this.folderPath = folderPath;
return folderPath
}
// 过程文件数据
public setExamProgressData = async (str: Object) => {
const {fileUtil,folderPath,progressDataFd} = this;
this.progressDataFd = await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`, JSON.stringify(str), progressDataFd);
}
// 无锡所接口数据
public setExamJudgeWuxiData = async (str) => {
const {fileUtil,folderPath,examJudgeWuxiDataFd} = this;
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`, str, examJudgeWuxiDataFd);
}
// 无锡所过程数据
public setExamJudgeWuxiProgressData = async (str) => {
const {fileUtil,folderPath,examJudgeWuxiProgressDataFd} = this;
this.examJudgeWuxiProgressDataFd = await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`, str, 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);
}
// 过程评判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);
}
// 过程评判回调数据
public setExamJudgeCallbackData = async (str: string) => {
const {fileUtil,folderPath,examJudgeCallbackDataFd} = this;
this.examJudgeCallbackDataFd = await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`, str, examJudgeCallbackDataFd);
}
// 过程评判日志调数据
public setExamJudgeLogData = async (str: string) => {
const {fileUtil,folderPath,examJudgeLogDataFd} = this;
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`, str, examJudgeLogDataFd);
}
// 设置四合一画面数据
public setFourAndOneLogData = async (str: string) => {
const {fileUtil,folderPath,fourAndOneLogDataFd} = this;
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`, str, 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);
}
//关闭所有文件写入
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`);
})
}
// 无锡所轨迹数据
public setExamLineData = async (plcStr) => {
const {fileUtil,folderPath,examLineDataFd} = this;
const plcData = plcStr.split(',');
const time = await getCurrentTime();
const lineData = [
/*帧头*/time,
/*卫星时间*/time,
/*经度*/ plcData[95],
/*纬度*/ plcData[95],
/*高度*/ plcData[86],
/*方位角*/ 0,
/*俯仰角*/ plcData[91],
/*速度角*/'',
/*速度*/ plcData[97],
/*横滚*/'',
/*卫星定位状态*/'',
/*卫星定向状态*/'',
/*前天线可用星数*/'',
/*后天线可用星数*/'',
/*东向位置坐标*/'',
/*北向位置坐标*/'',
/*天向位置坐标*/'',
/*东向速度*/'',
/*北向速度*/'',
/*评判信号1*/[plcData[14], plcData[19], plcData[5], '', plcData[2], plcData[3], plcData[7], plcData[8], plcData[13], plcData[12], plcData[17], '', plcData[4], plcData[11], plcData[20], plcData[9], 0].join(','),
/*评判信号2*/['', plcData[28], '', '', plcData[10], '', '', '', '', '', '', '', '', '', '', '', '', ''].join(','),
/*发动机转速*/ plcData[25],
/*结束符*/ time,
];
this.examLineDataFd = await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData), examLineDataFd);
};
}