439 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			439 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| // @ts-nocheck
 | ||
| import data_rdb from '@ohos.data.rdb';
 | ||
| import UIAbility from '@ohos.app.ability.UIAbility';
 | ||
| import { initCenterCache,initCenterCacheByKSPT,initEsModel,initialization } from '../../api/index'
 | ||
| import { dateFormat } from '../utils/tools';
 | ||
| import AccountTable from '../database/tables/AccountTable';
 | ||
| import MA_MARKRULE from '../constants/MA_MARKRULE';
 | ||
| import MA_SYSTEMPARM from '../constants/MA_SYSTEMPARM';
 | ||
| import MA_MAP_COLLECT from '../constants/MA_MAP_COLLECT';
 | ||
| import MA_MAP_COLLECT_SHAPE from '../constants/MA_MAP_COLLECT_SHAPE';
 | ||
| import MA_MAP_ITEMCLASS from '../constants/MA_MAP_ITEMCLASS';
 | ||
| import MA_MAP_POINT from '../constants/MA_MAP_POINT';
 | ||
| import MA_MAP_POINT_ITEM from '../constants/MA_MAP_POINT_ITEM';
 | ||
| import MA_MAP_ROAD from '../constants/MA_MAP_ROAD';
 | ||
| import MA_MAP_ROAD_LANE from '../constants/MA_MAP_ROAD_LANE';
 | ||
| import MA_MAP_SUBITEM from '../constants/MA_MAP_SUBITEM';
 | ||
| import MA_SYSSET from '../constants/MA_SYSSET';
 | ||
| import ES_CARINFO from '../constants/ES_CARINFO';
 | ||
| import ES_EXAMPOINTDETAIL from '../constants/ES_EXAMPOINTDETAIL';
 | ||
| import MA_MARKRULESET from '../constants/MA_MARKRULESET';
 | ||
| import MA_CDSBINFO from '../constants/MA_CDSBINFO';
 | ||
| import MA_ITEMINFO from '../constants/MA_ITEMINFO';
 | ||
| import MA_T_CARPARMSET from '../constants/MA_T_CARPARMSET';
 | ||
| import ES_CAR_VIDEO_PARAMETER from '../constants/ES_CAR_VIDEO_PARAMETER';
 | ||
| import IpConfigTable from '../constants/IpConfigTable';
 | ||
| import CommonConstants from '../constants/CommonConstants'
 | ||
| import DeviceInfoTable from '../constants/DeviceInfoTable'
 | ||
| import USER from '../constants/USER'
 | ||
| import util from '@ohos.util';
 | ||
| import zlib from '@ohos.zlib';
 | ||
| import FileModel from '../../pages/judgeSDK/utils/file-model';
 | ||
| // @ts-nocheck
 | ||
| //读表
 | ||
| //参数平台
 | ||
| const map = {
 | ||
|   'MA_MARKRULE': MA_MARKRULE,
 | ||
|   'MA_SYSTEMPARM': MA_SYSTEMPARM,
 | ||
|   'MA_MAP_COLLECT': MA_MAP_COLLECT,
 | ||
|   'MA_MAP_COLLECT_SHAPE': MA_MAP_COLLECT_SHAPE,
 | ||
|   'MA_MAP_ITEMCLASS': MA_MAP_ITEMCLASS,
 | ||
|   'MA_MAP_POINT': MA_MAP_POINT,
 | ||
|   'MA_MAP_POINT_ITEM': MA_MAP_POINT_ITEM,
 | ||
|   'MA_MAP_ROAD': MA_MAP_ROAD,
 | ||
|   'MA_MAP_ROAD_LANE': MA_MAP_ROAD_LANE,
 | ||
|   'MA_MAP_SUBITEM': MA_MAP_SUBITEM,
 | ||
|   'MA_SYSSET': MA_SYSSET,
 | ||
|   'ES_CARINFO': ES_CARINFO,
 | ||
|   'ES_EXAMPOINTDETAIL': ES_EXAMPOINTDETAIL,
 | ||
|   'MA_MARKRULESET': MA_MARKRULESET,
 | ||
|   'MA_CDSBINFO': MA_CDSBINFO,
 | ||
|   'MA_ITEMINFO': MA_ITEMINFO,
 | ||
|   'MA_T_CARPARMSET': MA_T_CARPARMSET,
 | ||
|   'ES_CAR_VIDEO_PARAMETER': ES_CAR_VIDEO_PARAMETER,
 | ||
|   'USER':USER
 | ||
| }
 | ||
