Commit 597c9cde authored by 李增强's avatar 李增强

m

parent d11e34dd
...@@ -8,10 +8,12 @@ import 'src/db.dart'; ...@@ -8,10 +8,12 @@ import 'src/db.dart';
import 'src/http.dart'; import 'src/http.dart';
import 'package:crypto/crypto.dart' as crypto; import 'package:crypto/crypto.dart' as crypto;
import 'src/tj/app.dart'; import 'src/tj/app.dart';
import 'src/tj/page.dart';
class QMTJ { class QMTJ {
static DB _db; static DB _db;
static App _app; static App _app;
static Page _page;
static void debug() { static void debug() {
Utils.debug(); Utils.debug();
...@@ -20,6 +22,7 @@ class QMTJ { ...@@ -20,6 +22,7 @@ class QMTJ {
static init() async { static init() async {
_db = DB(); _db = DB();
_app = App(_db); _app = App(_db);
_page = Page(_db);
_db.init(); _db.init();
Future.delayed(Duration(seconds: 5)).then((value) { Future.delayed(Duration(seconds: 5)).then((value) {
uploadPageTj(); uploadPageTj();
...@@ -37,51 +40,15 @@ class QMTJ { ...@@ -37,51 +40,15 @@ class QMTJ {
} }
/// PAGE 可见 /// PAGE 可见
static void pageAppear( static void onPageResume(
{int source, {String pageId, String lastPageId, Map<String, dynamic> extras}) async {
String pageId, _page.onResume(pageId: pageId, lastPageId: lastPageId, extras: extras);
String lastPageId,
Map<String, dynamic> extras}) async {
// String extrasStr = json.encode(extras);
// String id = _md5("${pageId}_${lastPageId}_$extrasStr");
// int disappearTime = 0;
// int appearTime = _getDateNow();
// Map<String, dynamic> map = {
// "id": id,
// "source": source,
// "page_id": pageId,
// "last_page_id": lastPageId,
// "appear_time": appearTime,
// "disappear_time": disappearTime,
// "extras": extrasStr,
// };
// await _db.ready;
// log("pageAppear", map);
// await _db.db.insert("page_tj", map);
} }
/// PAGE 不可见 /// PAGE 不可见
static void pageDisappear( static void onPagePause(
{String pageId, String lastPageId, Map<String, dynamic> extras}) async { {String pageId, String lastPageId, Map<String, dynamic> extras}) async {
// String extrasStr = json.encode(extras); _page.onPause(pageId: pageId, lastPageId: lastPageId, extras: extras);
// String id = _md5("${pageId}_${lastPageId}_$extrasStr");
// int disappearTime = _getDateNow();
// Map<String, dynamic> map = {
// "id": id,
// "page_id": pageId,
// "last_page_id": lastPageId,
// "disappear_time": disappearTime,
// "extras": extrasStr,
// };
// await _db.ready;
// log("pageDisappear", map);
// await _db.db.update(
// "page_tj",
// {
// "disappear_time": disappearTime,
// },
// where: "id = ? and disappear_time = 0",
// whereArgs: [id]);
} }
/// 点击 /// 点击
......
enum TJAppModelTypes { startUp, resume }
class TJAppModel {
String inter;
String appChannel;
String appVersion;
TJAppModelTypes type;
int appearTime;
int disappearTime;
Map<String, dynamic> extras;
TJAppModel(
{this.inter,
this.appChannel,
this.appVersion,
this.type,
this.appearTime,
this.disappearTime,
this.extras});
}
...@@ -16,33 +16,44 @@ String SQL_APP_TJ_TABLE = ''' ...@@ -16,33 +16,44 @@ String SQL_APP_TJ_TABLE = '''
String SQL_PAGE_TJ_TABLE = ''' String SQL_PAGE_TJ_TABLE = '''
CREATE TABLE page_tj ( CREATE TABLE page_tj (
id VARCHAR(32) , id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255), page_id VARCHAR(255),
last_page_id VARCHAR(255), last_page_id VARCHAR(255),
appear_time INTEGER(10), appear_time INTEGER(10),
disappear_time INTEGER(10), disappear_time INTEGER(10),
extras VARCHAR(255) extras VARCHAR(255),
inter VARCHAR(255),
app_channel VARCHAR(255),
app_version VARCHAR(255)
) )
'''; ''';
// 点击 // 点击
String SQL_TAP_TJ_TABLE = ''' String SQL_TAP_TJ_TABLE = '''
CREATE TABLE tap_tj ( CREATE TABLE tap_tj (
id VARCHAR(32) , id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255), page_id VARCHAR(255),
click_id VARCHAR(255), click_id VARCHAR(255),
click_time INTEGER(10), click_time INTEGER(10),
extras VARCHAR(255) extras VARCHAR(255),
inter VARCHAR(255),
app_channel VARCHAR(255),
app_version VARCHAR(255)
) )
'''; ''';
// 曝光 // 曝光
String SQL_EXPOSURE_TJ_TABLE = ''' String SQL_EXPOSURE_TJ_TABLE = '''
CREATE TABLE exposure_tj ( CREATE TABLE exposure_tj (
id VARCHAR(32) , id VARCHAR(32) ,
source INTEGER(10),
page_id VARCHAR(255), page_id VARCHAR(255),
exposure_id VARCHAR(255), exposure_id VARCHAR(255),
exposure_time INTEGER(10), exposure_time INTEGER(10),
extras VARCHAR(255) extras VARCHAR(255),
inter VARCHAR(255),
app_channel VARCHAR(255),
app_version VARCHAR(255)
) )
'''; ''';
...@@ -51,20 +51,24 @@ class App { ...@@ -51,20 +51,24 @@ class App {
// 上传数据至接口 // 上传数据至接口
void upload() async { void upload() async {
await _db.ready; await _db.ready;
List<Map> list = await _db.db.query("page_tj", limit: 100, offset: 0); List<Map> list = await _db.db.query("app_tj", limit: 100, offset: 0);
if (list.length == 0) { if (list.length == 0) {
return; return;
} }
String deviceId = await Utils.getDeviceId(); String deviceId = await Utils.getDeviceId();
bool result = bool result = await Utils.uploadData({
await Utils.uploadData({"device_id": deviceId, "projects": list}); "device_id": deviceId,
"projects": [
{"event_name": "app_stage", "event_data": list}
]
});
if (result) { if (result) {
List<String> ids = list.map((e) => e['id']).toList(); List<String> ids = list.map((e) => e['id']).toList();
await _db.db await _db.db
.rawDelete("delete from page_tj where id in('${ids.join("','")}')"); .rawDelete("delete from app_tj where id in('${ids.join("','")}')");
} }
if (Utils.isDebug) { if (Utils.isDebug) {
Utils.log("upload_result", {"ok": result, "length": list.length}); Utils.log("app upload_result", {"ok": result, "length": list.length});
} }
if (list.length == 100) { if (list.length == 100) {
upload(); upload();
......
import 'dart:convert';
import '../../src/db.dart';
import '../../src/utils.dart';
class Page {
DB _db;
Page(DB db) {
_db = db;
}
/// 页面回到前台
void onResume(
{String pageId, String lastPageId, Map<String, dynamic> extras}) async {
int disappearTime = 0;
int appearTime = Utils.getDateNow();
String extrasStr = json.encode(extras);
String id = Utils.md5("${pageId}_${lastPageId}_$extrasStr");
Map<String, dynamic> map = {
"id": id,
"page_id": pageId,
"last_page_id": lastPageId,
"appear_time": appearTime,
"disappear_time": disappearTime,
"extras": json.encode(extras)
};
Map<String, dynamic> common = await Utils.getCommonParams();
map.addAll(common);
await _db.ready;
Utils.log("page onResume", map);
await _db.db.insert("page_tj", map);
}
/// 页面进入后台
void onPause(
{String pageId, String lastPageId, Map<String, dynamic> extras}) async {
String extrasStr = json.encode(extras);
String id = Utils.md5("${pageId}_${lastPageId}_$extrasStr");
int disappearTime = Utils.getDateNow();
await _db.ready;
if (Utils.isDebug) {
Utils.log("page onPause", {
"id": id,
"page_id": pageId,
"last_page_id": lastPageId,
"disappear_time": disappearTime,
});
}
await _db.db.update(
"page_tj",
{
"disappear_time": disappearTime,
},
where: "id = ? and disappear_time = 0",
whereArgs: [id]);
}
// 上传数据至接口
void upload() async {
await _db.ready;
List<Map> list = await _db.db.query("page_tj", limit: 100, offset: 0);
if (list.length == 0) {
return;
}
String deviceId = await Utils.getDeviceId();
bool result = await Utils.uploadData({
"device_id": deviceId,
"projects": [
{"event_name": "page_scan", "event_data": list}
]
});
if (result) {
List<String> ids = list.map((e) => e['id']).toList();
await _db.db
.rawDelete("delete from page_tj where id in('${ids.join("','")}')");
}
if (Utils.isDebug) {
Utils.log("page upload_result", {"ok": result, "length": list.length});
}
if (list.length == 100) {
upload();
}
}
}
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