123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- const {
- parseUrlParams
- } = require('../shared')
- const SessionLog = require('./mod/sessionLog')
- const PageLog = require('./mod/pageLog')
- const EventLog = require('./mod/eventLog')
- const ErrorLog = require('./mod/errorLog')
- const Device = require('./mod/device')
- class UniStatReportDataReceiver {
-
- async report(params, context) {
- let res = {
- code: 0,
- msg: 'success'
- }
- if (!params || !params.requests) {
- return {
- code: 200,
- msg: 'Invild params'
- }
- }
-
- const requestParam = JSON.parse(params.requests)
- if (!requestParam || requestParam.length === 0) {
- return {
- code: 200,
- msg: 'Invild params'
- }
- }
-
- const sessionParams = []
- const pageParams = []
- const eventParams = []
- const errorParams = []
- const device = new Device()
- for (const ri in requestParam) {
-
- const urlParams = parseUrlParams(requestParam[ri], context)
- if (!urlParams.ak) {
- return {
- code: 201,
- msg: 'Not found appid'
- }
- }
- if (!urlParams.lt) {
- return {
- code: 202,
- msg: 'Not found this log type'
- }
- }
- switch (parseInt(urlParams.lt)) {
-
- case 1: {
- sessionParams.push(urlParams)
- break
- }
-
- case 3:
- case 11: {
- pageParams.push(urlParams)
- break
- }
-
- case 21: {
- eventParams.push(urlParams)
- break
- }
-
- case 31: {
- errorParams.push(urlParams)
- break
- }
-
- case 101: {
- res = await device.bindPush(urlParams)
- break
- }
- default: {
- console.log('Invalid type by param "lt:' + urlParams.lt + '"')
- break
- }
- }
- }
-
- if (sessionParams.length > 0) {
- const sessionLog = new SessionLog()
- res = await sessionLog.batchFill(sessionParams)
- }
-
- if (pageParams.length > 0) {
- const pageLog = new PageLog()
- res = await pageLog.fill(pageParams)
- }
-
- if (eventParams.length > 0) {
- const eventLog = new EventLog()
- res = await eventLog.fill(eventParams)
- }
-
- if (errorParams.length > 0) {
- const errorLog = new ErrorLog()
- res = await errorLog.fill(errorParams)
- }
- return res
- }
- }
- module.exports = UniStatReportDataReceiver
|