diff --git a/entry/src/main/ets/api/judge.ets b/entry/src/main/ets/api/judge.ets index 5ef5b2a7..cb10de62 100644 --- a/entry/src/main/ets/api/judge.ets +++ b/entry/src/main/ets/api/judge.ets @@ -1,13 +1,13 @@ import request from '../utils/Request'; import writeObjectOutNew from './judgeNew'; import http from '@ohos.net.http'; -import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model'; +import { MASYSSETTableType, RegulatoryInterfaceParams, WuxiExamType } from '../model'; import { GetSyncData } from '../utils/table/Operation'; import { GetCurrentTime } from '../utils/Common'; import FileUtils from '../utils/FileUtils'; import common from '@ohos.app.ability.common'; -let baseHost: string = AppStorage.get('host'); +let baseHost: string = AppStorage.get('host')!; // 下载模型 @@ -30,11 +30,11 @@ interface WR { export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath: string, context: common.UIAbilityContext): Promise { - const singlePlay: boolean = AppStorage.get('singlePlay') + const singlePlay: boolean = AppStorage.get('singlePlay') || false if (singlePlay) { return { code: 1 } } - let JGHOST: string = AppStorage.get("JGHOST") + let JGHOST: string = AppStorage.get("JGHOST") || "" //获取监管接口地址路径 if (!JGHOST) { const syssetParams: MASYSSETTableType[] = await GetSyncData("MA_SYSSET"); @@ -52,27 +52,33 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath }) } // const { xtlb, jkxlh, jkid, drvexam } = params; - const isJGNew: boolean = AppStorage.get('isJGNew') + const isJGNew: boolean = AppStorage.get('isJGNew') || false //新监管调用 if (isJGNew) { return await writeObjectOutNew(params, filePath, context) } - params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(drvexam.zp) + params.drvexam = params.drvexam ?? {}; + params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(params.drvexam.zp); const drvexamArrs = Reflect.ownKeys(params.drvexam) - .filter(dKey => params.drvexam[dKey] != undefined) + .filter(dKey => Reflect.get(params.drvexam, dKey) != undefined) .map((key: string) => ( - `<${key}>${params.drvexam[key]}`)); + `<${key}>${Reflect.get(params.drvexam, key)}`)); if (filePath) { - const fileUtil = new FileUtils(globalThis.context); + const fileUtil = new FileUtils(context); await fileUtil.initFolder(filePath); - fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({ + + let obj: WuxiExamType = { xtlb: params.xtlb, jkxlh: params.jkxlh, jkid: params.jkid, - drvexam: { ...params.drvexam, zp: '' }, - }) + `\n`); + drvexam: { + zp: "", + + }, + } + fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(obj) + `\n`); } //对象转换成xml @@ -108,7 +114,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath xml: true },) if (filePath) { - const fileUtil = new FileUtils(globalThis.context); + const fileUtil = new FileUtils(context); await fileUtil.initFolder(filePath); fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`); } @@ -134,7 +140,6 @@ interface UploadExamProgressDataParams { // 过程文件上传 export async function uploadExamProgressData(params: UploadExamProgressDataParams) { - // const singlePlay = globalThis.singlePlay const singlePlay: boolean = AppStorage.get('singlePlay') || false if (singlePlay) { return @@ -257,7 +262,7 @@ export async function uploadExamGrade(params: ESObject) { function validateIP(path: string) { const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`) const result = path.match(reg); - return result[0] + return result ? result[0] : ""; } // 上传运行时常 diff --git a/entry/src/main/ets/api/judgeNew.ets b/entry/src/main/ets/api/judgeNew.ets index 4cbb8f68..dab1f0c5 100644 --- a/entry/src/main/ets/api/judgeNew.ets +++ b/entry/src/main/ets/api/judgeNew.ets @@ -32,8 +32,8 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, context: common.UIAbilityContext): Promise { // const context: common.UIAbilityContext = AppStorage.get('context') const fileUtil = new FileUtils(context); - const basic = await getBasicConfig(data.jkid); - const params = await getParams(data.jkid, data.drvexam); + const basic = await getBasicConfig(data.jkid || ""); + const params = await getParams(data.jkid || "", data.drvexam ?? {} as DrvexamType); if (filePath) { let examData: WuxiExamType = { @@ -44,7 +44,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, sjbs: basic.sjbs, data: params.data, file: { - sjbs: params.file.sjbs, + sjbs: params?.file?.sjbs || "", // params: [] } } @@ -55,7 +55,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, console.info('surenjun', '调用新监管') let temp: WR try { - const JGHOST: string = AppStorage.get('JGHOST') + const JGHOST: string = AppStorage.get('JGHOST') || "" temp = await request({ host: JGHOST, method: http.RequestMethod.POST, @@ -95,7 +95,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams, export async function getParams(jkid: string, drvexam: DrvexamType): Promise { const carInfo: CarInfoType = AppStorage.get('carInfo')! - const examSubject: string = carInfo.examSubject; + const examSubject: string = carInfo.examSubject || "2"; switch (jkid) { //开始考试 case '17C51': @@ -104,7 +104,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise { const carInfo: CarInfoType = AppStorage.get('carInfo')! - const examSubject: string = carInfo.examSubject; + const examSubject: string = carInfo.examSubject || "2"; const syssetParam: MASYSSETTableType[] = await GetSyncData('MA_SYSSET'); let syssetObj: Record = {}; syssetParam.forEach(sys => { - syssetObj[sys.v_no] = decodeURIComponent(sys.v_value) + if (sys.v_no) { + syssetObj[sys.v_no] = decodeURIComponent(sys.v_value || "") + } }); let obj: WuxiExamType = { //外挂类别 diff --git a/entry/src/main/ets/model/Judge.ets b/entry/src/main/ets/model/Judge.ets index 23572f45..c371f228 100644 --- a/entry/src/main/ets/model/Judge.ets +++ b/entry/src/main/ets/model/Judge.ets @@ -807,13 +807,16 @@ export interface WR { // 无锡所数据 export interface WuxiExamType { - wglb: string - jkxlh: string, - glbm: string, - jgbh: string, - sjbs: string, + wglb?: string + jkxlh?: string, + glbm?: string, + jgbh?: string, + sjbs?: string, + xtlb?: string + jkid?: string data?: JudgeData, file?: JudgeFile + drvexam?: DrvexamType } diff --git a/entry/src/main/ets/pages/compontents/FaceCompare.ets b/entry/src/main/ets/pages/compontents/FaceCompare.ets index 1d439504..d44ce81d 100644 --- a/entry/src/main/ets/pages/compontents/FaceCompare.ets +++ b/entry/src/main/ets/pages/compontents/FaceCompare.ets @@ -8,7 +8,7 @@ import { CarInfoType, UDPParamType, VideoConfig } from '../../model'; import { NumberToByteArray } from '../../utils/Common'; import FileUtils from '../../utils/FileUtils'; import { CenterUDPClientInstance } from '../../utils/business/CenterUdpBusiness'; -import { takePhoto } from '../../utils/Video'; +import { takePhoto, takePhotoParam } from '../../utils/Video'; import { voiceService } from '../../utils/Voice'; interface ParamType { @@ -189,11 +189,11 @@ export default struct FaceCompare { async faceComparFn() { console.log('mmmmm0', 2) this.param.pztd = this.param.rlls - const data = await takePhoto(this.param, this.context, 'jt/', 1,) + const data: takePhotoParam = await takePhoto(this.param, this.context, 'jt/', 1,) this.base64 = this.imageBase64 + (data?.base64 || "") console.log('mmmmt', this.base64) faceCompare({ - sfzh: this.sfzh, + sfzh: this.sfzh.toString(), firstImage: this.firstImage.substr(22), secondImage: data?.base64 || "", type: "2", diff --git a/entry/src/main/ets/pages/judgeSDK/utils/filePhoto.ets b/entry/src/main/ets/pages/judgeSDK/utils/filePhoto.ets index 7a3f8463..7e1261b3 100644 --- a/entry/src/main/ets/pages/judgeSDK/utils/filePhoto.ets +++ b/entry/src/main/ets/pages/judgeSDK/utils/filePhoto.ets @@ -2,12 +2,12 @@ import { takePhoto } from '../../../utils/Video'; import promptAction from '@ohos.promptAction'; import { JudgeConfig } from './judgeConfig'; import FileUtils from '../../../utils/FileUtils'; -import {VideoConfig} from '../../../model/Common' +import { VideoConfig } from '../../../model/Common'; import common from '@ohos.app.ability.common'; export default class FilePhoto { - private params: VideoConfig - private context:common.UIAbilityContext + private params!: VideoConfig + private context!: common.UIAbilityContext public getPhoto = async () => { if (!JudgeConfig.isPhotoOpen) { return '' @@ -27,9 +27,8 @@ export default class FilePhoto { } } } - private fileUtil: FileUtils - constructor(context:common.UIAbilityContext) { + constructor(context: common.UIAbilityContext) { (async () => { //TODO 309参数 获取拍照摄像头拍照通道 const fileUtil = new FileUtils(context) @@ -37,15 +36,14 @@ export default class FilePhoto { await fileUtil.readFile('/mnt/hmdfs/100/account/device_view/local/files/duolun/config/config3.txt'); const config: VideoConfig = JSON.parse(strConfig as string) this.params = { - userName:config.userName, - pwd:config.pwd, - ip:config.ip, - port:config.port, - rlls:config.rlls, - pztd:config.pztd, + userName: config.userName, + pwd: config.pwd, + ip: config.ip, + port: config.port, + rlls: config.rlls, + pztd: config.pztd, } this.context = context - this.fileUtil = fileUtil })() } } \ No newline at end of file diff --git a/entry/src/main/ets/utils/Video.ets b/entry/src/main/ets/utils/Video.ets index 50f7623c..dd49ad39 100644 --- a/entry/src/main/ets/utils/Video.ets +++ b/entry/src/main/ets/utils/Video.ets @@ -3,7 +3,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; import record from '@ohos.rtsprecord'; import promptAction from '@ohos.promptAction'; import { GetCurrentTime, IsDaysAgo } from './Common'; -import { RecordHandleType, TakePhotoCallbackData, VideoConfig } from '../model'; +import { RecordHandleType, VideoConfig } from '../model'; import common from '@ohos.app.ability.common'; import dayTs from './Date'; import { GlobalConfig, VideoTag } from '../config'; @@ -113,7 +113,7 @@ export async function saveStartRecordVideo(path: string, context: common.UIAbili * @param context * @param type=0不获取base64 */ -interface takePhotoParam { +export interface takePhotoParam { name?: string, base64?: string, fileSize?: number, @@ -154,46 +154,58 @@ export async function delPic(day: number, type: number, context: common.UIAbilit } } -export async function takePhoto(param: VideoConfig, context: common.UIAbilityContext, dir: string, flag = 1, - callback?: (data: TakePhotoCallbackData) => void): Promise { +export async function takePhoto( + param: VideoConfig, + context: common.UIAbilityContext, + dir: string, + flag = 1, + callback?: (data: takePhotoParam) => void +): Promise { let video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`; const num = Math.floor(Math.random() * 10000); const fileName = `picture_record${num}.jpg`; - if (flag == 0) { - return new Promise((resolve, reject) => { + if (flag === 0) { + return new Promise((resolve, reject) => { rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => { if (snapResult && snapResult.errorCode === 0) { + const result: takePhotoParam = { + fileSize: snapResult.fileSize, + errorCode: snapResult.errorCode, + }; if (callback) { - callback({ - fileSize: snapResult.fileSize, - errorCode: snapResult.errorCode, - }); + callback(result); } - resolve(); + resolve(result); } else { promptAction.showToast({ message: `拍照失败`, duration: 3000, }); - reject(err); + reject({ + name: fileName, + base64: '', + fileSize: 0, + errorCode: err ? err.code : -1, + }); } }); }); } else { - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { const time = GetCurrentTime(); const date = time.split(' ')[0]; - let dirName = dir ? dir : date; + const dirName = dir || date; + rtsp_server.getVideoSnapshot( context, video_uri, fileName, dirName, true, - async (err: BusinessError, snapResult: record.RtspResult) => { - if (snapResult.result && snapResult.errorCode === 0) { + (err: BusinessError, snapResult: record.RtspResult) => { + if (snapResult && snapResult.errorCode === 0) { resolve({ base64: snapResult.dataString, name: snapResult.fileName, @@ -205,7 +217,12 @@ export async function takePhoto(param: VideoConfig, context: common.UIAbilityCon message: `拍照失败`, duration: 3000, }); - reject(false); + reject({ + name: fileName, + base64: '', + fileSize: 0, + errorCode: err ? err.code : -1, + }); } } ); diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index ba7c9fe5..8a446ad6 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -2,7 +2,7 @@ "meta": { "stableOrder": true }, - "lockfileVersion": 1, + "lockfileVersion": 3, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3",