diff --git a/entry/src/main/ets/api/checkCar.ts b/entry/src/main/ets/api/checkCar.ts index 942ac276..59674094 100644 --- a/entry/src/main/ets/api/checkCar.ts +++ b/entry/src/main/ets/api/checkCar.ts @@ -2,7 +2,7 @@ import request from "../common/utils/request" export async function carConfigurationInfo(params){ - return await request({ + return request({ url:'/der2/services/exam/carConfigurationInfo.ws', data:params, method:'post', @@ -12,7 +12,7 @@ export async function carConfigurationInfo(params){ //设备注册 export async function registrationDeviceNo(params){ - return await request({ + return request({ url:'/der2/services/exam/registrationDeviceNo.ws', data:` @@ -26,7 +26,7 @@ export async function registrationDeviceNo(params){ //自检结果上传 export async function uploadExamCarCheckResult(params){ - return await request({ + return request({ url:'/der2/services/exam/uploadExamCarCheckResult.ws', data:` diff --git a/entry/src/main/ets/api/dashboard.ts b/entry/src/main/ets/api/dashboard.ts index 9f97a1fd..ae332124 100644 --- a/entry/src/main/ets/api/dashboard.ts +++ b/entry/src/main/ets/api/dashboard.ts @@ -1,7 +1,7 @@ import request from "../common/utils/request" export async function timeSynchronization(params){ - return await request({ + return request({ url:'/der2/services/exam/timeSynchronization.ws', data:` diff --git a/entry/src/main/ets/api/index.ts b/entry/src/main/ets/api/index.ts index 12b7bea7..46d0bb7c 100644 --- a/entry/src/main/ets/api/index.ts +++ b/entry/src/main/ets/api/index.ts @@ -2,7 +2,7 @@ import request from "../common/utils/request" //同步时间 export async function timeSynchronization(params){ - return await request({ + return request({ url:'/der2/services/exam/timeSynchronization.ws', data:` @@ -19,7 +19,7 @@ export async function timeSynchronization(params){ //获取考车信息 export async function obtainCarExamInfo(params){ - return await request({ + return request({ url:'/der2/services/exam/obtainCarExamInfo.ws', data:` @@ -32,7 +32,7 @@ export async function obtainCarExamInfo(params){ } //获取参数平台考车信息 export async function initCarInfoCache(params){ - return await request({ + return request({ url:'/para/initCarInfoCache.ws', data:params.data, method:'post', @@ -42,7 +42,7 @@ export async function initCarInfoCache(params){ } //参数下发读表接口 export async function initCenterCache(params,url){ - return await request({ + return request({ url:'/para/initCenterCache.ws', data:params, method:'post', @@ -52,7 +52,7 @@ export async function initCenterCache(params,url){ } //参数下发读表接口 export async function initCenterCacheByKSPT(params,url){ - return await request({ + return request({ url:'/der2/services/para/initCenterCache.ws', data:params, method:'post', @@ -64,7 +64,7 @@ export async function initCenterCacheByKSPT(params,url){ //从参数平台获取模型 export async function initEsModel(params){ - return await request({ + return request({ url:'/para/initEsModel.ws', data:params, method:'post', @@ -74,7 +74,7 @@ export async function initEsModel(params){ } export async function initialization(params){ - return await request({ + return request({ url:'/der2/services/exam/initialization.ws', data:`${params.carId}${params.examinationRoomId}${params.shellVersion}${params.judgeVersion}${params.videoVersion}`, method:'post', @@ -85,7 +85,7 @@ export async function initialization(params){ //参数下发读表接口 export async function initCarParameter(params){ - return await request({ + return request({ url:'/der2/services/para/initCarParameter.ws', data:params, method:'post', diff --git a/entry/src/main/ets/api/judge.ts b/entry/src/main/ets/api/judge.ts index ca68eae1..de4627c1 100644 --- a/entry/src/main/ets/api/judge.ts +++ b/entry/src/main/ets/api/judge.ts @@ -8,7 +8,7 @@ let baseHost = globalThis.host; // 下载模型 export async function download() { - return await request({ + return request({ host: baseHost, url: '/para/initEsModel.ws', method: 'post', @@ -64,7 +64,7 @@ export async function writeObjectOut(params,filePath?:string): Promise { } //对象转换成xml - const temp = await request({ + const temp = request({ host: globalThis.JGHOST, url: '/dems_ws/services/TmriOutAccess?wsdl', data: ` @@ -115,7 +115,7 @@ export async function uploadExamProgressData(params) { if (singlePlay) { return } - return await request({ + return request({ url: '/der2/services/exam/uploadExamDataFile.ws', data: ` @@ -142,7 +142,7 @@ export async function uploadExamMileage(params) { return } const time = await getCurrentTime() - return await request({ + return request({ url: '/der2/services/exam/uploadExamMileage.ws', data: ` @@ -168,7 +168,7 @@ export async function uploadExamGrade(params) { } const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}`)) const time = await getCurrentTime() - return await request({ + return request({ url: '/der2/services/exam/uploadExamGrade.ws', data: ` @@ -190,7 +190,7 @@ function validateIP(path: string) { // 上传运行时常 export async function uploadHarmonyLiCheng(data) { - return await request({ + return request({ url: '/der2/services/data/harmonyLiCheng.ws', data, method: 'post', diff --git a/entry/src/main/ets/api/login.ts b/entry/src/main/ets/api/login.ts index 73ba096a..3c0764ff 100644 --- a/entry/src/main/ets/api/login.ts +++ b/entry/src/main/ets/api/login.ts @@ -2,7 +2,7 @@ import request from "../common/utils/request" export async function examinerLogin(params){ - return await request({ + return request({ url:'/der2/services/exam/examinerLogin.ws', data:` diff --git a/entry/src/main/ets/api/userInfo.ts b/entry/src/main/ets/api/userInfo.ts index 8db7e169..8e7e85ee 100644 --- a/entry/src/main/ets/api/userInfo.ts +++ b/entry/src/main/ets/api/userInfo.ts @@ -11,7 +11,7 @@ import request from "../common/utils/request" */ export async function faceCompare(params) { - return await request({ + return request({ url: '/der2/services/imageCompare/base64ImageStrCompare.ws', data: ` @@ -30,7 +30,7 @@ export async function faceCompare(params) { export async function getExaminationStudentInfo(params) { - return await request({ + return request({ url: '/der2/services/exam/getExaminationStudentInfo.ws', data: params, method: 'post', @@ -39,7 +39,7 @@ export async function getExaminationStudentInfo(params) { } //缺考 export async function examinationStuAbsent(params) { - return await request({ + return request({ url: '/der2/services/exam/examinationStuAbsent.ws', data: params, method: 'post', @@ -49,7 +49,7 @@ export async function examinationStuAbsent(params) { //获取断点续考 export async function getExaminationItem(params) { - return await request({ + return request({ url: '/der2/services/exam/getExaminationItem.ws', data: ` @@ -68,7 +68,7 @@ export async function getExaminationItem(params) { //参数下发读表接口 export async function getPhotosForOther(params) { - return await request({ + return request({ url: '/der2/services/third/getPhotosForOther.ws', data: `${params.sfzmhm}2${params.zptype}${params.ksrq}`, method: 'post', @@ -78,7 +78,7 @@ export async function getPhotosForOther(params) { } export async function setVideoText() { - return await request({ + return request({ url: 'http://admin:12345qwe@192.168.36.94/PSIA/Custom/SelfExt/OSD/channels/2/textOverlay', data: ` 1true0012222true0022223false004false005false006false007false008false00`, diff --git a/entry/src/main/ets/common/service/FileHelper.ts b/entry/src/main/ets/common/service/FileHelper.ts index c5c111ec..cd1edfa6 100644 --- a/entry/src/main/ets/common/service/FileHelper.ts +++ b/entry/src/main/ets/common/service/FileHelper.ts @@ -13,34 +13,62 @@ * limitations under the License. */ + // @ts-ignore import photoAccessHelper from '@ohos.file.photoAccessHelper' import dataSharePredicates from '@ohos.data.dataSharePredicates' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' +import fs from '@ohos.file.fs'; +import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -export class FileHelper { +class FileHelper { private userFileMgr: photoAccessHelper.PhotoAccessHelper = undefined; + private mediaLib: mediaLibrary.MediaLibrary = undefined; + + private baseDir: string ="" FILE_ASSET_FETCH_COLUMNS = [photoAccessHelper.PhotoKeys.URI, - photoAccessHelper.PhotoKeys.PHOTO_TYPE, - photoAccessHelper.PhotoKeys.DISPLAY_NAME, - photoAccessHelper.PhotoKeys.SIZE, - photoAccessHelper.PhotoKeys.DATE_ADDED, - photoAccessHelper.PhotoKeys.DATE_MODIFIED, - photoAccessHelper.PhotoKeys.DURATION, - photoAccessHelper.PhotoKeys.WIDTH, - photoAccessHelper.PhotoKeys.HEIGHT, - photoAccessHelper.PhotoKeys.DATE_TAKEN, - photoAccessHelper.PhotoKeys.ORIENTATION, - photoAccessHelper.PhotoKeys.FAVORITE, - photoAccessHelper.PhotoKeys.TITLE, - photoAccessHelper.PhotoKeys.POSITION, - photoAccessHelper.PhotoKeys.DATE_TRASHED, - photoAccessHelper.PhotoKeys.HIDDEN]; + photoAccessHelper.PhotoKeys.PHOTO_TYPE, + photoAccessHelper.PhotoKeys.DISPLAY_NAME, + photoAccessHelper.PhotoKeys.SIZE, + photoAccessHelper.PhotoKeys.DATE_ADDED, + photoAccessHelper.PhotoKeys.DATE_MODIFIED, + photoAccessHelper.PhotoKeys.DURATION, + photoAccessHelper.PhotoKeys.WIDTH, + photoAccessHelper.PhotoKeys.HEIGHT, + photoAccessHelper.PhotoKeys.DATE_TAKEN, + photoAccessHelper.PhotoKeys.ORIENTATION, + photoAccessHelper.PhotoKeys.FAVORITE, + photoAccessHelper.PhotoKeys.TITLE, + photoAccessHelper.PhotoKeys.POSITION, + photoAccessHelper.PhotoKeys.DATE_TRASHED, + photoAccessHelper.PhotoKeys.HIDDEN + ]; + constructor() { + this.mediaLib = mediaLibrary.getMediaLibrary(globalThis.context); this.userFileMgr = photoAccessHelper.getPhotoAccessHelper(globalThis.context); + this.baseDir = AppStorage.Get('sanBoxFileDir') + '/TextDir'; } + async queryFile(displayName): Promise { + var ret ; + console.info(` baoyihu queryFile displayName=${displayName}`); + let fetchOp = { + selections: `media_type=? AND display_name = ?`, + selectionArgs: [`${mediaLibrary.MediaType.AUDIO}`,displayName], + }; + console.log( 'baoyihu queryFile selections: '+fetchOp.selections +" args:" + fetchOp.selectionArgs); + let fileResult = await this.mediaLib.getFileAssets(fetchOp); + let retCount = fileResult.getCount(); + console.log( 'baoyihu queryFile count: '+retCount ); + if (retCount > 0) { + ret= fileResult.getFirstObject(); + console.log( 'baoyihu queryFile success ' ); + } + return Promise.resolve(ret); + } + + public async queryPhotoByDisplayName(displayName) { console.log( 'baoyihu queryPhotoByDisplayName begin DISPLAY_NAME:' +displayName ); @@ -67,7 +95,7 @@ export class FileHelper { } async getUserAlbumItemByDisplayName(displayName: string): Promise { - let fetchResult: photoAccessHelper.FetchResult = null + let fetchResult = null let album: photoAccessHelper.Album = null try { console.log( 'getUserAlbumItemByDisplayName'); @@ -116,9 +144,58 @@ export class FileHelper { } finally { } } + private savedPictureFile:string[] = []; + private savedVideoFile:string[] = []; + //1 是图片,2 是视频 + public addFile(fileName,file_type) + { + if(file_type==1) { + this.savedPictureFile.push(fileName); + } + else if(file_type==2) + { + this.savedVideoFile.push(fileName); + } + } + + public async trashPictureFiles(all_fileAsset) + { + + let albumFetchResult = null; + try { + albumFetchResult = await this.userFileMgr.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); + + let trashAlbum = await albumFetchResult.getFirstObject(); + trashAlbum.deleteAssets(all_fileAsset).then(() => { + console.log('baoyihu deletePictureOfAlbum trash ok : '); + }).catch((err) => { + console.log('baoyihu deletePictureOfAlbum trash faild : '); + }); + }catch (err) { + console.log('baoyihu deletePictureOfAlbum error: '+err); + } finally { + if (albumFetchResult != null) { + albumFetchResult.close(); + } + } + console.log( 'baoyihu deletePictureOfAlbum delete end' ); + } + public async deleteFileOfAlbum(album_Name,file_type): Promise { console.log('baoyihu deletePictureOfAlbum album_Name:'+album_Name); + var fileMap =[] + if(file_type==1) + { + fileMap = this.savedPictureFile.slice() + this.savedPictureFile.length = 0; + } + else + { + fileMap = this.savedVideoFile.slice() + this.savedVideoFile.length = 0; + } + var photoFetchResult =null; try { let album = await this.getUserAlbumItemByName(album_Name); @@ -130,15 +207,18 @@ export class FileHelper { }; photoFetchResult = await album.getAssets(fetchOptions) var all_fileAsset = await photoFetchResult.getAllObjects(); - var uri_array=[] - console.log( 'baoyihu deletePictureOfAlbum iterator begin',album_Name ); - for (let onfile of all_fileAsset) - { - console.log(album_Name, 'baoyihu deletePictureOfAlbum uri : ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName); - uri_array.push(onfile.uri); - } - await this.userFileMgr.deleteAssets(uri_array); + console.log( 'baoyihu deletePictureOfAlbum iterator begin' +fileMap.length); + // for (let onfile of all_fileAsset) + // { + // console.log( 'baoyihu deletePictureOfAlbum uri : ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName); + // if(fileMap.indexOf(onfile.displayName)>-1) + // { + // console.log( 'baoyihu deletePictureOfAlbum uri find one: ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName); + // uri_array.push(onfile.uri); + // } + // } + // await this.userFileMgr.deleteAssets(uri_array); let albumFetchResult = null; try { @@ -146,21 +226,21 @@ export class FileHelper { let trashAlbum = await albumFetchResult.getFirstObject(); trashAlbum.deleteAssets(all_fileAsset).then(() => { - console.log('baoyihu deletePictureOfAlbum trash ok : ',album_Name); + console.log('baoyihu deletePictureOfAlbum trash ok : '); }).catch((err) => { - console.log('baoyihu deletePictureOfAlbum trash faild : ',album_Name); + console.log('baoyihu deletePictureOfAlbum trash faild : '); }); }catch (err) { - console.log('baoyihu deletePictureOfAlbum error: '+err,album_Name); + console.log('baoyihu deletePictureOfAlbum error: '+err); } finally { if (albumFetchResult != null) { albumFetchResult.close(); } } - console.log( 'baoyihu deletePictureOfAlbum delete end',album_Name ); + console.log( 'baoyihu deletePictureOfAlbum delete end' ); } catch (err) { - console.log( 'baoyihu deletePictureOfAlbum failed with err: ' + err,album_Name); + console.log( 'baoyihu deletePictureOfAlbum failed with err: ' + err); } finally { if (photoFetchResult != null) { photoFetchResult.close(); @@ -168,8 +248,19 @@ export class FileHelper { } } - public async deleteAllPictures(): Promise { - console.log('baoyihu deleteAllPictures'); + public async deleteAllPictures(file_type): Promise { + console.log('baoyihu deleteAllPictures enter'); + var fileMap =[] + if(file_type==1) + { + fileMap = this.savedPictureFile.slice() + this.savedPictureFile.length = 0; + } + else + { + fileMap = this.savedVideoFile.slice() + this.savedVideoFile.length = 0; + } let photoFetchResult = null; try { let predicates = new dataSharePredicates.DataSharePredicates(); @@ -181,17 +272,24 @@ export class FileHelper { var all_fileAsset = await photoFetchResult.getAllObjects(); var uri_array=[] - console.log( 'baoyihu batch delete begin' ); + console.log( 'baoyihu deleteAllPictures batch delete begin fileMap.length' +fileMap.length); for (let onfile of all_fileAsset) { - console.log( 'baoyihu push one uri : ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName +', file_size: '+onfile.size); - uri_array.push(onfile.uri); + console.log( 'baoyihu deleteAllPictures find one uri : ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName +', file_size: '+onfile.size); + + if(fileMap.indexOf(onfile.displayName)>-1) + { + console.log( 'baoyihu deleteAllPictures uri find one: ' + onfile.uri +', photoType : '+onfile.photoType+', displayName : '+onfile.displayName); + uri_array.push(onfile.uri); + } } // await album.removeAssets(all_fileAsset); await this.userFileMgr.deleteAssets(uri_array); - console.log( 'baoyihu batch delete end' ); + + await this.trashPictureFiles(all_fileAsset); + console.log( 'baoyihu deleteAllPictures batch delete end' ); } catch (err) { - console.log( 'baoyihu get Album getPhotoAssets failed with err: ' + err); + console.log( 'baoyihu deleteAllPictures failed with err: ' + err); } finally { if (photoFetchResult != null) { photoFetchResult.close(); @@ -226,7 +324,7 @@ export class FileHelper { // } async getUserAlbumItemByName(albumName: string): Promise { - let fetchResult: photoAccessHelper.FetchResult = null + let fetchResult= null let album: photoAccessHelper.Album = null try { console.log( 'getUserAlbumItemByName'); @@ -259,7 +357,7 @@ export class FileHelper { console.log( "baoyihu createAlbum beging"); let albumAsset = await this.userFileMgr.createAlbum(albumName); console.log( 'baoyihu createAlbum success, albumType: ' + albumAsset.albumType +', albumSubtype: '+ albumAsset.albumSubtype - +', albumName: '+ albumAsset.albumName +', albumUri: '+ albumAsset.albumUri +', coverUri: ' + albumAsset.coverUri); + +', albumName: '+ albumAsset.albumName +', albumUri: '+ albumAsset.albumUri +', coverUri: ' + albumAsset.coverUri); return albumAsset.albumUri ; } catch (err) { console.log( 'baoyihu createAlbum failed with err: ' + err); @@ -275,7 +373,7 @@ export class FileHelper { let createOptions = { subtype: photoAccessHelper.PhotoSubtype.SCREENSHOT}; await this.userFileMgr.createAsset("picture2.jpg", createOptions,(err,photoResult)=>{ console.log( 'baoyihu createPhotoAsset return uri: ' + photoResult.uri +', photoType: '+ photoResult.photoType - +', displayName: '+ photoResult.displayName ); + +', displayName: '+ photoResult.displayName ); }); } catch (err) { console.log( 'baoyihu createPhotoAsset failed with err: ' + err); @@ -295,7 +393,7 @@ export class FileHelper { { let albumAsset:photoAccessHelper.Album = await fetchResult.getObjectByPosition(i); console.log( 'queryAlbum albumType: ' + albumAsset.albumType +', Subtype: '+ albumAsset.albumSubtype - +', Name: '+ albumAsset.albumName +', Uri: '+ albumAsset.albumUri +', coverUri: '+ albumAsset.coverUri); + +', Name: '+ albumAsset.albumName +', Uri: '+ albumAsset.albumUri +', coverUri: '+ albumAsset.coverUri); let predicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions = { @@ -331,6 +429,9 @@ export class FileHelper { }) } + + + public async deleteAllVideos(type: photoAccessHelper.AlbumType, subType: photoAccessHelper.AlbumSubtype ): Promise { let fetchResult:photoAccessHelper.FetchResult = null; try { @@ -382,4 +483,56 @@ export class FileHelper { } } } + + + public isPrime(number):boolean { + if (number < 2) { + return false; + } + for (let i = 2; i * i <= number; i++) { + if (number % i === 0) { + return false; + } + } + return true; + } + + public findPrimes(start, end):void + { + console.log(`baoyihu find Prime begin in the range ${start} to ${end} are:`); + var count = 0; + for (let number = start; number <= end; number++) + { + if (this.isPrime(number)) + { + count++; + //console.log("baoyihu find Number:"+number); + } + } + console.log("baoyihu find Prime count:"+count); + } + + + async createRandomFile(fileName): Promise { + try { + console.log("baoyihu createRandomFile enter baseDir:"+this.baseDir); + if (!fs.accessSync(this.baseDir)) + { + fs.mkdirSync(this.baseDir); + } + let depth = this.baseDir; + let myFile = depth + `/`+fileName; + console.log("baoyihu createRandomFile begin fileName:"+fileName+", filePath:"+myFile); + let file = fs.openSync(myFile, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + let str: string = "hello, world"+"\n"+"hello,openharmony"; + let writeLen = fs.writeSync(file.fd, str); + fs.closeSync(file); + console.log("baoyihu createRandomFile success:"+file); + } catch (e) + { + console.log("baoyihu createRandomFile failed:"+e); + } + } } +const fileHelper = new FileHelper(); +export default fileHelper ; \ No newline at end of file diff --git a/entry/src/main/ets/common/service/videoService.ts b/entry/src/main/ets/common/service/videoService.ts index cd461dca..514b4cc3 100644 --- a/entry/src/main/ets/common/service/videoService.ts +++ b/entry/src/main/ets/common/service/videoService.ts @@ -8,7 +8,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates' import { dateFormat, getCurrentTime, isSevenDaysAgo } from '../utils/tools' // import rtsp_server from '@ohos.rtsprecord'; import record from '@ohos.rtsprecord'; -import { FileHelper } from './FileHelper'; +import FileHelper from './FileHelper'; import FileUtil from '../utils/File'; import { GlobalConfig } from '../../config'; import promptAction from '@ohos.promptAction'; @@ -52,9 +52,9 @@ export async function startRecordVideo(param, td, context, dir, path?, index?) { } else { fileName = `${date}_${path}_${index || num}.mp4` } - + dir=date // @ts-ignore - var recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, date,dir); + var recordResult = rtsp_server.startRecordVideo(context, video_uri, fileName, dir); const handleId = recordResult.dataInt; reslove(handleId) } @@ -88,9 +88,9 @@ export async function endRecordVideo(record_handleObj) { export async function saveStartRecordVideo(path) { return new Promise(async (reslove, reject) => { const fileUtil = new FileUtil(globalThis.context) - const fileHelper = new FileHelper(); + // const fileHelper = new FileHelper(); const date = dateFormat(new Date).split(' ')[0] - fileHelper.createAlbum(date); + FileHelper.createAlbum(date); // const folderPath = await fileUtil.initFolder(`/${path}/${date}`); const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); const param = JSON.parse(data) @@ -179,7 +179,7 @@ interface takePhotoParam { * @param callback * @returns */ -const fileHelper = new FileHelper(); +// const fileHelper = new FileHelper(); export async function delPic(day,type) { let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(globalThis.context); @@ -195,12 +195,19 @@ export async function delPic(day,type) { }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let albums = await albumList.getAllObjects(); + for(let i=0;i<=albums.length;i++){ let albumName=albums[i].albumName // isSevenDaysAgo(albumName, day) console.log('albumNamealbumName',albumName) - if (isSevenDaysAgo(albumName, day)&&albumName!='jt'&&albumName!='pz') { + // isSevenDaysAgo(albumName, day)&&albumName!='jt'&&albumName!='pz' + if (albumName=='pz') { deleteAllFileByPiC(albumName, type) + // albums[i].deleteAssets(albums).then(() => { + // console.log('baoyihu deletePictureOfAlbum trash ok : '); + // }).catch((err) => { + // console.log('baoyihu deletePictureOfAlbum trash faild : '); + // }); } } @@ -229,6 +236,8 @@ export async function takePhoto(param, context, dir, flag = 1, callback?) { const date = time.split(' ')[0] let dirName=dir?dir:date rtsp_server.getVideoSnapshot(context, video_uri, fileName,dirName, true,async (err, snapResult) => { + console.log("baohaowen_detectLoop round end size1:" + JSON.stringify(snapResult)); + if(snapResult.result&&snapResult.errorCode==0){ resolve({ base64: snapResult.dataString, @@ -250,7 +259,7 @@ export async function takePhoto(param, context, dir, flag = 1, callback?) { } } export async function deleteAllPicturesFn(){ - fileHelper.deleteAllPictures(); + // FileHelper.deleteAllPictures(); deleteAllVideos(globalThis.context,photoAccessHelper.AlbumType.USER,photoAccessHelper.AlbumSubtype.VIDEO) } @@ -258,7 +267,8 @@ export async function deleteAllPicturesFn(){ //type:1 是图片 2是视频 export async function deleteAllFileByPiC(dirName, type = 1) { // const fileHelper = new FileHelper(); - fileHelper.deleteFileOfAlbum(dirName, type); + // fileHelper.deleteFileOfAlbum(dirName, type); + FileHelper.deleteFileOfAlbum(dirName, type); } export async function deleteAllVideos(context, type: photoAccessHelper.AlbumType, subType: photoAccessHelper.AlbumSubtype): Promise { diff --git a/entry/src/main/ets/common/utils/request.ts b/entry/src/main/ets/common/utils/request.ts index c7082726..de286590 100644 --- a/entry/src/main/ets/common/utils/request.ts +++ b/entry/src/main/ets/common/utils/request.ts @@ -2,12 +2,12 @@ import http from '@ohos.net.http'; import convertxml from '@ohos.convertxml'; import prompt from '@ohos.prompt' import { sendGreen } from '../../pages/judgeSDK/utils/judgeCommon'; -import {GlobalConfig} from '../../config/index' +import { GlobalConfig } from '../../config/index' import FileUtil from '../../common/utils/File'; import { dateFormat } from '../utils/tools' const config = { - host:GlobalConfig.host, + host: GlobalConfig.host, } /** @@ -22,226 +22,270 @@ const config = { */ // let httpRequest = http.createHttp(); -export default async function request(req: any) { - const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req; +export default async function request(req: any): Promise { + return new Promise((reslove, reject) => { let httpRequest = http.createHttp(); - const options = { + const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req; + try { + const options = { method: http.RequestMethod[method.toUpperCase()], header: { - 'Content-Type': xml ? 'text/xml' : 'application/json' + 'Content-Type': xml ? 'text/xml' : 'application/json' }, extraData: xml ? data : JSON.stringify(data), - } - //params转url拼接参数 - let paramsStr = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || ''; - paramsStr = paramsStr.toString(); - paramsStr = paramsStr.substring(0, paramsStr.length-1) - try { - let baseUrl=host?host:globalThis.host - // let baseUrl=host?config.csptHost:config.host' - console.log('响应头地址1' + baseUrl,url,options.extraData.length) - const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, {...options}); - // fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList)) - // writeLog({ - // time:dateFormat(new Date()), - // url, - // result:JSON.stringify(result), - // extraData: JSON.stringify(data), - // state:'end' - // }) + } + let paramsStr = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || ''; + paramsStr = paramsStr.toString(); + paramsStr = paramsStr.substring(0, paramsStr.length - 1) + let baseUrl = host ? host : globalThis.host + // let baseUrl=host?config.csptHost:config.host' + console.log('响应头地址1' + baseUrl, url, options.extraData.length) + // const {result,responseCode} = await + httpRequest.request(`${baseUrl}${url}${paramsStr}`, { + ...options + }) + .then(async(data) => { + const result = data.result console.log('响应头地址' + JSON.stringify(result)) - let res:any = xml ? xmlToJson(result,url) : result; + let res: any = xml ? xmlToJson(result, url) : result; console.log('响应头地址' + JSON.stringify(res)) let resObj = null; - if(typeof res === "string"){ - res=JSON.parse(res) + if (typeof res === "string") { + res = JSON.parse(res) } //处理中心服务code - if(res.Envelope){ - const msgXml = res.Envelope.Body.writeObjectOutResponse.return; - //Envelope.Body.writeObjectOutResponse.return - const dd = handleCenterCode(msgXml,isNewCenter); - httpRequest.destroy(); - return dd + if (res.Envelope) { + const msgXml = res.Envelope.Body.writeObjectOutResponse.return; + //Envelope.Body.writeObjectOutResponse.return + const dd = handleCenterCode(msgXml, isNewCenter); + httpRequest.destroy(); + // @ts-ignore + reslove(dd) + // return dd } - if(!xml){ - if(res.head.resultCode === '0'){ - return res - }else{ - const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage - prompt.showToast({ - message: decodeURIComponent(resultMessage), - duration: 3000 - }); - return false - } - } - for( let i in res ) { - resObj = res[i].head - } - console.info('jiangsong:res in request' + url + JSON.stringify(resObj)) - if(resObj.resultCode === '0') { + if (!xml) { + if (res.head.resultCode === '0') { + // return res httpRequest.destroy(); - return res - }else { + reslove(res) + } else { + const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage prompt.showToast({ - message: decodeURIComponent(resObj.resultMessage), - duration: 3000 + message: decodeURIComponent(resultMessage), + duration: 3000 }); httpRequest.destroy(); - return res + reject(false) + } } + for (let i in res) { + resObj = res[i].head + } + console.info('jiangsong:res in request' + url + JSON.stringify(resObj)) + if (resObj.resultCode === '0') { + httpRequest.destroy(); + reslove(res) + } else { + prompt.showToast({ + message: decodeURIComponent(resObj.resultMessage), + duration: 3000 + }); + httpRequest.destroy(); + reject(res) + } + }).catch(Error=>{ + console.info('test-error0' + url + ' error:resp: ' + JSON.stringify(Error)) + reject(Error) + }) + // fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList)) + // writeLog({ + // time:dateFormat(new Date()), + // url, + // result:JSON.stringify(result), + // extraData: JSON.stringify(data), + // state:'end' + // }) + } catch (e) { - console.info('test-error' + url + ' error:resp: '+ JSON.stringify(e)) - if(!e||!(e?.message)){ - httpRequest.destroy(); - return {code:-1} - } - const code = e?.code; - prompt.showToast({ - message: e?.message, - duration: 5000 - }); + console.info('test-error' + url + ' error:resp: ' + JSON.stringify(e)) + if (!e || !(e?.message)) { httpRequest.destroy(); - switch (code){ - //断网 - case 2300007: return {code:2300007} - // 超时 - case 2300028: return {code:2300028} - default: - } - return {code:e.code} + reject({ + code: -1 + }) + // httpRequest.destroy(); + // return {code:-1} + } + const code = e?.code; + prompt.showToast({ + message: e?.message, + duration: 5000 + }); + // httpRequest.destroy(); + switch (code) { + //断网 + case 2300007: + return { + code: 2300007 + } + // 超时 + case 2300028: + return { + code: 2300028 + } + default: + } + // return {code:e.code} + httpRequest.destroy(); + reject({ + code: e.code + }) } + }) + } -async function writeLog(param){ - const fileUtil = new FileUtil(globalThis.context) - const folderPath = await fileUtil.initFolder(`/errorMsg/`); - fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(param)+`\n`) + +async function writeLog(param) { + const fileUtil = new FileUtil(globalThis.context) + const folderPath = await fileUtil.initFolder(`/errorMsg/`); + fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(param) + `\n`) } //xml格式转JSON -function xmlToJson(result,url) { - console.log("xmlToJson begin",url); - let xmlOptions = {trim : false, declarationKey:"_declaration", - instructionKey : "_instruction", attributesKey : "_attributes", - textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", - commentKey : "_comment", parentKey : "_parent", typeKey : "_type", - nameKey : "_name", elementsKey : "_elements", "skipPreprocess" : true} +function xmlToJson(result, url) { + console.log("xmlToJson begin", url); + let xmlOptions = { + trim: false, + declarationKey: "_declaration", + instructionKey: "_instruction", + attributesKey: "_attributes", + textKey: "_text", + cdataKey: "_cdata", + doctypeKey: "_doctype", + commentKey: "_comment", + parentKey: "_parent", + typeKey: "_type", + nameKey: "_name", + elementsKey: "_elements", + "skipPreprocess": true + } - let strXml = result.toString(); - let conv = new convertxml.ConvertXML(); + let strXml = result.toString(); + let conv = new convertxml.ConvertXML(); - console.log("xmlToJson result.length = " + result.length); - console.log("xmlToJson result content = " + result); - // @ts-ignore - let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions); - console.log("xmlToJson deeml begin"); - let res = deeml(xmlArr); - console.log("xmlToJson end",url); - return res + console.log("xmlToJson result.length = " + result.length); + console.log("xmlToJson result content = " + result); + // @ts-ignore + let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions); + console.log("xmlToJson deeml begin"); + let res = deeml(xmlArr); + console.log("xmlToJson end", url); + return res } //处理中心服务code -function handleCenterCode(msgXml,isNewCenter){ - //新监管 - if(isNewCenter){ - const msg = JSON.parse(msgXml); - const result = msg?.data[0]?.result; - if(result){ - const {code,message,retval} = result - if(code != '1'){ - const rMessage = decodeURIComponent(message as string) - // globalThis.title=rMessage - // globalThis.type='1' - // globalThis.errorDialog.open() - prompt.showToast({ - message:rMessage, - duration: 3000 - }); - return {code,message} - }else{ - return { code ,keystr:retval} - } - } - } - - //正则匹配code message字段 - const [code,message,keystr] = [/(.*)<\/code>/i,/(.*)<\/message>/i,/(.*)<\/keystr>/i].map(pattern=>{ - const patternArr = pattern.exec(msgXml); - return patternArr && patternArr[1] - }); - - if(code != '1'){ - prompt.showToast({ - message: decodeURIComponent(message as string), - duration: 3000 - }); +function handleCenterCode(msgXml, isNewCenter) { + //新监管 + if (isNewCenter) { + const msg = JSON.parse(msgXml); + const result = msg?.data[0]?.result; + if (result) { + const {code,message,retval} = result + if (code != '1') { + const rMessage = decodeURIComponent(message as string) + // globalThis.title=rMessage // globalThis.type='1' - // globalThis.title=decodeURIComponent(message as string) // globalThis.errorDialog.open() - return {code,message:decodeURIComponent(message)} - }else{ - return { code ,keystr, message } + prompt.showToast({ + message: rMessage, + duration: 3000 + }); + return { code, message } + } else { + return { code, keystr: retval } + } } + } + + //正则匹配code message字段 + const [code, message, keystr] = [/(.*)<\/code>/i, /(.*)<\/message>/i, /(.*)<\/keystr>/i].map(pattern => { + const patternArr = pattern.exec(msgXml); + return patternArr && patternArr[1] + }); + + if (code != '1') { + prompt.showToast({ + message: decodeURIComponent(message as string), + duration: 3000 + }); + // globalThis.type='1' + // globalThis.title=decodeURIComponent(message as string) + // globalThis.errorDialog.open() + return { code, message: decodeURIComponent(message) } + } else { + return { code, keystr, message } + } } //JSON转xml格式 -const deeml = (elements,_name?)=>{ - const json = {} +const deeml = (elements, _name?) => { + const json = {} - elements.map(ele =>{ - const _elements = ele._elements - if(ele._type === 'element'){ - if(_elements==undefined){ - return - } - const thisJson = json[ele._name] - if(_elements && _elements.length === 1 && _elements[0]._type === 'text'){ - // 如果值存在了 - if(thisJson){ - handleCommonArr(_elements[0]._text) - }else{ - json[ele._name] = _elements[0]._text - } - }else{ - if(thisJson){ - handleCommonArr( deeml(ele._elements,ele._name) ) - }else{ - json[ele._name] = deeml(ele._elements,ele._name) - } - } - - //通用处理重复标签 - function handleCommonArr(obj){ - if(thisJson){ - if(Array.isArray(thisJson)){ - json[ele._name].push(obj) - }else{ - json[ele._name] = [json[ele._name],obj] - } - }else{ - json[ele._name] = obj - } - }0 - }else{ - //标签上有属性 - if(ele._attributes){ - json[_name] = { - value: ele._text, - attributes:ele.__attributes - } - } + elements.map(ele => { + const _elements = ele._elements + if (ele._type === 'element') { + if (_elements == undefined) { + return + } + const thisJson = json[ele._name] + if (_elements && _elements.length === 1 && _elements[0]._type === 'text') { + // 如果值存在了 + if (thisJson) { + handleCommonArr(_elements[0]._text) + } else { + json[ele._name] = _elements[0]._text } + } else { + if (thisJson) { + handleCommonArr(deeml(ele._elements, ele._name)) + } else { + json[ele._name] = deeml(ele._elements, ele._name) + } + } - }); - return json + //通用处理重复标签 + function handleCommonArr(obj) { + if (thisJson) { + if (Array.isArray(thisJson)) { + json[ele._name].push(obj) + } else { + json[ele._name] = [json[ele._name], obj] + } + } else { + json[ele._name] = obj + } + } + + 0 + } else { + //标签上有属性 + if (ele._attributes) { + json[_name] = { + value: ele._text, + attributes: ele.__attributes + } + } + } + + }); + return json }; function isEmpty(param) { - return!Object.keys(param).length; + return !Object.keys(param).length; } diff --git a/entry/src/main/ets/pages/CarCheck.ets b/entry/src/main/ets/pages/CarCheck.ets index dcd684d7..6205345a 100644 --- a/entry/src/main/ets/pages/CarCheck.ets +++ b/entry/src/main/ets/pages/CarCheck.ets @@ -157,6 +157,7 @@ export default struct Index { } carConfigurationInfo(param).then(res => { + // @ts-ignore const data = res.body.ES_CHECK_CAR_ITEM[0].ITEMS.split(';'); this.checkList = [] const list = data diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 7aef4837..b375211b 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -3,7 +3,7 @@ import router from '@ohos.router'; import { getCarInfo, getDeviceInfo } from '../common/service/terminalService'; import { setCurrentTime } from '../common/service/timeService'; import { getCurrentTime, string2Bytes } from '../common/utils/tools'; -import { FileHelper } from '../common/service/FileHelper'; +import FileHelper from '../common/service/FileHelper'; import { getEsCarModel, } from '../common/service/initable'; import FileUtil from '../common/utils/File'; import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; @@ -523,13 +523,13 @@ struct Index { } async createAlbum() { - this.fileHelper = new FileHelper(); + // this.fileHelper = new FileHelper(); const time = await getCurrentTime() const date = time.split(' ')[0] - this.fileHelper.createAlbum('jt') + FileHelper.createAlbum('jt') // this.fileHelper.createAlbum('2025-01-02') - this.fileHelper.createAlbum('pz'); - this.fileHelper.createAlbum(date); + FileHelper.createAlbum('pz'); + FileHelper.createAlbum(date); } diff --git a/entry/src/main/ets/pages/Register.ets b/entry/src/main/ets/pages/Register.ets index 151948aa..ae3855c0 100644 --- a/entry/src/main/ets/pages/Register.ets +++ b/entry/src/main/ets/pages/Register.ets @@ -128,8 +128,10 @@ export default struct Index { console.log('globalThis.deviceNo',globalThis.deviceNo) // upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }]) registrationDeviceNo(param).then(res => { + // @ts-ignore if (res.registrationDeviceNoRsp.head.resultCode == '0') { promptAction.showToast({ + // @ts-ignore message: decodeURIComponent(res.registrationDeviceNoRsp.head.resultMessage), duration: 3000 }); diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index 73392faf..7cdbed35 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -172,7 +172,6 @@ struct UserInfo { if (res.sfzmhm == user.sfzmhm) { flag = true res.kssycs = user.kssycs - this.getCurrentStudent(res.sfzmhm) } }) @@ -595,6 +594,7 @@ struct UserInfo { setTimeout(() => { this.updateTimeLimit = false }, 3000) + // @ts-ignore if (!res || res?.getExaminationStudentInfoRsp?.head?.resultCode == '1') { this.dataList = [] this.list = [] @@ -603,7 +603,9 @@ struct UserInfo { let dataList = [] this.list = [] + // @ts-ignore for (let key in res.getExaminationStudentInfoRsp.body) { + // @ts-ignore const a = res.getExaminationStudentInfoRsp.body[key] if (a instanceof Array) { dataList = a @@ -640,7 +642,7 @@ struct UserInfo { this.dataList = dataList const user = this.dataList.filter(res => { - res.kssycs = '1' + return res.kssycs == '1' }) if (this.dataList.length) { if (user.length) { @@ -741,6 +743,7 @@ struct UserInfo { } globalThis.udpClient2.sendMsgExt(param, this.context) + // @ts-ignore if (res.examinationStuAbsentRsp.head.resultCode == '0') { this.pageIndex = 0 this.qkFlag = false @@ -767,6 +770,7 @@ struct UserInfo { examinationRoomId }); + // @ts-ignore if (examItems?.getExaminationItemRsp?.body?.kssycs != 0) { this.getExaminationStudentInfoFn() } else { @@ -784,6 +788,7 @@ struct UserInfo { let examItems = { getExaminationItemRsp: { body: { ykxx: '' } } }; if (!globalThis.singlePlay) { //获取已考项目 + // @ts-ignore examItems = await getExaminationItem({ time: getCurrentTime(), carId, diff --git a/entry/src/main/ets/pages/compontents/FaceCompare.ets b/entry/src/main/ets/pages/compontents/FaceCompare.ets index 3a3c5367..254fef4b 100644 --- a/entry/src/main/ets/pages/compontents/FaceCompare.ets +++ b/entry/src/main/ets/pages/compontents/FaceCompare.ets @@ -197,6 +197,7 @@ export default struct FaceCompare { }) .then(res => { console.log('mmmmm8', JSON.stringify(res)) + // @ts-ignore if (res.imageCompareRsp.head.resultCode=='0') { this.controller.stop() this.showFaceCompare = !this.showFaceCompare diff --git a/entry/src/main/ets/pages/judgeSDK/judge.ts b/entry/src/main/ets/pages/judgeSDK/judge.ts index 035df47c..2fbc7b95 100644 --- a/entry/src/main/ets/pages/judgeSDK/judge.ts +++ b/entry/src/main/ets/pages/judgeSDK/judge.ts @@ -1566,7 +1566,7 @@ export default class Judge { const msgStr = strArr[num]; if(msgStr == ''){ console.info(judgeTag, '模拟数据考试结束') - globalThis.windowClass.setWindowSystemBarEnable(['navigation']) + // globalThis.windowClass.setWindowSystemBarEnable(['navigation']) clearInterval(judgeTimer) this.checkExamIsEnd(true) return