| const centerToMap={
 | ||
|   'ItemInfo':MA_ITEMINFO,
 | ||
|   'MarkRule':MA_MARKRULE,
 | ||
|   'SystemParm':MA_SYSTEMPARM,
 | ||
|   'mapCollectList':MA_MAP_COLLECT,
 | ||
|   'mapCollectshapeList':MA_MAP_COLLECT_SHAPE,
 | ||
|   // MA_MAP_ITEMCLASS:MA_MAP_ITEMCLASS
 | ||
|   'mapPointList':MA_MAP_POINT,
 | ||
|   // 'MA_MAP_POINT_ITEM':MA_MAP_POINT_ITEM,
 | ||
|   'mapRoadList':MA_MAP_ROAD,
 | ||
|   'mapRoadLaneList':MA_MAP_ROAD_LANE,
 | ||
|   'mapSubitemList':MA_MAP_SUBITEM,
 | ||
|   'Sysset':MA_SYSSET,
 | ||
|   'CarInfo':ES_CARINFO,
 | ||
|   // 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
 | ||
|   // 'MA_MARKRULESET':MA_MARKRULE,
 | ||
|   'Cdsbinfo':MA_CDSBINFO,
 | ||
|   't_carparmset':MA_T_CARPARMSET,
 | ||
|   // 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
 | ||
| }
 | ||
| function sqlInsertCommonFn(tableName,resultArr){
 | ||
|   return new Promise((resolve,reject)=>{
 | ||
|     const accountTable = new AccountTable(() => {
 | ||
|     }, map[tableName]);
 | ||
|     accountTable.getRdbStore(() => {
 | ||
|       accountTable.query('0',  (result) => {
 | ||
|         if (result.length == 0) {
 | ||
|           let INSERT_SQL = "INSERT INTO "+tableName
 | ||
|           + " ("+ map[tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
 | ||
| 
 | ||
|           resultArr.map((data,i) => {
 | ||
|             data.id=`${i}`
 | ||
|             let str='('
 | ||
|             map[tableName].ACCOUNT_TABLE.columns.map((res,index)=>{
 | ||
|               if(map[tableName].ACCOUNT_TABLE.columns.length-1==index){
 | ||
|                 str+=`"${data[res]||'1'}"`
 | ||
|               }else{
 | ||
|                 str+=`"${data[res]||'1'}"`+','
 | ||
|               }
 | ||
|             })
 | ||
|             if(i==resultArr.length-1){
 | ||
|               str+=')'
 | ||
|             }else{
 | ||
|               str+='),'
 | ||
|             }
 | ||
|             INSERT_SQL+=str
 | ||
|           })
 | ||
| 
 | ||
|           accountTable.sqlOperate(INSERT_SQL,tableName,(val)=>{
 | ||
|             resolve(val)
 | ||
|           })
 | ||
| 
 | ||
|         }
 | ||
|         else {
 | ||
|           delSyncTable(tableName).then(()=>{
 | ||
|             let INSERT_SQL2 = "INSERT INTO "+tableName + " ("+ map[tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
 | ||
| 
 | ||
|             resultArr.map((data,i) => {
 | ||
|               data.id=`${i}`
 | ||
|               let str='('
 | ||
|               map[tableName].ACCOUNT_TABLE.columns.map((res,index)=>{
 | ||
|                 if(map[tableName].ACCOUNT_TABLE.columns.length-1==index){
 | ||
|                   str+=`"${data[res]||'1'}"`
 | ||
|                 }else{
 | ||
|                   str+=`"${data[res]||'1'}"`+','
 | ||
|                 }
 | ||
|               })
 | ||
|               if(i==resultArr.length-1){
 | ||
|                 str+=')'
 | ||
|               }else{
 | ||
|                 str+='),'
 | ||
|               }
 | ||
|               INSERT_SQL2+=str
 | ||
|             })
 | ||
| 
 | ||
|             accountTable.sqlOperate(INSERT_SQL2,tableName,(val)=>{
 | ||
|               resolve(true)
 | ||
|             })
 | ||
|           })
 | ||
| 
 | ||
|         }
 | ||
|       }, true);
 | ||
|     });
 | ||
|   })
 | ||
| }
 | ||
| export async function getDataBaseTable(params) {
 | ||
|   return new Promise((resolve, reject) => {
 | ||
|     const accountTable = new AccountTable(() => {
 | ||
|     }, map[params.tableName]);
 | ||
|     accountTable.getRdbStore(() => {
 | ||
|       accountTable.query('0', async (result) => {
 | ||
|         if (result.length != 0) {
 | ||
|           resolve();
 | ||
|           return
 | ||
|         } else {
 | ||
|           const date = new Date()
 | ||
|           if(!globalThis.timeInfo?.paraKdid){
 | ||
|             prompt.showToast({
 | ||
|               message: 'paraKdid获取失败',
 | ||
|               duration: 3000
 | ||
|             });
 | ||
|             return
 | ||
|           }
 | ||
|           const str = { "head": { "time": dateFormat(date) },
 | ||
|             "body":
 | ||
|             { "tableName": params.tableName, // 表名
 | ||
|               "paraKdid": globalThis.timeInfo?.paraKdid, //参数平台kdid
 | ||
|               "examinationRoomId": globalThis.carInfo?.examinationRoomId, //考试平台kdid
 | ||
|               "typeRsp": "0" // 赋默认值0,无需改变
 | ||
|             }
 | ||
|           }
 | ||
|           let res: any = await initCenterCache(str)
 | ||
|           if( res.body[params.tableName].length==0){
 | ||
|             resolve();
 | ||
|             return
 | ||
|           }
 | ||
| 
 | ||
|           let INSERT_SQL = "INSERT INTO "+params.tableName
 | ||
|           + " ("+ map[params.tableName].ACCOUNT_TABLE.columns.toString()+") VALUES "
 | ||
| 
 | ||
|           res.body[params.tableName].map((data,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]||'1'}"`
 | ||
|               }else{
 | ||
|                 str+=`"${data[res]||'1'}"`+','
 | ||
|               }
 | ||
|             })
 | ||
|             if(i==res.body[params.tableName].length-1){
 | ||
|               str+=')'
 | ||
|             }else{
 | ||
|               str+='),'
 | ||
|             }
 | ||
|             INSERT_SQL+=str
 | ||
|           })
 | ||
| 
 | ||
|           accountTable.sqlOperate(INSERT_SQL,params.tableName,()=>{
 | ||
|             resolve(true)
 | ||
|           })
 | ||
|         }
 | ||
|       }, true);
 | ||
|     });
 | ||
