fix: 更新多个组件中的类型声明和逻辑,提升代码一致性

This commit is contained in:
wangzhongjie 2025-04-09 14:22:27 +08:00
parent e69b09dc4a
commit 4330fcfd5f
5 changed files with 166 additions and 162 deletions

View File

@ -5,6 +5,7 @@ import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model';
import { GetSyncData } from '../utils/table/Operation';
import { GetCurrentTime } from '../utils/Common';
import FileUtils from '../utils/FileUtils';
import common from '@ohos.app.ability.common';
let baseHost: string = AppStorage.get<string>('host');
@ -26,7 +27,9 @@ interface WR {
}
// 通用监管接口
export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath?: string): Promise<WR> {
export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath: string,
context: common.UIAbilityContext): Promise<WR> {
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
if (singlePlay) {
return { code: 1 }
@ -52,7 +55,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath
const isJGNew: boolean = AppStorage.get<boolean>('isJGNew')
//新监管调用
if (isJGNew) {
return await writeObjectOutNew(params, filePath)
return await writeObjectOutNew(params, filePath, context)
}
params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(drvexam.zp)
@ -73,7 +76,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath
}
//对象转换成xml
JGHOST = AppStorage.get<string>("JGHOST")
JGHOST = AppStorage.get<string>("JGHOST") || ""
const temp = await request<object>({
host: JGHOST,
url: '/dems_ws/services/TmriOutAccess?wsdl',
@ -132,7 +135,7 @@ interface UploadExamProgressDataParams {
// 过程文件上传
export async function uploadExamProgressData(params: UploadExamProgressDataParams) {
// const singlePlay = globalThis.singlePlay
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) {
return
}
@ -169,7 +172,7 @@ interface UploadExamProgressDataParams2 {
export async function uploadExamProgressData2(params: UploadExamProgressDataParams2) {
// const singlePlay = globalThis.singlePlay
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) {
return
}
@ -204,7 +207,7 @@ interface UploadExamMileage {
// 上传考试里程
export async function uploadExamMileage(params: UploadExamMileage) {
// const singlePlay = globalThis.singlePlay
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) {
return
@ -231,7 +234,7 @@ export async function uploadExamMileage(params: UploadExamMileage) {
// 上传考试成绩
export async function uploadExamGrade(params: ESObject) {
// const singlePlay = globalThis.singlePlay
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) {
return
}

View File

@ -28,8 +28,9 @@ interface WR {
code: number
}
export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, filePath: string): Promise<WR> {
const context: common.UIAbilityContext = AppStorage.get('context')
export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, filePath: string,
context: common.UIAbilityContext): Promise<WR> {
// const context: common.UIAbilityContext = AppStorage.get('context')
const fileUtil = new FileUtils(context);
const basic = await getBasicConfig(data.jkid);
const params = await getParams(data.jkid, data.drvexam);

View File

@ -172,6 +172,7 @@ struct UserInfo {
}
}
private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
private title = ''
private type = '2'
errorDialog: CustomDialogController = new CustomDialogController({
@ -199,7 +200,6 @@ struct UserInfo {
}
}
private avPlayer!: VoiceAnnounce
private context = getContext(this) as common.UIAbilityContext;
private labelBlocks: LabelBlockType[] = [
{ label: '考生姓名', key: 'xm' },
{ label: '身份证号', key: 'sfzmhm' },
@ -1045,7 +1045,7 @@ struct UserInfo {
jkid: '17C51',
}
console.info('surenjunjianguan', JSON.stringify(param))
const temp = await writeObjectOut(param);
const temp = await writeObjectOut(param, "", this.context);
AppStorage.setOrCreate('lsh', this.currentUser.lsh)
this.examinerLoginInfo.ksyh = this.currentUser.ksy1sfzmhm
AppStorage.setOrCreate('examinerInfo', this.examinerLoginInfo)

View File

@ -191,7 +191,7 @@ export default struct DeductedPopup {
kssj: time
},
}
const code = await writeObjectOut(beginData)
const code = await writeObjectOut(beginData, "", this.context)
//TODO code待处理
// if (code == 1) {
//
@ -223,7 +223,7 @@ export default struct DeductedPopup {
ksdd: decodeURI(this.ksdd)
}
};
const code = await writeObjectOut(photoData);
const code = await writeObjectOut(photoData, "", this.context);
console.info('surenjun uploadProgressPhoto end',)
}
@ -250,7 +250,7 @@ export default struct DeductedPopup {
kfsj: time
}
}
const code = await writeObjectOut(kfData);
const code = await writeObjectOut(kfData, "", this.context);
}
// 项目结束
@ -273,7 +273,7 @@ export default struct DeductedPopup {
jssj: time
}
}
const code = await writeObjectOut(endProjectData);
const code = await writeObjectOut(endProjectData, "", this.context);
}
//考试结束
@ -297,7 +297,7 @@ export default struct DeductedPopup {
dwlc: '',
}
}
const code = await writeObjectOut(endData);
const code = await writeObjectOut(endData, "", this.context);
}
//获取sysset表数据

View File

@ -179,6 +179,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服务序列号
@ -226,60 +258,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 () => {
@ -443,38 +421,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;
@ -513,9 +459,9 @@ export default class Judge {
}
//本地轨迹回放地址
private trajectoryPath: string
//当前科目二的考试项目
// private currentKm2ItemsObj: any
private isTrajectoryOpen: boolean;
//当前科目二的考试项目
// 调代理接口是否断网了
private isJudgeDisConnect: boolean;
// 断网数据补传
@ -527,9 +473,70 @@ export default class Judge {
const examDataStr = await this.fileUtil.readFile(`${folderPath}/wuxi_dis_progress_data.txt`);
const examDataArr = examDataStr.split('\n');
for (let examDataStr of examDataArr) {
const code = await writeObjectOut(JSON.parse(examDataStr));
const code = await writeObjectOut(JSON.parse(examDataStr), "", this.context);
}
}
// 考试过程照片
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, this.context);
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');
@ -599,66 +606,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 = 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) {