From f61ec2bc2e92316346abd4108a02b8c1f3d012b1 Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Tue, 20 Aug 2024 09:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E6=AE=BC=E5=95=8F=E9=A1=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/common/service/indexService.ts | 32 +++++++- .../ets/common/utils/UdpClientByCenter.ts | 41 +++++++++- entry/src/main/ets/common/utils/request.ts | 7 +- entry/src/main/ets/pages/ExaminerLogin.ets | 3 + entry/src/main/ets/pages/Index.ets | 13 ++- entry/src/main/ets/pages/UserInfo.ets | 82 ++++++++++++------- .../ets/pages/compontents/errorMsgDialog.ets | 66 ++++++++++----- 7 files changed, 178 insertions(+), 66 deletions(-) diff --git a/entry/src/main/ets/common/service/indexService.ts b/entry/src/main/ets/common/service/indexService.ts index 27c19d23..75d5517f 100644 --- a/entry/src/main/ets/common/service/indexService.ts +++ b/entry/src/main/ets/common/service/indexService.ts @@ -16,7 +16,7 @@ import { } from '../../common/service/initable' import { GlobalConfig } from '../../config/index' import testNapi from '@ohos.hiserialsdk' - +import fs from '@ohos.file.fs'; let num = 0 export async function getliushuiNum(context) { @@ -41,7 +41,37 @@ export async function getliushuiNum(context) { // return str } } +export async function deleteAllFIleLog(){ + let options = { + "recursion": false, + "listNum": 0, + }; + let filenames = fs.listFileSync(GlobalConfig.comoonfileWriteAddress+'/PLC/', options); + console.info("listFile succeed",JSON.stringify(filenames)); + for (let i = 0; i < filenames.length; i++) { + if(isSevenDaysAgo(filenames[i])){ + fs.rmdir(GlobalConfig.comoonfileWriteAddress+'/PLC/'+filenames[i], (err) => { + if (err) { + console.error("rmdir failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("rmdir succeed"); + } + }); + } + // console.info("filename: %s", filenames[i]); + } +} +function isSevenDaysAgo(date) { + const today = new Date(); // 当前日期 + const target = new Date(date); // 需要判断的日期 + + const diff = today.getTime() - target.getTime(); // 计算两个日期之间的毫秒数差异 + const diffDays = diff / (1000 * 60 * 60 * 24); // 将毫秒转换为天数 + + // 如果差异天数正好是7,则原日期是当前日期的前七天 + return diffDays > 7; +} //配置流水号 export async function setliushuiNum(context) { const fileUtil = new FileUtil(context) diff --git a/entry/src/main/ets/common/utils/UdpClientByCenter.ts b/entry/src/main/ets/common/utils/UdpClientByCenter.ts index ba891753..678dc210 100644 --- a/entry/src/main/ets/common/utils/UdpClientByCenter.ts +++ b/entry/src/main/ets/common/utils/UdpClientByCenter.ts @@ -24,6 +24,8 @@ 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 { formatTime } from '../../../chengmai/ets/common/utils/tools'; export default class UdpClientByCenter { @@ -32,6 +34,7 @@ export default class UdpClientByCenter { private oppositeIp: string = '' private oppositeIpPort: string = '' private udpMsg: any = '' + private chafenFlag: number = 0 private num: number = 0 private fileUtil: FileUtil private udp: UDPSocket = null @@ -246,9 +249,10 @@ export default class UdpClientByCenter { callback({ id, length, body: list, sendId: this.sendId }) - this.interval=setInterval(()=>{ - },3000) + // this.interval=setInterval(()=>{ + // + // },3000) }); } @@ -303,18 +307,40 @@ export default class UdpClientByCenter { console.log(`${TAG} udp222 on message array buffer:${str}`); strachArr[28] = globalThis.chuankoMsg || strachArr[28] + // this.stashFn(str) const newArr = JSON.parse(JSON.stringify(strachArr)) - // this.stashFn=()=>{} + this.writeLog({ + time:dateFormat(new Date()), + PLC: JSON.stringify(newArr.toString()), + }) + if(strachArr[83]!='4'){ + this.chafenFlag++ + if(this.chafenFlag>=15&&!globalThis.dialogOpen){ + globalThis.title='差分状态异常' + globalThis.type='3' + AppStorage.SetOrCreate('errorMsg', 1); + } + }else{ + globalThis.dialogOpen=false + } + this.chafenFlag=0 callback && callback(newArr.toString()) this.currentValue = newArr.toString(); } else { callback && callback('') } + console.log('messageTimeEnd') this.testIfUdpConnetced(callback) } + async writeLog(param){ + const fileUtil = new FileUtil(globalThis.context) + const date=dateFormat(new Date).split(' ')[0] + const folderPath = await fileUtil.initFolder(`/PLC/${date}`); + fileUtil.editFile(`${folderPath}/plcLog.txt`, JSON.stringify(param)+`\n`) + } //获取当前UDP信号 getCurrentMessage = () => { return this.currentValue @@ -328,6 +354,8 @@ export default class UdpClientByCenter { const arrRedBuffer = Array2Byte(arrRed).buffer const arrGreenBugger = Array2Byte(arrGreen).buffer let num = 0 + globalThis.dialogOpen=false + //监听udp是否断开 clearInterval(globalThis.messageTimer) globalThis.messageTimer = setInterval(() => { @@ -341,14 +369,19 @@ export default class UdpClientByCenter { console.log(TAG, 'plc udp信号丢失') if (num == 3) { getUDP(globalThis.context,true) - num = 0 } + globalThis.title='plc udp信号丢失' + globalThis.type='3' + if(!globalThis.dialogOpen){ + AppStorage.SetOrCreate('errorMsg', 1); + } prompt.showToast({ message: 'plc udp信号丢失', duration: 2000 }); } + this.plcUdpError = true; }, 2000) }, 3000) diff --git a/entry/src/main/ets/common/utils/request.ts b/entry/src/main/ets/common/utils/request.ts index 14390ade..30dece37 100644 --- a/entry/src/main/ets/common/utils/request.ts +++ b/entry/src/main/ets/common/utils/request.ts @@ -41,12 +41,7 @@ export default async function request(req: any) { // let baseUrl=host?config.csptHost:config.host' console.log('响应头地址' + baseUrl,url) - // writeLog({ - // time:dateFormat(new Date()), - // url, - // extraData: JSON.stringify(data), - // state:'start' - // }) + const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, options); // fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList)) // writeLog({ diff --git a/entry/src/main/ets/pages/ExaminerLogin.ets b/entry/src/main/ets/pages/ExaminerLogin.ets index 7a1d8153..03d9ac09 100644 --- a/entry/src/main/ets/pages/ExaminerLogin.ets +++ b/entry/src/main/ets/pages/ExaminerLogin.ets @@ -101,6 +101,9 @@ export default struct Index { } router.pushUrl({ url: 'pages/UserInfo', + params:{ + type:1 + } }, router.RouterMode.Single); console.log('res11', JSON.stringify(res)) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 28f7b03b..feb561f1 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -10,7 +10,7 @@ import FileUtil from '../common/utils/File'; import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; import { initJudgeUdp } from '../common/utils/UdpJudge'; import { getTCP } from '../common/utils/GlobalTcp'; -import { getliushuiNum, setliushuiNum, takePhotoFn } from '../common/service/indexService'; +import { getliushuiNum, setliushuiNum, takePhotoFn,deleteAllFIleLog } from '../common/service/indexService'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import worker, { MessageEvents } from '@ohos.worker'; import promptAction from '@ohos.promptAction' @@ -62,7 +62,7 @@ struct Index { .height(69 * this.ratio * this.dialogRatio) .backgroundImage($r('app.media.button_nor')) .backgroundImageSize({ width: '100%', height: '100%' }) - .margin({ bottom: 12 * this.ratio }) + // .margin({ bottom: 12 * this.ratio }) } build() { @@ -421,6 +421,7 @@ struct Index { } async initParams() { + deleteAllFIleLog() //设置plc udp 同步requesthost await getUDP(this.context, false) this.loading = false @@ -446,9 +447,13 @@ struct Index { this.heartMsg() } const data=AppStorage.Get('errorMsg'); // returns 47 - console.log('1123',data) + console.log('1123',data,globalThis.type) if(data==1){ - this.errorDialog.open() + if(globalThis.type=='3'&&!globalThis.dialogOpen){ + globalThis.dialogOpen=true + }else if(globalThis.type=='1'){ + this.errorDialog.open() + } } }, 1000) //下载模型 diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index 0d3ef90b..636677d8 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -72,6 +72,7 @@ struct UserInfo { @State signNum: number = 0; @State isCanClick: boolean = true; @State updateTimeLimit: boolean = false + @State ksksLimit: boolean = false @State faceFlag: string = '0'; @State FaceOpenStatue: string = '0'; //是否开启人脸识别 @State faceCatchImg: string = '' @@ -119,6 +120,7 @@ struct UserInfo { ) async onPageShow() { this.updateTimeLimit=false + this.ksksLimit=false console.log('响应头地址响应头地址') const mediaTest = new FilePhoto(this.context); this.filePhoto = new FilePhoto(this.context); @@ -128,39 +130,47 @@ struct UserInfo { this.initData() //身份证读卡器初始化 // this.openDeviceByIDCard() + const routerParam=router.getParams()||{type :0}; + console.log('routerParam',JSON.stringify(routerParam)) // @ts-ignore - this.list =await getSyncData('USERLIST') - // @ts-ignore - const data=await getSyncData('USER') - console.log('datadata',JSON.stringify(data)); - console.log('datadata2',JSON.stringify(this.list)) + if(routerParam.type!=1){ + // @ts-ignore + this.list =await getSyncData('USERLIST') + // @ts-ignore + const data=await getSyncData('USER') + console.log('datadata',JSON.stringify(data)); + console.log('datadata2',JSON.stringify(this.list)) - const user=data[0] - if(user&&Number(user.kssycs)){ - this.list.forEach(res=>{ - if(res.sfzmhm==user.sfzmhm){ - res.kssycs=user.kssycs - this.getCurrentStudent(res.sfzmhm) + const user=data[0] + if(user&&Number(user.kssycs)){ + this.list.forEach(res=>{ + if(res.sfzmhm==user.sfzmhm){ + res.kssycs=user.kssycs + this.getCurrentStudent(res.sfzmhm) + } + }) + + }else if(user&&(user.kssycs=='0'||user.kssycs=='')){ + console.log('datadatadatadata') + this.list=this.list.filter(res=>{ + return res.sfzmhm!=user.sfzmhm + }) + this.pageIndex=0 + this.dataList = this.list.slice(this.pageIndex * 4, this.pageIndex * 4 + 4) + if(this.dataList.length){ + this.currentUser=this.dataList[0] + }else{ + this.currentUser=EmptyCandidateObject } - }) - - }else if(user&&(user.kssycs=='0'||user.kssycs=='')){ - console.log('datadatadatadata') - this.list=this.list.filter(res=>{ - return res.sfzmhm!=user.sfzmhm - }) - this.pageIndex=0 - this.dataList = this.list.slice(this.pageIndex * 4, this.pageIndex * 4 + 4) - if(this.dataList.length){ - this.currentUser=this.dataList[0] - }else{ - this.currentUser=EmptyCandidateObject } + this.list.forEach((res,index)=>{ + res.id=index.toString() + }) + await upDateTableByArray('USERLIST', this.list||[]) + }else{ + this.getExaminationStudentInfoFn() } - this.list.forEach((res,index)=>{ - res.id=index.toString() - }) - await upDateTableByArray('USERLIST', this.list||[]) + // 如果是单机模式则模拟假数据 //获取sysset表数据 @@ -353,7 +363,6 @@ struct UserInfo { carNo: globalThis.carInfo.carNo, placeId: globalThis.carInfo.examinationRoomId } - globalThis.udpClient2.sendMsgExt(param, this.context) } @@ -515,6 +524,7 @@ struct UserInfo { qkFn() { this.faceCompareSucess = 0 + this.ksksLimit=false if (globalThis.singlePlay) { this.qkFlag = false return @@ -616,6 +626,7 @@ struct UserInfo { kString:keystr || '' } }, router.RouterMode.Single); + this.updateTimeLimit=false this.stopDeviceById() this.stepFlag = false }) @@ -882,6 +893,10 @@ struct UserInfo { Image($r('app.media.qk_btn')) .commStyle() .onClick(() => { + if(this.ksksLimit){ + return + } + this.ksksLimit=true this.qkFlag = true }) @@ -906,6 +921,10 @@ struct UserInfo { Image($r('app.media.ksks_btn')) .commStyle() .onClick(async () => { + if(this.ksksLimit){ + return + } + console.log('routerParamrouterParam') try { await this.checkSignal() this.faceCompareSucess = 0 @@ -913,6 +932,8 @@ struct UserInfo { if (!this.currentUser.xm) { return } + this.ksksLimit=true + if (globalThis.singlePlay) { const {examSubject} = globalThis.carInfo; this.currentUser.id='0' @@ -924,6 +945,8 @@ struct UserInfo { kfdm: this.sczbkf, } }, router.RouterMode.Single); + this.ksksLimit=false + this.stopDeviceById() return } @@ -963,6 +986,7 @@ struct UserInfo { } .commStyle() .onClick(() => { + this.ksksLimit=false this.qkFlag = false }) diff --git a/entry/src/main/ets/pages/compontents/errorMsgDialog.ets b/entry/src/main/ets/pages/compontents/errorMsgDialog.ets index c0a06f3e..24f9a866 100644 --- a/entry/src/main/ets/pages/compontents/errorMsgDialog.ets +++ b/entry/src/main/ets/pages/compontents/errorMsgDialog.ets @@ -5,36 +5,26 @@ export default struct errorMsgDialog { } confirm: () => void = () => { } + dialogRatio:number=0.8 title?: string type: string //1 tip 2loading 3Dialog @State angle: number = 0 + @Styles + commStyle(){ + .width(220 * globalThis.ratio * this.dialogRatio ) + .height(69 * globalThis.ratio * this.dialogRatio) + .backgroundImage($r('app.media.button_nor')) + .backgroundImageSize({ width: '100%', height: '100%' }) + // .margin({ bottom: 12 * this.ratio }) + } + build() { Column() { if(this.title){ Text(this.title) - .fontSize(30) - .margin(120) - } - if (this.type=='3') { - Row() { - Button('取消') - .onClick(() => { - if (this.controller != undefined) { - this.confirm() - this.controller.close() - } - }) - .margin(20) - Button('确定') - .onClick(() => { - if (this.controller != undefined) { - this.cancel() - this.controller.close() - } - }) - .margin(20) - } + .fontSize(30* this.dialogRatio) + .margin(120* this.dialogRatio) } if (this.type=='2') { Image($r('app.media.open_loading')) @@ -50,6 +40,38 @@ export default struct errorMsgDialog { }) .margin(50) } + if (this.type=='3') { + Row() { + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Text(' 取 消 ') + .fontSize(24 * globalThis.ratio* this.dialogRatio ) + .fontColor('#fff') + .width(100 * globalThis.ratio* this.dialogRatio) + } + .commStyle() + .onClick(() => { + if (this.controller != undefined) { + this.cancel() + this.controller.close() + } + }).margin({ right: 10 * globalThis.ratio * this.dialogRatio}) + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Text(' 确 定 ') + .fontSize(24 * globalThis.ratio* this.dialogRatio) + .fontColor('#fff') + .width(100 * globalThis.ratio* this.dialogRatio) + } + .commStyle() + .onClick(() => { + if (this.controller != undefined){ + this.confirm() + this.controller.close() + } + }) + } + + } }.backgroundColor('#E6E3DF') .borderRadius(19 * globalThis.ratio) .constraintSize({ minWidth: 520 })