|   })
 | ||
| }
 | ||
| 
 | ||
| export async function upDateTable(params) {
 | ||
|   return new Promise((resolve, reject) => {
 | ||
|     const date = new Date()
 | ||
|     let paraKdid=''
 | ||
|     let examinationRoomId=''
 | ||
|     paraKdid=globalThis.timeInfo?globalThis.timeInfo?.paraKdid:''
 | ||
|     examinationRoomId= globalThis.carInfo?globalThis.carInfo.examinationRoomId:''
 | ||
|     if(!paraKdid|| !examinationRoomId){
 | ||
|       resolve(false)
 | ||
|       return
 | ||
|     }
 | ||
| 
 | ||
|     const str = { "head": { "time": dateFormat(date) },
 | ||
|       "body":
 | ||
|       { "tableName": params.tableName, // 表名
 | ||
|         "paraKdid": paraKdid, //参数平台kdid
 | ||
|         "examinationRoomId": examinationRoomId, //考试平台kdid
 | ||
|         "typeRsp": "0" // 赋默认值0,无需改变
 | ||
|       }
 | ||
|     }
 | ||
|     const url=globalThis.timeInfo.url
 | ||
| 
 | ||
|     initCenterCache(str,url).then(async (res)=>{
 | ||
|       if(!res||res==undefined||res==''){
 | ||
|         resolve(false)
 | ||
|         return
 | ||
|       }
 | ||
|       try {
 | ||
|         const result=await sqlInsertCommonFn(params.tableName,res.body[params.tableName])
 | ||
|         resolve(result)
 | ||
|       }catch (error){
 | ||
|         console.log(error)
 | ||
|       }
 | ||
|     })
 | ||
|   });
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| //
 | ||
| export async function upDateTableConfig(tableName,arr) {
 | ||
|   sqlInsertCommonFn(tableName,arr)
 | ||
| }
 | ||
| //考试平台
 | ||
| export async function getMySystemSetTable(params) {
 | ||
|   return new Promise((resolve, reject) => {
 | ||
|     const date = new Date()
 | ||
|     if(!globalThis.timeInfo?.paraKdid){
 | ||
|       prompt.showToast({
 | ||
|         message: 'paraKdid获取失败',
 | ||
|         duration: 3000
 | ||
|       });
 | ||
|       return
 | ||
|     }
 | ||
|     const str = { "head": { "time": dateFormat(date) },
 | ||
|       "body":
 | ||
|       { "tableName": params.tableName, // 表名
 | ||
|         "paraKdid": globalThis.timeInfo?.kdid, //考试平台kdid
 | ||
|         "examinationRoomId": globalThis.timeInfo?.kdid, //考试平台kdid
 | ||
|         "typeRsp": "0" // 赋默认值0,无需改变
 | ||
|       }
 | ||
|     }
 | ||
|    initCenterCacheByKSPT(str).then((res)=>{
 | ||
|      if( res.body[params.tableName].length==0){
 | ||
|        resolve();
 | ||
|        return
 | ||
|      }
 | ||
|      sqlInsertCommonFn(params.tableName,res.body[params.tableName]).then((result)=>{
 | ||
|        resolve(result)
 | ||
|      })
 | ||
|    })
 | ||
| 
 | ||
| 
 | ||
|   })
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| export async function getSyncData(tableName) {
 | ||
|   return new Promise((resolve, reject) => {
 | ||
|     const accountTable = new AccountTable(() => {
 | ||
|     }, map[tableName]);
 | ||
|     accountTable.getRdbStore(() => {
 | ||
|       accountTable.query('0', async (result) => {
 | ||
|         resolve(result)
 | ||
|       }, true);
 | ||
|     });
 | ||
|   })
 | ||
| 
 | ||
| }
 | ||
| export async function delSyncTable(tableName){
 | ||
|   return new Promise((resolve,reject)=>{
 | ||
|     const accountTable = new AccountTable(() => {
 | ||
|     }, map[tableName]);
 | ||
|     accountTable.deleteTableData(()=>{
 | ||
|       console.log('lll')
 | ||
|       resolve(true)
 | ||
|     },tableName)
 | ||
| 
 | ||
|   })
 | ||
| }
 | ||
| 
 | ||
| //获取车模、场地模型
 | ||
| export async function getEsCarModel(context){
 | ||
|   const date = new Date()
 | ||
|   if(!globalThis.timeInfo?.paraKdid){
 | ||
|     prompt.showToast({
 | ||
|       message: 'paraKdid获取失败',
 | ||
|       duration: 3000
 | ||
|     });
 | ||
|     return
 | ||
|   }
 | ||
|   const carStr = { "head": { "time": dateFormat(date) },
 | ||
|     "body":
 | ||
|     {
 | ||
|       "rtkType":"1",//1:车模 2:场地模型
 | ||
|       "rspType":"0", //返回类型
 | ||
|       "paraKdid": globalThis.timeInfo.paraKdid, //参数平台kdid
 | ||
|       "examinationRoomId": globalThis.timeInfo.kdid, //考试平台kdid
 | ||
|       // "carMac":"MAC-HCPAD-210",
 | ||
|       "carMac":globalThis.deviceNo
 | ||
|     }
 | ||
|   }
 | ||
|   const venueStr =  { "head": { "time": dateFormat(date) },
 | ||
|     "body":
 | ||
|     {
 | ||
|       "rtkType":"2",//1:车模 2:场地模型
 | ||
|       "rspType":"0", //返回类型
 | ||
|       "paraKdid": globalThis.timeInfo.paraKdid, //参数平台kdid
 | ||
|       "examinationRoomId": globalThis.timeInfo.kdid, //考试平台kdid
 | ||
|       // "carMac":"MAC-HCPAD-210",
 | ||
|       "carMac":globalThis.deviceNo
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
| 
 | ||
|   let carRes: any = await initEsModel(carStr);
 | ||
|   let venueRes: any = await initEsModel(venueStr);
 | ||
| 
 | ||
|   const carModel = carRes.body.ES_MODEL[0][1];
 | ||
|   const venueModel = venueRes.body.ES_MODEL[0][2];
 | ||
| 
 | ||
|   let tmpBase64Array = carModel.split("\r\n")
 | ||
|   let newBase64Str:string = '';
 | ||
|   for (let i = 0; i < tmpBase64Array.length; ++i) {
 | ||
|     newBase64Str += tmpBase64Array[i];
 | ||
|   }
 | ||
|   const base64 = new util.Base64();
 | ||
|   let result = base64.decodeSync(newBase64Str);
 | ||
|   const fileModel= new FileModel(context);
 | ||
|   await fileModel.initFolder()
 | ||
|   await fileModel.storingFiles(result.buffer)
 | ||
| }
 | ||
| 
 | ||
| export async function upDataZhongxinginitialization(){
 | ||
|   return new Promise((resolve, reject) => {
 | ||
|     if(!globalThis.carInfo?.carId){
 | ||
| 
 | ||
|       resolve(false)
 | ||
|       return
 | ||
|     }
 | ||
|     const str = {
 | ||
|       "carId":  globalThis.carInfo?.carId, // 表名
 | ||
|       "examinationRoomId": globalThis.carInfo?.examinationRoomId, //考试平台kdid
 | ||
|       videoVersion:'1.0',
 | ||
|       judgeVersion:globalThis.judgeVersion,
 | ||
|       shellVersion:  globalThis.version
 | ||
|     }
 | ||
|     initialization(str).then(async(res)=>{
 | ||
|       if(!res){
 | ||
|         resolve(false)
 | ||
|         return
 | ||
|       }
 | ||
|       let flag
 | ||
|       for(let key in res.initializationRsp.body){
 | ||
|         if(!centerToMap[key]){
 | ||
|           continue
 | ||
|         }
 | ||
|         try{
 | ||
|            flag=  await setSyncCenterSqlData(key,res)
 | ||
|         }catch (error){
 | ||
|           console.log(error)
 | ||
|         }
 | ||
|         if(!flag){
 | ||
|           resolve(false)
 | ||
|           return
 | ||
|         }
 | ||
|       }
 | ||
|       resolve(true)
 | ||
|     })
 | ||
| 
 | ||
|   })
 | ||
| }
 | ||
| function setSyncCenterSqlData(key,res){
 | ||
|   return new Promise((resolve,reject)=>{
 | ||
|     const mapName={
 | ||
|       'ItemInfo':'MA_ITEMINFO',
 | ||
|       'MarkRule':'MA_MARKRULE',
 | ||
|       'SystemParm':'MA_SYSTEMPARM',
 | ||
|       'mapCollectList':'MA_MAP_COLLECT',
 | ||
|       'mapCollectshapeList':'MA_MAP_COLLECT_SHAPE',
 | ||
|       // MA_MAP_ITEMCLASS:MA_MAP_ITEMCLASS
 | ||
|       'mapPointList':'MA_MAP_POINT',
 | ||
|       // 'MA_MAP_POINT_ITEM':MA_MAP_POINT_ITEM,
 | ||
|       'mapRoadList':'MA_MAP_ROAD',
 | ||
|       'mapRoadLaneList':'MA_MAP_ROAD_LANE',
 | ||
|       'mapSubitemList':'MA_MAP_SUBITEM',
 | ||
|       'Sysset':'MA_SYSSET',
 | ||
|       'CarInfo':'ES_CARINFO',
 | ||
|       // 'ES_EXAMPOINTDETAIL':ES_EXAMPOINTDETAIL,
 | ||
|       // 'MA_MARKRULESET':MA_MARKRULE,
 | ||
|       'Cdsbinfo':'MA_CDSBINFO',
 | ||
|       't_carparmset':'MA_T_CARPARMSET',
 | ||
|       // 'ES_CAR_VIDEO_PARAMETER':ES_CAR_VIDE0pO_PARAMETER
 | ||
|     }
 | ||
|     const accountTable = new AccountTable(() => {
 | ||
|     }, centerToMap[key]);
 | ||
|     let  arrList
 | ||
|     if(res.initializationRsp.body[key].record instanceof  Array){
 | ||
|       arrList =res.initializationRsp.body[key].record
 | ||
|     }else{
 | ||
|       arrList=[res.initializationRsp.body[key].record]
 | ||
|     }
 | ||
|     res
 | ||
|       sqlInsertCommonFn(mapName[key],arrList).then((result)=>{
 | ||
|         console.log(key,'表建立成功')
 | ||
|         if(result){
 | ||
|           resolve(true)
 | ||
|         }else{
 | ||
|           resolve(false)
 | ||
|         }
 | ||
|       }).catch((msg)=>{
 | ||
|         reject(false)
 | ||
|         console.log(msg)
 | ||
|       })
 | ||
|   })
 | ||
| 
 | ||
| }
 |