Commit 5bec8fd5 authored by 李增强's avatar 李增强

m

parent 61a3e5b9
...@@ -10,26 +10,16 @@ class QMTJ { ...@@ -10,26 +10,16 @@ class QMTJ {
static DB _db; static DB _db;
static String _appStartUpId; static String _appStartUpId;
static bool isDebug = false;
static void debug() {
isDebug = true;
}
static void init() async { static void init() async {
_appStartUpId = _md5(_getDateNow().toString()); _appStartUpId = _md5(_getDateNow().toString());
_db = new DB(); _db = new DB();
await _db.init(); await _db.init();
var app_tj = await _db.db.query("app_tj");
print('=============================================================app_tj');
print(app_tj);
print('=============================================================app_tj');
var page_tj = await _db.db.query("page_tj");
print('=============================================================page_tj');
print(page_tj);
print('=============================================================page_tj');
var a = await _db.db.query("tap_tj");
print('=============================================================tap_tj');
print(a);
print('=============================================================tap_tj');
var exposure = await _db.db.query("exposure_tj");
print('=============================================================exposure');
print(exposure);
print('=============================================================exposure');
} }
/// APP 启动 /// APP 启动
...@@ -38,14 +28,16 @@ class QMTJ { ...@@ -38,14 +28,16 @@ class QMTJ {
int disappearTime = 0; int disappearTime = 0;
int appearTime = _getDateNow(); int appearTime = _getDateNow();
String id = _appStartUpId; String id = _appStartUpId;
await _db.db.insert("app_tj", { Map<String, dynamic> map = {
"id": id, "id": id,
"type": type, "type": type,
"source": source, "source": source,
"disappear_time": disappearTime, "disappear_time": disappearTime,
"appear_time": appearTime, "appear_time": appearTime,
"extras": json.encode(extras), "extras": json.encode(extras),
}); };
log("appStart", map);
await _db.db.insert("app_tj", map);
} }
/// APP 可见 /// APP 可见
...@@ -57,20 +49,28 @@ class QMTJ { ...@@ -57,20 +49,28 @@ class QMTJ {
int disappearTime = 0; int disappearTime = 0;
int appearTime = _getDateNow(); int appearTime = _getDateNow();
String id = _appStartUpId; String id = _appStartUpId;
await _db.db.insert("app_tj", { Map<String, dynamic> map = {
"id": id, "id": id,
"type": type, "type": type,
"source": source, "source": source,
"disappear_time": disappearTime, "disappear_time": disappearTime,
"appear_time": appearTime, "appear_time": appearTime,
"extras": json.encode(extras), "extras": json.encode(extras),
}); };
log("appAppear", map);
await _db.db.insert("app_tj", map);
} }
/// APP 不可见 /// APP 不可见
static void appDisappear() { static void appDisappear() {
_db.db.update("app_tj", {"disappear_time": _getDateNow()}, int disappearTime = _getDateNow();
_db.db.update("app_tj", {"disappear_time": disappearTime},
where: "id = ? and disappear_time = 0", whereArgs: [_appStartUpId]); where: "id = ? and disappear_time = 0", whereArgs: [_appStartUpId]);
Map<String, dynamic> map = {
"id": _appStartUpId,
"disappear_time": disappearTime,
};
log("appDisappear", map);
} }
/// PAGE 可见 /// PAGE 可见
...@@ -83,7 +83,7 @@ class QMTJ { ...@@ -83,7 +83,7 @@ class QMTJ {
String id = _md5("${pageId}_${lastPageId}_$extrasStr"); String id = _md5("${pageId}_${lastPageId}_$extrasStr");
int disappearTime = 0; int disappearTime = 0;
int appearTime = _getDateNow(); int appearTime = _getDateNow();
await _db.db.insert("page_tj", { Map<String, dynamic> map = {
"id": id, "id": id,
"source": source, "source": source,
"page_id": pageId, "page_id": pageId,
...@@ -91,7 +91,9 @@ class QMTJ { ...@@ -91,7 +91,9 @@ class QMTJ {
"appear_time": appearTime, "appear_time": appearTime,
"disappear_time": disappearTime, "disappear_time": disappearTime,
"extras": extrasStr, "extras": extrasStr,
}); };
log("pageAppear", map);
await _db.db.insert("page_tj", map);
} }
/// PAGE 不可见 /// PAGE 不可见
...@@ -99,13 +101,22 @@ class QMTJ { ...@@ -99,13 +101,22 @@ class QMTJ {
{String pageId, String lastPageId, Map<String, dynamic> extras}) async { {String pageId, String lastPageId, Map<String, dynamic> extras}) async {
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();
await _db.db.update( await _db.db.update(
"page_tj", "page_tj",
{ {
"disappear_time": _getDateNow(), "disappear_time": disappearTime,
}, },
where: "id = ? and disappear_time = 0", where: "id = ? and disappear_time = 0",
whereArgs: [id]); whereArgs: [id]);
Map<String, dynamic> map = {
"id": id,
"page_id": pageId,
"last_page_id": lastPageId,
"disappear_time": disappearTime,
"extras": extrasStr,
};
log("pageDisappear", map);
} }
/// 点击 /// 点击
...@@ -120,14 +131,16 @@ class QMTJ { ...@@ -120,14 +131,16 @@ class QMTJ {
int clickTime = _getDateNow(); int clickTime = _getDateNow();
String extrasStr = json.encode(extras); String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${clickId}_${extrasStr}_${clickTime}"); String id = _md5("${pageId}_${clickId}_${extrasStr}_${clickTime}");
await _db.db.insert("tap_tj", { Map<String, dynamic> map = {
"id": id, "id": id,
"source": source, "source": source,
"page_id": pageId, "page_id": pageId,
"click_id": clickId, "click_id": clickId,
"click_time": clickTime, "click_time": clickTime,
"extras": extrasStr, "extras": extrasStr,
}); };
log("tap", map);
await _db.db.insert("tap_tj", map);
} }
/// 曝光 /// 曝光
...@@ -142,14 +155,16 @@ class QMTJ { ...@@ -142,14 +155,16 @@ class QMTJ {
int exposureTime = _getDateNow(); int exposureTime = _getDateNow();
String extrasStr = json.encode(extras); String extrasStr = json.encode(extras);
String id = _md5("${pageId}_${exposureId}_${extrasStr}_${exposureTime}"); String id = _md5("${pageId}_${exposureId}_${extrasStr}_${exposureTime}");
await _db.db.insert("exposure_tj", { Map<String, dynamic> map = {
"id": id, "id": id,
"source": source, "source": source,
"page_id": pageId, "page_id": pageId,
"exposure_id": exposureId, "exposure_id": exposureId,
"exposure_time": exposureTime, "exposure_time": exposureTime,
"extras": extrasStr, "extras": extrasStr,
}); };
log("exposure", map);
await _db.db.insert("exposure_tj", map);
} }
/// 获取当前时间戳,单位:秒 /// 获取当前时间戳,单位:秒
...@@ -164,4 +179,13 @@ class QMTJ { ...@@ -164,4 +179,13 @@ class QMTJ {
var digest = crypto.md5.convert(bytes); var digest = crypto.md5.convert(bytes);
return digest.toString(); return digest.toString();
} }
static void log(String type, Map<String, dynamic> map) {
if (!isDebug) {
return;
}
print("$type=======================s===========================$type");
print(map);
print("$type=======================e===========================$type");
}
} }
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