fix: 重构初始化中心表相关代码,优化类型定义和数据库操作
This commit is contained in:
parent
7b45c1f0f9
commit
329833c228
@ -1,5 +1,6 @@
|
||||
import request from "../utils/Request"
|
||||
import http from "@ohos.net.http"
|
||||
import { InitializeTheCentralTableType, ResponseDataType } from "../model"
|
||||
|
||||
interface timeSynchronizationParams {
|
||||
time: string
|
||||
@ -87,7 +88,7 @@ export async function initCarInfoCache(params: initCarInfoCacheParams) {
|
||||
|
||||
//参数下发读表接口
|
||||
export async function initCenterCache(params: object, url: string) {
|
||||
const timeInfo=AppStorage.get('timeInfo')
|
||||
const timeInfo = AppStorage.get('timeInfo')
|
||||
return await request<object>({
|
||||
url: '/para/initCenterCache.ws',
|
||||
data: params,
|
||||
@ -120,17 +121,9 @@ export async function initEsModel(params) {
|
||||
})
|
||||
}
|
||||
|
||||
interface initializationParams {
|
||||
carId: string
|
||||
examinationRoomId: string
|
||||
shellVersion: string
|
||||
judgeVersion: string
|
||||
videoVersion: string
|
||||
host: string
|
||||
}
|
||||
|
||||
export async function initialization(params: initializationParams) {
|
||||
return await request<object>({
|
||||
export async function initialization(params: InitializeTheCentralTableType) {
|
||||
return await request<ResponseDataType>({
|
||||
url: '/der2/services/exam/initialization.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?><initializationReq><body><carId>${params.carId}</carId><examinationRoomId>${params.examinationRoomId}</examinationRoomId><shellVersion>${params.shellVersion}</shellVersion><judgeVersion>${params.judgeVersion}</judgeVersion><videoVersion>${params.videoVersion}</videoVersion><carInfo></carInfo><map_Road></map_Road><map_Road_Lane></map_Road_Lane><map_SubItem></map_SubItem><t_CarParmSet></t_CarParmSet><map_ItemClass></map_ItemClass><map_Point></map_Point><map_Point_Item></map_Point_Item><CDSBINFO></CDSBINFO><MARKRULESET></MARKRULESET></body></initializationReq>`,
|
||||
method: http.RequestMethod.POST,
|
||||
|
||||
@ -75,11 +75,9 @@ const centerToMap = {
|
||||
'Map_SubItem': MA_MAP_SUBITEM,
|
||||
'Sysset': MA_SYSSET,
|
||||
'CarInfo': ES_CARINFO,
|
||||
// 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
|
||||
'MarkRuleSet': MA_MARKRULE,
|
||||
'Cdsbinfo': MA_CDSBINFO,
|
||||
'T_CarParmSet': MA_T_CARPARMSET,
|
||||
// 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
|
||||
}
|
||||
|
||||
// 建表操作
|
||||
@ -403,7 +401,7 @@ export async function upDataZhongxinginitialization(param) {
|
||||
|
||||
for (let key in res.initializationRsp.body) {
|
||||
if (!centerToMap[key]) {
|
||||
continue
|
||||
continue
|
||||
}
|
||||
const data = await setSyncCenterSqlData(key, res, param)
|
||||
if (!data) {
|
||||
@ -444,8 +442,6 @@ function setSyncCenterSqlData(key, res, param) {
|
||||
'Cdsbinfo': 'MA_CDSBINFO',
|
||||
'T_CarParmSet': 'MA_T_CARPARMSET',
|
||||
}
|
||||
// const accountTable = new AccountTable(() => {
|
||||
// }, centerToMap[key],param.context);
|
||||
let arrList
|
||||
if (res.initializationRsp.body[key].record instanceof Array) {
|
||||
arrList = res.initializationRsp.body[key].record
|
||||
|
||||
@ -1 +1,3 @@
|
||||
export * from "./LogEnum";
|
||||
export * from "./LogEnum";
|
||||
|
||||
export * from "./global"
|
||||
@ -1,4 +1,5 @@
|
||||
import { ColumnInfo, ColumnType } from '../common/database/DbSql'
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
export const MA_SYS_SET_COLUMN: ColumnInfo[] = [
|
||||
{
|
||||
@ -12,11 +13,14 @@ export const MA_SYS_SET_COLUMN: ColumnInfo[] = [
|
||||
type: ColumnType.STRING
|
||||
}
|
||||
]
|
||||
|
||||
export interface TableDefinition {
|
||||
tableName: string;
|
||||
sqlCreate: string;
|
||||
columns: string[];
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
export interface TableMapType {
|
||||
MA_MARKRULE: TableDefinition,
|
||||
MA_SYSTEMPARM: TableDefinition,
|
||||
@ -43,6 +47,7 @@ export interface TableMapType {
|
||||
DeviceInfoTable: TableDefinition,
|
||||
CommonConstants: TableDefinition
|
||||
}
|
||||
|
||||
export interface CenterTableMapType {
|
||||
ItemInfo: TableDefinition,
|
||||
MarkRule: TableDefinition,
|
||||
@ -63,3 +68,14 @@ export interface CenterTableMapType {
|
||||
Cdsbinfo: TableDefinition,
|
||||
T_CarParmSet: TableDefinition,
|
||||
}
|
||||
|
||||
export interface InitializeTheCentralTableType {
|
||||
singlePlay?: boolean
|
||||
carId?: string
|
||||
examinationRoomId?: string
|
||||
judgeVersion?: string
|
||||
shellVersion?: string
|
||||
host?: string
|
||||
videoVersion?: string
|
||||
context?: common.UIAbilityContext
|
||||
}
|
||||
@ -14,10 +14,16 @@ interface Head {
|
||||
|
||||
interface ImageCompareRsp {
|
||||
head: Head;
|
||||
body: ESObject
|
||||
}
|
||||
|
||||
export interface FaceCompareResp {
|
||||
imageCompareRsp: ImageCompareRsp
|
||||
imageCompareRsp?: ImageCompareRsp
|
||||
|
||||
}
|
||||
|
||||
export interface ResponseDataType {
|
||||
initializationRsp?: ImageCompareRsp
|
||||
}
|
||||
|
||||
export interface ExaminerLoginInfo {
|
||||
|
||||
17
entry/src/main/ets/utils/File.ets
Normal file
17
entry/src/main/ets/utils/File.ets
Normal file
@ -0,0 +1,17 @@
|
||||
import common from "@ohos.app.ability.common";
|
||||
|
||||
// export default class FileUtil {
|
||||
// private context: common.UIAbilityContext
|
||||
//
|
||||
// constructor() {
|
||||
// }
|
||||
//
|
||||
// // 创建文件夹
|
||||
//
|
||||
// // 创建并覆盖文件
|
||||
//
|
||||
// // 创建或者编辑文件
|
||||
// // 关闭文件
|
||||
// // 读取文件
|
||||
// // 删除文件夹或者文件1:文件夹 2:文件 3:自定义目录下文件
|
||||
// }
|
||||
@ -1,7 +1,12 @@
|
||||
import { TableDefinition, User } from '../../model';
|
||||
import { InitializeTheCentralTableType, ResponseDataType, TableDefinition, User } from '../../model';
|
||||
import DB, { ColumnInfo, ColumnType } from '../DbSql';
|
||||
import { ParameterPlatform } from './Relationship';
|
||||
import { CenterMap, ParameterPlatform, RemappingTableName } from './Relationship';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import Prompt from '@system.prompt';
|
||||
import { initialization } from '../../api';
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import { GlobalConfig } from '../../config';
|
||||
import { sqlInsertCommonFn } from '../../common/service/initable';
|
||||
|
||||
// 建表操作
|
||||
export async function InitTable() {
|
||||
@ -80,6 +85,69 @@ export async function DeleteSyncTable(tableName: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
|
||||
// 初始化中心表
|
||||
export async function InitializeTheCentralTable(params: InitializeTheCentralTableType): Promise<boolean> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const fileUtil = new FileUtil(params.context)
|
||||
let flag = false
|
||||
// 单机模式
|
||||
if (params.singlePlay) {
|
||||
const tableList =
|
||||
['MA_SYSSET', 'MA_SYSTEMPARM', 'MA_MARKRULE', 'MA_MARKRULESET', 'ES_CARINFO', 'MA_MAP_ROAD', 'MA_MAP_ROAD_LANE',
|
||||
'MAP_SUBITEM', 'MA_T_CARPARMSET', 'MA_MAP_ITEMCLASS', 'MA_MAP_POINT', 'MA_MAP_POINT_ITEM'];
|
||||
for (let i = 0; i <= tableList.length - 1; i++) {
|
||||
const data =
|
||||
await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + `/config/tableList/${tableList[i]}.txt`);
|
||||
flag = await SqlInsertTable(tableList[i], JSON.parse(data) || [])
|
||||
}
|
||||
if (!flag) {
|
||||
Prompt.showToast({
|
||||
message: '本地文件初始化数据库失败'
|
||||
})
|
||||
}
|
||||
resolve(flag)
|
||||
}
|
||||
// 非单机模式
|
||||
if (params.carId) {
|
||||
resolve(false)
|
||||
}
|
||||
const str: InitializeTheCentralTableType = {
|
||||
carId: params?.carId,
|
||||
examinationRoomId: params.examinationRoomId,
|
||||
videoVersion: '1.0',
|
||||
judgeVersion: params.judgeVersion,
|
||||
shellVersion: params.shellVersion,
|
||||
host: params.host
|
||||
}
|
||||
const res: ResponseDataType = await initialization(str)
|
||||
if (!res || res.initializationRsp.head.resultCode == "1") {
|
||||
resolve(false)
|
||||
}
|
||||
for (const key of Object.keys(res.initializationRsp.body)) {
|
||||
if (CenterMap[key]) {
|
||||
continue
|
||||
}
|
||||
// TODO 后续替换类型
|
||||
let arrList: ESObject[] = []
|
||||
if (res.initializationRsp.body[key] instanceof Array) {
|
||||
arrList = res.initializationRsp.body[key]
|
||||
} else {
|
||||
arrList.push(res.initializationRsp.body[key])
|
||||
}
|
||||
const folderPath = await fileUtil.initFolder(`/config/tableList`);
|
||||
fileUtil.addFile(`${folderPath}/${RemappingTableName[key]}.txt`, JSON.stringify(arrList))
|
||||
const result = await SqlInsertTable(RemappingTableName[key], arrList)
|
||||
if (!result) {
|
||||
Prompt.showToast({
|
||||
message: '初始化数据库失败'
|
||||
})
|
||||
}
|
||||
resolve(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -119,4 +119,42 @@ export const CenterMap = new Map([
|
||||
['MarkRuleSet', MA_MARKRULE],
|
||||
['Cdsbinfo', MA_CDSBINFO],
|
||||
['T_CarParmSet', MA_T_CARPARMSET],
|
||||
]);
|
||||
|
||||
// const mapName = {
|
||||
// 'ItemInfo': 'MA_ITEMINFO',
|
||||
// 'MarkRule': 'MA_MARKRULE',
|
||||
// 'SystemParm': 'MA_SYSTEMPARM',
|
||||
// 'Map_Collect': 'MA_MAP_COLLECT',
|
||||
// 'Map_Collect_Shape': 'MA_MAP_COLLECT_SHAPE',
|
||||
// 'Map_ItemClass': 'MA_MAP_ITEMCLASS',
|
||||
// 'Map_Point': 'MA_MAP_POINT',
|
||||
// 'Map_Point_Item': 'MA_MAP_POINT_ITEM',
|
||||
// 'Map_Road': 'MA_MAP_ROAD',
|
||||
// 'Map_Road_Lane': 'MA_MAP_ROAD_LANE',
|
||||
// 'Map_SubItem': 'MAP_SUBITEM',
|
||||
// 'Sysset': 'MA_SYSSET',
|
||||
// 'CarInfo': 'ES_CARINFO',
|
||||
// // 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
|
||||
// 'MarkRuleSet': 'MA_MARKRULESET',
|
||||
// 'Cdsbinfo': 'MA_CDSBINFO',
|
||||
// 'T_CarParmSet': 'MA_T_CARPARMSET',
|
||||
// }
|
||||
export const RemappingTableName = new Map([
|
||||
['ItemInfo', 'MA_ITEMINFO'],
|
||||
['MarkRule', 'MA_MARKRULE'],
|
||||
['SystemParm', 'MA_SYSTEMPARM'],
|
||||
['Map_Collect', 'MA_MAP_COLLECT'],
|
||||
['Map_Collect_Shape', 'MA_MAP_COLLECT_SHAPE'],
|
||||
['Map_ItemClass', 'MA_MAP_ITEMCLASS'],
|
||||
['Map_Point', 'MA_MAP_POINT'],
|
||||
['Map_Point_Item', 'MA_MAP_POINT_ITEM'],
|
||||
['Map_Road', 'MA_MAP_ROAD'],
|
||||
['Map_Road_Lane', 'MA_MAP_ROAD_LANE'],
|
||||
['Map_SubItem', 'MAP_SUBITEM'],
|
||||
['Sysset', 'MA_SYSSET'],
|
||||
['CarInfo', 'ES_CARINFO'],
|
||||
['MarkRuleSet', 'MA_MARKRULESET'],
|
||||
['Cdsbinfo', 'MA_CDSBINFO'],
|
||||
['T_CarParmSet', 'MA_T_CARPARMSET']
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user