trans.js
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
var config;
var db;
function init(options) {
config = options.config;
db = options.db;
}
function _getByMessageid(messageid, cb) {
let dbConnection = db.connection();
if (!dbConnection) {
cb("db is not connected");
return;
}
let query = "SELECT * FROM T_TRANS WHERE 1=1";
let filter = {"MESSAGEID": messageid};
let queryWithFilter = db.composeQueryWithFilter(query, filter);
dbConnection.execute(queryWithFilter.query, queryWithFilter.values, function(err, res) {
if (err) {
cb(err, null);
return;
}
let retval = db.createResultObject(res);
if (retval && retval.length > 0) {
cb(null, retval[0]);
}
else {
cb(null, null);
}
});
}
function getByMessageid(req, res, next) {
_getByMessageid(req.params.messageid, function(err, result) {
if (err) {
res.send(err.message);
return;
}
res.send(result);
});
}
function _getLastHourSalesPerChipInfo(cb, hour) {
if (!hour) {
hour = 1;
}
let dbConnection = db.connection();
if (!dbConnection) {
cb("db is not connected");
return;
}
let query = "select CHIP_INFO, COUNT(1) as TRX, sum(PRICE) as AMOUNT, max(TIME_START) as LAST_TS from T_TRANS where TIME_START >= sysdate - :hour / 24 and CHIP_INFO is not null and (TRANS_STAT = '200' or TRANS_STAT = '1200') group by CHIP_INFO";
dbConnection.execute(query, [hour], function(err, res) {
if (err) {
cb(err, null);
return;
}
let retval = db.createResultObject(res);
if (retval && retval.length > 0) {
cb(null, retval);
}
else {
cb(null, null);
}
});
}
function getLastHourSalesPerChipInfo(req, res, next) {
_getLastHourSalesPerChipInfo(function(err, result) {
if (err) {
res.send(err.message);
return;
}
res.send(result);
});
}
exports.init = init;
exports.getByMessageid = getByMessageid
exports.getLastHourSalesPerChipInfo = getLastHourSalesPerChipInfo;