1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import dataRdb from '@ohos.data.rdb' 16import database from './DatabaseUtils' 17import BundleManager from '../utils/BundleMangerUtils'; 18import { dateFormat } from '../utils/TimeUtils' 19import { ReportItem } from '../entity/LocalConfigEntity' 20import { sql_t_general_info, dbVersion, dbName } from '../constant/ConstantSQL'; 21import { AppFileRealDir } from '../constant/ConstantsPath' 22import SPLogger from '../utils/SPLogger' 23 24 25const TAG = "LocalRepository" 26 27 28export function initDb(): void { 29 dataRdb.getRdbStore(globalThis.abilityContext, { 30 name: dbName 31 }, dbVersion) 32 .then(rdbStore => { 33 rdbStore.executeSql(sql_t_general_info, null).catch(err => { 34 SPLogger.DEBUG(TAG, "--> createTable t_genneral_info err:" + err) 35 }) 36 SPLogger.DEBUG(TAG, "--> createTable start execute sql_t_genneral_info:" + sql_t_general_info) 37 return rdbStore 38 }) 39 40 getReportListDb().then(res => { 41 globalThis.reportList = res 42 let bundleNameArr = [] 43 for (let reportItemKey in globalThis.reportList) { 44 bundleNameArr.push(globalThis.reportList[reportItemKey].packageName) 45 } 46 47 BundleManager.getIconByBundleName(bundleNameArr).then(map => { 48 globalThis.iconMap = map 49 }) 50 51 let resReport: Array<ReportItem> = res 52 53 globalThis.sumTest = resReport.length 54 globalThis.sumTestTime = 0 55 56 let sumTestAppMap = new Map 57 for (let resReportKey in resReport) { 58 sumTestAppMap.set(resReport[resReportKey].appName, "") 59 globalThis.sumTestTime += Number(resReport[resReportKey].testDuration).valueOf() 60 } 61 globalThis.sumTestApp = sumTestAppMap.size 62 }).catch(err => { 63 SPLogger.DEBUG(TAG, "getReportListDb ERR:" + err); 64 }) 65} 66 67 68export async function getReportListDb(): Promise<Array<ReportItem>> { 69 var result = Array<ReportItem>() 70 await database.queryGeneralData().then(generals => { 71 for (var i = 0; i < generals.length; i++) { 72 var curGeneralInfo = generals[i] 73 result.push( 74 new ReportItem( 75 curGeneralInfo.taskId.toString(), 76 AppFileRealDir + curGeneralInfo.sessionId.toString(), 77 curGeneralInfo.packageName, 78 "", 79 curGeneralInfo.taskName, 80 curGeneralInfo.appName, 81 dateFormat(curGeneralInfo.startTime), 82 curGeneralInfo.testDuration.toString(), 83 false 84 )) 85 } 86 }) 87 return result 88}