From 1fb5fa23b9ed498cc7977b7cae849c1d38f0e1ce Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Fri, 17 Oct 2025 10:02:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=A6=E5=92=8C=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 4 +- entry/src/main/ets/pages/Judge.ets | 5 +- .../ets/pages/Judge/SmallJudgeBusiness.ets | 6 +-- entry/src/main/ets/pages/UserInfo.ets | 25 +++++---- entry/src/main/ets/utils/Common.ets | 54 ++++++++++++------- entry/src/main/ets/utils/SerialPort.ets | 18 +++---- entry/src/main/ets/utils/UdpUtils.ets | 2 +- .../ets/utils/business/CenterUdpBusiness.ets | 2 +- .../ets/utils/business/JudgeUdpBusiness.ets | 2 - entry/src/main/ets/utils/table/Operation.ets | 5 +- .../ets/workers/DifferentialCorrection.ets | 12 ++--- 11 files changed, 79 insertions(+), 56 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index a378740..00c3c80 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,9 +5,9 @@ "name": "default", "material": { "certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.cer", - "storePassword": "0000001BD807731D6FB9F044E3DF0E0429F4BB4214FE1608E25B4197041FBF36DDA3C6760585312F2864B6", + "storePassword": "0000001B42BCAC6B534ABB3B488F5C45764278201EE92A007F988939EC561EEB8ED64F737B8A11A7A72A1E", "keyAlias": "debugKey", - "keyPassword": "0000001BFA38BF5235541496B5FF9ED9FFA764AB53FABC873D21DC230060209C2FF24ACE5DA09413B0C138", + "keyPassword": "0000001B2A149F63C38A6F5B972EC903EB0ADAB7978BA6C33B8E460C7353BD0BC2248776AB2FD2AE009A98", "profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p7b", "signAlg": "SHA256withECDSA", "storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p12" diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index 9629a0d..de951f8 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -427,7 +427,8 @@ export struct JudgePage { const carlistArr = info.carlist === '' ? [] : (decodeURI(info.carlist || "").split(',') || []); const newKey = key.split('~').join('_') const xmdm = Number(key.split('~')[0]) - const currentProject: ProjectInfo = Reflect.get(this.projectsObj, xmdm) + const data: ProjectInfos = JSON.parse(JSON.stringify(this.projectsObj)) + const currentProject: ProjectInfo = Reflect.get(data, xmdm) if (currentProject && (carlistArr.length == 0 || carlistArr.includes(this.carlist))) { Reflect.set(this.itemInfoObj!, newKey, { modelKey: newKey, @@ -461,7 +462,7 @@ export struct JudgePage { const examItems: string | undefined = currentParams?.examItems; // 2024-01-03 16:29:26;0;20300,;2,4^2,4;null; if (examItems !== '' && examItems !== undefined) { - dConsole.info(JudgeTag, 'surenjun examItems=>', JSON.stringify(examItems)) + dConsole.info(JudgeTag, 'surenjun examItems=>', examItems) const examItemsArrs = examItems.split(';'); const startTime = examItemsArrs[0] const ddxkKsxmArr = examItemsArrs[2]?.split(',').filter(item => item) || [] diff --git a/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets b/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets index 93fa62c..de3cc22 100644 --- a/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets +++ b/entry/src/main/ets/pages/Judge/SmallJudgeBusiness.ets @@ -99,11 +99,12 @@ export class SmallJudge extends BaseJudge implements BaseJudgeImpl { public async GetJudgeInitData(context: common.UIAbilityContext, markRuleListObj: object, carType: string, carName: string, systemparmArr: SYSTEM_PARAM[], carinfoArr: CAR_INFO[], examSubject: string, itemInfoObj: ItemInfos, judgeConfig: SyssetConfig[], carlist: string, mapPointArr: MAPPOINT[], mapPointItemArr: MAPITEMPOINTITEM[]) { const carInfo = AppStorage.get('carInfo'); const examType = carInfo?.examSubject == '2' ? 'km2' : 'km3' - + dConsole.log(JudgeTag, "itemInfoObj", itemInfoObj) let allitems: ItemInfo[] = []; if (examSubject == '2' && itemInfoObj) { allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => { - const cdsb: CDSBInfo = Reflect.get(itemInfoObj, cdsbKey); + // const cdsb: CDSBInfo = Reflect.get(itemInfoObj, cdsbKey); + const cdsb: CDSBInfo = Object.entries(itemInfoObj).find((arr: Array) => arr[0] === cdsbKey)![1] const model = GetModelData(`${examType}/${cdsb.modelKey}.txt`, context) const temp: ItemInfo = { xmdm: cdsb?.xmdm || 0, @@ -298,7 +299,6 @@ export class SmallJudge extends BaseJudge implements BaseJudgeImpl { } public async JudgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) { - const isTrajectoryOpen = JudgeConfig.isTrajectoryOpen; const trajectoryPath = JudgeConfig.trajectoryPath; let strArr: string[] = []; diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index e56374b..8a024b3 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -156,14 +156,6 @@ struct UserInfoPage { @State singlePlay: boolean = false private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; private avPlayer!: VoiceAnnounce - private labelBlocks: LabelBlockType[] = [ - { label: '考生姓名', key: 'xm' }, - { label: '身份证号', key: 'sfzmhm' }, - { label: ' 流 水 号 ', key: 'lsh' }, - { label: '考试路线', key: 'ksxl' }, - { label: '待考次数', key: 'kssycs' }, - { label: '考试员名', key: 'ksy2' }, - ] //开始考试准备 prePareExam = async () => { dConsole.log(StartExamTag, 'prePareExam') @@ -180,9 +172,12 @@ struct UserInfoPage { if (this.singlePlay) { this.currentUser.id = '0' dConsole.log(StartExamTag, '开始考试3', this.currentUser) - SqlInsertTable('USER', [this.currentUser]).catch((e: BusinessError) => { - dConsole.log(StartExamTag, "error", JSON.stringify(e)) - }) + try { + // let data: Array = JSON.parse(JSON.stringify([this.currentUser])) + await SqlInsertTable('USER', [this.currentUser]) + } catch (e) { + dConsole.error(StartExamTag, '开始考试插入用户表失败', JSON.stringify(e)) + } // 初始化开始考试过程数据文件夹 InitializeExamProcessData(this.currentUser) dConsole.log(StartExamTag, '开始考试4') @@ -213,6 +208,14 @@ struct UserInfoPage { } } + private labelBlocks: LabelBlockType[] = [ + { label: '考生姓名', key: 'xm' }, + { label: '身份证号', key: 'sfzmhm' }, + { label: ' 流 水 号 ', key: 'lsh' }, + { label: '考试路线', key: 'ksxl' }, + { label: '待考次数', key: 'kssycs' }, + { label: '考试员名', key: 'ksy2' }, + ] async aboutToAppear() { this.avPlayer = new VoiceAnnounce(this.context); diff --git a/entry/src/main/ets/utils/Common.ets b/entry/src/main/ets/utils/Common.ets index 7ea88e5..ffbc43a 100644 --- a/entry/src/main/ets/utils/Common.ets +++ b/entry/src/main/ets/utils/Common.ets @@ -109,11 +109,11 @@ export function NumberToByteArray(number: number | string, len: number): number[ return arrBytes; } -/* - * 将字符串填充为指定长度的字符串,前面补0 - * @param str 要填充的字符串或数字 - * @param len 目标长度 - * @return 返回填充后的字符串 +/** + * 将字符串填充为指定长度的字符串,前面补0 + * @param str 要填充的字符串或数字 + * @param len 目标长度 + * @return 返回填充后的字符串 */ export function FillZero(str: string | number, len: number): string { str = str.toString(); @@ -176,10 +176,10 @@ export function DeepClone(target: T): T { return target; } -/* - * 检查文件或目录是否存在 - * @param path 文件或目录的路径 - * @return 返回一个 Promise,解析为 true 如果存在,否则为 false +/** + * 检查文件或目录是否存在 + * @param path 文件或目录的路径 + * @return 返回一个 Promise,解析为 true 如果存在,否则为 false */ export function IsExit(path: string): Promise { return new Promise((resolve, reject) => { @@ -222,6 +222,8 @@ export function CreateDir(path: string): Promise { /** * 写文件 + * @params fd 文件描述符 + * @params data 写入的数据 */ export function EditFile(fd: number, data: string): Promise { return new Promise((resolve, reject) => { @@ -252,10 +254,25 @@ export function CreateFile(path: string): Promise { }) } -/* - * 将秒数转换为灵活的时间格式(HH:MM:SS) - * @param seconds 要转换的秒数 - * @return 返回格式化后的时间字符串 +/** + * 读取文件内容 + * @params path 文件具体路径 + */ +export function ReadFileContent(path: string): Promise { + return new Promise((resolve, reject) => { + try { + const data = fs.readTextSync(path) + resolve(data) + } catch (e) { + reject(e) + } + }) +} + +/** + * 将秒数转换为灵活的时间格式(HH:MM:SS) + * @param seconds 要转换的秒数 + * @return 返回格式化后的时间字符串 */ export function FormatTimeFlexible(seconds: number): string { if (seconds < 0) { @@ -291,10 +308,10 @@ export function ApplyForAuthorization(context: Context, permissionList: Array { const permissions: Array = [ @@ -351,4 +368,5 @@ export const GetPhotoBase64 = async (context: common.UIAbilityContext): Promise< return '' } } -} \ No newline at end of file +} + diff --git a/entry/src/main/ets/utils/SerialPort.ets b/entry/src/main/ets/utils/SerialPort.ets index 5b972aa..eb24fc1 100644 --- a/entry/src/main/ets/utils/SerialPort.ets +++ b/entry/src/main/ets/utils/SerialPort.ets @@ -1,4 +1,3 @@ -import testNapi from '@ohos.hiserialsdk'; import HiSerialSDK from '@ohos.hiserialsdk'; import { SerialPortTag } from '../config'; @@ -8,7 +7,7 @@ import { SerialPortTag } from '../config'; */ export const OpenSerialPort = (serialPort: string) => { return new Promise((resolve, reject) => { - testNapi.SerialOpenAsync(serialPort, (value: number) => { + HiSerialSDK.SerialOpenAsync(serialPort, (value: number) => { if (value === -1) { console.error(SerialPortTag, "打开串口失败!") reject(-1) @@ -28,7 +27,7 @@ export const OpenSerialPort = (serialPort: string) => { export const InitSerialPortData = async (fd: number, speed: number) => { return new Promise((resolve, reject) => { - testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => { + HiSerialSDK.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => { // 0 成功 -1失败 if (value === 0) { console.log(SerialPortTag, "初始化成功!") @@ -49,9 +48,10 @@ export const InitSerialPortData = * @returns Promise 成功返回发送的字节数,失败返回-1 */ export const SendSerialPortData = (fd: number, data: number[]) => { - // console.log(SerialPortTag, "wzj-----发送数据") + console.log(SerialPortTag, "wzj-----发送数据") return new Promise((resolve, reject) => { - testNapi.SerialSendAsync(fd, data, (value: number) => { + HiSerialSDK.SerialSendAsync(fd, data, (value: number) => { + console.log(SerialPortTag, "发送数据完成!") if (value === -1) { console.error(SerialPortTag, "发送失败!") reject(-1) @@ -68,9 +68,9 @@ export const SendSerialPortData = (fd: number, data: number[]) => { * @returns Promise 成功返回接收到的数据,失败返回-1 */ export const ReceiveSerialPortData = (fd: number, timeout: number,) => { - // console.log(SerialPortTag, "wzj-----接受数据") + console.log(SerialPortTag, "wzj-----接受数据") return new Promise((resolve) => { - testNapi.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => { + HiSerialSDK.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => { resolve(value) }) }) @@ -78,13 +78,13 @@ export const ReceiveSerialPortData = (fd: number, timeout: number,) => { // 主动接受数据 export const ReceiveSerialPortDataBySelf = (fd: number, callback: Function) => { - testNapi.SerialListenCallbackSet(fd, callback) + HiSerialSDK.SerialListenCallbackSet(fd, callback) } // 取消主动接受 export const CancelReceiveSerialPortData = async (fd: number) => { return new Promise((resolve, reject) => { - let result: number = testNapi.SerialListenCallbackCancel(fd) + let result: number = HiSerialSDK.SerialListenCallbackCancel(fd) if (result === 0) { resolve(true) } else { diff --git a/entry/src/main/ets/utils/UdpUtils.ets b/entry/src/main/ets/utils/UdpUtils.ets index 8b1a70d..35e7a1a 100644 --- a/entry/src/main/ets/utils/UdpUtils.ets +++ b/entry/src/main/ets/utils/UdpUtils.ets @@ -82,7 +82,7 @@ export default class UdpClient { address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1 } }).then(res => { - console.log(UDPTag, "udp发送成功", JSON.stringify(res)) + // console.log(UDPTag, "udp发送成功", JSON.stringify(res)) }).catch((e: BusinessError) => { console.error(UDPTag, "udp发送失败", JSON.stringify(e)) }) diff --git a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets index e0f1bf3..7359ce0 100644 --- a/entry/src/main/ets/utils/business/CenterUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/CenterUdpBusiness.ets @@ -43,7 +43,7 @@ class CenterUDPBusiness { console.log(CenterUdpTag, "心跳", JSON.stringify(this.carInfo)) // 组装消息,一秒发送一次 this.timer = setInterval(() => { - console.log(CenterUdpTag, "发送心跳") + // console.log(CenterUdpTag, "发送心跳") // 生成流水号 SerialNumberInstance.generate() // console.log(CenterUdpTag, "流水号生成") diff --git a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets index 510828d..98586d1 100644 --- a/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets +++ b/entry/src/main/ets/utils/business/JudgeUdpBusiness.ets @@ -19,8 +19,6 @@ import { SerialNumberInstance } from '../SerialNumber'; import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils'; import { testKm2Items, testKm3Items } from '../../mock'; -// import { examCalcGpsDistance } from '../../pages/Judge/JudgeUtils'; - class JudgeUdpBusiness { private static instance: JudgeUdpBusiness diff --git a/entry/src/main/ets/utils/table/Operation.ets b/entry/src/main/ets/utils/table/Operation.ets index a81d49e..d216c17 100644 --- a/entry/src/main/ets/utils/table/Operation.ets +++ b/entry/src/main/ets/utils/table/Operation.ets @@ -34,7 +34,10 @@ export function SqlInsertTable(tableName: string, data: Array, delFl const columns: string = columnsData?.filter((column) => column !== "id").join(",") || ""; const values = data.map(item => { const value = columnsData?.filter(column => column !== "id") - .map((column) => `'${Reflect.get(item, column) || ""}'`) + .map((column) => { + // return `'${Reflect.get(item, column) || ""}'` + return `'${Object.entries(item).find((keyArr: Array) => keyArr[0] === column)?.[1] || ""}'` + }) .join(",") return `(${value})` }).join(",") diff --git a/entry/src/main/ets/workers/DifferentialCorrection.ets b/entry/src/main/ets/workers/DifferentialCorrection.ets index f33117b..e86f5f7 100644 --- a/entry/src/main/ets/workers/DifferentialCorrection.ets +++ b/entry/src/main/ets/workers/DifferentialCorrection.ets @@ -1,6 +1,6 @@ // 处理worker线程的消息tcp拿差分改正数,udp给后置机 import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; -import { WorkerTag } from '../config'; +import { SerialPortTag, WorkerTag } from '../config'; import { CenterCallBackMsgType, EnvironmentConfigurationType, @@ -10,14 +10,14 @@ import { } from '../model'; import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; import { DifferentialSignal } from '../utils/business/DifferentialSignal'; +import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness'; import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness'; import { SerialPortService } from '../utils/business/SerialPortService'; const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - console.log(WorkerTag, `Worker received message: ${e.data}`); + console.log(WorkerTag, `Worker收到主线程消息: ${e.data}`) const result: WorkerMessage = JSON.parse(e.data); initFn(result) // TODO 内部已经实现,外部未实现 @@ -39,7 +39,7 @@ workerPort.onmessage = (e: MessageEvents) => { // 初始化函数 function initFn(result: WorkerMessage) { // 初始化差分校正TCP - DifferentialSignal.init(result.config); + DifferentialSignal.init(result.config) // 定时发送TCP消息 DifferentialSignal.sendData() // 初始化后置机UDP @@ -70,7 +70,7 @@ function getDataFn(config: EnvironmentConfigurationType) { // 需要观察 // console.log(WorkerTag, "后置机消息", data) const res = await SerialPortService.getData() - // console.log(SerialPortTag, "档位原始数据", res) + console.log(SerialPortTag, "档位原始数据", res) if (res.length > 0) { const dataArray = data.split(","); // 替换data的第28位 @@ -113,7 +113,7 @@ function closedFn(result: WorkerMessage) { workerPort.onmessageerror = (e: MessageEvents) => { - console.log(WorkerTag, `Worker received message error: ${e.data}`); + console.log(WorkerTag, `Worker received message error: ${e.data}`) }