Merge pull request 'lv_chengmai' (#38) from lv_chengmai into main

Reviewed-on: #38
This commit is contained in:
wangzhongjie 2024-07-30 10:41:50 +08:00
commit b987bac5f0
5 changed files with 445 additions and 462 deletions

View File

@ -3,20 +3,22 @@ import promptAction from '@ohos.promptAction'
import router from '@ohos.router' import router from '@ohos.router'
import { dateFormat } from '../utils/tools' import { dateFormat } from '../utils/tools'
import FileUtil from '../../common/utils/File' import FileUtil from '../../common/utils/File'
import AccountTable from '../../common/database/tables/AccountTable'; import AccountTable from '../../common/database/tables/AccountTable'
import MA_SYSSET from '../../common/constants/MA_SYSSET'; import MA_SYSSET from '../../common/constants/MA_SYSSET'
import { takePhoto, deleteAllFileByPiC } from '../../common/service/videoService' import { takePhoto } from '../../common/service/videoService'
import { import {
getDataBaseTable,
upDateTable,
getMySystemSetTable,
delSyncTable, delSyncTable,
upDataZhongxinginitialization getDataBaseTable,
getMySystemSetTable,
upDataZhongxinginitialization,
upDateTable
} from '../../common/service/initable' } from '../../common/service/initable'
import { GlobalConfig } from '../../config/index' import { GlobalConfig } from '../../config/index'
import testNapi from '@ohos.hiserialsdk' import testNapi from '@ohos.hiserialsdk'
let num = 0 let num = 0
export async function getliushuiNum(context) { export async function getliushuiNum(context) {
console.log('getLiushuihao') console.log('getLiushuihao')
const fileUtil = new FileUtil(context) const fileUtil = new FileUtil(context)
@ -39,6 +41,7 @@ export async function getliushuiNum(context){
// return str // return str
} }
} }
//配置流水号 //配置流水号
export async function setliushuiNum(context) { export async function setliushuiNum(context) {
const fileUtil = new FileUtil(context) const fileUtil = new FileUtil(context)
@ -78,21 +81,11 @@ export async function setliushuiNum(context) {
export async function getDoubleCeneterTable(param) { export async function getDoubleCeneterTable(param) {
return new Promise(async (reslove, reject) => { return new Promise(async (reslove, reject) => {
// MA_SYSSET双中心下做合并表格操作 // MA_SYSSET双中心下做合并表格操作
const db = new AccountTable(() => { delSyncTable('MA_SYSSET', param.context).then(async () => {
}, MA_SYSSET);
db.getRdbStore(() => {
db.query('0', async (array) => {
if (array.length) {
delSyncTable('MA_SYSSET').then(async () => {
await getDataBaseTable({ tableName: 'MA_SYSSET' }, param) await getDataBaseTable({ tableName: 'MA_SYSSET' }, param)
await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param) await getMySystemSetTable({ tableName: 'MA_SYSSET' }, param)
}) })
} else {
await getDataBaseTable({ tableName: 'MA_SYSSET' },param)
await getMySystemSetTable({ tableName: 'MA_SYSSET' },param)
}
})
},param.context)
const typeObj = { const typeObj = {
'MA_MARKRULE': false, 'MA_MARKRULE': false,
'MA_SYSTEMPARM': false, 'MA_SYSTEMPARM': false,
@ -130,6 +123,7 @@ export async function getDoubleCeneterTable(param) {
}) })
} }
//单中心存表 //单中心存表
export async function getSingleCenterTable(param) { export async function getSingleCenterTable(param) {
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
@ -259,8 +253,10 @@ export async function takePhotoFn(context) {
} }
}, 3000) }, 3000)
} }
let fd let fd
const devPath = "/dev/ttyS3" const devPath = "/dev/ttyS3"
function openChuankouFn(callback) { function openChuankouFn(callback) {
console.log('SerialOpen in indexservice, path=' + devPath) console.log('SerialOpen in indexservice, path=' + devPath)
@ -323,7 +319,9 @@ function getChuankouFnMsg() {
// let revTestInfo = testNapi?.SerialRecv(globalThis.fd, timeout); // let revTestInfo = testNapi?.SerialRecv(globalThis.fd, timeout);
} }
let chuankou let chuankou
export async function getChuankouFn() { export async function getChuankouFn() {
if (globalThis.fd) { if (globalThis.fd) {
return return

View File

@ -1,7 +1,5 @@
// @ts-nocheck // @ts-nocheck
import data_rdb from '@ohos.data.rdb'; import { initCenterCache, initCenterCacheByKSPT, initEsModel, initialization } from '../../api/index';
import UIAbility from '@ohos.app.ability.UIAbility';
import { initCenterCache,initCenterCacheByKSPT,initEsModel,initialization } from '../../api/index'
import { dateFormat } from '../utils/tools'; import { dateFormat } from '../utils/tools';
import AccountTable from '../database/tables/AccountTable'; import AccountTable from '../database/tables/AccountTable';
import MA_MARKRULE from '../constants/MA_MARKRULE'; import MA_MARKRULE from '../constants/MA_MARKRULE';
@ -23,12 +21,12 @@ import MA_ITEMINFO from '../constants/MA_ITEMINFO';
import MA_T_CARPARMSET from '../constants/MA_T_CARPARMSET'; import MA_T_CARPARMSET from '../constants/MA_T_CARPARMSET';
import ES_CAR_VIDEO_PARAMETER from '../constants/ES_CAR_VIDEO_PARAMETER'; import ES_CAR_VIDEO_PARAMETER from '../constants/ES_CAR_VIDEO_PARAMETER';
import IpConfigTable from '../constants/IpConfigTable'; import IpConfigTable from '../constants/IpConfigTable';
import CommonConstants from '../constants/CommonConstants' import CommonConstants from '../constants/CommonConstants';
import DeviceInfoTable from '../constants/DeviceInfoTable' import DeviceInfoTable from '../constants/DeviceInfoTable';
import USER from '../constants/USER' import USER from '../constants/USER';
import util from '@ohos.util'; import util from '@ohos.util';
import zlib from '@ohos.zlib';
import FileModel from '../../pages/judgeSDK/utils/fileModel'; import FileModel from '../../pages/judgeSDK/utils/fileModel';
// @ts-nocheck // @ts-nocheck
//读表 //读表
//参数平台 //参数平台
@ -79,7 +77,7 @@ const centerToMap={
// 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER // 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
} }
function sqlInsertCommonFn(tableName,resultArr,context?){ function sqlInsertCommonFn(tableName, resultArr, context?, delFlag = true) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const accountTable = new AccountTable(() => { const accountTable = new AccountTable(() => {
}, map[tableName], context); }, map[tableName], context);
@ -113,7 +111,9 @@ function sqlInsertCommonFn(tableName,resultArr,context?){
}) })
} }
else { else {
if (delFlag) {
await delSyncTable(tableName, context) await delSyncTable(tableName, context)
}
const result = await sqlInsertCommonFn(tableName, resultArr, context) const result = await sqlInsertCommonFn(tableName, resultArr, context)
resolve(result) resolve(result)
} }
@ -121,17 +121,10 @@ function sqlInsertCommonFn(tableName,resultArr,context?){
}, context); }, context);
}) })
} }
//参数平台 //参数平台
export async function getDataBaseTable(params, reqParam) { export async function getDataBaseTable(params, reqParam) {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
const accountTable = new AccountTable(() => {
}, map[params.tableName],context);
accountTable.getRdbStore(() => {
accountTable.query('0', async (result) => {
if (result.length != 0) {
resolve();
return
} else {
const date = new Date() const date = new Date()
if (!reqParam?.paraKdid) { if (!reqParam?.paraKdid) {
prompt.showToast({ prompt.showToast({
@ -153,46 +146,22 @@ export async function getDataBaseTable(params,reqParam) {
resolve(); resolve();
return return
} }
let INSERT_SQL = "INSERT INTO "+params.tableName
+ " ("+ map[params.tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
if (params.tableName == 'MA_SYSSET') { if (params.tableName == 'MA_SYSSET') {
res.body[params.tableName] = res.body[params.tableName].filter(res => { res.body[params.tableName] = res.body[params.tableName].filter(res => {
return res['v_no'] >= 300 && res['v_no'] <= 700 return res['v_no'] >= 300 && res['v_no'] <= 700
}) })
} }
sqlInsertCommonFn(param.tableName, res.body[params.tableName]).then((val) => {
reslove(val)
})
})
}
res.body[params.tableName].map((data,i) => {
// data.id=`${i}`
data.id=i
let str='('
map[params.tableName].ACCOUNT_TABLE.columns.map((res,index)=>{
if(map[params.tableName].ACCOUNT_TABLE.columns.length-1==index){
str+=data[res]?`"${data[res]}"`:'NULL'
}else{
str+=(data[res]?`"${data[res]}"`:'NULL')+','
}
})
if(i==res.body[params.tableName].length-1){
str+=')'
}else{
str+='),'
}
INSERT_SQL+=str
})
accountTable.sqlOperate(INSERT_SQL,params.tableName,()=>{
resolve(true)
})
}
}, true);
},reqParam.context);
})
}
//依据数组和表名更新sql表 //依据数组和表名更新sql表
export async function upDateTableByArray(tableName, arr) { export async function upDateTableByArray(tableName, arr) {
sqlInsertCommonFn(tableName, arr) sqlInsertCommonFn(tableName, arr)
} }
//更新双中心表 //更新双中心表
export async function upDateTable(params, reqParam) { export async function upDateTable(params, reqParam) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -258,7 +227,7 @@ export async function getMySystemSetTable(params,reqParam) {
return res['v_no'] < 300 || res['v_no'] > 700 return res['v_no'] < 300 || res['v_no'] > 700
}) })
} }
sqlInsertCommonFn(params.tableName,res.body[params.tableName],reqParam.context).then((result)=>{ sqlInsertCommonFn(params.tableName, res.body[params.tableName], reqParam.context, false).then((result) => {
resolve(result) resolve(result)
}) })
}) })
@ -390,6 +359,7 @@ export async function upDataZhongxinginitialization(param){
}) })
}) })
} }
function setSyncCenterSqlData(key, res, param) { function setSyncCenterSqlData(key, res, param) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const mapName = { const mapName = {

View File

@ -1,12 +1,13 @@
import TcpClient from './TcpClient'; import TcpClient from './TcpClient';
import { getSyncData} from '../service/initable' import { getSyncData } from '../service/initable';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
export async function getTCP() { export async function getTCP() {
getSyncData('IpConfigTable').then(async (result: Array<any>) => { getSyncData('IpConfigTable').then(async (result: Array<any>) => {
console.log('result222', JSON.stringify(result)) console.log('result222', JSON.stringify(result))
if (result.length) { if (result.length) {
if(globalThis.TcpClient&&globalThis.getCloseTcp){ if (globalThis.TcpClient && globalThis.TcpClient.closeTcp) {
globalThis.TcpClient.closeTcp(async () => { globalThis.TcpClient.closeTcp(async () => {
// const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort) // const tcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
// globalThis.TcpClient = tcpClient // globalThis.TcpClient = tcpClient
@ -68,7 +69,8 @@ export async function getTCP() {
} else { } else {
globalThis.TcpClient = {} globalThis.TcpClient = {}
globalThis.TcpClient.onMessage=()=>{} globalThis.TcpClient.onMessage = () => {
}
} }
}) })
} }

View File

@ -1,9 +1,7 @@
import socket from '@ohos.net.socket'; import socket from '@ohos.net.socket';
import buffer from '@ohos.buffer'; import hilog from '@ohos.hilog';
const TAG = 'socketTag[TcpDemo.TcpClient]' const TAG = 'socketTag[TcpDemo.TcpClient]'
import prompt from '@ohos.prompt'
import hilog from '@ohos.hilog';
export default class TcpClient { export default class TcpClient {
private localIp: string = '' private localIp: string = ''
@ -21,6 +19,7 @@ export default class TcpClient {
console.log(TAG, 'new Tcp', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort) console.log(TAG, 'new Tcp', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort)
this.tcp = socket.constructTCPSocketInstance(); this.tcp = socket.constructTCPSocketInstance();
} }
onError(callback?) { onError(callback?) {
this.tcp.on('error', err => { this.tcp.on('error', err => {
console.log(TAG, 'tcpOnerror', JSON.stringify(err)) console.log(TAG, 'tcpOnerror', JSON.stringify(err))
@ -34,6 +33,7 @@ export default class TcpClient {
// }) // })
}); });
} }
rebindTcp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) { rebindTcp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.localIp = localIp this.localIp = localIp
@ -41,7 +41,9 @@ export default class TcpClient {
this.localIpPort = localIpPort this.localIpPort = localIpPort
this.oppositeIpPort = oppositeIpPort this.oppositeIpPort = oppositeIpPort
console.log(TAG, 'tcpreBind', this.localIp, this.localIpPort) console.log(TAG, 'tcpreBind', this.localIp, this.localIpPort)
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => { let promise = this.tcp.bind({
address: this.localIp, port: parseInt(this.localIpPort), family: 1
}, err => {
if (err) { if (err) {
globalThis.getCloseTcp = true globalThis.getCloseTcp = true
hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err)); hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
@ -61,10 +63,13 @@ export default class TcpClient {
// }); // });
} }
bindTcp() { bindTcp() {
console.log(TAG, 'tcpbind', this.localIp, 'localIp', this.localIpPort) console.log(TAG, 'tcpbind', this.localIp, 'localIp', this.localIpPort)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => { let promise = this.tcp.bind({
address: this.localIp, port: parseInt(this.localIpPort), family: 1
}, err => {
if (err) { if (err) {
console.log('testTag tcp bind faile'); console.log('testTag tcp bind faile');
globalThis.getCloseTcp = true globalThis.getCloseTcp = true
@ -87,10 +92,15 @@ export default class TcpClient {
} }
connectTcp() { connectTcp() {
console.log(TAG, 'tcpConnect', this.oppositeIp, 'localIp', this.oppositeIpPort) console.log(TAG, 'tcpConnect', this.oppositeIp, 'localIp', this.oppositeIpPort)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let promise = this.tcp.connect({ address: {address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1} , timeout: 6000}); let promise = this.tcp.connect({
address: {
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
}, timeout: 6000
});
promise.then(() => { promise.then(() => {
this.tcp.setExtraOptions({ this.tcp.setExtraOptions({
@ -113,6 +123,7 @@ export default class TcpClient {
globalThis.getCloseTcp = true globalThis.getCloseTcp = true
setTimeout(() => { setTimeout(() => {
this.connectTcp() this.connectTcp()
resolve(false)
}, 2000) }, 2000)
console.log('testTagconnect,error') console.log('testTagconnect,error')
@ -153,11 +164,13 @@ export default class TcpClient {
// callback(value.message) // callback(value.message)
}); });
} }
offTcp(callback) { offTcp(callback) {
console.log(TAG, 'tcpofff') console.log(TAG, 'tcpofff')
this.tcp.off('testTagofmessg', callback); this.tcp.off('testTagofmessg', callback);
} }
closeTcp(callback) { closeTcp(callback) {
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
console.log(TAG, 'tcpClose') console.log(TAG, 'tcpClose')

View File

@ -111,7 +111,7 @@ export default struct Index {
carConfigurationInfoFn() { carConfigurationInfoFn() {
if (globalThis.singlePlay) { if (globalThis.singlePlay) {
// //
const str = "1:5;2:5;3:5;4:5;5:5;6:5;7:5;8:5;9:5;10:5;11:5;12:5;13:5;14:5;15:5;16:5;17:5;18:5;19:5;20:5;21:5;22:2;23:5;24:5;25:5;" const str = "1:5;2:5;3:5;4:5;5:5;6:5;7:5;8:5;9:5;10:5;11:5;12:5;13:5;14:5;15:5;16:5;17:5;18:5;19:5;20:5;21:5;22:2;23:5;24:5"
const data = str.split(';') const data = str.split(';')
this.checkList = [] this.checkList = []
const list = data const list = data
@ -166,7 +166,7 @@ export default struct Index {
getPLCInfo() { getPLCInfo() {
const that = this const that = this
globalThis.udpClient && globalThis.udpClient.onMessage_1((msg) => { globalThis.udpClient.onMessage_1 && globalThis.udpClient.onMessage_1((msg) => {
if (!this.breakFlag) { if (!this.breakFlag) {
return return
} }