From 0d6b3c7c07d3349516e05c15cb1940093b43af64 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Fri, 21 Feb 2025 15:38:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8E=E5=8D=97=E5=90=8E=E7=BD=AE?= =?UTF-8?q?=E6=9C=BA=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/api/judgeNew.ts | 36 +++++++++++-------- .../ets/common/utils/UdpClientByCenter.ts | 23 ++++-------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/entry/src/main/ets/api/judgeNew.ts b/entry/src/main/ets/api/judgeNew.ts index 9fac6e5d..70289ca0 100644 --- a/entry/src/main/ets/api/judgeNew.ts +++ b/entry/src/main/ets/api/judgeNew.ts @@ -1,8 +1,8 @@ import { getSyncData } from '../common/service/initable'; -import request from "../common/utils/request" -let baseHost = globalThis.host; +import request from '../common/utils/request'; import FileUtil from '../common/utils/File'; -import FileLog from '../pages/judgeSDK/utils/fileLog'; + +let baseHost = globalThis.host; //监管接口序列号映射 const gjxlhObj = { @@ -14,28 +14,34 @@ const gjxlhObj = { '17C56': '02-21-000014', } -interface WR{ - message?:string - code:number +interface WR { + message?: string + code: number } -export default async function writeObjectOutNew(data,filePath): Promise { +export default async function writeObjectOutNew(data, filePath): Promise { const fileUtil = new FileUtil(globalThis.context); const {jkid , drvexam} = data; const basic = await getBasicConfig(jkid); const params = await getParams(jkid, drvexam); const {wglb,jkxlh,glbm,jgbh,sjbs} = basic; - if(filePath){ - await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify({ - wglb,jkxlh,glbm,jgbh,sjbs, - data:params.data, - file:{...params.file,param:[]}, + if (filePath) { + await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({ + wglb, + jkxlh, + glbm, + jgbh, + sjbs, + data: params.data, + file: { + ...params.file, param: [] + }, })); } // let connectTimeout = sjbs === '02-21-000014' ?60000:1 - console.info('surenjun','调用新监管') + console.info('surenjun', '调用新监管') let temp try { temp = await request({ @@ -69,8 +75,8 @@ export default async function writeObjectOutNew(data,filePath): Promise { temp = e } console.log("temp message: ", JSON.stringify(temp)) - if(filePath){ - await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`); + if (filePath) { + await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`); } return temp diff --git a/entry/src/main/ets/common/utils/UdpClientByCenter.ts b/entry/src/main/ets/common/utils/UdpClientByCenter.ts index c8794029..e16cf0a8 100644 --- a/entry/src/main/ets/common/utils/UdpClientByCenter.ts +++ b/entry/src/main/ets/common/utils/UdpClientByCenter.ts @@ -13,13 +13,13 @@ * limitations under the License. */ +// @ts-ignore import socket, { UDPSocket } from '@ohos.net.socket'; import { Array2Byte, dateFormat, fillZero, string2Bytes } from '../utils/tools'; import FileUtil from '../../common/utils/File'; import prompt from '@ohos.prompt'; import promptAction from '@ohos.promptAction'; import { getUDP } from './GlobalUdp'; -import UdpByOne from './UdpByOne'; const TAG = '[UdpDemo.UdpClient]' @@ -47,7 +47,6 @@ export default class UdpClientByCenter { private isWorking: Boolean = false private plcUdpError = false; private initParam - private UPDOne: any constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { this.localIp = udplocalIp @@ -58,7 +57,6 @@ export default class UdpClientByCenter { } this.udp = socket.constructUDPSocketInstance(); this.initPath() - this.UPDOne = new UdpByOne() } getStatus() { @@ -146,14 +144,14 @@ export default class UdpClientByCenter { //length消息体bufferlength id消息类型id bodyStr消息体string // setMsyBody(id,bodyByte){ - setMsgHead({ id, list, placeId=62, carNo=489 }) { + setMsgHead({id, list, placeId=62, carNo=489}) { let a = string2Bytes(`${id}${fillZero(placeId, 3)}`, 2 * 8); let b = string2Bytes(`${fillZero(carNo, 4)}${globalThis.lshNo}`, 4 * 8); let c = string2Bytes(list.length, 2 * 8); return [...a, ...b, ...c]; } - setMsgBody({ id, list }) { + setMsgBody({id,list}) { let tmpList = [] tmpList = list @@ -257,16 +255,10 @@ export default class UdpClientByCenter { list.push(arr[i]) } this.stashFn({ - id, - length, - body: list, - sendId: this.sendId + id, length, body: list, sendId: this.sendId }) callback({ - id, - length, - body: list, - sendId: this.sendId + id, length, body: list, sendId: this.sendId }) @@ -298,15 +290,12 @@ export default class UdpClientByCenter { }) } - // TODO 赋值onMessage_1 //plc onMessage_1(callback?) { this.onMessage_1Callback = callback; - this.UPDOne.receiveMsg(callback); - // this.udp && this.udp.on('message', this.message_1Fn); + this.udp && this.udp.on('message', this.message_1Fn); } - closeMessage_1() { console.info('surenjun', 'getUDP关闭udp message监听事件') this.udp.off('message', this.message_1Fn);