refactor: 移除未使用的工具方法,优化代码结构和导入逻辑
This commit is contained in:
		
							parent
							
								
									c4623c8345
								
							
						
					
					
						commit
						89db5301ec
					
				| @ -1,11 +1,11 @@ | ||||
| import request from '../utils/Request'; | ||||
| import { getCurrentTime } from '../common/utils/tools'; | ||||
| import { getSyncData } from '../common/service/initable'; | ||||
| import writeObjectOutNew from './judgeNew'; | ||||
| import FileUtil from '../common/utils/File'; | ||||
| import http from '@ohos.net.http'; | ||||
| import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model'; | ||||
| import { GetSyncData } from '../utils/table/Operation'; | ||||
| import { GetCurrentTime } from '../utils/Common'; | ||||
| 
 | ||||
| let baseHost: string = AppStorage.get('host'); | ||||
| 
 | ||||
| @ -209,7 +209,7 @@ export async function uploadExamMileage(params: UploadExamMileage) { | ||||
|   if (singlePlay) { | ||||
|     return | ||||
|   } | ||||
|   const time = await getCurrentTime() | ||||
|   const time = await GetCurrentTime() | ||||
|   return request<object>({ | ||||
|     url: '/der2/services/exam/uploadExamMileage.ws', | ||||
|     data: `<?xml version="1.0" encoding="UTF-8"?> | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| import promptAction from '@ohos.promptAction' | ||||
| import router from '@ohos.router' | ||||
| import { dateFormat } from '../utils/tools' | ||||
| import FileUtil from '../../common/utils/File' | ||||
| import { deleteAllFileByPiC, takePhoto } from '../../service/videoService' | ||||
| import { | ||||
|  | ||||
| @ -1,5 +1,4 @@ | ||||
| import { initCenterCache, initCenterCacheByKSPT, initEsModel, initialization } from '../../api/index'; | ||||
| import { dateFormat } from '../utils/tools'; | ||||
| import AccountTable from '../database/tables/AccountTable'; | ||||
| import MA_MARKRULE from '../constants/MA_MARKRULE'; | ||||
| import MA_SYSTEMPARM from '../constants/MA_SYSTEMPARM'; | ||||
| @ -401,7 +400,7 @@ export async function upDataZhongxinginitialization(param) { | ||||
| 
 | ||||
|         for (let key in res.initializationRsp.body) { | ||||
|           if (!centerToMap[key]) { | ||||
|               continue | ||||
|             continue | ||||
|           } | ||||
|           const data = await setSyncCenterSqlData(key, res, param) | ||||
|           if (!data) { | ||||
|  | ||||
| @ -1,74 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * @file 日期工具 | ||||
|  */ | ||||
| 
 | ||||
| const NINE = 9; // 这是数字9 | ||||
| 
 | ||||
| export default class DateTimeUtil { | ||||
|   /** | ||||
|    * 时分秒 | ||||
|    */ | ||||
|   getTime(): string { | ||||
|     const DATETIME = new Date(); | ||||
|     return this.concatTime( | ||||
|       DATETIME.getHours(), | ||||
|       DATETIME.getMinutes(), | ||||
|       DATETIME.getSeconds() | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 年月日 | ||||
|    */ | ||||
|   getDate(): string { | ||||
|     const DATETIME = new Date(); | ||||
|     return this.concatDate( | ||||
|       DATETIME.getFullYear(), | ||||
|       DATETIME.getMonth() + 1, | ||||
|       DATETIME.getDate() | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 日期不足两位补充0 | ||||
|    * @param value-数据值 | ||||
|    */ | ||||
|   fill(value: number): string { | ||||
|     return (value > NINE ? '' : '0') + value; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 年月日格式修饰 | ||||
|    * @param year | ||||
|    * @param month | ||||
|    * @param date | ||||
|    */ | ||||
|   concatDate(year: number, month: number, date: number): string { | ||||
|     return `${year}${this.fill(month)}${this.fill(date)}`; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 时分秒格式修饰 | ||||
|    * @param hours | ||||
|    * @param minutes | ||||
|    * @param seconds | ||||
|    */ | ||||
|   concatTime(hours: number, minutes: number, seconds: number): string { | ||||
|     return `${this.fill(hours)}${this.fill(minutes)}${this.fill(seconds)}`; | ||||
|   } | ||||
| } | ||||
| @ -1,5 +0,0 @@ | ||||
| export default { | ||||
|   comoonfileWriteAddress:'/mnt/hmdfs/100/account/device_view/local/files', | ||||
|   videoSavePath:'/mnt/hmdfs/100/account/device_view/local/files/Videos/', | ||||
|   picSavePath:'/mnt/hmdfs/100/account/device_view/local/files/Pictures/' | ||||
| } | ||||
| @ -2,8 +2,6 @@ | ||||
| import UdpClientByCenter from './UdpClientByCenter'; | ||||
| import { getChuankouFn } from '../../common/service/indexService'; | ||||
| import FileUtil from '../../common/utils/File'; | ||||
| import { GlobalConfig } from '../../config/index'; | ||||
| import { Array2Byte, string2Bytes } from './tools'; | ||||
| 
 | ||||
| export async function sendMsg(val) { | ||||
|   // globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
 | ||||
|  | ||||
| @ -1,45 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| import hilog from '@ohos.hilog'; | ||||
| 
 | ||||
| class Logger { | ||||
|   private domain: number; | ||||
|   private prefix: string; | ||||
|   private format: string = '%{public}s, %{public}s'; | ||||
| 
 | ||||
|   constructor(prefix: string) { | ||||
|     this.prefix = prefix; | ||||
|     this.domain = 0xff00; | ||||
|   } | ||||
| 
 | ||||
|   debug(...args: string[]): void { | ||||
|     hilog.debug(this.domain, this.prefix, this.format, args); | ||||
|   } | ||||
| 
 | ||||
|   info(...args: string[]): void { | ||||
|     hilog.info(this.domain, this.prefix, this.format, args); | ||||
|   } | ||||
| 
 | ||||
|   warn(...args: string[]): void { | ||||
|     hilog.warn(this.domain, this.prefix, this.format, args); | ||||
|   } | ||||
| 
 | ||||
|   error(...args: string[]): void { | ||||
|     hilog.error(this.domain, this.prefix, this.format, args); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export default new Logger('[Samples_Camera]'); | ||||
| @ -3,7 +3,6 @@ import hilog from '@ohos.hilog'; | ||||
| import { getTCP } from './GlobalTcp'; | ||||
| import prompt from '@ohos.prompt'; | ||||
| import FileUtil from './File'; | ||||
| import { dateFormat } from './tools'; | ||||
| import App from '@system.app'; | ||||
| 
 | ||||
| const TAG = 'socketTag[TcpDemo.TcpClient]' | ||||
| @ -13,8 +12,10 @@ export default class TcpClient { | ||||
|   private localIpPort: string = '' | ||||
|   private oppositeIp: string = '' | ||||
|   private oppositeIpPort: string = '' | ||||
|   private num: number = 0//重连次数
 | ||||
|   private tcpSendNum: number = 0//重连次数
 | ||||
|   private num: number = 0 | ||||
|   //重连次数
 | ||||
|   private tcpSendNum: number = 0 | ||||
|   //重连次数
 | ||||
|   private folderPath | ||||
| 
 | ||||
|   private tcp: any = null | ||||
| @ -36,7 +37,7 @@ export default class TcpClient { | ||||
|       //   PLC:`${TAG} tcpOnerror  ${JSON.stringify(err)}`,
 | ||||
|       // })
 | ||||
| 
 | ||||
|       AppStorage.setOrCreate('getCloseTcp',true) | ||||
|       AppStorage.setOrCreate('getCloseTcp', true) | ||||
| 
 | ||||
| 
 | ||||
|       console.log(TAG, 'getCloseTtcpOnerror', JSON.stringify(err)) | ||||
| @ -50,10 +51,9 @@ export default class TcpClient { | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|   bindTcp() { | ||||
|     this.writeLog({ | ||||
|       time:dateFormat(new Date()), | ||||
|       time: dateFormat(new Date()), | ||||
|       message: `${TAG} tcpbind localIp${this.localIp} ${this.localIpPort}`, | ||||
|     }) | ||||
|     return new Promise((resolve, reject) => { | ||||
| @ -62,7 +62,7 @@ export default class TcpClient { | ||||
|       }, err => { | ||||
|         if (err) { | ||||
|           this.writeLog({ | ||||
|             time:dateFormat(new Date()), | ||||
|             time: dateFormat(new Date()), | ||||
|             message: `${TAG} tcpbind error ${JSON.stringify(err)}`, | ||||
|           }) | ||||
|           setTimeout(async () => { | ||||
| @ -87,8 +87,8 @@ export default class TcpClient { | ||||
| 
 | ||||
|   connectTcp() { | ||||
|     this.writeLog({ | ||||
|       time:dateFormat(new Date()), | ||||
|       message: `${TAG} tcpConnect oppositeIp ${ this.oppositeIp} ${this.oppositeIpPort}`, | ||||
|       time: dateFormat(new Date()), | ||||
|       message: `${TAG} tcpConnect oppositeIp ${this.oppositeIp} ${this.oppositeIpPort}`, | ||||
|     }) | ||||
|     return new Promise((resolve, reject) => { | ||||
|       let promise = this.tcp.connect({ | ||||
| @ -102,7 +102,7 @@ export default class TcpClient { | ||||
|         }, err => { | ||||
|           if (err) { | ||||
|             this.writeLog({ | ||||
|               time:dateFormat(new Date()), | ||||
|               time: dateFormat(new Date()), | ||||
|               message: `${TAG} TCPconnect error ${JSON.stringify(err)}`, | ||||
|             }) | ||||
|             setTimeout(() => { | ||||
| @ -112,12 +112,12 @@ export default class TcpClient { | ||||
|             return; | ||||
|           } | ||||
|         }); | ||||
|         AppStorage.setOrCreate('getCloseTcp',false) | ||||
|         AppStorage.setOrCreate('getCloseTcp', false) | ||||
|         resolve(true) | ||||
|       }).catch(err => { | ||||
|         console.log('socketTag','error') | ||||
|         console.log('socketTag', 'error') | ||||
|         this.writeLog({ | ||||
|           time:dateFormat(new Date()), | ||||
|           time: dateFormat(new Date()), | ||||
|           message: `${TAG} TCPconnect error2 ${JSON.stringify(err)}`, | ||||
|         }) | ||||
| 
 | ||||
| @ -142,14 +142,14 @@ export default class TcpClient { | ||||
|         reslove(true) | ||||
|       }).catch(err => { | ||||
|         this.tcpSendNum++ | ||||
|         if(!AppStorage.get('getCloseTcp')&&this.tcpSendNum>10){ | ||||
|         if (!AppStorage.get('getCloseTcp') && this.tcpSendNum > 10) { | ||||
|           setTimeout(async () => { | ||||
|             getTCP(true) | ||||
|           }, 3000) | ||||
|           this.tcpSendNum=0 | ||||
|           this.tcpSendNum = 0 | ||||
|           return | ||||
|         } | ||||
|         AppStorage.set('getCloseTcp',true) | ||||
|         AppStorage.set('getCloseTcp', true) | ||||
|         console.log(`${TAG} TCPsend error ${JSON.stringify(err)}`) | ||||
|         // this.writeLog({
 | ||||
|         //   time:dateFormat(new Date()),
 | ||||
| @ -166,7 +166,7 @@ export default class TcpClient { | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC:`${TAG} Tcponmessage`,
 | ||||
|       // })
 | ||||
|       AppStorage.setOrCreate('tcpUdpError',false) | ||||
|       AppStorage.setOrCreate('tcpUdpError', false) | ||||
|       // console.log('messageLengt',,value.message.length))
 | ||||
|       // console.log("on message, message:" + value.message+ ", remoteInfo:" )
 | ||||
|       if (value) { | ||||
| @ -179,10 +179,10 @@ export default class TcpClient { | ||||
|         callback && callback('') | ||||
|       } | ||||
|       clearInterval(globalThis.intervaltcp) | ||||
|       globalThis.intervaltcp=setInterval(()=>{ | ||||
|       globalThis.intervaltcp = setInterval(() => { | ||||
|         //程序断开
 | ||||
|         if (globalThis.tcpUdpError) { | ||||
|           console.log(TAG,'tcp信号丢失') | ||||
|           console.log(TAG, 'tcp信号丢失') | ||||
|           // getTCP()
 | ||||
|           prompt.showToast({ | ||||
|             message: 'tcp信号丢失', | ||||
| @ -190,24 +190,27 @@ export default class TcpClient { | ||||
|           }); | ||||
|         } | ||||
|         this.writeLog({ | ||||
|           time:dateFormat(new Date()), | ||||
|           time: dateFormat(new Date()), | ||||
|           message: `${TAG} tcp信号丢失`, | ||||
|         }) | ||||
|         AppStorage.setOrCreate('tcpUdpError',true) | ||||
|       },3000) | ||||
|         AppStorage.setOrCreate('tcpUdpError', true) | ||||
|       }, 3000) | ||||
|       // callback(value.message)
 | ||||
|     }); | ||||
|   } | ||||
|   async writeLog(param){ | ||||
| 
 | ||||
|   async writeLog(param) { | ||||
|     // const fileUtil = new FileUtil(globalThis.context)
 | ||||
|     // fileUtil.editFile(`${this.folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
 | ||||
|   } | ||||
|   async initPath(){ | ||||
| 
 | ||||
|   async initPath() { | ||||
|     return | ||||
|     const fileUtil = new FileUtil(globalThis.context) | ||||
|     const date=dateFormat(new Date).split(' ')[0] | ||||
|     const date = dateFormat(new Date).split(' ')[0] | ||||
|     this.folderPath = await fileUtil.initFolder(`/PLC/${date}`); | ||||
|   } | ||||
| 
 | ||||
|   offTcp(callback) { | ||||
|     console.log(TAG, 'tcpofff') | ||||
|     this.tcp.off('testTagofmessg', callback); | ||||
| @ -218,9 +221,9 @@ export default class TcpClient { | ||||
|       console.log(TAG, 'tcpClose') | ||||
|       let promise = this.tcp.close(); | ||||
|       promise.then(() => { | ||||
|         AppStorage.setOrCreate('getCloseTcp',true) | ||||
|         AppStorage.setOrCreate('getCloseTcp', true) | ||||
|         this.writeLog({ | ||||
|           time:dateFormat(new Date()), | ||||
|           time: dateFormat(new Date()), | ||||
|           message: `${TAG} tcp closeSuccess`, | ||||
|         }) | ||||
|         callback() | ||||
| @ -230,7 +233,7 @@ export default class TcpClient { | ||||
|           getTCP(true) | ||||
|         }, 9000) | ||||
|         this.writeLog({ | ||||
|           time:dateFormat(new Date()), | ||||
|           time: dateFormat(new Date()), | ||||
|           message: `${TAG} tcpclose error ${JSON.stringify(err)}`, | ||||
|         }) | ||||
| 
 | ||||
|  | ||||
| @ -15,21 +15,19 @@ | ||||
| 
 | ||||
| // @ts-ignore
 | ||||
| import socket, { UDPSocket } from '@ohos.net.socket'; | ||||
| import { Array2Byte } from '../utils/tools' | ||||
| import FileUtil from '../../common/utils/File' | ||||
| import { fillZero, string2Bytes } from '../utils/tools' | ||||
| 
 | ||||
| const TAG = '[UdpDemo.UdpClient]' | ||||
| import hilog from '@ohos.hilog'; | ||||
| import prompt from '@ohos.prompt' | ||||
| import promptAction from '@ohos.promptAction'; | ||||
| import { getUDP } from './GlobalUdp'; | ||||
| import { dateFormat } from '../utils/tools' | ||||
| import { getSyncData } from '../service/initable'; | ||||
| import App from '@system.app'; | ||||
| 
 | ||||
| 
 | ||||
| export default class UdpClientByCenter { | ||||
|   public currentValue: string = '' | ||||
|   private localIp: string = '' | ||||
|   private localIpPort: string = '' | ||||
|   private oppositeIp: string = '' | ||||
| @ -50,9 +48,6 @@ export default class UdpClientByCenter { | ||||
|   private isWorking: Boolean = false | ||||
|   private plcUdpError = false; | ||||
|   private initParam | ||||
|   private onMessage_1Callback: Function = () => { | ||||
|   } | ||||
|   public currentValue: string = '' | ||||
| 
 | ||||
|   constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { | ||||
|     this.localIp = udplocalIp | ||||
| @ -129,9 +124,6 @@ export default class UdpClientByCenter { | ||||
|     return view; | ||||
|   } | ||||
| 
 | ||||
|   //length消息体bufferlength   id消息类型id  bodyStr消息体string
 | ||||
|   // setMsyBody(id,bodyByte){
 | ||||
| 
 | ||||
|   // {id: 31,list:[0,1,'0000000000000'],carNo:489,placeId:62}
 | ||||
|   setWholeMsg(params) { | ||||
|     let head = this.setMsgHead(params); | ||||
| @ -144,6 +136,9 @@ export default class UdpClientByCenter { | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   //length消息体bufferlength   id消息类型id  bodyStr消息体string
 | ||||
|   // setMsyBody(id,bodyByte){
 | ||||
| 
 | ||||
|   setMsgHead({ id, list, placeId=62, carNo=489 }) { | ||||
|     let a = string2Bytes(`${id}${fillZero(placeId, 3)}`, 2 * 8); | ||||
|     let b = string2Bytes(`${fillZero(carNo, 4)}${AppStorage.get('lshNo')}`, 4 * 8); | ||||
| @ -399,6 +394,9 @@ export default class UdpClientByCenter { | ||||
|     }, 2000) | ||||
|   } | ||||
| 
 | ||||
|   private onMessage_1Callback: Function = () => { | ||||
|   } | ||||
| 
 | ||||
|   // initHeartSendMsg(param,context){
 | ||||
|   //     console.log('1111param',JSON.stringify(param))
 | ||||
|   //     this.initParam=param
 | ||||
|  | ||||
| @ -1,11 +1,8 @@ | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| import { Array2Byte, fillZero, string2Bytes, stringToASC } from '../../common/utils/tools'; | ||||
| import { testKm2Items, testKm3Items } from '../../pages/judgeSDK/dataTest/index'; | ||||
| import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig'; | ||||
| import { setJudgeUdp, setTopLineUdp } from './GlobalUdp'; | ||||
| import { convertGpsCoord2 } from '../utils/tools'; | ||||
| import { examCalcGpsDistance } from '../../pages/judgeSDK/api' | ||||
| import GetDistance from '../utils/GetDistance' | ||||
| 
 | ||||
| export const initJudgeUdp = async () => { | ||||
|   AppStorage.setOrCreate('serialIndex', 0) | ||||
|  | ||||
| @ -1,11 +0,0 @@ | ||||
| export default class SingleInterval{ | ||||
|   private interval:number=-1 | ||||
|   constructor(time:number,callback) { | ||||
|     this.interval = setInterval(()=>{ | ||||
|      callback() | ||||
|    },time||6000) | ||||
|   } | ||||
|   clear(){ | ||||
|     clearInterval(this.interval) | ||||
|   } | ||||
| } | ||||
| @ -1,278 +0,0 @@ | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| 
 | ||||
| // export function isSevenDaysAgo(date, days = 2) {
 | ||||
| //   const today = new Date(); // 当前日期
 | ||||
| //   const target = new Date(date); // 需要判断的日期
 | ||||
| //   console.info("listFile succeed1", JSON.stringify(target));
 | ||||
| //
 | ||||
| //   const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异
 | ||||
| //   const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数
 | ||||
| //   console.info("listFile succeed2", JSON.stringify(diffDays));
 | ||||
| //   // 如果差异天数正好是2,则原日期是当前日期的前2天
 | ||||
| //   console.log('diffDays', diffDays, days)
 | ||||
| //   return diffDays >= (Number(days));
 | ||||
| // }
 | ||||
| 
 | ||||
| // export async function writeLog(path,param){
 | ||||
| //   return
 | ||||
| //   const fileUtil = new FileUtil(globalThis.context)
 | ||||
| //   const date=dateFormat(new Date).split(' ')[0]
 | ||||
| //   const folderPath = await fileUtil.initFolder(`/${path}/${date}`);
 | ||||
| //   fileUtil.editFile(`${folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`)
 | ||||
| // }
 | ||||
| ///**时间格式化*/
 | ||||
| //export function dateFormat(fmt, date) {
 | ||||
| //    var ret;
 | ||||
| //    const opt = {
 | ||||
| //        "y+": date.getFullYear().toString(),        // 年
 | ||||
| //        "m+": (date.getMonth() + 1).toString(),     // 月
 | ||||
| //        "d+": date.getDate().toString(),            // 日
 | ||||
| //        "H+": date.getHours().toString(),           // 时
 | ||||
| //        "M+": date.getMinutes().toString(),         // 分
 | ||||
| //        "S+": date.getSeconds().toString()          // 秒
 | ||||
| //        // 有其他格式化字符需求可以继续添加,必须转化成字符串
 | ||||
| //    };
 | ||||
| //    for (var k in opt) {
 | ||||
| //        ret = new RegExp("(" + k + ")").exec(fmt);
 | ||||
| //        if (ret) {
 | ||||
| //            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
 | ||||
| //        };
 | ||||
| //    };
 | ||||
| //    return fmt;
 | ||||
| //}
 | ||||
| 
 | ||||
| /** | ||||
|  * 日期不足两位补 0 | ||||
|  * | ||||
|  * @param {string} value - 数据值 | ||||
|  * @return {string} - 日期不足两位补 0 | ||||
|  */ | ||||
| function fill(value: number) { | ||||
|   return (value > 9 ? '' : '0') + value; | ||||
| } | ||||
| 
 | ||||
| export function dateFormat(t) { | ||||
|   let year = t.getFullYear() | ||||
|   let month = t.getMonth() + 1 | ||||
|   let day = t.getDate() | ||||
|   let hours = t.getHours() | ||||
|   let minutes = t.getMinutes() | ||||
|   let seconds = t.getSeconds() | ||||
|   return year + "-" + fill(month) + "-" + fill(day) + " " + fill(hours) + ":" + fill(minutes) + ":" + fill(seconds); | ||||
| } | ||||
| 
 | ||||
| // export function dateVersionFormat(t) {
 | ||||
| //   let year = t.getFullYear()
 | ||||
| //   let month = t.getMonth() + 1
 | ||||
| //   let day = t.getDate()
 | ||||
| //   let hours = t.getHours()
 | ||||
| //   let minutes = t.getMinutes()
 | ||||
| //   let seconds = t.getSeconds()
 | ||||
| //   return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
 | ||||
| // }
 | ||||
| 
 | ||||
| 
 | ||||
| //同步时时间
 | ||||
| // export async function timeSynchronize() {
 | ||||
| //   let date = new Date();
 | ||||
| //   console.info('jiangsong1:timeSynchronization begin ');
 | ||||
| //
 | ||||
| //   let params = {
 | ||||
| //     time: dateFormat(date),
 | ||||
| //     deviceNo: AppStorage.get('deviceNo'),
 | ||||
| //     version: AppStorage.get('baseInfo').version,
 | ||||
| //     judgeVersion: AppStorage.get('baseInfo').judgeVersion
 | ||||
| //   }
 | ||||
| //   let res: any = await timeSynchronization(params)
 | ||||
| //   res = res.timeSynchronizationRsp;
 | ||||
| //   AppStorage.setOrCreate('timeInfo', res.body)
 | ||||
| //
 | ||||
| //
 | ||||
| //   return res;
 | ||||
| // }
 | ||||
| 
 | ||||
| // export async function setCurrentTime(): Promise<void> {
 | ||||
| //   let res = await timeSynchronize();
 | ||||
| //   let currentTime = res.head.time;
 | ||||
| //   let times = new Date(currentTime).getTime();
 | ||||
| //   console.log('jiangsong:times==' + times);
 | ||||
| //   try {
 | ||||
| //     await systemTime.setTime(times);
 | ||||
| //     // systemTime.setTime(times).then(() => {
 | ||||
| //     //   console.info(`Succeeded in setting time.`);
 | ||||
| //     // }).catch((error) => {
 | ||||
| //     //   console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
 | ||||
| //     // });
 | ||||
| //   } catch (e) {
 | ||||
| //     console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
 | ||||
| //   }
 | ||||
| // }
 | ||||
| enum timeType { | ||||
|   fulltime = 1 | ||||
| } | ||||
| 
 | ||||
| //获取当前时间并转化
 | ||||
| export async function getCurrentTime(type?: timeType): Promise<string> { | ||||
|   const date = await systemTime.getDate(); | ||||
|   const year = date.getFullYear(); | ||||
|   let month = date.getMonth() + 1; | ||||
|   month = month < 10 ? '0' + month : month; | ||||
|   let dates = date.getDate(); | ||||
|   dates = dates < 10 ? '0' + dates : dates; | ||||
|   let h = date.getHours(); | ||||
|   h = h < 10 ? '0' + h : h; | ||||
|   let m = date.getMinutes(); | ||||
|   m = m < 10 ? '0' + m : m; | ||||
|   let s = date.getSeconds(); | ||||
|   s = s < 10 ? '0' + s : s; | ||||
|   if (type === 1) { | ||||
|     return `${year}${month}${dates}${h}${m}${s}` | ||||
|   } else { | ||||
|     return `${year}-${month}-${dates} ${h}:${m}:${s}` | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| //获取时分秒毫秒
 | ||||
| // export async function getCurrentHourTime(): Promise<string> {
 | ||||
| //
 | ||||
| //   const date = await systemTime.getDate();
 | ||||
| //   const year = date.getFullYear();
 | ||||
| //   let month = date.getMonth() + 1;
 | ||||
| //   let h = date.getHours();
 | ||||
| //   h = h < 10 ? '0' + h : h;
 | ||||
| //   let m = date.getMinutes();
 | ||||
| //   m = m < 10 ? '0' + m : m;
 | ||||
| //   let s = date.getSeconds();
 | ||||
| //   s = s < 10 ? '0' + s : s;
 | ||||
| //   let ss = date.getMilliseconds();
 | ||||
| //   let nowSS = ''
 | ||||
| //   if (ss < 10) {
 | ||||
| //     nowSS = '00' + ss
 | ||||
| //   }
 | ||||
| //   if (ss >= 10 && ss < 100) {
 | ||||
| //     nowSS = '0' + s
 | ||||
| //   }
 | ||||
| //   return `${h}${m}${s}${nowSS || ss}`
 | ||||
| // }
 | ||||
| 
 | ||||
| //时间戳转日期
 | ||||
| // export function formatTime(time: number): string {
 | ||||
| //   const h = parseInt(time / 3600)
 | ||||
| //   const minute = parseInt(time / 60 % 60)
 | ||||
| //   const second = Math.ceil(time % 60)
 | ||||
| //
 | ||||
| //   const hours = h < 10 ? '0' + h : h
 | ||||
| //   const formatSecond = second > 59 ? 59 : second
 | ||||
| //   return `${hours > 0 ? `${hours}:` : `${hours}:`}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ?
 | ||||
| //     '0' + formatSecond : formatSecond}`
 | ||||
| //
 | ||||
| // }
 | ||||
| 
 | ||||
| 
 | ||||
| // 根据指定个数分割数组
 | ||||
| export function chunkArr(arr, size: number) { | ||||
|   //判断如果不是数组(就没有length),或者size没有传值,size小于1,就返回空数组
 | ||||
|   if (!arr.length || !size || size < 1) { | ||||
|     return [] | ||||
|   } | ||||
|   let [start, end, result] = [null, null, []] | ||||
|   for (let i = 0; i < Math.ceil(arr.length / size); i++) { | ||||
|     start = i * size | ||||
|     end = start + size | ||||
|     result.push(arr.slice(start, end)) | ||||
|   } | ||||
|   return result | ||||
| } | ||||
| 
 | ||||
| //对象深拷贝
 | ||||
| export function deepClone(target) { | ||||
|   // 如果是对象,且不是原始值null
 | ||||
|   if (typeof target === 'object' && target !== 'null') { | ||||
|     // 创建容器
 | ||||
|     const result = Array.isArray(target) ? [] : {}; | ||||
|     const keys = Object.keys(target); //注解二
 | ||||
|     // Object.keys()会过滤掉原型链上的属性
 | ||||
|     keys.forEach(key => { | ||||
|       result[key] = deepClone(target[key]) | ||||
|     }) | ||||
|     return result; | ||||
|   } | ||||
|   // 如果是原始值,则直接返回
 | ||||
|   return target; | ||||
| } | ||||
| 
 | ||||
| export function stringToASC(str) { | ||||
|   const tempStr = str + ''; | ||||
|   const strArr = tempStr.split(''); | ||||
|   return strArr.map(str => str.charCodeAt()) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| export function fillZero(str, len) { | ||||
|   str = str + ''; | ||||
|   if (str.length > len || !len) { | ||||
|     return str | ||||
|   } | ||||
| 
 | ||||
|   let num = len - str.length; | ||||
|   let zeroStr = ''; | ||||
|   for (var i = 0; i < num; i++) { | ||||
|     zeroStr = zeroStr + '0' | ||||
|   } | ||||
| 
 | ||||
|   return zeroStr + str; | ||||
| } | ||||
| 
 | ||||
| // 字符串转字节
 | ||||
| export function string2Bytes(number, len) { | ||||
|   let str = (Math.floor(+number)).toString(2); | ||||
|   if (str.length > len) { | ||||
|     console.log('数据长度不对~~'); | ||||
|     return | ||||
|   } | ||||
|   var byteString = fillZero(str, len); | ||||
| 
 | ||||
|   var arrBytes = new Array(); | ||||
|   for (var i = byteString.length; i > 0; ) { | ||||
|     let j = i - 8; | ||||
|     if (j < 0) { | ||||
|       j = 0 | ||||
|     } | ||||
|     var s = byteString.slice(j, i); | ||||
|     var v = parseInt(s, 2); | ||||
|     arrBytes.push(v); | ||||
|     i = i - 8 | ||||
| 
 | ||||
|   } | ||||
|   return arrBytes; | ||||
| } | ||||
| 
 | ||||
| //数组数据转字节
 | ||||
| export function Array2Byte(array) { | ||||
|   var buf = new ArrayBuffer(array.length); | ||||
|   var view = new Uint8Array(buf); | ||||
|   for (var i = 0; i != array.length; ++i) { | ||||
|     view[i] = array[i] & 0xFF; | ||||
|   } | ||||
|   return view; | ||||
| } | ||||
| 
 | ||||
| //经纬度转换
 | ||||
| export function convertGpsCoord2(num) { | ||||
|   const tempNum = Math.floor(num); | ||||
|   const du = Math.floor(tempNum / 100); | ||||
|   const fen = tempNum % 100 + num - tempNum; | ||||
|   return du + fen / 60 | ||||
| } | ||||
| 
 | ||||
| export function debounce(fn, delay) { | ||||
|   // 利用闭包定义定时器id变量存储
 | ||||
|   let timer = null; | ||||
|   return () => { | ||||
|     // 如果有值就清除定时器,重新计时
 | ||||
|     if (timer) { | ||||
|       clearTimeout(timer) | ||||
|     } | ||||
|     timer = setTimeout(fn, delay); | ||||
|   } | ||||
| } | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -3,7 +3,6 @@ import hilog from '@ohos.hilog'; | ||||
| import window from '@ohos.window'; | ||||
| import relationalStore from '@ohos.data.relationalStore' | ||||
| import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; | ||||
| import { Array2Byte } from '../common/utils/tools' | ||||
| import { GlobalConfig } from '../config/global' | ||||
| import { tcpUtil } from '../common/utils/TcpRequest'; | ||||
| import { initTable } from '../common/service/initable'; | ||||
| @ -30,7 +29,6 @@ export default class EntryAbility extends UIAbility { | ||||
| 
 | ||||
|   onDestroy() { | ||||
|     const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00] | ||||
|     const arrCloseBuffer = Array2Byte(arrClose).buffer | ||||
|     // TODO UDP缺失 | ||||
|     // globalThis?.lightLineUdp?.send(arrCloseBuffer); | ||||
|     hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); | ||||
|  | ||||
| @ -2,13 +2,13 @@ import router from '@ohos.router'; | ||||
| import { carConfigurationInfo, uploadExamCarCheckResult } from '../api/checkCar'; | ||||
| import TopLogo from './compontents/TopLogo'; | ||||
| import testNapi from '@ohos.hiserialsdk'; | ||||
| import { dateFormat } from '../common/utils/tools'; | ||||
| import { DwMapData, PassData, RealNumData, StackValueData, WarnFlagData, WarnFlagTipData } from '../mock'; | ||||
| import { BaseInfoType, RouteParamsType } from '../model/Common'; | ||||
| import { CarCheckDataType, CarConfigurationParams, CarInfoType } from '../model'; | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| import { SpzdType } from '../model'; | ||||
| import { voiceService } from '../utils/Voice'; | ||||
| import dayTs from '../utils/Date'; | ||||
| 
 | ||||
| @Entry | ||||
| @Component | ||||
| @ -282,7 +282,7 @@ struct Index { | ||||
|         } | ||||
|         let date = new Date(); | ||||
|         const data: CarCheckDataType = { | ||||
|           time: dateFormat(date), | ||||
|           time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"), | ||||
|           carId: this.carInfo.carId, | ||||
|           examinationRoomId: this.carInfo.examinationRoomId, | ||||
|           plateNo: this.carInfo.plateNo, | ||||
|  | ||||
| @ -1,7 +1,6 @@ | ||||
| import common from '@ohos.app.ability.common'; | ||||
| import router from '@ohos.router'; | ||||
| 
 | ||||
| import { getCurrentTime, string2Bytes } from '../common/utils/tools'; | ||||
| import { getEsCarModel, getSyncData, } from '../common/service/initable'; | ||||
| import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; | ||||
| import { initJudgeUdp } from '../common/utils/UdpJudge'; | ||||
| @ -9,7 +8,6 @@ import { judgeConfig } from './judgeSDK/utils/judgeConfig'; | ||||
| import { getTCP } from '../common/utils/GlobalTcp'; | ||||
| import promptAction from '@ohos.promptAction'; | ||||
| import errorMsgDialog from './compontents/errorMsgDialog'; | ||||
| import GetDistance from '../common/utils/GetDistance'; | ||||
| import imageBtn from './compontents/imageBtn'; | ||||
| import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | ||||
| import { BaseInfoType } from '../model/Common'; | ||||
| @ -20,6 +18,8 @@ import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| import { delPic } from '../utils/Video'; | ||||
| import { FileHelper } from '../utils/FileHelp'; | ||||
| import GetDistance from '../utils/business/GetDistance'; | ||||
| import { GetCurrentTime, NumberToByteArray } from '../utils/Common'; | ||||
| 
 | ||||
| 
 | ||||
| @Entry | ||||
| @ -427,16 +427,16 @@ struct Index { | ||||
|   } | ||||
| 
 | ||||
|   async heartMsg() { | ||||
|     const signNum = AppStorage.get('signNum') as Number | ||||
|     const statue = AppStorage.get('statue') as Number | ||||
|     const signNum = AppStorage.get('signNum') as number | ||||
|     const statue = AppStorage.get('statue') as number | ||||
|     const lsh = AppStorage.get('lsh') as String | ||||
|     const arr = [signNum || 0, statue || 1] | ||||
|     let tmpList: number[] = []; | ||||
|     tmpList.push(string2Bytes(arr[0], 1 * 8)[0]) | ||||
|     tmpList.push(string2Bytes(arr[1], 1 * 8)[0]) | ||||
|     tmpList.push(NumberToByteArray(arr[0], 1 * 8)[0]) | ||||
|     tmpList.push(NumberToByteArray(arr[1], 1 * 8)[0]) | ||||
|     const str = lsh || '0000000000000' | ||||
|     for (let i = 0; i < str.length; i++) { | ||||
|       tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0]) | ||||
|       tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0]) | ||||
|     } | ||||
|     // TODO 未改 | ||||
|     // const param = { | ||||
| @ -488,7 +488,7 @@ struct Index { | ||||
| 
 | ||||
|   async createAlbum() { | ||||
|     this.fileHelper = new FileHelper(); | ||||
|     const time = await getCurrentTime() | ||||
|     const time = await GetCurrentTime() | ||||
|     const date = time.split(' ')[0] | ||||
|     this.fileHelper.createAlbum('jt') | ||||
|     // this.fileHelper.createAlbum('2025-01-02') | ||||
|  | ||||
| @ -24,7 +24,6 @@ import { | ||||
|   SYSTEMPARMARR | ||||
| } from './judgeSDK/api/judgeSDK.d'; | ||||
| 
 | ||||
| import { chunkArr, getCurrentTime } from '../common/utils/tools'; | ||||
| import { getSyncData } from '../common/service/initable'; | ||||
| import { judgeConfig } from './judgeSDK/utils/judgeConfig'; | ||||
| import FileUtil from '../common/utils/File'; | ||||
| @ -47,6 +46,8 @@ import { | ||||
| } from '../model'; | ||||
| import { GetSyncData } from '../utils/table/Operation'; | ||||
| import dayTs from '../utils/Date'; | ||||
| import { GetCurrentTime } from '../utils/Common'; | ||||
| import { chunkArr } from './judgeSDK/utils/Common'; | ||||
| 
 | ||||
| @Entry | ||||
| @Component | ||||
| @ -158,17 +159,17 @@ struct Index { | ||||
|   } | ||||
| 
 | ||||
|   async aboutToAppear() { | ||||
|     const time = await getCurrentTime() | ||||
|     const time = await GetCurrentTime() | ||||
|     this.carInfo = AppStorage.get('carInfo') | ||||
|     this.singlePlay = AppStorage.get('singlePlay') | ||||
|     this.startTime = time.split(' ')[1] | ||||
|     this.startFullTime = await getCurrentTime(1); | ||||
|     this.startFullTime = await GetCurrentTime(1); | ||||
|     // this.startHourTime = await getCurrentHourTime() | ||||
|     this.startTime = dayTs().format("HHmmssSSS") | ||||
|     this.startExamTime = time | ||||
| 
 | ||||
|     setInterval(async () => { | ||||
|       this.time = await getCurrentTime(); | ||||
|       this.time = await GetCurrentTime(); | ||||
|       this.examTime += 1; | ||||
|     }, 1000); | ||||
|     //初始化数据库表 | ||||
| @ -808,7 +809,7 @@ struct Index { | ||||
|                 }) | ||||
| 
 | ||||
|                 //科目二 | ||||
|                 if (this.examSubject == 2) { | ||||
|                 if (this.examSubject == "2") { | ||||
|                   Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween }) { | ||||
|                     List({}) { | ||||
|                       ForEach(chunkArr(this.projects, 2), (item) => { | ||||
|  | ||||
| @ -1,11 +1,11 @@ | ||||
| import TopLogo from './compontents/TopLogo' | ||||
| import { registrationDeviceNo } from '../api/checkCar' | ||||
| import { dateFormat } from '../common/utils/tools' | ||||
| import deviceManager from '@ohos.distributedHardware.deviceManager' | ||||
| import promptAction from '@ohos.promptAction' | ||||
| import FileUtil from '../common/utils/File' | ||||
| import common from '@ohos.app.ability.common' | ||||
| import { DeviceParamType, ApiResponseType } from '../model' | ||||
| import dayTs from '../utils/Date' | ||||
| 
 | ||||
| @Entry | ||||
| @Component | ||||
| @ -117,7 +117,7 @@ struct Index { | ||||
|   async registrationDeviceNoFn() { | ||||
|     const date = new Date() | ||||
|     const param: DeviceParamType = { | ||||
|       time: dateFormat(date), | ||||
|       time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"), | ||||
|       deviceName: this.ip, | ||||
|       type: '1' | ||||
|     } | ||||
|  | ||||
| @ -2,7 +2,6 @@ import { examinationStuAbsent, getExaminationItem, getExaminationStudentInfo } f | ||||
| import router from '@ohos.router'; | ||||
| import TopLogo from './compontents/TopLogo'; | ||||
| import Md5 from '../common/utils/md5'; | ||||
| import { dateFormat, getCurrentTime, string2Bytes } from '../common/utils/tools'; | ||||
| import FaceCompare from './compontents/FaceCompare'; | ||||
| import { writeObjectOut } from '../api/judge'; | ||||
| import testNapi from '@ohos.idcard'; | ||||
| @ -43,6 +42,7 @@ import { BusinessError } from '@ohos.base'; | ||||
| import { GetSyncData } from '../utils/table/Operation'; | ||||
| import { GetCurrentUserKeyValue } from './UserInfo/utils'; | ||||
| import dayTs from '../utils/Date'; | ||||
| import { GetCurrentTime, NumberToByteArray } from '../utils/Common'; | ||||
| 
 | ||||
| @Entry | ||||
| @Component | ||||
| @ -484,7 +484,7 @@ struct UserInfo { | ||||
|   //考点端查询缺考指令内容消息请求 | ||||
|   getqkFn() { | ||||
|     let tmpList: Array<number> = []; | ||||
|     tmpList.push(string2Bytes(AppStorage.get('signNum'), 1 * 8)[0]) | ||||
|     tmpList.push(NumberToByteArray(AppStorage.get('signNum'), 1 * 8)[0]) | ||||
|     const param: QKParamType = { | ||||
|       id: 41, | ||||
|       list: tmpList, | ||||
| @ -804,8 +804,8 @@ struct UserInfo { | ||||
|     examinationStuAbsent(param).then(res => { | ||||
|       const arr = [this.signNum || 0, 1] | ||||
|       let tmpList: number[] = []; | ||||
|       tmpList.push(string2Bytes(arr[0], 1 * 8)[0]) | ||||
|       tmpList.push(string2Bytes(arr[1], 1 * 8)[0]) | ||||
|       tmpList.push(NumberToByteArray(arr[0], 1 * 8)[0]) | ||||
|       tmpList.push(NumberToByteArray(arr[1], 1 * 8)[0]) | ||||
| 
 | ||||
|       const param: UDPParamType = { | ||||
|         id: 43, | ||||
| @ -834,7 +834,7 @@ struct UserInfo { | ||||
|     } | ||||
|     // const { carId, examinationRoomId } = this.carInfo; | ||||
|     const examItems = await getExaminationItem({ | ||||
|       time: await getCurrentTime() || "", | ||||
|       time: await GetCurrentTime() || "", | ||||
|       carId: this.carInfo.carId, | ||||
|       lsh: this.currentUser.lsh || '', | ||||
|       examinationRoomId: this.carInfo.examinationRoomId | ||||
| @ -861,7 +861,7 @@ struct UserInfo { | ||||
|     if (!this.singlePlay) { | ||||
|       //获取已考项目 | ||||
|       examItems = await getExaminationItem({ | ||||
|         time: await getCurrentTime(), | ||||
|         time: await GetCurrentTime(), | ||||
|         carId: this.carInfo.carId, | ||||
|         lsh: this.currentUser.lsh || '', | ||||
|         examinationRoomId: this.carInfo.examinationRoomId | ||||
| @ -1036,7 +1036,7 @@ struct UserInfo { | ||||
|       ksysfzmhm: this.currentUser.ksy1sfzmhm || '', | ||||
|       ksxl: this.currentUser.xldm, | ||||
|       zp: photoBase64, | ||||
|       kssj: dateFormat(date) || '', | ||||
|       kssj: dayTs(date).format("YYYY-MM-DD HH:mm:ss") || '', | ||||
|       kchp: decodeURI(this.carInfo.plateNo), | ||||
|       Ksy2sfzmhm: this.currentUser.ksy2sfzmhm || '' | ||||
|     } | ||||
|  | ||||
| @ -3,11 +3,11 @@ import { faceCompare } from '../../api/userInfo'; | ||||
| import FileUtil from '../../common/utils/File'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| 
 | ||||
| import { string2Bytes } from '../../common/utils/tools'; | ||||
| import { takePhoto } from '../../service/videoService'; | ||||
| import { GlobalConfig } from '../../config/index'; | ||||
| import { VideoConfigData } from '../../mock'; | ||||
| import { CarInfoType, UDPParamType, VideoConfig } from '../../model'; | ||||
| import { NumberToByteArray } from '../../utils/Common'; | ||||
| 
 | ||||
| interface ParamType { | ||||
|   id?: number; | ||||
| @ -186,7 +186,7 @@ export default struct FaceCompare { | ||||
| 
 | ||||
|   getqkFn() { | ||||
|     let tmpList: number[] = []; | ||||
|     tmpList.push(string2Bytes(AppStorage.get('signNum'), 1 * 8)[0]) | ||||
|     tmpList.push(NumberToByteArray(AppStorage.get('signNum'), 1 * 8)[0]) | ||||
|     const param: ParamType = { | ||||
|       id: 41, | ||||
|       list: tmpList, | ||||
| @ -242,7 +242,7 @@ export default struct FaceCompare { | ||||
|     const str = this.lsh | ||||
|     console.log('this.lshbitbit', this.lsh, this.carInfo.carNo, this.carInfo.examinationRoomId) | ||||
|     for (let i = 0; i < str.length; i++) { | ||||
|       tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0]) | ||||
|       tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0]) | ||||
|     } | ||||
|     const param: UDPParamType = { | ||||
|       id: 46, | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import router from '@ohos.router'; | ||||
| import { getCurrentTime } from '../../common/utils/tools'; | ||||
| import { GetCurrentTime } from '../../utils/Common'; | ||||
| import imageBtn from '../compontents/imageBtn'; | ||||
| 
 | ||||
| @Component | ||||
| @ -51,9 +51,9 @@ export default struct TopLogo { | ||||
|   } | ||||
| 
 | ||||
|   async aboutToAppear() { | ||||
|     this.timeText = await getCurrentTime(); | ||||
|     this.timeText = await GetCurrentTime(); | ||||
|     this.timer = setInterval(async () => { | ||||
|       this.timeText = await getCurrentTime(); | ||||
|       this.timeText = await GetCurrentTime(); | ||||
|     }, 1000) | ||||
|     // this.vocObj = new voiceService(async (status,val) => { | ||||
|     //   if (status == 'idle') { | ||||
|  | ||||
| @ -3,12 +3,12 @@ import { judgeConfig } from '../../judgeSDK/utils/judgeConfig'; | ||||
| import FileUtil from '../../../common/utils/File'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| import VoiceAnnounce from '../../judgeSDK/utils/voiceAnnouncements'; | ||||
| import { getCurrentTime } from '../../../common/utils/tools'; | ||||
| import { MarkRule, SYSSET } from '../../judgeSDK/api/judgeSDK.d'; | ||||
| import { writeObjectOut } from '../../../api/judge'; | ||||
| import JudgeTask from '../../judgeSDK/utils/judgeTask'; | ||||
| import FilePhoto from '../../judgeSDK/utils/filePhoto'; | ||||
| import { CarInfoType } from '../../../model'; | ||||
| import { GetCurrentTime } from '../../../utils/Common'; | ||||
| 
 | ||||
| interface SEL { | ||||
|   fontColor: string | ||||
| @ -215,7 +215,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 = await GetCurrentTime(); | ||||
|     const beginData = { | ||||
|       xtlb: '17', | ||||
|       jkxlh: serialNumber, | ||||
| @ -245,7 +245,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 = await GetCurrentTime(); | ||||
|     console.info('surenjun uploadProgressPhoto',) | ||||
|     const photoBase64 = await getPhoto() | ||||
|     const photoData = { | ||||
| @ -276,7 +276,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 = await GetCurrentTime(); | ||||
|     const kfData = { | ||||
|       xtlb: '17', | ||||
|       jkxlh: serialNumber, | ||||
| @ -303,7 +303,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 = await GetCurrentTime(); | ||||
|     const endProjectData = { | ||||
|       xtlb: '17', | ||||
|       jkxlh: serialNumber, | ||||
| @ -329,7 +329,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 = await GetCurrentTime(); | ||||
|     const photoBase64 = await getPhoto(); | ||||
|     const endData = { | ||||
|       xtlb: '17', | ||||
|  | ||||
| @ -11,17 +11,7 @@ import FileUtil from '../../common/utils/File'; | ||||
| import FileLog from './utils/fileLog'; | ||||
| import JudgeTask from './utils/judgeTask'; | ||||
| import { judgeConfig } from './utils/judgeConfig'; | ||||
| import UsbService from '../../service/usbService'; | ||||
| import { KF, LANE } from '../judgeSDK/api/judgeSDK.d'; | ||||
| import { | ||||
|   Array2Byte, | ||||
|   convertGpsCoord2, | ||||
|   deepClone, | ||||
|   fillZero, | ||||
|   getCurrentTime, | ||||
|   string2Bytes, | ||||
|   stringToASC | ||||
| } from '../../common/utils/tools'; | ||||
| 
 | ||||
| import { | ||||
|   getCarStatus, | ||||
| @ -54,6 +44,9 @@ import { | ||||
| import { writeObjectOut } from '../../api/judge'; | ||||
| import { saveStartRecordVideo } from '../../utils/Video'; | ||||
| import common from '@ohos.app.ability.common'; | ||||
| import { Array2Byte, convertGpsCoord2, deepClone, fillZero, string2Bytes } from './utils/Common'; | ||||
| import { GetCurrentTime, StringToASCII } from '../../utils/Common'; | ||||
| import UsbService from '../../utils/USB'; | ||||
| 
 | ||||
| const judgeTag = 'SURENJUN_JUDGE' | ||||
| 
 | ||||
| @ -80,8 +73,8 @@ export default class Judge { | ||||
|     const { carId, examinationRoomId } = carInfo | ||||
|     const folderPath = fileLog.folderPath | ||||
|     const base64 = new util.Base64(); | ||||
|     const time = await getCurrentTime(); | ||||
|     const endTime = await getCurrentTime(1) | ||||
|     const time = await GetCurrentTime(); | ||||
|     const endTime = await GetCurrentTime(1) | ||||
|     let examDataBase64 | ||||
|     //TODO try catch报错待优化 | ||||
|     const examDataStr: string = await fileUtil.readFile(`${folderPath}/wuxi_progress_data.txt`); | ||||
| @ -262,40 +255,6 @@ export default class Judge { | ||||
|   private isExamEnd: boolean | ||||
|   // 是否发送udp | ||||
|   private isUdpEnd: boolean = false | ||||
|   // 处理udp plc信号 | ||||
|   handleUdp = async (msg) => { | ||||
|     console.info('plc信号', msg) | ||||
|     // const { fileLog, getPlcData, usbService, isUdpEnd, isExamEnd, judgeUI } = this | ||||
|     const stachArr = msg.split(',') | ||||
|     if (stachArr[0] != '#DN_GD' || this.isUdpEnd) { | ||||
|       return | ||||
|     } | ||||
|     const plcData = await this.getPlcData(msg); | ||||
|     // 4.过程数据 | ||||
|     await this.fileLog.setExamJudgeData(plcData) | ||||
|     //检测到有无锡所设备接入,需要发送特定的数据,供检测 | ||||
|     if (this.usbService.isWXUSBDevice) { | ||||
|       const str = await senorToWXDataStr(msg); | ||||
|       this.usbService.sendUSB(str) | ||||
|     } | ||||
|     const param350 = 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('udpIndex') as number; | ||||
|     let [prevJd, preWd] = [0, 0] | ||||
|     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服务序列号 | ||||
| @ -482,6 +441,40 @@ export default class Judge { | ||||
| 
 | ||||
|     return tempData | ||||
|   } | ||||
|   // 处理udp plc信号 | ||||
|   handleUdp = async (msg) => { | ||||
|     console.info('plc信号', msg) | ||||
|     // const { fileLog, getPlcData, usbService, isUdpEnd, isExamEnd, judgeUI } = this | ||||
|     const stachArr = msg.split(',') | ||||
|     if (stachArr[0] != '#DN_GD' || this.isUdpEnd) { | ||||
|       return | ||||
|     } | ||||
|     const plcData = await this.getPlcData(msg); | ||||
|     // 4.过程数据 | ||||
|     await this.fileLog.setExamJudgeData(plcData) | ||||
|     //检测到有无锡所设备接入,需要发送特定的数据,供检测 | ||||
|     if (this.usbService.isWXUSBDevice) { | ||||
|       const str = await senorToWXDataStr(msg); | ||||
|       this.usbService.sendUSB(str) | ||||
|     } | ||||
|     const param350 = 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('udpIndex') as number; | ||||
|     let [prevJd, preWd] = [0, 0] | ||||
|     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) => { | ||||
|     // const { fileLog, setJudgeItem, setJudgeMark, endExam } = this; | ||||
| @ -525,74 +518,13 @@ export default class Judge { | ||||
|   private isTrajectoryOpen: boolean; | ||||
|   // 调代理接口是否断网了 | ||||
|   private isJudgeDisConnect: boolean; | ||||
|   // 考试过程照片 | ||||
|   uploadProgressPhoto = async (ksxm) => { | ||||
|     const time = await getCurrentTime(); | ||||
|     const { judgeUI, plcData, getPhoto, fileLog, filePath } = this; | ||||
|     const photoBase64 = await getPhoto(); | ||||
|     const carInfo = AppStorage.get('carInfo'); | ||||
|     const { examSubject, plateNo, carNo } = carInfo; | ||||
|     const { lsh, idCard, serialNumber, projectsObj, ksdd, judgeConfigObj } = judgeUI; | ||||
|     const { sensor, gps } = plcData | ||||
|     const project = projectsObj[ksxm] | ||||
| 
 | ||||
|     const data = { | ||||
|       xtlb: '17', | ||||
|       jkxlh: serialNumber, | ||||
|       jkid: '17C54', | ||||
|       drvexam: { | ||||
|         lsh, | ||||
|         kskm: examSubject, | ||||
|         ksxm: project.projectCodeCenter, | ||||
|         sfzmhm: idCard, | ||||
|         kchp: encodeURI(plateNo), | ||||
|         zpsj: time, | ||||
|         zp: photoBase64, | ||||
|         cs: Math.floor((judgeConfigObj['350'] == 0 ? gps.sd : sensor.cs) * 1.852), | ||||
|         ksdd: encodeURI(ksdd) | ||||
|       } | ||||
|     }; | ||||
|     const { code } = await this.sendWriteObjectOut(data, filePath); | ||||
|     if (code === 2300007) { | ||||
|       this.isJudgeDisConnect = true | ||||
|     } | ||||
|     promptWxCode('17C54', code) | ||||
|     console.info(judgeTag, '上传照片 end') | ||||
|   } | ||||
|   private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11] | ||||
|   private lane: LANE = { | ||||
|     road: '', num: 0, count: 0 | ||||
|   } | ||||
|   private videoData: any | ||||
|   private disConnectNum: number = 0; | ||||
|   //调用监管接口 | ||||
|   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) => { | ||||
|     const carInfo = AppStorage.get('carInfo'); | ||||
|     const { examSubject, plateNo } = carInfo; | ||||
|     const { judgeUI, fileLog, getSbbm, xmxh, filePath } = this; | ||||
|     const { lsh, idCard, serialNumber, projectsObj, ksdd, kslx, xldm } = judgeUI | ||||
|     const time = await getCurrentTime(); | ||||
|     const time = await GetCurrentTime(); | ||||
|     const project = projectsObj[ksxm] | ||||
|     const sbxh = getSbbm(ksxm, xmxh) | ||||
|     const data = { | ||||
| @ -628,7 +560,7 @@ export default class Judge { | ||||
|     const { examSubject, plateNo, carNo } = carInfo; | ||||
|     const { judgeUI, fileLog, getSbxh, xmxh, getSbbm, filePath } = this; | ||||
|     const { lsh, idCard, serialNumber, projectsObj, cdsbInfoObj, ksdd, kslx, xldm, } = judgeUI | ||||
|     const time = await getCurrentTime(); | ||||
|     const time = await GetCurrentTime(); | ||||
|     const project = projectsObj[ksxm] | ||||
|     const sbxh = examSubject == 3 ? undefined : getSbbm(ksxm, xmxh) | ||||
| 
 | ||||
| @ -658,6 +590,67 @@ export default class Judge { | ||||
|     console.info(judgeTag, '项目结束 end') | ||||
|     promptWxCode('17C55', code) | ||||
|   } | ||||
|   private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11] | ||||
|   private lane: LANE = { | ||||
|     road: '', num: 0, count: 0 | ||||
|   } | ||||
|   private videoData: any | ||||
|   private disConnectNum: number = 0; | ||||
|   //调用监管接口 | ||||
|   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 | ||||
|   } | ||||
|   // 考试过程照片 | ||||
|   uploadProgressPhoto = async (ksxm) => { | ||||
|     const time = await GetCurrentTime(); | ||||
|     const { judgeUI, plcData, getPhoto, fileLog, filePath } = this; | ||||
|     const photoBase64 = await getPhoto(); | ||||
|     const carInfo = AppStorage.get('carInfo'); | ||||
|     const { examSubject, plateNo, carNo } = carInfo; | ||||
|     const { lsh, idCard, serialNumber, projectsObj, ksdd, judgeConfigObj } = judgeUI; | ||||
|     const { sensor, gps } = plcData | ||||
|     const project = projectsObj[ksxm] | ||||
| 
 | ||||
|     const data = { | ||||
|       xtlb: '17', | ||||
|       jkxlh: serialNumber, | ||||
|       jkid: '17C54', | ||||
|       drvexam: { | ||||
|         lsh, | ||||
|         kskm: examSubject, | ||||
|         ksxm: project.projectCodeCenter, | ||||
|         sfzmhm: idCard, | ||||
|         kchp: encodeURI(plateNo), | ||||
|         zpsj: time, | ||||
|         zp: photoBase64, | ||||
|         cs: Math.floor((judgeConfigObj['350'] == 0 ? gps.sd : sensor.cs) * 1.852), | ||||
|         ksdd: encodeURI(ksdd) | ||||
|       } | ||||
|     }; | ||||
|     const { code } = await this.sendWriteObjectOut(data, filePath); | ||||
|     if (code === 2300007) { | ||||
|       this.isJudgeDisConnect = true | ||||
|     } | ||||
|     promptWxCode('17C54', code) | ||||
|     console.info(judgeTag, '上传照片 end') | ||||
|   } | ||||
| 
 | ||||
|   constructor(judgeUI) { | ||||
|     this.serialIndex = 1; | ||||
| @ -1141,7 +1134,7 @@ export default class Judge { | ||||
|     const { examSubject, plateNo, carNo } = carInfo; | ||||
|     const { judgeUI, getProjectInfo, fileLog, xmmcSingleCode, xmmcEndCode, filePath } = this; | ||||
|     const { lsh, idCard, serialNumber, ksdd, projectsObj } = judgeUI | ||||
|     const time = await getCurrentTime(); | ||||
|     const time = await GetCurrentTime(); | ||||
|     const project = getProjectInfo(ksxm); | ||||
|     //科目三夜间行驶.模拟灯光、上车准备出现通用评判,ksxm为当前进行的项目 | ||||
|     const checkProjects = ['17', '41', '1']; | ||||
| @ -1285,7 +1278,7 @@ export default class Judge { | ||||
|     const { lsh, idCard, serialNumber, kssycs, totalScore, judgeConfigObj, isAllProjectsEnd, passingScore } = judgeUI | ||||
|     //TODO 断网考试结束补传 | ||||
|     // await uploadDisConnectData(); | ||||
|     const time = await getCurrentTime(); | ||||
|     const time = await GetCurrentTime(); | ||||
|     const photoBase64 = await getPhoto(); | ||||
|     const { d1, d2, d3, d4, d5 } = ksjs | ||||
|     const data = { | ||||
| @ -1492,12 +1485,12 @@ export default class Judge { | ||||
|     const translateProject = getTranslateProject(); | ||||
|     const sbxh = getSbxh(xmdm, xmxh) | ||||
|     const { carzt, dcjl, qjjl, dxjl, bxjl } = performInfo || {}; | ||||
|     const asclshArr = stringToASC( | ||||
|     const asclshArr = StringToASCII( | ||||
|       fillZero((singlePlay ? (examSubject == 2 ? '0000000000000' : '1111111111111') : lsh) || 0, 13) | ||||
|     ); | ||||
|     //13不足要补0 | ||||
|     const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13)) | ||||
|     const ascsbxhArr = stringToASC(sbxh) | ||||
|     const ascksyhArr = StringToASCII(fillZero(ksyh || 0, 13)) | ||||
|     const ascsbxhArr = StringToASCII(sbxh) | ||||
|     const translateSignals = getTranslateSignals( | ||||
|       [zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd].concat(getDwStatusType(dw)) | ||||
|         .concat(getCarStatusType(carzt)).concat([ygq, sensor.wd, 0]) | ||||
|  | ||||
							
								
								
									
										80
									
								
								entry/src/main/ets/pages/judgeSDK/utils/Common.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								entry/src/main/ets/pages/judgeSDK/utils/Common.ets
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,80 @@ | ||||
| // 根据指定个数分割数组 | ||||
| export function chunkArr<T>(arr: T[], size: number): T[][] { | ||||
|   //判断如果不是数组(就没有length),或者size没有传值,size小于1,就返回空数组 | ||||
|   if (!arr.length || !size || size < 1) { | ||||
|     return [] | ||||
|   } | ||||
|   let start = 0 | ||||
|   let end = 0 | ||||
|   let result: T[][] = [] | ||||
|   for (let i = 0; i < Math.ceil(arr.length / size); i++) { | ||||
|     start = i * size | ||||
|     end = start + size | ||||
|     result.push(arr.slice(start, end)) | ||||
|   } | ||||
|   return result | ||||
| } | ||||
| 
 | ||||
| //对象深拷贝 | ||||
| export function deepClone<T>(target: T): T { | ||||
|   // 如果是对象,且不是原始值null | ||||
|   if (typeof target === 'object' && target !== null) { | ||||
|     // 创建容器 | ||||
|     const result: ESObject = Array.isArray(target) ? [] : {}; | ||||
|     const keys = Object.keys(target) as Array<keyof T>; //注解二 | ||||
|     keys.forEach(key => { | ||||
|       Reflect.set(result, key, deepClone(target[key])); | ||||
|     }); | ||||
|     return result; | ||||
|   } | ||||
|   // 如果是原始值,则直接返回 | ||||
|   return target; | ||||
| } | ||||
| 
 | ||||
| export function fillZero(str: string | number, len: number): string { | ||||
|   str = str.toString(); | ||||
|   if (str.length >= len || len <= 0) { | ||||
|     return str; | ||||
|   } | ||||
|   const zeroStr = '0'.repeat(len - str.length); | ||||
|   return zeroStr + str; | ||||
| } | ||||
| 
 | ||||
| //经纬度转换 | ||||
| export function convertGpsCoord2(num: number): number { | ||||
|   const tempNum = Math.floor(num); | ||||
|   const du = Math.floor(tempNum / 100); | ||||
|   const fen = tempNum % 100 + num - tempNum; | ||||
|   return du + fen / 60 | ||||
| } | ||||
| 
 | ||||
| export function Array2Byte(array: number[]): Uint8Array { | ||||
|   const buf = new ArrayBuffer(array.length); | ||||
|   const view = new Uint8Array(buf); | ||||
|   for (let i = 0; i < array.length; i++) { | ||||
|     view[i] = array[i] & 0xFF; | ||||
|   } | ||||
|   return view; | ||||
| } | ||||
| 
 | ||||
| export function string2Bytes(number: number, len: number): number[] | undefined { | ||||
|   let str = Math.floor(number).toString(2); | ||||
|   if (str.length > len) { | ||||
|     console.log('数据长度不对~~'); | ||||
|     return; | ||||
|   } | ||||
|   const byteString = fillZero(str, len); | ||||
| 
 | ||||
|   const arrBytes: number[] = []; | ||||
|   for (let i = byteString.length; i > 0; ) { | ||||
|     let j = i - 8; | ||||
|     if (j < 0) { | ||||
|       j = 0; | ||||
|     } | ||||
|     const s = byteString.slice(j, i); | ||||
|     const v = parseInt(s, 2); | ||||
|     arrBytes.push(v); | ||||
|     i -= 8; | ||||
|   } | ||||
|   return arrBytes; | ||||
| } | ||||
| @ -1,11 +1,5 @@ | ||||
| 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' | ||||
| import { GetCurrentTime } from '../../../utils/Common' | ||||
| 
 | ||||
| interface StuInfo { | ||||
|   name: string | ||||
| @ -16,11 +10,7 @@ interface StuInfo { | ||||
| 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 | ||||
| @ -31,93 +21,60 @@ export default class FileLog { | ||||
|   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); | ||||
|     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; | ||||
|     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); | ||||
|     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; | ||||
|     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); | ||||
|     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); | ||||
|     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; | ||||
|     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; | ||||
|     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); | ||||
|     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 { fileUtil, folderPath, examLineDataFd } = this; | ||||
|     const plcData = plcStr.split(','); | ||||
|     const time = await getCurrentTime(); | ||||
|     const time = await GetCurrentTime(); | ||||
|     const lineData = [ | ||||
|     /*帧头*/time, | ||||
|       /*卫星时间*/time, | ||||
| @ -138,11 +95,43 @@ export default class FileLog { | ||||
|       /*天向位置坐标*/'', | ||||
|       /*东向速度*/'', | ||||
|       /*北向速度*/'', | ||||
|       /*评判信号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(','), | ||||
|       /*评判信号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); | ||||
|     this.examLineDataFd = | ||||
|       await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData), examLineDataFd); | ||||
|   }; | ||||
|   //后续文件路径待替换 | ||||
|   private fileUtil: FileUtil | ||||
|   private stuInfo: StuInfo | ||||
|   // 设置文件夹 | ||||
|   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 | ||||
|   } | ||||
| 
 | ||||
|   constructor(context) { | ||||
|     const fileUtil = new FileUtil(context) | ||||
|     this.fileUtil = fileUtil | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   //关闭所有文件写入 | ||||
|   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`); | ||||
|     }) | ||||
|   } | ||||
| } | ||||
| @ -1,7 +1,7 @@ | ||||
| import { Array2Byte, string2Bytes } from '../../../common/utils/tools'; | ||||
| import { testMarkRules, testRealExam } from '../dataTest/index'; | ||||
| 
 | ||||
| import systemTime from '@ohos.systemDateTime'; | ||||
| import { Array2Byte } from './Common'; | ||||
| 
 | ||||
| //获取本地扣分项 | ||||
| export const getTestMarkRules = () => { | ||||
| @ -26,7 +26,7 @@ export const getTranslateSignals = (tempItems) => { | ||||
|     arr.push(temp.join('')); | ||||
|   } | ||||
|   const temp = arr.map(numStr => parseInt(numStr, 2)) | ||||
|   return temp.map(item => string2Bytes(item, 8)[0]) | ||||
|   return temp.map(item => NumberToByteArray(item, 8)[0]) | ||||
| } | ||||
| 
 | ||||
| // c++评判考车行驶状态转换 | ||||
| @ -4,7 +4,11 @@ enum timeType { | ||||
|   fulltime = 1 | ||||
| } | ||||
| 
 | ||||
| // 获取当前时间 | ||||
| /** | ||||
|  * 获取当前时间 | ||||
|  * @param type | ||||
|  * @returns | ||||
|  */ | ||||
| export function GetCurrentTime(type?: timeType): string { | ||||
|   if (type === 1) { | ||||
|     return dayTs().format("YYYYMMDDHHmmss") | ||||
| @ -13,7 +17,12 @@ export function GetCurrentTime(type?: timeType): string { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| //是否是多少天前 | ||||
| /** | ||||
|  * 是否是指定天数之前 | ||||
|  * @param date | ||||
|  * @param days | ||||
|  * @returns | ||||
|  */ | ||||
| export function IsDaysAgo(date: string | number | Date, days: number = 2): boolean { | ||||
|   const today = dayTs(); // 当前日期 | ||||
|   const target = dayTs(date).format("YYYY-MM-DD HH:mm:ss.SSS"); // 需要判断的日期 | ||||
| @ -34,4 +43,74 @@ export function StringToBytes(str: string): Uint8Array { | ||||
|     bytes[i] = str.charCodeAt(i); | ||||
|   } | ||||
|   return bytes; | ||||
| } | ||||
| // import { | ||||
| //   Array2Byte, | ||||
| //   convertGpsCoord2, | ||||
| //   deepClone, | ||||
| //   fillZero, | ||||
| //   getCurrentTime, | ||||
| //   string2Bytes, | ||||
| //   stringToASC | ||||
| // } from '../../common/utils/tools'; | ||||
| 
 | ||||
| /** | ||||
|  * 字符串转ASCII码 | ||||
|  */ | ||||
| export function StringToASCII(str: string): number[] { | ||||
|   const arr: number[] = []; | ||||
|   for (let i = 0; i < str.length; i++) { | ||||
|     arr.push(str.charCodeAt(i)); | ||||
|   } | ||||
|   return arr; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * 数组转字节 | ||||
|  */ | ||||
| export function ArrayToByteArray(array: number[]): Uint8Array { | ||||
|   const buf = new ArrayBuffer(array.length); | ||||
|   const view = new Uint8Array(buf); | ||||
|   for (let i = 0; i < array.length; i++) { | ||||
|     view[i] = array[i] & 0xFF; | ||||
|   } | ||||
|   return view; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * 字符串转字节数组 | ||||
|  * @param number 要转换的数字 | ||||
|  * @param len 字节数 | ||||
|  * @returns 返回字节数组 | ||||
|  */ | ||||
| export function NumberToByteArray(number: number, len: number): number[] | undefined { | ||||
|   let str = Math.floor(number).toString(2); | ||||
|   if (str.length > len) { | ||||
|     console.log('数据长度不对~~'); | ||||
|     return; | ||||
|   } | ||||
|   const byteString = FillZero(str, len); | ||||
| 
 | ||||
|   const arrBytes: number[] = []; | ||||
|   for (let i = byteString.length; i > 0; ) { | ||||
|     let j = i - 8; | ||||
|     if (j < 0) { | ||||
|       j = 0; | ||||
|     } | ||||
|     const s = byteString.slice(j, i); | ||||
|     const v = parseInt(s, 2); | ||||
|     arrBytes.push(v); | ||||
|     i -= 8; | ||||
|   } | ||||
|   return arrBytes; | ||||
| } | ||||
| 
 | ||||
| export function FillZero(str: string | number, len: number): string { | ||||
|   str = str.toString(); | ||||
|   if (str.length >= len || len <= 0) { | ||||
|     return str; | ||||
|   } | ||||
|   const zeroStr = '0'.repeat(len - str.length); | ||||
|   return zeroStr + str; | ||||
| } | ||||
| @ -1,30 +1,22 @@ | ||||
| import FileUtil from './File' | ||||
| import {getCurrentTime} from './tools' | ||||
| import {uploadHarmonyLiCheng} from '../../api/judge' | ||||
| import { uploadHarmonyLiCheng } from '../../api/judge' | ||||
| import { GetCurrentTime } from '../Common' | ||||
| 
 | ||||
| const LOGTAG = 'GetDistance' | ||||
| export default class GetDistance { | ||||
| 
 | ||||
|   //后续文件路径待替换 | ||||
|   private fileUtil: FileUtil | ||||
| export default class GetDistance { | ||||
|   public folderPath: string | ||||
|   public timeStr: string | ||||
|   public totalDistance: number | ||||
|   public totalTime:number | ||||
|   public totalTime: number | ||||
|   public date: string | ||||
|   public fd: number | ||||
| 
 | ||||
|   constructor(context) { | ||||
|     const fileUtil = new FileUtil(context) | ||||
|     this.fileUtil = fileUtil; | ||||
|   } | ||||
| 
 | ||||
|   // 设置文件夹 | ||||
|   public initFolder= async () => { | ||||
|     const {fileUtil} = this | ||||
|     const time = await getCurrentTime() | ||||
|   public initFolder = async () => { | ||||
|     const { fileUtil } = this | ||||
|     const time = await GetCurrentTime() | ||||
|     const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`); | ||||
|     console.info('surenjun folderPath=>' ,folderPath); | ||||
|     console.info('surenjun folderPath=>', folderPath); | ||||
|     const date = time.split(' ')[0].split('-').join('_') | ||||
|     const timeStr = time.split(' ')[1] | ||||
|     this.timeStr = timeStr | ||||
| @ -32,45 +24,53 @@ export default class GetDistance { | ||||
|     this.totalDistance = 0; | ||||
|     this.totalTime = 0; | ||||
|     this.date = date; | ||||
|     this.fd=await fileUtil.editFile( | ||||
|       `${folderPath}/${date}.txt`,`程序启动时间:${timeStr} 累计行驶距离:${this.totalDistance}m 累计运行时常:${this.totalTime}min`,this.fd | ||||
|     this.fd = await fileUtil.editFile( | ||||
|       `${folderPath}/${date}.txt`, | ||||
|       `程序启动时间:${timeStr} 累计行驶距离:${this.totalDistance}m 累计运行时常:${this.totalTime}min`, this.fd | ||||
|     ); | ||||
|     return folderPath | ||||
|   } | ||||
|   //后续文件路径待替换 | ||||
|   private fileUtil: FileUtil | ||||
| 
 | ||||
|   constructor(context) { | ||||
|     const fileUtil = new FileUtil(context) | ||||
|     this.fileUtil = fileUtil; | ||||
|   } | ||||
| 
 | ||||
|   // 过程文件数据 | ||||
|   public setTimeData = async (str:number) => { | ||||
|     const {fileUtil,folderPath,timeStr,date,totalDistance} = this; | ||||
|     console.log('folderPath',folderPath) | ||||
|   public setTimeData = async (str: number) => { | ||||
|     const { fileUtil, folderPath, timeStr, date, totalDistance } = this; | ||||
|     console.log('folderPath', folderPath) | ||||
|     const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || ''; | ||||
|     const contentArr = content.split('\n').filter(item => item) | ||||
|     console.info('surenjun contentArr',JSON.stringify(contentArr)) | ||||
|     this.totalDistance += (str * 1 > 200 ? 200 : str*1) | ||||
|     console.info('surenjun contentArr', JSON.stringify(contentArr)) | ||||
|     this.totalDistance += (str * 1 > 200 ? 200 : str * 1) | ||||
|     this.totalTime += 1; | ||||
|     contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime/60)}min`+ '\n' | ||||
|     console.info('surenjun',contentArr.join('\n')) | ||||
|     console.log('folderPath',folderPath,date) | ||||
|     contentArr[contentArr.length - 1] = | ||||
|       `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime / | ||||
|         60)}min` + '\n' | ||||
|     console.info('surenjun', contentArr.join('\n')) | ||||
|     console.log('folderPath', folderPath, date) | ||||
|     this.uploadData() | ||||
| 
 | ||||
|     // await fileUtil.addFile( | ||||
|     //   `${folderPath}/${date}.txt`,contentArr.join('\n') | ||||
|     // ); | ||||
|   } | ||||
| 
 | ||||
|   //上传行驶里程数据 | ||||
|   uploadData = async () => { | ||||
|     setInterval(()=>{ | ||||
|     setInterval(() => { | ||||
|       const { carId } = AppStorage.get('carInfo'); | ||||
|       const {date,timeStr,totalDistance}= this; | ||||
|       const { date, timeStr, totalDistance } = this; | ||||
|       return | ||||
|       //"carid":"1001","startTime":"2024-08-24 08:09:01","time":"111233", "mileage":"1222" | ||||
|       uploadHarmonyLiCheng({ | ||||
|         carid:carId, | ||||
|         startTime:`${date.split('_').join('-')} ${timeStr}`, | ||||
|         time:timeStr, | ||||
|         mileage:totalDistance | ||||
|         carid: carId, | ||||
|         startTime: `${date.split('_').join('-')} ${timeStr}`, | ||||
|         time: timeStr, | ||||
|         mileage: totalDistance | ||||
|       }) | ||||
|     },5000) | ||||
|     }, 5000) | ||||
|   } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user