refactor: 优化流水号管理和摄像头遮挡检测逻辑,重构相关函数
This commit is contained in:
		
							parent
							
								
									95825e2b77
								
							
						
					
					
						commit
						7df1bab099
					
				| @ -16,263 +16,13 @@ import fs from '@ohos.file.fs'; | ||||
| 
 | ||||
| let num = 0 | ||||
| 
 | ||||
| async function getliushuiNum(data) { | ||||
|   // let data = AppStorage.get('liushuiNo')
 | ||||
|   if (data) { | ||||
|     num = Number(data) + 1 | ||||
|     let str = num.toString() | ||||
|     for (let i = 0; str.length <= 5; i++) { | ||||
|       str = '0' + str | ||||
|     } | ||||
|     AppStorage.setOrCreate('lshNo', str) | ||||
|   } else { | ||||
|     num = 0 | ||||
|     let str = num.toString() | ||||
|     for (let i = 0; str.length <= 5; i++) { | ||||
|       str = '0' + str | ||||
|     } | ||||
|     AppStorage.setOrCreate('lshNo', str) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export async function deleteAllFIleLog(path) { | ||||
|   let options = { | ||||
|     "recursion": false, | ||||
|     "listNum": 0, | ||||
|   }; | ||||
| 
 | ||||
|   let filenames = fs.listFileSync(path, options); | ||||
|   console.info("listFile succeed", JSON.stringify(filenames)); | ||||
|   for (let i = 0; i < filenames.length; i++) { | ||||
|     console.info("listFile succeed", JSON.stringify(filenames[i])); | ||||
| 
 | ||||
|     if (isSevenDaysAgo(filenames[i])) { | ||||
|       fs.rmdir(path + 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, saveDays?) { | ||||
|   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", (diffDays)); | ||||
|   // 如果差异天数正好是2,则原日期是当前日期的前2天
 | ||||
|   return diffDays > (saveDays || 2); | ||||
| } | ||||
| 
 | ||||
| export async function setVideoParam() { | ||||
|   // return
 | ||||
|   // const fileUtil = new FileUtil(context)
 | ||||
|   // console.log('configconfig',)
 | ||||
|   // try {
 | ||||
|   //   const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
 | ||||
|   //
 | ||||
|   // } catch (error) {
 | ||||
|   //   const param: VideoConfig = VideoConfigData
 | ||||
|   //   const folderPath = await fileUtil.initFolder(`/config`);
 | ||||
|   //   fileUtil.addFile(`${folderPath}/config3.txt`, JSON.stringify(param))
 | ||||
|   // }
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| //配置流水号
 | ||||
| export async function setliushuiNum() { | ||||
|   const data = AppStorage.get('liushuiNo') | ||||
|   const liushuiDate = AppStorage.get('liushuiDate') | ||||
|   getliushuiNum(data) | ||||
|   if (data && liushuiDate) { | ||||
|     const date = new Date() | ||||
|     const time1 = liushuiDate.split(' ')[0] | ||||
|     const time2 = dateFormat(date).split(' ')[0] | ||||
|     if (time1 != time2) { | ||||
|       AppStorage.setOrCreate('liushuiDate', dateFormat(date)); | ||||
|       AppStorage.setOrCreate('liushuiNo', '0'); | ||||
|     } else { | ||||
|       AppStorage.setOrCreate('liushuiNo', Number(data) + 1); | ||||
|     } | ||||
|   } else { | ||||
|     const date = new Date() | ||||
|     // PersistentStorage.PersistProp('liushuiNo', 0);
 | ||||
|     // PersistentStorage.PersistProp('liushuiDate', dateFormat(date));
 | ||||
|     AppStorage.setOrCreate('liushuiNo', '0'); | ||||
|     AppStorage.setOrCreate('liushuiDate', dateFormat(date)); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| //双中心表
 | ||||
| export async function getDoubleCeneterTable(param) { | ||||
|   return new Promise(async (reslove, reject) => { | ||||
|     // MA_SYSSET双中心下做合并表格操作
 | ||||
|     delSyncTable('MA_SYSSET', param.context).then(async () => { | ||||
|       await getDataBaseTable({ tableName: 'MA_SYSSET' }, param) | ||||
|       await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param) | ||||
|     }) | ||||
| 
 | ||||
|     const typeObj = { | ||||
|       'MA_MARKRULE': false, | ||||
|       'MA_SYSTEMPARM': false, | ||||
|       'MA_MAP_COLLECT': false, | ||||
|       'MA_MAP_COLLECT_SHAPE': false, | ||||
|       'MA_MAP_ITEMCLASS': false, | ||||
|       'MA_MAP_POINT': false, | ||||
|       'MA_MAP_POINT_ITEM': false, | ||||
|       'MA_MAP_ROAD': false, | ||||
|       'MA_MAP_ROAD_LANE': false, | ||||
|       'MA_MAP_SUBITEM': false, | ||||
|       'ES_CARINFO': false, | ||||
|       'ES_EXAMPOINTDETAIL': false, | ||||
|       'MA_MARKRULESET': false, | ||||
|       'ES_CAR_VIDEO_PARAMETER': false, | ||||
|       'MA_CDSBINFO': false, | ||||
|       'MA_ITEMINFO': false, | ||||
|       'MA_T_CARPARMSET': false | ||||
|     } | ||||
|     for (let key in typeObj) { | ||||
|       typeObj[key] = await upDateTable({ tableName: key }, param) | ||||
|       if (!typeObj[key]) { | ||||
|         promptAction.showToast({ | ||||
|           message: `未能查询到${key}表数据, 请先检查网络是否连接正常`, | ||||
|           duration: 3000 | ||||
|         }); | ||||
|         reslove(false) | ||||
|         return | ||||
|       } | ||||
|     } | ||||
|     reslove(true) | ||||
|     router.pushUrl({ | ||||
|       url: 'pages/ExaminerLogin', | ||||
|     }, router.RouterMode.Single); | ||||
|   }) | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| //单中心存表
 | ||||
| export async function getSingleCenterTable(param) { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     console.log('teststet0') | ||||
|     upDataZhongxinginitialization(param).then((result) => { | ||||
|       console.log('kkkkkkkkkkk', result) | ||||
|       if (result) { | ||||
|         resolve(true) | ||||
|       } else { | ||||
|         console.log('联网更新失败,请检查网络后重新更新') | ||||
|         resolve(false) | ||||
|       } | ||||
|     }).catch((error) => { | ||||
|       resolve(false) | ||||
|       console.log(error) | ||||
|     }) | ||||
| 
 | ||||
|   }) | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| let interval | ||||
| 
 | ||||
| export async function takePhotoFn(context) { | ||||
|   let param = { | ||||
|     videoNum: '1', | ||||
|     spls: '1', | ||||
|     wz: '0,0', | ||||
|     faceFlag: false, | ||||
|     shuiying: true, | ||||
|     pztd: '2', | ||||
|     ljlx: '', | ||||
|     ip: '192.168.36.94', | ||||
|     port: '554', | ||||
|     userName: 'admin', | ||||
|     pwd: '12345qwe', | ||||
|     td1: '1', | ||||
|     td2: '2', | ||||
|     td3: '3', | ||||
|     td4: '4', | ||||
|     videoRecord1: false, | ||||
|     videoRecord2: true, | ||||
|     videoRecord3: false, | ||||
|     videoRecord4: false, | ||||
|     text1: '', | ||||
|     text2: '', | ||||
|     text3: '', | ||||
|     dolt: '', | ||||
|     fontSize: '', | ||||
|     rlls: '1', | ||||
|     spzd4: false, | ||||
|     spzd3: false, | ||||
|     spzd2: false, | ||||
|     spzd1: false, | ||||
|     zdyz: '5', | ||||
|   } | ||||
|   const spzd = { | ||||
|     spzd1: false, | ||||
|     spzd2: false, | ||||
|     spzd3: false, | ||||
|     spzd4: false, | ||||
|   } | ||||
|   const map = {} | ||||
|   const fileUtil = new FileUtil(context) | ||||
|   const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); | ||||
|   console.log('sizesize', fileData) | ||||
|   param = JSON.parse(fileData) | ||||
|   console.log('paramparam') | ||||
|   clearInterval(interval) | ||||
|   interval = setTimeout(async () => { | ||||
|     const arr = ['spzd1', 'spzd2', 'spzd3', 'spzd4'] | ||||
| 
 | ||||
|     for (let key in map) { | ||||
|       map[key] = false | ||||
|       // param[key] = false
 | ||||
|     } | ||||
|     for (let i = 0; i <= arr.length - 1; i++) { | ||||
|       let key1 = arr[i] | ||||
|       if (param[key1]) { | ||||
|         param.pztd = param[`td${Number(i) + 1}`] | ||||
|         takePhoto(param, context, 'jt/', 0, (data) => { | ||||
|           if (data.errorCode != 0) { | ||||
|             console.log('拍照失败') | ||||
|             return | ||||
|           } | ||||
|           console.log('takePhototakePhoto', JSON.stringify(data)) | ||||
|           const zdyz = AppStorage.get('param854Str') ? Number(AppStorage.get('param854Str')) : Number(param.zdyz) | ||||
|           console.log('takePhototakePhoto', JSON.stringify(zdyz),) | ||||
| 
 | ||||
|           if (Number(data.fileSize) <= (zdyz * 1000)) { | ||||
|             map[key1] = true | ||||
|             promptAction.showToast({ | ||||
|               message: `视频遮挡`, | ||||
|               duration: 3000 | ||||
|             }); | ||||
|             spzd[key1] = true | ||||
|           } else { | ||||
|             map[key1] = false | ||||
|             spzd[key1] = false | ||||
|           } | ||||
|           AppStorage.setOrCreate('spzd', spzd) | ||||
| 
 | ||||
|           setTimeout(() => { | ||||
|             takePhotoFn() | ||||
|           }, 3000) | ||||
|         }) | ||||
| 
 | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|   }, 3000) | ||||
| } | ||||
| // 判断摄像头是否遮挡
 | ||||
| 
 | ||||
| const devPath = "/dev/ttyS3" | ||||
| let chuankoufd | ||||
|  | ||||
| @ -29,9 +29,9 @@ export interface User { | ||||
| 
 | ||||
| export interface VideoConfig { | ||||
|   videoNum?: string, | ||||
|   spls: string | ||||
|   faceFlag: boolean | ||||
|   pztd: string | ||||
|   spls?: string | ||||
|   faceFlag?: boolean | ||||
|   pztd?: string | ||||
|   ljlx?: string | ||||
|   ip1?: string | ||||
|   port1?: string | ||||
| @ -64,12 +64,12 @@ export interface VideoConfig { | ||||
|   text3?: string | ||||
|   dolt?: string, | ||||
|   fontSize?: string | ||||
|   rlls: string, | ||||
|   rlls?: string, | ||||
|   spzd4: boolean, | ||||
|   spzd3: boolean, | ||||
|   spzd2: boolean, | ||||
|   spzd1: boolean, | ||||
|   zdyz: string, | ||||
|   zdyz?: string, | ||||
| } | ||||
| 
 | ||||
| export interface CommonType { | ||||
|  | ||||
| @ -8,7 +8,6 @@ import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; | ||||
| import { initJudgeUdp } from '../common/utils/UdpJudge'; | ||||
| import { judgeConfig } from './judgeSDK/utils/judgeConfig'; | ||||
| import { getTCP } from '../common/utils/GlobalTcp'; | ||||
| import { setliushuiNum, takePhotoFn } from '../common/service/indexService'; | ||||
| import promptAction from '@ohos.promptAction'; | ||||
| import errorMsgDialog from './compontents/errorMsgDialog'; | ||||
| import GetDistance from '../common/utils/GetDistance'; | ||||
| @ -17,7 +16,7 @@ import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | ||||
| import { BaseInfoType } from '../model/Common'; | ||||
| import { CarInfoType } from '../model'; | ||||
| import { InitializeTheCentralTableType, MASYSSETTableType, TimeInfo } from '../model'; | ||||
| import { GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils'; | ||||
| import { GetCarInfo, GetDeviceInfo, SetCurrentTime, SetSerialNumber, UseAuth } from './Index/utils'; | ||||
| import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation'; | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| import { delPic } from '../utils/Video'; | ||||
| @ -522,11 +521,13 @@ struct Index { | ||||
|       this.initParamFlag = true | ||||
|     }, 3000) | ||||
|     initJudgeUdp() | ||||
|     takePhotoFn(this.context) | ||||
|     // TODO 摄像头遮挡 | ||||
|     // takePhotoFn(this.context) | ||||
|     clearInterval(this.interval) | ||||
|     this.interval = setInterval(() => { | ||||
|       this.num++ | ||||
|       setliushuiNum() | ||||
|       // setliushuiNum() | ||||
|       SetSerialNumber() | ||||
|       // getliushuiNum(this.context) | ||||
|       if (this.num >= 3) { | ||||
|         this.heartMsg() | ||||
|  | ||||
| @ -8,7 +8,8 @@ import { | ||||
|   CarConfigurationParamsType, | ||||
|   ObtainCarExamInfoParams, | ||||
|   ObtainCarExamInfoRspBody, | ||||
|   TimeSynchronizationParams | ||||
|   TimeSynchronizationParams, | ||||
|   VideoConfig | ||||
| } from "../../model"; | ||||
| import dayTs from "../../utils/Date"; | ||||
| import { obtainCarExamInfo, timeSynchronization } from "../../api"; | ||||
| @ -16,6 +17,7 @@ import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; | ||||
| import { BusinessError } from "@ohos.base"; | ||||
| import App from "@system.app"; | ||||
| import systemTime from "@ohos.systemTime"; | ||||
| import { VideoConfigData } from "../../mock"; | ||||
| 
 | ||||
| //获取设备信息 | ||||
| export async function GetDeviceInfo(context: common.UIAbilityContext): Promise<string> { | ||||
| @ -97,4 +99,53 @@ export async function SetCurrentTime(): Promise<void> { | ||||
|   } catch (error) { | ||||
|     console.log('时间同步失败', error) | ||||
|   } | ||||
| } | ||||
| } | ||||
| 
 | ||||
| //TODO 摄像头遮挡 indexService takePhotoFn | ||||
| export async function TakePhoto(context: common.UIAbilityContext) { | ||||
|   let interval: number = -1 | ||||
|   let param: VideoConfig = VideoConfigData | ||||
|   let spzd: VideoConfig = { | ||||
|     spzd1: false, | ||||
|     spzd2: false, | ||||
|     spzd3: false, | ||||
|     spzd4: false, | ||||
|   } | ||||
|   let map = {} | ||||
|   const fileUtil = new FileUtil(context) | ||||
|   const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); | ||||
|   param = JSON.parse(fileData) | ||||
|   clearInterval(interval) | ||||
|   interval = setTimeout(async () => { | ||||
|     const arr = ['spzd1', 'spzd2', 'spzd3', 'spzd4'] | ||||
|   }, 3000) | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| async function obtainSerialNumber(data: string) { | ||||
|   let num = data ? Number(data) + 1 : 0; | ||||
|   let str = num.toString().padStart(6, '0'); | ||||
|   AppStorage.setOrCreate<string>('lshNo', str); | ||||
| } | ||||
| 
 | ||||
| //设置流水号 | ||||
| export async function SetSerialNumber() { | ||||
|   const data = AppStorage.get<string>("liushuiNo"); | ||||
|   const serialNumberTime = AppStorage.get<string>("liushuiDate"); | ||||
|   obtainSerialNumber(data); | ||||
|   const date = dayTs().format('YYYY-MM-DD HH:mm:ss'); | ||||
| 
 | ||||
|   if (data && serialNumberTime) { | ||||
|     const diffDays = dayTs().diff(serialNumberTime, 'day'); | ||||
|     if (diffDays === 0) { | ||||
|       AppStorage.setOrCreate<string>('liushuiDate', date); | ||||
|       AppStorage.setOrCreate<string>('liushuiNo', '0'); | ||||
|     } else { | ||||
|       AppStorage.setOrCreate<string>('liushuiNo', (Number(data) + 1).toString()); | ||||
|     } | ||||
|   } else { | ||||
|     AppStorage.setOrCreate('liushuiNo', '0'); | ||||
|     AppStorage.setOrCreate('liushuiDate', date); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -10,6 +10,7 @@ import FileUtil from '../common/utils/File'; | ||||
| import dayTs from './Date'; | ||||
| import { GlobalConfig, VideoTag } from '../config'; | ||||
| import { BusinessError } from '@ohos.base'; | ||||
| import { VideoConfigData } from '../mock'; | ||||
| 
 | ||||
| const rtsp_server = record.createServer(); | ||||
| //开始录屏 | ||||
| @ -245,4 +246,6 @@ export async function deleteAllVideos(context: common.UIAbilityContext, type: ph | ||||
|       fetchResult.close(); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user