fix: 优化代码格式,统一引入语法和类型定义

This commit is contained in:
wangzhongjie 2025-04-02 14:24:13 +08:00
parent 27dc3f0ab9
commit 83e1acce25
10 changed files with 507 additions and 52 deletions

View File

@ -1,13 +1,15 @@
import request from "../utils/Request"
import http from "@ohos.net.http"
import request from '../utils/Request'
import http from '@ohos.net.http'
import {
ApiResponseType,
InitializeTheCentralTableType,
InitModelParams,
InitModelResponse,
ObtainCarExamInfoParams,
ResponseDataType,
TimeSynchronizationParams,
TimeSynchronizationRspBody
} from "../model"
} from '../model'
//同步时间
@ -109,9 +111,9 @@ export async function initCenterCacheByKSPT(params: object, url: string) {
//从参数平台获取模型
// TODO 类型需要补全
export async function initEsModel(params: ESObject) {
export async function initEsModel(params: InitModelParams) {
const timeInfo: TimeSynchronizationRspBody = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')
return await request<object>({
return await request<InitModelResponse>({
url: '/para/initEsModel.ws',
data: params,
method: http.RequestMethod.POST,

View File

@ -1,10 +1,11 @@
import request from '../utils/Request'
import http from '@ohos.net.http'
import { UserLoginType } from '../model/ExaminerLogin'
import { ApiResponseType } from '../model'
export async function examinerLogin(params: UserLoginType) {
return request({
return request<ApiResponseType>({
url: '/der2/services/exam/examinerLogin.ws',
data: `<?xml version="1.0" encoding="UTF-8" ?>
<examinerLoginReq>

View File

@ -2,21 +2,20 @@ import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import { GlobalConfig } from '../config/global';
import { initTable } from '../common/service/initable';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import { BaseInfoType, CarInfoType, ExaminerInfoType } from '../model';
import { tcpUtil } from '../utils/TcpRequest';
import DB from '../utils/DbSql';
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { InitTable } from '../utils/table/Operation';
export default class EntryAbility extends UIAbility {
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try {
console.log("sql first")
await DB.init(this.context)
// 创建一个user表
await initTable()
await InitTable()
console.log("sql first success")
} catch (e) {
console.error('sql first error', e)

View File

@ -117,10 +117,12 @@ export interface CarInfoType {
messagePort?: string
}
// TODO
export interface ExaminerInfoType {
code?: string
ksyxm?: string
name?: string
sfzmhm?: string
statusRgpp?: string
}
// 一些运行配置

View File

@ -14,6 +14,26 @@ export interface ApiResponseType {
// 缺考
examinationStuAbsentRsp?: ExaminationStuAbsentRsp
// 考官登录
examinerLoginRsp?: ExaminerLoginRsp
}
interface ExaminerLoginRsp {
head: Head
body: ExaminerLoginInfo
}
export interface ExaminerLoginInfo {
carId?: string;
examinationRoomId?: string;
examinerName?: string;
examinerPwd?: string;
username?: string;
kgxm?: string;
ksyh?: string;
plateNo?: string
isNeedCheck?: string
examSubject?: string
}
interface ExaminationStuAbsentRsp {
@ -66,10 +86,32 @@ export interface TimeSynchronizationParams {
}
interface Head {
resultCode: string;
time: string;
resultMessage: string;
checkCode: string;
resultCode?: string;
time?: string;
resultMessage?: string;
checkCode?: string;
}
export interface InitModelParams {
head: Head;
body: InitModelBody;
}
export interface InitModelResponse {
body: InitModelResponseBody
}
interface InitModelResponseBody {
// TODO
ES_MODEL: ESObject
}
interface InitModelBody {
rtkType?: string;
rspType?: string;
paraKdid?: string;
examinationRoomId?: string;
carMac?: string;
}
// -----new-----
@ -98,18 +140,6 @@ export interface ResponseDataType {
initializationRsp?: ImageCompareRsp
}
export interface ExaminerLoginInfo {
carId?: string;
examinationRoomId?: string;
examinerName?: string;
examinerPwd?: string;
username?: string;
kgxm?: string;
ksyh?: string;
plateNo?: string
isNeedCheck?: string
examSubject?: string
}
export interface SpzdType {
carId?: string;

View File

@ -6,7 +6,7 @@ import imageBtn from './compontents/imageBtn';
import { UserLoginType } from '../model/ExaminerLogin';
import { BusinessError } from '@ohos.base';
import { examinerLogin } from '../api/login';
import { CarInfoType, ExaminerLoginInfo } from '../model/index';
import { ApiResponseType, CarInfoType, ExaminerInfoType, ExaminerLoginInfo } from '../model/index';
import { CryptoJS } from '@ohos/crypto-js';
@ -108,8 +108,8 @@ struct Index {
this.limit = true
try {
// TODO
examinerLogin(param).then((res: ESObject) => {
AppStorage.setOrCreate('examinerInfo', res?.examinerLoginRsp?.body)
examinerLogin(param).then((res: ApiResponseType) => {
AppStorage.setOrCreate<ExaminerInfoType>('examinerInfo', res?.examinerLoginRsp?.body)
console.log('res?.examinerLoginRsp?.head?.resultCode', res?.examinerLoginRsp?.head?.resultCode,
JSON.stringify(res))
this.errorDialog.close()

View File

@ -1,8 +1,7 @@
import common from '@ohos.app.ability.common';
import router from '@ohos.router';
import { getEsCarModel, getSyncData, } from '../common/service/initable';
import { initJudgeUdp } from '../common/utils/UdpJudge';
// import { initJudgeUdp } from '../common/utils/UdpJudge';
import { judgeConfig } from './judgeSDK/utils/judgeConfig';
import promptAction from '@ohos.promptAction';
import errorMsgDialog from './compontents/errorMsgDialog';
@ -24,6 +23,7 @@ import { GetCurrentTime } from '../utils/Common';
import { ObtainSignalData } from '../utils/business/ObtainSignalData';
import { CentralHeartbeat } from '../utils/business/CentralHeartbeat';
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { initJudgeUdp } from '../utils/business/UdpJudge';
@Entry
@ -170,7 +170,7 @@ struct Index {
return
}
//判断数据库是否有表数据,有则直接跳转,没有则读取本地数据
getSyncData('MA_SYSSET').then((data: Array<string>) => {
GetSyncData<MASYSSETTableType>('MA_SYSSET').then((data: Array<MASYSSETTableType>) => {
console.log('datadata', JSON.stringify(data))
if (data?.[0]) {
router.pushUrl({
@ -466,7 +466,6 @@ struct Index {
});
if (this.singlePlay == undefined || this.singlePlay == null) {
// setVideoParam()
console.log('diyidiy')
this.context.resourceManager.getRawFileContent("welcome.wav")
.then(() => {
this.avPlayer.playAudio(['welcome.wav'])
@ -505,7 +504,7 @@ struct Index {
ObtainSignalData.init();
CentralHeartbeat.init();
CentralHeartbeat.sendHeartData()
CentralHeartbeat.getData((data:centerCallBackMsgType)=>{
CentralHeartbeat.getData((data: centerCallBackMsgType) => {
if (data.id == 32) {
AppStorage.setOrCreate('signNum', data.body[1])
}
@ -520,13 +519,6 @@ struct Index {
// await setCurrentTime();
await SetCurrentTime()
this.timeInfo = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')
// const distanceClass = AppStorage.get<boolean>('distanceClass')
// if (!distanceClass) {
// const distanceClass = new GetDistance(this.context)
// await distanceClass.initFolder()
// AppStorage.setOrCreate('distanceClass', distanceClass)
// console.info('surenjun', 'distanceClass=>初始化完成')
// }
DrivingDataStorage.init(this.context)
DrivingDataStorage.initializeTheDrivingDataFolder()
setTimeout(() => {
@ -547,10 +539,4 @@ struct Index {
}, 1000)
this.createAlbum()
}
async getModel() {
const context = this.context;
//下载模型
await getEsCarModel(context)
}
}

View File

@ -0,0 +1,129 @@
import emitter from '@ohos.events.emitter';
export const EVENTID = {
//远程扣分处理
kfEventId: 35,
//远程扣分查询
kfAskEventId: 36,
//远程扣分确认
kfConfirmEventId: 37,
//远程开始考试
beginExamEventId: 11,
//远程结束考试
endExamEventId: 12
}
export default class JudgeEmitter {
//监听开始考试
public onBeginExam = async (callBack?: Function) => {
console.info('surenjun', '注册远程开始考试事件')
this.beginExamCallBack = callBack
}
//监听结束考试
public onEndExam = async (callBack?: Function) => {
console.info('surenjun', '注册远程结束考试事件')
this.endExamCallBack = callBack
}
//监听扣分处理
public onKfExam = async (callBack?: Function) => {
console.info('surenjun', '注册远程扣分考试事件')
this.kfContent = callBack
}
//开始考试
public sendBeginExam = async (content: string) => {
emitter.emit({
eventId: EVENTID.beginExamEventId
}, {
data: {
directives: content
}
});
}
//结束考试
public sendEndExam = async (content: string) => {
emitter.emit({
eventId: EVENTID.endExamEventId
}, {
data: {
directives: content
}
});
}
private directives: string
//扣分
public sendKfContent = async (kfxh: string) => {
const directives = this.directives
console.info('surenjun', `udpEvent收到扣分事件。kfxh=>${kfxh};directives=>${directives}`)
emitter.emit({
eventId: EVENTID.kfEventId
}, {
data: {
directives,
kfxh
}
});
}
//监听扣分指令
public sendOnKf = async (directives: string) => {
//TODO 临时存储指令编号
this.directives = directives
globalThis.judgeUdp.askKf(directives)
}
// 获取扣分项目编号
public onConfirmKf = async (kfxh: string) => {
const directives = this.directives;
emitter.emit({
eventId: EVENTID.kfConfirmEventId
}, {
data: {
kfxh, directives
}
});
}
constructor() {
this.init()
}
init = async () => {
console.info('surenjun', '开始注册udp事件')
emitter.off(EVENTID.beginExamEventId)
emitter.off(EVENTID.endExamEventId)
emitter.off(EVENTID.kfConfirmEventId)
emitter.off(EVENTID.kfEventId)
emitter.on({
eventId: EVENTID.beginExamEventId
}, () => {
this?.beginExamCallBack()
});
emitter.on({
eventId: EVENTID.endExamEventId
}, () => {
this?.endExamCallBack()
});
emitter.on({
eventId: EVENTID.kfEventId
}, (data) => {
console.info('surenjun EVENTID.kfEvent' + JSON.stringify(data))
this?.kfContent(data)
});
}
private beginExamCallBack: Function = () => {
}
private endExamCallBack: Function = () => {
}
private confirmExamCallBack: Function = () => {
}
private kfContent: Function = () => {
}
}

View File

@ -0,0 +1,304 @@
import systemTime from '@ohos.systemDateTime';
import { testKm2Items, testKm3Items } from '../../pages/judgeSDK/dataTest/index';
import { judgeConfig } from '../../pages/judgeSDK/utils/judgeConfig';
import { examCalcGpsDistance } from '../../pages/judgeSDK/api';
export const initJudgeUdp = async () => {
globalThis.serialIndex = 0;
globalThis.udpIndex = 0;
const udp = await setJudgeUdp()
globalThis.judgeUdp = udp
const arrBlue = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00];
const arrBlueBuffer = Array2Byte(arrBlue).buffer
const lightLineUdp = await setTopLineUdp();
if (lightLineUdp) {
lightLineUdp.send(arrBlueBuffer);
}
globalThis.lightLineUdp = lightLineUdp
let [prevJd, preWd] = [0, 0]
globalThis.udpClient.onMessage_1(async (msg) => {
const stachArr = msg.split(',')
if (stachArr[0] != '#DN_GD') {
return
}
const udpIndex = globalThis.udpIndex;
const isJudge = globalThis.isJudge;
if (udpIndex % 5 === 0 && !isJudge) {
const bytes = await getMessageHeartbeat(msg);
const msgArr = msg.split(',');
const jd = convertGpsCoord2(msgArr[96] * 1);
const wd = convertGpsCoord2(msgArr[95] * 1 || 0);
udp.send(bytes)
if (prevJd && msgArr[83] == 4) {
const distance = await examCalcGpsDistance({
jd1: prevJd,
wd1: preWd,
jd2: jd,
wd2: wd,
h: msgArr[90] * 1 || 1,
})
//@ts-ignore
// globalThis.distanceClass?.setTimeData(((distance / 100).toFixed(2)) * 1)
}
prevJd = jd;
preWd = wd;
}
globalThis.udpIndex += 1
})
}
export const getMessageHeartbeat = async (msg) => {
const carInfo = globalThis.carInfo;
const { examSubject, plateNo } = carInfo;
const ksyh = '0000000000000'
const { fourInOneScreen:{ gpsDigit } } = judgeConfig
const asclshArr = stringToASC(fillZero(
globalThis.singlePlay
? '1111111111111'
: globalThis.lsh,
13));
const ascksyhArr = stringToASC(fillZero(examSubject == 2 ? '0000000000000' : '1111111111111', 13))
const ascsbxhArr = stringToASC('00000000')
// const ascsbxhArr = stringToASC('153216400880')
const serialIndex = globalThis.serialIndex
const tempData = await getPlcData(msg);
const examType = examSubject == 2 ? 2 : 3
const { sensor, gps } = tempData;
const { zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd, ygq, cs, fdjzs, dw } = sensor
const { jd, wd, hxj, fyj, hbg, sd } = gps
const translateSignals = getTranslateSignals(
[zfxd, yfxd, shtd, ygd, jgd, skd, dh1, dh2, lhq, jsc, ssc, fsc, lb, mkg, aqd].concat(getDwStatusType(dw))
.concat([0, 0, ygq, sensor.wd, 0])
)
const translateProject = getTranslateProject();
//@ts-ignore
const translateJd = convertGpsCoord2(wd).toFixed(gpsDigit) * Math.pow(10, gpsDigit);
//@ts-ignore
const translateWd = convertGpsCoord2(jd).toFixed(gpsDigit) * Math.pow(10, gpsDigit)
//@ts-ignore
const translateProjects = translateProject.map(numStr => string2Bytes(parseInt(numStr, 2), 8)[0])
//@ts-ignore
let tempSd = (sd * 1.852).toFixed(0) * 1
if (tempSd < 1) {
tempSd = 0
}
const arr = [
//考生号
asclshArr.map(lsh => string2Bytes(lsh, 8)[0]),
//考试员号
ascksyhArr.map(ksyh => string2Bytes(ksyh, 8)[0]),
//科目类型(0:未考试 1:科目二 2:科目三) + 考试开始时间
string2Bytes(`${0}${'00:00:000'}`, 4 * 8),
// 消息序号
string2Bytes(serialIndex, 2 * 8),
translateSignals,
//@ts-ignore
string2Bytes(tempSd * 100, 2 * 8), string2Bytes(fdjzs / 100, 8), string2Bytes(translateJd, 4 * 8),
string2Bytes(translateWd, 4 * 8), string2Bytes(1, 8),
//GPS东向距离
string2Bytes(0, 4 * 8),
//GPS北向距离
string2Bytes(0, 4 * 8),
//航向角 俯仰角 高程(海拔)
//@ts-ignore
string2Bytes((hxj) * 100, 2 * 8), string2Bytes(fyj * 100, 2 * 8), string2Bytes(hbg * 100, 4 * 8),
//dddd
translateProjects,
//当前项目编号
string2Bytes(0, 8),
//场地设备编号
ascsbxhArr.map(sbxh => string2Bytes(sbxh, 8)[0]),
//本次考试行驶距离
string2Bytes(0, 2 * 8),
//扣分值
string2Bytes(0, 2 * 8),
//扣分数
string2Bytes(0, 2 * 8),
//扣分项数量
string2Bytes(0, 8),
//n个扣分序号
[].map(kf => string2Bytes(kf.markcatalog, 8)),
//牵引车第二gps精度、纬度
string2Bytes(0, 4 * 8), string2Bytes(0, 4 * 8),
//牵引车第二航向角
string2Bytes(0, 2 * 8),
//摩托压线 Byte[20],
string2Bytes(0, 20 * 8),
//考试用时
string2Bytes(fillZero(0 + '', 4), 4 * 8),
//项目用时
string2Bytes(fillZero(0, 2), 2 * 8),
//设备信号状态
string2Bytes(0, 4 * 8),
]
let tempArr = [];
arr.forEach(itemArr => {
tempArr = tempArr.concat(itemArr)
})
globalThis.serialIndex = 0;
return Array2Byte(tempArr)
}
// 中心plc实时信号转换成字节
const getTranslateSignals = (tempItems) => {
const len = Math.floor(tempItems.length / 8);
const arr = [];
for (let i = 0; i < len; i++) {
const temp = tempItems.slice(i * 8, (i + 1) * 8);
arr.push(temp.join(''));
}
const temp = arr.map(numStr => parseInt(numStr, 2))
return temp.map(item => string2Bytes(item, 8)[0])
}
// 中心所有项目转换
const getTranslateProject = () => {
const examSubject = globalThis.examSubject;
const tempItems = (examSubject == 2 ? testKm2Items : testKm3Items).map(code => {
return {
code, status: '0'
}
})
const arr = [];
for (let i = 0; i <= 4; i++) {
const temp = tempItems.slice(i * 4, (i + 1) * 4);
let tempArr = temp.map(item => item.status)
if (i === 4) {
tempArr = examSubject == 2
//bit36-bit39保留
? tempArr.concat(['00', '00'])
//bit30-bit39保留
: tempArr.concat(['00', '00', '00'])
}
// if (i === 3 && examSubject == 3) {
// tempArr = tempArr.concat(['00'])
// }
arr.push(tempArr.join(''));
}
return arr
}
// 中心实时项目状态转换
const getCenterProjectStatus = (status) => {
switch (status) {
//不考
case 0:
return '00'
//未考
case 1:
return '01'
//已考
case 2:
return '10'
}
}
// plc数据转换成对象
const getPlcData = async (plc: string) => {
const time = await systemTime.getCurrentTime()
const p = plc.split(',').map((val, key) => {
if (key !== 27 && key !== 92) {
//@ts-ignore
return val * 1
} else {
return val
}
});
const tempData = {
sensor: {
//安全带 车门门开关 手刹 脚刹 副刹 离合器 喇叭 示宽灯 近光灯 远光灯
aqd: p[19],
mkg: p[14],
ssc: p[13],
jsc: p[12],
fsc: p[18],
lhq: p[17],
lb: p[4],
skd: p[9],
jgd: p[7],
ygd: p[8],
//左方向灯 右方向灯 双跳灯 雾灯 雨刮器 点火1 点火2 发动机转速 档位 车速
zfxd: p[2],
yfxd: p[3],
shtd: p[20],
wd: p[10],
ygq: p[11],
dh1: p[5],
dh2: p[6],
fdjzs: p[25],
dw: p[28],
cs: p[23],
//@ts-ignore 方向盘
fxp: p[27].split('_')[0] * 1,
//累计脉冲 溜车脉冲 超声波左后 超声波右后 超声波右前 超声波左前 座椅 仪表盘 后视镜 倒车镜 光照 雨量
ljmc: p[24],
lcmc: 0,
csbzh: p[32],
csbyh: p[30],
csbyq: p[31],
csbzq: p[29],
zy: 0,
tbp: 0,
hsj: 0,
dcj: 0,
gx: 0,
yl: 0
},
gps: {
//TODO 办卡类型 定位差分状态
bklx: p[56],
dwzt: p[83],
//@ts-ignore 角度差分状态
jdzt: p[92].split('-')[0] * 1,
//TODO gps数据
//gps时间 经度 纬度 航向角 俯仰角 海拔高 高度差 速度
sj: time,
jd: p[96],
wd: p[95],
hxj: p[90],
fyj: p[91],
hbg: p[85],
gdc: p[86],
sd: p[97],
//龄期 经度因子 纬度因子 定位搜星数
age: p[87],
jdyz: p[89],
wdyz: p[88],
dwsxs: p[84],
//@ts-ignore 角度搜星数
jdsxs: p[92].split('-')[1] * 1
},
}
return tempData
}
const getDwStatusType = (dw) => {
switch (dw) {
case 0:
return [0, 0, 0, 0]
case 1:
return [0, 0, 0, 1]
case 2:
return [0, 0, 1, 0]
case 3:
return [0, 0, 1, 1]
case 4:
return [0, 1, 0, 0]
case 5:
return [0, 1, 0, 1]
case 9:
return [1, 0, 0, 1]
default:
return [0, 0, 0, 0]
}
}

View File

@ -1,4 +1,6 @@
import { InitializeTheCentralTableType, ResponseDataType, User } from '../../model';
import {
InitializeTheCentralTableType, ResponseDataType, User
} from '../../model';
import DB, { ColumnInfo, ColumnType } from '../DbSql';
import { CenterMap, ParameterPlatform, RemappingTableName } from './Relationship';
import { BusinessError } from '@ohos.base';