Commit d42cedae authored by 李增强's avatar 李增强

m

parent 17525f2c
...@@ -10,16 +10,21 @@ class QMTJ { ...@@ -10,16 +10,21 @@ class QMTJ {
static DB _db; static DB _db;
static String _appStartUpId; static String _appStartUpId;
static Future<bool> ready;
static bool isDebug = false; static bool isDebug = false;
static void debug() { static void debug() {
isDebug = true; isDebug = true;
} }
static Future<void> init() async { static init() {
_appStartUpId = _md5(_getDateNow().toString()); _appStartUpId = _md5(_getDateNow().toString());
_db = new DB(); ready = new Future<bool>(() async {
await _db.init(); _db = new DB();
await await _db.init();
return true;
});
} }
/// APP 启动 /// APP 启动
...@@ -36,6 +41,7 @@ class QMTJ { ...@@ -36,6 +41,7 @@ class QMTJ {
"appear_time": appearTime, "appear_time": appearTime,
"extras": json.encode(extras), "extras": json.encode(extras),
}; };
await ready;
log("appStart", map); log("appStart", map);
await _db.db.insert("app_tj", map); await _db.db.insert("app_tj", map);
} }
...@@ -57,20 +63,22 @@ class QMTJ { ...@@ -57,20 +63,22 @@ class QMTJ {
"appear_time": appearTime, "appear_time": appearTime,
"extras": json.encode(extras), "extras": json.encode(extras),
}; };
await ready;
log("appAppear", map); log("appAppear", map);
await _db.db.insert("app_tj", map); await _db.db.insert("app_tj", map);
} }
/// APP 不可见 /// APP 不可见
static void appDisappear() { static void appDisappear() async {
int disappearTime = _getDateNow(); int disappearTime = _getDateNow();
_db.db.update("app_tj", {"disappear_time": disappearTime},
where: "id = ? and disappear_time = 0", whereArgs: [_appStartUpId]);
Map<String, dynamic> map = { Map<String, dynamic> map = {
"id": _appStartUpId, "id": _appStartUpId,
"disappear_time": disappearTime, "disappear_time": disappearTime,
}; };
await ready;
log("appDisappear", map); log("appDisappear", map);
_db.db.update("app_tj", {"disappear_time": disappearTime},
where: "id = ? and disappear_time = 0", whereArgs: [_appStartUpId]);
} }
/// PAGE 可见 /// PAGE 可见
...@@ -92,6 +100,7 @@ class QMTJ { ...@@ -92,6 +100,7 @@ class QMTJ {
"disappear_time": disappearTime, "disappear_time": disappearTime,
"extras": extrasStr, "extras": extrasStr,
}; };
await ready;
log("pageAppear", map); log("pageAppear", map);
await _db.db.insert("page_tj", map); await _db.db.insert("page_tj", map);
} }
...@@ -102,6 +111,9 @@ class QMTJ { ...@@ -102,6 +111,9 @@ class QMTJ {
String extrasStr = json.encode(extras); String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${lastPageId}_$extrasStr"); String id = _md5("${pageId}_${lastPageId}_$extrasStr");
int disappearTime = _getDateNow(); int disappearTime = _getDateNow();
await ready;
log("pageDisappear", map);
await _db.db.update( await _db.db.update(
"page_tj", "page_tj",
{ {
...@@ -116,7 +128,6 @@ class QMTJ { ...@@ -116,7 +128,6 @@ class QMTJ {
"disappear_time": disappearTime, "disappear_time": disappearTime,
"extras": extrasStr, "extras": extrasStr,
}; };
log("pageDisappear", map);
} }
/// 点击 /// 点击
...@@ -139,6 +150,7 @@ class QMTJ { ...@@ -139,6 +150,7 @@ class QMTJ {
"click_time": clickTime, "click_time": clickTime,
"extras": extrasStr, "extras": extrasStr,
}; };
await ready;
log("tap", map); log("tap", map);
await _db.db.insert("tap_tj", map); await _db.db.insert("tap_tj", map);
} }
...@@ -163,6 +175,7 @@ class QMTJ { ...@@ -163,6 +175,7 @@ class QMTJ {
"exposure_time": exposureTime, "exposure_time": exposureTime,
"extras": extrasStr, "extras": extrasStr,
}; };
await ready;
log("exposure", map); log("exposure", map);
await _db.db.insert("exposure_tj", map); await _db.db.insert("exposure_tj", map);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment