fix: 优化打印结构
This commit is contained in:
parent
80c715d2c9
commit
cd282045d3
@ -49,4 +49,7 @@ export const HomeTag = '[Home]';
|
||||
export const JudgeTag = '[Judge]';
|
||||
|
||||
//初始化表
|
||||
export const InitTableTag = '[InitTable]';
|
||||
export const InitTableTag = '[InitTable]';
|
||||
|
||||
//数据库操作
|
||||
export const DbOperationTag = '[DbOperation]';
|
||||
@ -16,9 +16,8 @@ import { UseAuth } from '../utils/Common';
|
||||
export default class EntryAbility extends UIAbility {
|
||||
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
console.log(EntryTag, "多伦鸿蒙车载程序启动")
|
||||
await DB.init(this.context)
|
||||
try {
|
||||
await DB.init(this.context)
|
||||
await InitTable()
|
||||
let fileUtil = new FileUtils(this.context)
|
||||
// 一些地址配置
|
||||
const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
|
||||
@ -31,6 +30,7 @@ export default class EntryAbility extends UIAbility {
|
||||
const host = `http://${result.centerIp}:${result.centerPort}`
|
||||
AppStorage.setOrCreate<string>("host", host)
|
||||
}
|
||||
await InitTable()
|
||||
} catch (e) {
|
||||
console.error(EntryTag, 'sql first error', e)
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export enum ColumnType {
|
||||
class DbUtils {
|
||||
rdbStore: relationalStore.RdbStore | undefined = undefined
|
||||
|
||||
// 初始化
|
||||
// 初始化 无需记录日志
|
||||
init(context: common.UIAbilityContext) {
|
||||
let config: relationalStore.StoreConfig = {
|
||||
name: 'car.db',
|
||||
@ -73,7 +73,7 @@ class DbUtils {
|
||||
})
|
||||
}
|
||||
|
||||
// 执行sql
|
||||
// 执行sql 无法记录
|
||||
executeSql(sql: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.rdbStore) {
|
||||
|
||||
@ -5,19 +5,19 @@ import { BusinessError } from '@ohos.base';
|
||||
import Prompt from '@system.prompt';
|
||||
import { initialization } from '../../api';
|
||||
|
||||
import { GlobalConfig, InitTableTag } from '../../config';
|
||||
import { DbOperationTag, GlobalConfig, InitTableTag } from '../../config';
|
||||
import FileUtils from '../FileUtils';
|
||||
import { dConsole } from '../LogWorker';
|
||||
|
||||
// 建表操作
|
||||
export async function InitTable() {
|
||||
ParameterPlatform.forEach(item => {
|
||||
console.log("表名", item.sqlCreate)
|
||||
dConsole.log(DbOperationTag, "表名", item.sqlCreate)
|
||||
if (item) {
|
||||
DB.executeSql(item.sqlCreate).then(() => {
|
||||
console.log("表创建成功", item.tableName)
|
||||
dConsole.log(DbOperationTag, "表创建成功", item.tableName)
|
||||
}).catch((err: BusinessError) => {
|
||||
console.log("表创建失败", item.tableName, err)
|
||||
dConsole.log(DbOperationTag, "表创建失败", item.tableName, err)
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -40,12 +40,12 @@ export function SqlInsertTable(tableName: string, data: Array<RecordType>, delFl
|
||||
}).join(",")
|
||||
let INSERT_SQL = "INSERT INTO " + tableName
|
||||
+ " (" + columns + ") VALUES " + values
|
||||
console.log('表插入语句,', INSERT_SQL, 'tableName', tableName)
|
||||
dConsole.log(DbOperationTag, '表插入语句,', INSERT_SQL, 'tableName', tableName)
|
||||
DB.executeSql(INSERT_SQL).then(() => {
|
||||
console.log('插入表成功', 'tableName', tableName)
|
||||
dConsole.log(DbOperationTag, '插入表成功', 'tableName', tableName)
|
||||
resolve(true)
|
||||
}).catch((err: BusinessError) => {
|
||||
console.log('插入表失败,', JSON.stringify(err), 'tableName', tableName)
|
||||
dConsole.error(DbOperationTag, '插入表失败,', JSON.stringify(err), 'tableName', tableName)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
@ -77,8 +77,10 @@ export async function GetSyncData<T>(tableName: string): Promise<T[]> {
|
||||
} as ColumnInfo;
|
||||
});
|
||||
DB.queryListBySql<T>(`select * from ${tableName}`, columns).then((res: T[]) => {
|
||||
dConsole.log(DbOperationTag, '获取表数据成功', 'tableName', tableName, '数据长度', res.length);
|
||||
resolve(res);
|
||||
}).catch((err: BusinessError) => {
|
||||
dConsole.error(DbOperationTag, '获取表数据失败', JSON.stringify(err), 'tableName', tableName);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user