2024-07-16 16:32:16 +08:00

316 lines
8.2 KiB
TypeScript

// @ts-nocheck
import promptAction from '@ohos.promptAction'
import router from '@ohos.router'
import { dateFormat } from '../utils/tools'
import FileUtil from '../../common/utils/File'
import AccountTable from '../../common/database/tables/AccountTable'
import MA_SYSSET from '../../common/constants/MA_SYSSET'
import { takePhoto } from '../../common/service/videoService'
import {
delSyncTable,
getDataBaseTable,
getMySystemSetTable,
upDataZhongxinginitialization,
upDateTable
} from '../../common/service/initable'
import { GlobalConfig } from '../../config/index'
import testNapi from '@ohos.hiserialsdk'
export async function getliushuiNum() {
console.log('getLiushuihao')
this.fileUtil = new FileUtil(this.context)
const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/liushui.txt');
if (data === '' || data === undefined) {
this.num = 0
let str = this.num.toString()
for (let i = 0; str.length <= 5; i++) {
str = '0' + str
}
this.lsh = str
// return str
} else {
this.num = Number(JSON.parse(data).value) + 1
let str = this.num.toString()
for (let i = 0; str.length <= 5; i++) {
str = '0' + str
}
this.lsh = str
// return str
}
}
//配置流水号
export async function setliushuiNum(context) {
const fileUtil = new FileUtil(context)
try {
const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/liushui.txt');
const date = new Date()
const time1 = JSON.parse(fileData).date.split(' ')[0]
const time2 = dateFormat(date).split(' ')[0]
if (time1 == time2) {
const param = {
date: dateFormat(date),
value: Number(JSON.parse(fileData).value) + 1
}
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
return
}
const param = {
date: dateFormat(date),
value: 0
}
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
} catch (err) {
const date = new Date()
const param = {
date: dateFormat(date),
value: 0
}
const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/liushui.txt`, JSON.stringify(param))
}
}
//双中心表
export async function getDoubleCeneterTable() {
return new Promise(async (reslove, reject) => {
// MA_SYSSET双中心下做合并表格操作
const db = new AccountTable(() => {
}, MA_SYSSET);
db.getRdbStore(() => {
db.query('0', async (array) => {
if (array.length) {
delSyncTable('MA_SYSSET').then(async () => {
await getDataBaseTable({ tableName: 'MA_SYSSET' })
await getMySystemSetTable({ tableName: 'MA_SYSSET' })
})
} else {
await getDataBaseTable({ tableName: 'MA_SYSSET' })
await getMySystemSetTable({ tableName: 'MA_SYSSET' })
}
})
})
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 })
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() {
return new Promise((reslove, reject) => {
upDataZhongxinginitialization().then((result) => {
if (result) {
router.pushUrl({
url: 'pages/ExaminerLogin',
}, router.RouterMode.Single)
reslove(true)
} else {
promptAction.showDialog({
title: '提示',
message: '联网更新失败,请检查网络后重新更新',
buttons: [
{
text: '确认',
color: '#000000',
},
{
text: '取消',
color: '#000000',
}
],
})
.then(data => {
reslove(false)
})
.catch(err => {
reslove(false)
})
reslove(false)
}
}).catch((error) => {
reslove(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',
}
globalThis.spzd = {
spzd1: false,
spzd2: false,
spzd3: false,
spzd4: false,
}
globalThis.takePhotoNum = 0
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 key = arr[i]
if (param[key]) {
param.pztd = param[`td${Number(i) + 1}`]
takePhoto(param, context, 'jt/', 0, (data) => {
if (Number(data.fileSize) <= (Number(param.zdyz) * 1000)) {
map[key] = true
promptAction.showToast({
message: `视频遮挡`,
duration: 3000
});
globalThis.spzd[key] = true
} else {
map[key] = false
globalThis.spzd[key] = false
}
setTimeout(() => {
takePhotoFn()
}, 3000)
})
}
}
globalThis.takePhotoNum++
if (globalThis.takePhotoNum >= 20) {
globalThis.takePhotoNum = 0
// deleteAllFileByPiC('jt')
}
}, 3000)
}
let fd
const devPath = "/dev/ttyS3"
async function openChuankouFn(): Promise<number> {
console.log('fdfd1111 start')
fd = await testNapi.SerialOpen(devPath);
globalThis.fd = fd
console.log('fdfd1111', globalThis.fd)
let parity = 0x4e; // 'N'
let ret = await testNapi.SerialSet(globalThis.fd, 115200, 0, 8, 1, parity);
console.log('setNum', ret)
return ret
}
async function getChuankouFnMsg() {
let timeout = 50000; // 2秒超时
let databuff = [0x61, 0xAA, 0x0A, 0X15, 0X00]; // send ABCDE
console.log('fdfd', globalThis.fd)
let uint8Arr = new Uint8Array(databuff);
testNapi.SerialSend(globalThis.fd, uint8Arr).then((ret) => {
console.log('mmmm', ret)
testNapi?.SerialRecv(globalThis.fd, timeout, 12).then((revTestInfo) => {
console.log('revTestInfo', revTestInfo.recevedBuf.length)
const message = revTestInfo?.recevedBuf?.toString()
console.log('chuankou', message)
if (message == '') {
return
}
const msg = message?.split(',')
if (!msg?.length) {
return
}
if (msg[0] != '98' || msg[1] != '85' || msg.length < 9) {
return
}
globalThis.chuankoMsg = msg[9]
})
});
}
export async function getChuankouFn() {
if (globalThis.fd) {
return
}
openChuankouFn().then((fd) => {
setInterval(() => {
getChuankouFnMsg()
}, 1000)
})
}