新代码

This commit is contained in:
“wangzhongjie” 2024-03-05 15:44:53 +08:00
parent 0fe5385625
commit 848282fe04
6 changed files with 130 additions and 78 deletions

View File

@ -27,6 +27,7 @@ export default class UdpClient {
private oppositeIpPort: string = ''
private udp: any = null
private stashFn
constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
this.localIp = udplocalIp
@ -72,7 +73,9 @@ export default class UdpClient {
console.log(`${TAG} udp bind failed:${JSON.stringify(err)}`);
});
}
setMsgCallBack(callback){
this.stashFn=callback
}
sendMsg(msg: string) {
let promise = this.udp.send({
data: msg,
@ -114,6 +117,8 @@ export default class UdpClient {
if (strachArr[0] != '#DN_GD') {
return
}
this.stashFn(str)
this.stashFn=()=>{}
callback(str)
} else {
callback('')

View File

@ -161,12 +161,15 @@ export default class UdpClientByCenter {
console.log(`${TAG} udpLine send fail:${JSON.stringify(err)}`);
});
}
setMsgCallBack(callback){
this.stashFn=callback
}
sendMsg(param,context?) {
if(context){
this.context=context
}
this.sendId=param.id
console.log('sendMsg',JSON.stringify(param))
const msgData=this.setWholeMsg(param)
// const msgData=this.setMsyBody('31','010000000000000')
let promise = this.udp.send({
@ -176,7 +179,6 @@ export default class UdpClientByCenter {
port: parseInt(this.oppositeIpPort),
}
});
this.stashFn=param.callback?param.callback:()=>{}
promise.then(() => {
if(param.sendCallback){
param.sendCallback()

View File

@ -184,7 +184,8 @@ struct Index {
for (let i = 0;i < str.length; i++) {
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param= {id: 31,list:tmpList,carNo: globalThis.carInfo.carNo,placeId: globalThis.carInfo.examinationRoomId}
const param= {id: 31,list:tmpList,carNo: globalThis.carInfo.carNo,placeId: globalThis.carInfo.examinationRomId}
// globalThis.udpClient2.initHeartSendMsg(param,this.context)
globalThis.udpClient2.sendMsg(param, this.context)
}
@ -194,11 +195,10 @@ struct Index {
getUDP()
getUDP2()
setInterval(() => {
setliushuiNum(this.context)
this.heartMsg(this.context)
setliushuiNum()
this.heartMsg()
}, 1000)
// getTCP()
// const TcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) {

View File

@ -16,6 +16,7 @@ import WebRTCVoice from './webRTC/'
import promptAction from '@ohos.promptAction'
import { CandidateData, EmptyCandidateObject } from "../mock/CandidateData"
import {string2Bytes} from '../common/utils/tools'
import { getSyncData } from '../common/service/initable'
@Entry
@Component
struct UserInfo {
@ -69,8 +70,6 @@ struct UserInfo {
@State grantDept: string = '';
@State effectDate: string = '';
@State interval: any = null;
@State interval2: any = null;
@State interval3: any = null;
@State studentRefreshStatue: string = '0';
@State photo: string = 'data:image/bmp;base64,';
@State numCount: number = 0;
@ -80,21 +79,21 @@ struct UserInfo {
subscriber;
@State faceCatchImg: string = ''
onPageShow() {
async onPageShow() {
//语音功能
const systemParms:any = await getSyncData('MA_SYSTEMPARM')
console.log('systemParms',systemParms.length)
new WebRTCVoice(this.context);
//初始化数据
this.initData()
//身份证读卡器初始化
this.openDeviceByIDCard()
// this.openDeviceByIDCard()
// 如果是单机模式则模拟假数据
this.initSysset()
initJudgeUdp()
this.interval=setInterval(()=>{
this.heartMsg()
},1000)
this.heartMsg()
}
//身份证读卡器初始化
openDeviceByIDCard(){
@ -107,6 +106,9 @@ struct UserInfo {
console.error("zzctest Failed to Open Device");
}
}
stopDeviceById(){
testNapi&&testNapi.StopReadCard()
}
// 通过身份证获取当前学员
getCurrentStudent(id) {
let flag = false
@ -122,7 +124,7 @@ struct UserInfo {
// this.currentUser.kszp=this.photo+res.kszp
// this.currentUser.ksmjzp=this.photo+this.currentUser.ksmjzp
if (globalThis.singlePlay) {
testNapi.StopReadCard();
this.stopDeviceById()
// globalThis.statue=4
router.pushUrl({
url: 'pages/Judge',
@ -224,15 +226,7 @@ struct UserInfo {
}
async heartMsg() {
const arr = [globalThis.signNum||0, globalThis.statue||1]
let tmpList = [];
tmpList.push(string2Bytes(arr[0], 1 * 8)[0])
tmpList.push(string2Bytes(arr[1], 1 * 8)[0])
const str =globalThis.lsh|| '0000000000000'
for (let i = 0;i < str.length; i++) {
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param= {id: 31,list:tmpList,carNo: globalThis.carInfo.carNo,placeId: globalThis.carInfo.examinationRoomId,callback:(val)=>{
globalThis.udpClient2.setMsgCallBack((val)=>{
if(val.id=='32'){
globalThis.signNum=val.body[1]
if(val.body[0]=='7'){
@ -243,8 +237,7 @@ struct UserInfo {
console.log('qkfnqkfn',val.body[0])
this.qkFn()
}
}}
globalThis.udpClient2.sendMsg(param, this.context)
})
}
getqkFn() {
let tmpList = [];
@ -277,21 +270,28 @@ struct UserInfo {
that.ksxtbh = ksxtbhArr?.[0]?.v_value || '222'
const studentRefreshParam = syssetParams.filter(sys => sys.v_no === '452')
that.studentRefreshStatue = studentRefreshParam?.[0]?.v_value || '0'
const faceParam = syssetParams.filter(sys => sys.v_no === '17')
that.FaceOpenStatue = faceParam?.[0]?.v_value || '0'
const faceParam = syssetParams.filter(sys => sys.v_no === '2313')
that.FaceOpenStatue =faceParam?.[0]?.v_value=='3'? '1':'0'
that.FaceOpenStatue = '0'
console.log('that.FaceOpenStatue',that.FaceOpenStatue)
// faceParam?.[0]?.v_value ||
// 1身份证读卡器 2指纹 3人脸
if(faceParam?.[0]?.v_value=='1'){
that.openDeviceByIDCard()
}
console.log('mmmmm',that.FaceOpenStatue)
//0不自动更新 1自动更新不限次数 2没有考生更新2次
if (that.studentRefreshStatue == '2') {
clearInterval(that.interval2)
that.interval2 = setInterval(() => {
clearInterval(that.interval)
that.interval = setInterval(() => {
if (that.dataList.length == 0 && that.numCount < 3) {
that.numCount++
that.getExaminationStudentInfoFn()
}
}, 5000)
} else if (that.studentRefreshStatue == '1') {
clearInterval(that.interval2)
that.interval2 = setInterval(() => {
clearInterval(that.interval)
that.interval = setInterval(() => {
if (that.dataList.length == 0) {
that.getExaminationStudentInfoFn()
}
@ -303,6 +303,7 @@ struct UserInfo {
}
changeFaceCompareSuccess() {
globalThis.statue = 2
console.log('this.faceCompareSuces', this.faceCompareSucess, JSON.stringify(this.currentUser))
if (this.faceCompareSucess > 0) {
this.sfbdinterfaceFn()
@ -334,12 +335,12 @@ struct UserInfo {
if (!res) {
this.dataList = []
this.currentUser = EmptyCandidateObject
console.log('currentUser', JSON.stringify(this.currentUser))
this.errorMsg = decodeURI(res.getExaminationStudentInfoRsp.head.resultMessage)
return
}
let dataList = []
this.list = []
for (let key in res.getExaminationStudentInfoRsp.body) {
const a = res.getExaminationStudentInfoRsp.body[key]
if (a instanceof Array) {
@ -438,7 +439,7 @@ struct UserInfo {
ksxtbh: this.ksxtbh || '222',
sfzmhm: this.currentUser.sfzmhm || '',
ksysfzmhm: this.currentUser.ksy1sfzmhm || '',
zp: encodeURIComponent(this.faceCatchImg || ''),
zp: encodeURIComponent((this.faceCatchImg||this.currentUser.kszp.substr(22)) || ''),
kssj: dateFormat(date) || '',
kchp: decodeURI(plateNo),
Ksy2sfzmhm: this.currentUser.ksy2sfzmhm || ''
@ -455,6 +456,7 @@ struct UserInfo {
globalThis.lsh = this.currentUser.lsh
globalThis.ksyh = this.currentUser.ksy1sfzmhm || this.currentUser.ksy2sfzmhm
this.currentUser.id = '1'
console.log('codecode',code)
if (code) {
this.AccountTable.query('0', (result) => {
if (result.length == 0) {
@ -466,7 +468,8 @@ struct UserInfo {
url: 'pages/Judge',
params: { examItems: examItems?.getExaminationItemRsp?.body?.ykxx }
}, router.RouterMode.Single);
testNapi.StopReadCard();
this.stopDeviceById()
})
})
} else {
@ -478,7 +481,7 @@ struct UserInfo {
params: { examItems: examItems?.getExaminationItemRsp?.body?.ykxx }
}, router.RouterMode.Single);
globalThis.statue = 4
testNapi.StopReadCard();
this.stopDeviceById()
})
})
}
@ -492,8 +495,8 @@ struct UserInfo {
}
outClick() {
clearInterval(this.interval)
clearInterval(this.interval2)
testNapi.StopReadCard();
this.stopDeviceById()
globalThis.udpClient2.setMsgCallBack(()=>{})
}
// 几个按钮公共样式
@Styles
@ -646,7 +649,7 @@ struct UserInfo {
router.pushUrl({
url: 'pages/Judge',
}, router.RouterMode.Single);
testNapi.StopReadCard();
this.stopDeviceById()
})
})
} else {
@ -655,7 +658,7 @@ struct UserInfo {
router.pushUrl({
url: 'pages/Judge',
}, router.RouterMode.Single);
testNapi.StopReadCard();
this.stopDeviceById()
})
})
}
@ -678,8 +681,8 @@ struct UserInfo {
faceCompareSucess: $faceCompareSucess,
getqkFlag: $getqkFlag,
faceCatchImg: $faceCatchImg,
lsh: globalThis.lsh,
showFaceCompare: $showFaceCompare,
lsh: globalThis.lsh,
})
}
if (this.qkFlag) {

View File

@ -5,6 +5,7 @@ import common from '@ohos.app.ability.common';
import promptAction from '@ohos.promptAction'
import { startRecordVideo, endRecordVideo,takePhoto } from '../common/service/videoService'
import configAddress from '../common/utils/FileConfig'
import util from '@ohos.util';
@Entry
@Component
struct Index {
@ -33,7 +34,7 @@ struct Index {
shuiying: true,
pztd: '2',
ljlx: '',
ip: '192.168.7.112',
ip: '192.168.36.94',
port: '554',
userName: 'admin',
pwd: '12345qwe',
@ -60,7 +61,7 @@ struct Index {
shuiying: true,
pztd: '2',
ljlx: '',
ip: '192.168.7.112',
ip: '192.168.36.94',
port: '554',
userName: 'admin',
pwd: '12345qwe',
@ -148,7 +149,9 @@ struct Index {
}
for (let i = 1; i <= 4; i++) {
if (this.param['videoRecord'+i]) {
this.getfilehandleCode(i)
// setTimeout(()=>{
this.getfilehandleCode(i)
// },500)
}
}
promptAction.showToast({
@ -163,6 +166,7 @@ struct Index {
.margin({ bottom: 10 * this.ratio })
.onClick(() => {
for (let i = 1; i <= 4; i++) {
console.log('rocord_handle',JSON.stringify(this.rocordHandleObj))
if (this.rocordHandleObj['rocord_handle'+i]) {
endRecordVideo(this.rocordHandleObj['rocord_handle'+i])
this.rocordHandleObj['rocord_handle'+i] = -1
@ -186,11 +190,31 @@ struct Index {
})
return
}
await takePhoto(this.param,this.context,0,'pz')
promptAction.showToast({
message: '抓图完成',
duration: 3000
})
try{
const buffer =await takePhoto(this.param,this.context,1,'pz/')
// let view: Uint8Array = new Uint8Array(buffer); // 使用Uint8Array读取arrayBuffer的数据
// let textDecoder: util.TextDecoder = util.TextDecoder.create(); // 调用util模块的TextDecoder类
// const str = textDecoder.decodeWithStream(view).trim(); // 对view解码
// console.log("daihai base64 str = " + str);
// console.log("daihai base64 length = " + str.length);
promptAction.showToast({
message: '抓图完成',
duration: 3000
})
// takePhoto(this.param,this.context,1,'pz/').then((data) => {
// console.log('daihai suc')
promptAction.showToast({
message: '抓图完成',
duration: 3000
})
// }).catch((err) => {
// console.log('daihai err: ' + err)
// })
}catch (error){
console.log('daihai',error)
}
})
.margin({ bottom: 10 * this.ratio })
}.margin({ right: 38 * this.ratio, top: 110 * this.ratio })
@ -371,7 +395,7 @@ struct Index {
.onChange((value: string) => {
this.param.ip = value
})
TextInput({ text: this.param['td'+index+1], controller: this.inputController })
TextInput({ text: this.param['td'+(Number(index)+1)], controller: this.inputController })
.type(InputType.Normal)
.borderRadius(2)
.width(96 * this.ratio)
@ -380,7 +404,7 @@ struct Index {
.margin({ right: 10 * this.ratio })
.fontSize(this.inputFontSize * this.ratio)
.onChange((value: string) => {
this.param.td1 = value
this.param['td'+(Number(index)+1)] = value
})
TextInput({ text: this.param.userName, controller: this.inputController })
.type(InputType.Normal)
@ -589,7 +613,7 @@ struct Index {
.width('100%')
.height(395 * this.ratio)
.backgroundColor('#CCC4B8')
.position({ x: 0, y: 460 * this.ratio })
.position({ x: 0, y: 260 * this.ratio })
.border({ radius: { topLeft: 24 * this.ratio, topRight: 24 * this.ratio } })
}
@ -604,7 +628,7 @@ struct Index {
}
async getfilehandleCode(td){
const record_handle = await startRecordVideo(this.param,td,this.context,'lp')
this.rocordHandleObj['rocord_handle1'+td]=record_handle
this.rocordHandleObj['rocord_handle'+td]=record_handle
}
outClick() {
this.openFlag = false
@ -622,6 +646,9 @@ struct Index {
async writeConfig() {
this.oldParam = JSON.parse(JSON.stringify(this.param))
this.videoArr=JSON.parse(JSON.stringify(this.videoArr))
console.log('videoArr',JSON.stringify(this.videoArr))
console.log('videoArr2',JSON.stringify(this.param))
const folderPath = await this.fileUtil.initFolder(`/config`);
this.fileUtil.addFile(`${folderPath}/config3.txt`, JSON.stringify(this.param), 'overWrite')
this.showFlag = false

View File

@ -23,13 +23,14 @@ struct FaceCompare {
@Prop lsh: string;
@Prop firstImage: string;
@Link faceCompareSucess: number;
@Link showFaceCompare: boolean;
@Link getqkFlag: boolean;
@Link faceCatchImg: string;
@State imageThumbnail: string = '';
private times = 1; //人脸比对失败次数, 超过3次将不会自动比对需要点击重新打开重新触发
private vocObj = null;
@State callBackFlag: boolean = false;
@State @Watch('clearIntervalFn') showFaceCompare: Boolean = false;
@State @Watch('clearIntervalFn') showFaceCompareFlag: Boolean = false;
@State video_url: string = 'rtsp://admin:12345qwe@192.168.5.41:8000/h264/ch2/main/av_stream'
@State previewUri: Resource = $r('app.media.2_nor')
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
@ -87,6 +88,7 @@ struct FaceCompare {
.width('48%')
.height('100%')
Row() {
Image(this.firstImage)
.width('100%')
@ -155,8 +157,8 @@ struct FaceCompare {
this.controller.stop()
this.vocObj && this.vocObj.releasePlayer()
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.faceCompareSucess = -1
})
}
.width('100%')
@ -193,7 +195,11 @@ struct FaceCompare {
}
async faceComparFn() {
const result = await takePhoto(this.param, this.context, 1,'jt')
console.log('mmmmm0',1)
const result = await takePhoto(this.param, this.context, 1,'jt/')
console.log('mmmmm8',9)
faceCompare({
sfzh: this.sfzh,
firstImage: this.firstImage.substr(22),
@ -201,9 +207,12 @@ struct FaceCompare {
type: 2,
verifyType: 1
}).then(res => {
console.log('mmmmm8',res)
if (res) {
this.controller.stop()
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.faceCompareSucess = 1;
// this.faceCatchImg = result
this.vocObj.playAudio({
@ -239,6 +248,7 @@ struct FaceCompare {
this.callBackFlag = true
}
}
globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param, this.context)
this.interval = setInterval(() => {
if (this.callBackFlag) {
const param2 = {
@ -246,31 +256,32 @@ struct FaceCompare {
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId,
callback: (val) => {
if (val.id == '48') {
if (val.body[13] == '1') {
this.showFaceCompare = !this.showFaceCompare
this.vocObj && this.vocObj.releasePlayer()
this.faceCompareSucess = 1
clearInterval(this.interval)
} else if (val.body[13] == '0' && this.callBackFlag) {
globalThis.statue = 2
this.vocObj && this.vocObj.playAudio({
type: 1,
name: 'face_chekc_fail.wav'
})
}
}
}
}
globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param2, this.context)
}
}, 1000)
globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param, this.context)
globalThis.udpClient2.setMsgCallBack((val) => {
if (val.id == '48') {
if (val.body[13] == '1') {
this.showFaceCompareFlag=!this.showFaceCompareFlag
this.showFaceCompare = !this.showFaceCompare
this.vocObj && this.vocObj.releasePlayer()
this.faceCompareSucess = 1
clearInterval(this.interval)
} else if (val.body[13] == '0' && this.callBackFlag) {
globalThis.statue = 2
this.vocObj && this.vocObj.playAudio({
type: 1,
name: 'face_chekc_fail.wav'
})
}
}
})
}
async getVideoConfig() {
console.log('faceEnterIn')
this.vocObj = new voiceService(async (status, val, next) => {
if (status == 'idle') {
if (val == 'face_check.mp3' || val == 'face_fail.mp3') {
@ -289,6 +300,7 @@ struct FaceCompare {
}
} else if (val == 'yzcg.wav') {
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
globalThis.statue = 4
this.faceCompareSucess = 1;
this.vocObj && this.vocObj.releasePlayer()
@ -297,11 +309,14 @@ struct FaceCompare {
this.vocObj && this.vocObj.releasePlayer()
this.faceCompareSucess = -1
this.showFaceCompare = !this.showFaceCompare
this.showFaceCompareFlag=!this.showFaceCompareFlag
}
}
});
const data = await this.fileUtil.readFile(configAddress.comoonfileWriteAddress + '/config/config3.txt');
console.log('faceEnterIn,data',data)
setTimeout(() => {
this.vocObj && this.vocObj.playAudio({
type: 1,
@ -310,10 +325,10 @@ struct FaceCompare {
}, 1000)
this.param = JSON.parse(data)
this.param.userName = JSON.parse(data).userName
this.param.ip = JSON.parse(data).ip
this.param.pwd = JSON.parse(data).pwd
this.param.port = JSON.parse(data).port
this.param.rlls = JSON.parse(data).rlls
this.param.ip = this.param.ip
this.param.pwd = this.param.pwd
this.param.port = this.param.port
this.param.rlls = this.param.rlls
this.controller.start()
}