diff --git a/entry/src/main/ets/api/index.ets b/entry/src/main/ets/api/index.ets index e32134ba..a4a2ced7 100644 --- a/entry/src/main/ets/api/index.ets +++ b/entry/src/main/ets/api/index.ets @@ -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({ 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({ +export async function initialization(params: InitializeTheCentralTableType) { + return await request({ url: '/der2/services/exam/initialization.ws', data: `${params.carId}${params.examinationRoomId}${params.shellVersion}${params.judgeVersion}${params.videoVersion}`, method: http.RequestMethod.POST, diff --git a/entry/src/main/ets/common/service/initable.ets b/entry/src/main/ets/common/service/initable.ets index c5d2acaf..b93d796e 100644 --- a/entry/src/main/ets/common/service/initable.ets +++ b/entry/src/main/ets/common/service/initable.ets @@ -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 diff --git a/entry/src/main/ets/config/index.ets b/entry/src/main/ets/config/index.ets index d7778648..6343a6a4 100644 --- a/entry/src/main/ets/config/index.ets +++ b/entry/src/main/ets/config/index.ets @@ -1 +1,3 @@ -export * from "./LogEnum"; \ No newline at end of file +export * from "./LogEnum"; + +export * from "./global" \ No newline at end of file diff --git a/entry/src/main/ets/model/Table.ets b/entry/src/main/ets/model/Table.ets index 3d5a1004..bccf0a0c 100644 --- a/entry/src/main/ets/model/Table.ets +++ b/entry/src/main/ets/model/Table.ets @@ -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 +} \ No newline at end of file diff --git a/entry/src/main/ets/model/api.ets b/entry/src/main/ets/model/api.ets index 3551c9cf..34d47792 100644 --- a/entry/src/main/ets/model/api.ets +++ b/entry/src/main/ets/model/api.ets @@ -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 { diff --git a/entry/src/main/ets/utils/File.ets b/entry/src/main/ets/utils/File.ets new file mode 100644 index 00000000..f5f4301d --- /dev/null +++ b/entry/src/main/ets/utils/File.ets @@ -0,0 +1,17 @@ +import common from "@ohos.app.ability.common"; + +// export default class FileUtil { +// private context: common.UIAbilityContext +// +// constructor() { +// } +// +// // 创建文件夹 +// +// // 创建并覆盖文件 +// +// // 创建或者编辑文件 +// // 关闭文件 +// // 读取文件 +// // 删除文件夹或者文件1:文件夹 2:文件 3:自定义目录下文件 +// } \ No newline at end of file diff --git a/entry/src/main/ets/utils/table/Operation.ets b/entry/src/main/ets/utils/table/Operation.ets index 976c3f8f..af966380 100644 --- a/entry/src/main/ets/utils/table/Operation.ets +++ b/entry/src/main/ets/utils/table/Operation.ets @@ -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 { } +// 初始化中心表 +export async function InitializeTheCentralTable(params: InitializeTheCentralTableType): Promise { + 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) + } + }) +} + + diff --git a/entry/src/main/ets/utils/table/Relationship.ets b/entry/src/main/ets/utils/table/Relationship.ets index 9969f49c..077f8969 100644 --- a/entry/src/main/ets/utils/table/Relationship.ets +++ b/entry/src/main/ets/utils/table/Relationship.ets @@ -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'] ]); \ No newline at end of file