fix: 优化时间获取逻辑,移除不必要的 await

This commit is contained in:
wangzhongjie 2025-03-31 15:36:36 +08:00
parent 8ba301348d
commit fca24538d0
7 changed files with 191 additions and 184 deletions

View File

@ -198,7 +198,7 @@ interface UploadExamMileage {
examinationRoomId: string
lsh: string
kslc: number
kskssj:string
kskssj: string
}
// 上传考试里程
@ -236,7 +236,7 @@ export async function uploadExamGrade(params: ESObject) {
return
}
const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}</${key}>`))
const time = await getCurrentTime()
const time = GetCurrentTime()
return request<object>({
url: '/der2/services/exam/uploadExamGrade.ws',
data: `<?xml version="1.0" encoding="UTF-8"?>

View File

@ -468,7 +468,7 @@ struct UserInfo {
async heartMsg() {
// TODO UDP缺失
CentralHeartbeat.getData((val:centerCallBackMsgType)=>{
CentralHeartbeat.getData((val: centerCallBackMsgType) => {
if (val.id == 32) {
AppStorage.setOrCreate('signNum', val.body[1])
if (val.body[0] == 7) {
@ -838,7 +838,7 @@ struct UserInfo {
}
// const { carId, examinationRoomId } = this.carInfo;
const examItems = await getExaminationItem({
time: await GetCurrentTime() || "",
time: GetCurrentTime() || "",
carId: this.carInfo.carId,
lsh: this.currentUser.lsh || '',
examinationRoomId: this.carInfo.examinationRoomId
@ -865,7 +865,7 @@ struct UserInfo {
if (!this.singlePlay) {
//获取已考项目
examItems = await getExaminationItem({
time: await GetCurrentTime(),
time: GetCurrentTime(),
carId: this.carInfo.carId,
lsh: this.currentUser.lsh || '',
examinationRoomId: this.carInfo.examinationRoomId

View File

@ -51,9 +51,9 @@ export default struct TopLogo {
}
async aboutToAppear() {
this.timeText = await GetCurrentTime();
this.timeText = GetCurrentTime();
this.timer = setInterval(async () => {
this.timeText = await GetCurrentTime();
this.timeText = GetCurrentTime();
}, 1000)
// this.vocObj = new voiceService(async (status,val) => {
// if (status == 'idle') {

View File

@ -216,7 +216,7 @@ export default struct DeductedPopup {
const carInfo: CarInfoType = this.carInfo;
const { examSubject, plateNo } = carInfo;
const { serialNumber, lsh, idCard, ksxl, kslx, ksdd } = this
const time = await GetCurrentTime();
const time = GetCurrentTime();
const beginData = {
xtlb: '17',
jkxlh: serialNumber,
@ -246,7 +246,7 @@ export default struct DeductedPopup {
const { serialNumber, lsh, idCard, ksdd, kfdmArr, getPhoto } = this;
const carInfo = this.carInfo;
const { examSubject, plateNo, carNo } = carInfo;
const time = await GetCurrentTime();
const time = GetCurrentTime();
console.info('surenjun uploadProgressPhoto',)
const photoBase64 = await getPhoto()
const photoData = {
@ -277,7 +277,7 @@ export default struct DeductedPopup {
const kf = kfdmArr[kfLen -1];
const carInfo: CarInfoType = this.carInfo;
const { examSubject } = this.carInfo;
const time = await GetCurrentTime();
const time = GetCurrentTime();
const kfData = {
xtlb: '17',
jkxlh: serialNumber,
@ -304,7 +304,7 @@ export default struct DeductedPopup {
const carInfo = this.carInfo;
const { examSubject, plateNo, carNo } = carInfo;
const { lsh, idCard, serialNumber, ksdd, kslx, ksxl, } = this;
const time = await GetCurrentTime();
const time = GetCurrentTime();
const endProjectData = {
xtlb: '17',
jkxlh: serialNumber,
@ -330,7 +330,7 @@ export default struct DeductedPopup {
const { serialNumber, lsh, idCard, score, getPhoto } = this;
const carInfo: CarInfoType = this.carInfo;
const { examSubject, plateNo } = carInfo;
const time = await GetCurrentTime();
const time = GetCurrentTime();
const photoBase64 = await getPhoto();
const endData = {
xtlb: '17',

View File

@ -185,6 +185,38 @@ export default class Judge {
private isExamEnd: boolean
// 是否发送udp
private isUdpEnd: boolean = false
// 处理udp plc信号
handleUdp = async (msg: string) => {
console.info('plc信号', msg)
const stachArr = msg.split(',')
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
return
}
const plcData = await this.getPlcData(msg);
// 4.过程数据
await this.fileLog.setExamJudgeData(JSON.stringify(plcData))
//检测到有无锡所设备接入,需要发送特定的数据,供检测
// if (this.usbService.isWXUSBDevice) {
// const str = await senorToWXDataStr(msg);
// this.usbService.sendUSB(str)
// }
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
//TODO 暂时关闭差分检测异常
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
if (!this.isExamEnd) {
await examJudgeRealExam(plcData)
}
let udpIndex = AppStorage.get<number>('udpIndex');
if (udpIndex % 5 === 0 && !this.isUdpEnd) {
// TODO UPD缺失
// const judgeUdp = globalThis.judgeUdp
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
// judgeUdp.send(bytes)
}
AppStorage.setOrCreate('udpIndex', udpIndex++)
}
//是否手动结束考试
private isManual: boolean
//UDP服务序列号
@ -201,8 +233,8 @@ export default class Judge {
const folderPath = fileLog.folderPath
const base64 = new util.Base64();
const time = await GetCurrentTime();
const endTime = await GetCurrentTime(1)
const time = GetCurrentTime();
const endTime = GetCurrentTime(1)
let examDataBase64: string = ''
//TODO try catch报错待优化
const examDataStr: string = await this.fileUtil.readFile(`${folderPath}/wuxi_progress_data.txt`);
@ -232,60 +264,6 @@ export default class Judge {
console.info(judgeTag, '过程数据文件上传 end')
}
private judgeTask: JudgeTask
// 检测扣分、结束项目时该项目是否开始
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: JudgeEventKf) => {
if (xmdm == 20) {
return true
}
const judgeUI = this.judgeUI;
const judgeTask = this.judgeTask;
const projectsObj = this.judgeUI.projectsObj
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
const isUpload = currentProject.isUpload
//如果项目没有开始
console.info('surenjun isUpload=>', isUpload)
if (!isUpload) {
console.info(judgeTag, '项目补传开始')
//项目开始补传
judgeTask.addTask(async () => {
await this.beginProject(xmdm)
}, {
isDelay: true
})
judgeTask.addTask(async () => {
await this.uploadProgressPhoto(xmdm)
}, {
isDelay: true
})
currentProject.isUpload = true;
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
//扣分补传
if (currentType == 2) {
judgeTask.addTask(async () => {
await this.pointsDedute(xmdm, kf)
}, {
isDelay: true
})
}
//扣分补传判断是否合格 不合格补传项目结束
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
judgeTask.addTask(async () => {
await this.endProject(xmdm)
}, {
isDelay: true
})
currentProject.isEnd = true;
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
}
judgeTask.addTask(async () => {
this.checkExamIsEnd()
})
return false;
} else {
return true
}
}
private tempData: Plc
//实时计算gps经纬度距离
handDistance = async () => {
@ -449,38 +427,6 @@ export default class Judge {
AppStorage.setOrCreate('msgStr', plc)
return tempData
}
// 处理udp plc信号
handleUdp = async (msg: string) => {
console.info('plc信号', msg)
const stachArr = msg.split(',')
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
return
}
const plcData = await this.getPlcData(msg);
// 4.过程数据
await this.fileLog.setExamJudgeData(JSON.stringify(plcData))
//检测到有无锡所设备接入,需要发送特定的数据,供检测
// if (this.usbService.isWXUSBDevice) {
// const str = await senorToWXDataStr(msg);
// this.usbService.sendUSB(str)
// }
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
//TODO 暂时关闭差分检测异常
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
if (!this.isExamEnd) {
await examJudgeRealExam(plcData)
}
let udpIndex = AppStorage.get<number>('udpIndex');
if (udpIndex % 5 === 0 && !this.isUdpEnd) {
// TODO UPD缺失
// const judgeUdp = globalThis.judgeUdp
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
// judgeUdp.send(bytes)
}
AppStorage.setOrCreate('udpIndex', udpIndex++)
}
// 处理轨迹plc信号
handleTrajectoryUdp = async (strArr: string[]) => {
// const { fileLog, setJudgeItem, setJudgeMark, endExam } = this;
@ -519,9 +465,9 @@ export default class Judge {
}
//本地轨迹回放地址
private trajectoryPath: string
//当前科目二的考试项目
// private currentKm2ItemsObj: any
private isTrajectoryOpen: boolean;
//当前科目二的考试项目
// 调代理接口是否断网了
private isJudgeDisConnect: boolean;
// 断网数据补传
@ -536,11 +482,72 @@ export default class Judge {
const code = await writeObjectOut(JSON.parse(examDataStr));
}
}
// 考试过程照片
uploadProgressPhoto = async (ksxm: number) => {
const time = GetCurrentTime();
const judgeUI = this.judgeUI
const plcData = this.plcData
const photoBase64 = await this.getPhoto();
const carInfo = AppStorage.get<CarInfoType>('carInfo');
const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, ksxm)
const judgeConfig_305: number = Reflect.get(judgeUI.judgeConfigObj, '305')
const drvexam: DrvexamType = {
lsh: judgeUI.lsh,
kskm: carInfo.examSubject,
ksxm: project.projectCodeCenter,
sfzmhm: judgeUI.idCard,
kchp: encodeURI(carInfo.plateNo),
zpsj: time,
zp: photoBase64,
cs: Math.floor((judgeConfig_305 == 0 ? plcData.gps.sd : plcData.sensor.cs) * 1.852),
ksdd: encodeURI(judgeUI.ksdd)
}
const data: RegulatoryInterfaceParams = {
xtlb: '17',
jkxlh: judgeUI.serialNumber,
jkid: '17C54',
drvexam
};
const temp: WR = await this.sendWriteObjectOut(data, this.filePath);
if (temp.code === 2300007) {
this.isJudgeDisConnect = true
}
promptWxCode('17C54', temp.code)
console.info(judgeTag, '上传照片 end')
}
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
private lane: LANE = {
road: '', num: 0, count: 0
}
private videoData: RecordHandleType
private disConnectNum: number = 0;
//调用监管接口
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
const temp = await writeObjectOut(data, filePath);
console.log("wzj", JSON.stringify(temp))
//断网&网络超时次数计算
if (temp.code == 2300007 || temp.code == 2300028) {
this.disConnectNum += 1;
if (this.disConnectNum < 5) {
return await this.sendWriteObjectOut(data, filePath)
}
}
if (this.disConnectNum >= 5) {
console.info('surenjun', '123')
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
this.judgeUI.disConnectErrorOpen = true
}
this.disConnectNum = 0
return temp
}
// 项目开始接口同步
beginProject = async (ksxm: number) => {
const carInfo = AppStorage.get<CarInfoType>('carInfo');
const judgeUI = this.judgeUI
const time = await GetCurrentTime();
const time = GetCurrentTime();
const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, ksxm)
const sbxh = this.getSbbm(ksxm, this.xmxh)
@ -574,7 +581,7 @@ export default class Judge {
endProject = async (ksxm: number) => {
const carInfo = AppStorage.get<CarInfoType>('carInfo');
const judgeUI = this.judgeUI;
const time = await GetCurrentTime();
const time = GetCurrentTime();
const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, ksxm)
const sbxh = judgeUI.examSubject == '3' ? undefined : this.getSbbm(ksxm, this.xmxh)
@ -605,66 +612,59 @@ export default class Judge {
console.info(judgeTag, '项目结束 end')
promptWxCode('17C55', temp.code)
}
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
private lane: LANE = {
road: '', num: 0, count: 0
}
private videoData: RecordHandleType
private disConnectNum: number = 0;
//调用监管接口
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
const temp = await writeObjectOut(data, filePath);
console.log("wzj", JSON.stringify(temp))
//断网&网络超时次数计算
if (temp.code == 2300007 || temp.code == 2300028) {
this.disConnectNum += 1;
if (this.disConnectNum < 5) {
return await this.sendWriteObjectOut(data, filePath)
// 检测扣分、结束项目时该项目是否开始
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: JudgeEventKf) => {
if (xmdm == 20) {
return true
}
const judgeUI = this.judgeUI;
const judgeTask = this.judgeTask;
const projectsObj = this.judgeUI.projectsObj
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
const isUpload = currentProject.isUpload
//如果项目没有开始
console.info('surenjun isUpload=>', isUpload)
if (!isUpload) {
console.info(judgeTag, '项目补传开始')
//项目开始补传
judgeTask.addTask(async () => {
await this.beginProject(xmdm)
}, {
isDelay: true
})
judgeTask.addTask(async () => {
await this.uploadProgressPhoto(xmdm)
}, {
isDelay: true
})
currentProject.isUpload = true;
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
//扣分补传
if (currentType == 2) {
judgeTask.addTask(async () => {
await this.pointsDedute(xmdm, kf)
}, {
isDelay: true
})
}
//扣分补传判断是否合格 不合格补传项目结束
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
judgeTask.addTask(async () => {
await this.endProject(xmdm)
}, {
isDelay: true
})
currentProject.isEnd = true;
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
}
judgeTask.addTask(async () => {
this.checkExamIsEnd()
})
return false;
} else {
return true
}
if (this.disConnectNum >= 5) {
console.info('surenjun', '123')
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
this.judgeUI.disConnectErrorOpen = true
}
this.disConnectNum = 0
return temp
}
// 考试过程照片
uploadProgressPhoto = async (ksxm: number) => {
const time = await GetCurrentTime();
const judgeUI = this.judgeUI
const plcData = this.plcData
const photoBase64 = await this.getPhoto();
const carInfo = AppStorage.get<CarInfoType>('carInfo');
const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, ksxm)
const judgeConfig_305: number = Reflect.get(judgeUI.judgeConfigObj, '305')
const drvexam: DrvexamType = {
lsh: judgeUI.lsh,
kskm: carInfo.examSubject,
ksxm: project.projectCodeCenter,
sfzmhm: judgeUI.idCard,
kchp: encodeURI(carInfo.plateNo),
zpsj: time,
zp: photoBase64,
cs: Math.floor((judgeConfig_305 == 0 ? plcData.gps.sd : plcData.sensor.cs) * 1.852),
ksdd: encodeURI(judgeUI.ksdd)
}
const data: RegulatoryInterfaceParams = {
xtlb: '17',
jkxlh: judgeUI.serialNumber,
jkid: '17C54',
drvexam
};
const temp: WR = await this.sendWriteObjectOut(data, this.filePath);
if (temp.code === 2300007) {
this.isJudgeDisConnect = true
}
promptWxCode('17C54', temp.code)
console.info(judgeTag, '上传照片 end')
}
constructor(judgeUI: JudgeUI) {
@ -1233,7 +1233,7 @@ export default class Judge {
const ksdd = judgeUI.ksdd
const projectsObj = judgeUI.projectsObj
const time = await GetCurrentTime();
const time = GetCurrentTime();
const project = this.getProjectInfo(ksxm);
//科目三夜间行驶.模拟灯光、上车准备出现通用评判ksxm为当前进行的项目
const checkProjects = ['17', '41', '1'];
@ -1394,7 +1394,7 @@ export default class Judge {
const passingScore = judgeUI.passingScore;
//TODO 断网考试结束补传
// await uploadDisConnectData();
const time = await GetCurrentTime();
const time = GetCurrentTime();
const photoBase64 = await getPhoto();
const d1 = ksjs.d1;
const d2 = ksjs.d2;

View File

@ -1,6 +1,5 @@
import { GetCurrentTime } from '../../../utils/Common'
import FileUtils from '../../../utils/FileUtils'
import { GetCurrentTime } from '../../../utils/Common';
import FileUtils from '../../../utils/FileUtils';
import common from '@ohos.app.ability.common';
interface StuInfo {
@ -23,23 +22,28 @@ export default class FileLog {
public fourAndOneLogDataFd: number = undefined
public fourAndOneLogDataBytesFd: number = undefined
public examLineDataFd: number = undefined
//后续文件路径待替换
private fileUtil: FileUtils
// 过程文件数据
public setExamProgressData = async (str: Object) => {
this.progressDataFd =
await this.fileUtil.editFile(`${this.folderPath}/exam_progress_data.txt`, JSON.stringify(str), this.progressDataFd);
await this.fileUtil.editFile(`${this.folderPath}/exam_progress_data.txt`, JSON.stringify(str),
this.progressDataFd);
}
// 无锡所接口数据
public setExamJudgeWuxiData = async (str:string) => {
this.examJudgeWuxiDataFd = await this.fileUtil.editFile(`${this.folderPath}/wuxi_exam_data.txt`, str, this.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:string) => {
public setExamJudgeWuxiProgressData = async (str: string) => {
this.examJudgeWuxiProgressDataFd =
await this.fileUtil.editFile(`${this.folderPath}/wuxi_progress_data.txt`, str, this.examJudgeWuxiProgressDataFd);
}
// plc文件数据
public setPlcProgressData = async (str: Object) => {
this.plcDataFd = await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str), this.plcDataFd);
this.plcDataFd =
await this.fileUtil.editFile(`${this.folderPath}/plc_data.txt`, JSON.stringify(str), this.plcDataFd);
}
// 过程评判json数据
public setExamJudgeData = async (str: string) => {
@ -49,24 +53,27 @@ export default class FileLog {
// 过程评判回调数据
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,
this.examJudgeCallbackDataFd);
}
// 过程评判日志调数据
public setExamJudgeLogData = async (str: string) => {
this.examJudgeLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str, this.examJudgeLogDataFd);
this.examJudgeLogDataFd =
await this.fileUtil.editFile(`${this.folderPath}/judge_log_data.txt`, str, this.examJudgeLogDataFd);
}
// 设置四合一画面数据
public setFourAndOneLogData = async (str: string) => {
this.fourAndOneLogDataFd = await this.fileUtil.editFile(`${this.folderPath}/four_one_log_data.txt`, str, this.fourAndOneLogDataFd);
this.fourAndOneLogDataFd =
await this.fileUtil.editFile(`${this.folderPath}/four_one_log_data.txt`, str, this.fourAndOneLogDataFd);
}
public setFourAndOneLogDataBytes = async (str: string) => {
this.fourAndOneLogDataBytesFd =
await this.fileUtil.editFile(`${this.folderPath}/four_one_log_byte_data.txt`, str, this.fourAndOneLogDataBytesFd);
}
// 无锡所轨迹数据
public setExamLineData = async (plcStr:string) => {
public setExamLineData = async (plcStr: string) => {
const plcData = plcStr.split(',');
const time = await GetCurrentTime();
const time = GetCurrentTime();
const lineData = [
/*帧头*/time,
/*卫星时间*/time,
@ -94,23 +101,23 @@ export default class FileLog {
/*结束符*/ time,
];
this.examLineDataFd =
await this.fileUtil.editFile(`${this.folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData),this.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) => {
this.stuInfo = stuInfo;
const time = await GetCurrentTime()
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}`);
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) {
constructor(context: common.UIAbilityContext) {
const fileUtil = new FileUtils(context)
this.fileUtil = fileUtil

View File

@ -42,7 +42,7 @@ export async function startRecordVideo(param: VideoConfig, td: number, context:
console.log(VideoTag, `Rtsprecord startRecordVideo begin`, video_uri);
const num = Math.floor(Math.random() * 10000)
let fileName: string
const time = await GetCurrentTime()
const time = GetCurrentTime()
const date = time.split(' ')[0]
fileName = !path ? `${date}_movie_record${num}.mp4` : `${date}_${path}_${index || num}.mp4`;
let recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, date);
@ -168,7 +168,7 @@ export async function takePhoto(param: VideoConfig, context: common.UIAbilityCon
});
} else {
return new Promise<takePhotoParam>(async (resolve, reject) => {
const time = await GetCurrentTime()
const time = GetCurrentTime()
const date = time.split(' ')[0]
let dirName = dir ? dir : date
rtsp_server.getVideoSnapshot(context, video_uri, fileName, dirName, true,