issue.js
4.4 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchTimes = exports.Issues = exports.Issue = void 0;
const Core = require("../table");
const Model = require("../model");
const moment = require("moment");
const _ = require("lodash");
const config = require("../../../../config");
const cache_1 = require("../../../cache");
async function Issue(issueId) {
let t = await Model.Issue.findOne({
where: {
Id: issueId
}
});
return t;
}
exports.Issue = Issue;
;
const Issues = async (root, args, context, isUpdateCache = false) => {
let lotId = 72;
if (parseInt(args.lotId) > 0) {
lotId = parseInt(args.lotId);
}
// console.info(args);
return (0, cache_1.cache)(async ({ lotId, limit }) => {
let sql = `select * from core_issue where LotteryId=${lotId}
and (EndTime<'${moment().add(3, `hour`).format(`YYYY-MM-DD HH:mm:ss`)}')
order by Name desc limit ${args.limit || 30}
`;
if ([45, 73, 72, 74, 75].includes(lotId) && (args.is_end == null || args.is_end == 1)) {
let old_match = await Core.Match.findOne({
where: {
//MatchTime:{$lt:`${moment().add(-118,"minute").format(`YYYY-MM-DD HH:mm:ss`)}`},
//IssueName:`${moment().format(`YYYY-MM-DD HH:mm:ss`)}`,
LotteryId: lotId,
MatchState: '完',
},
limit: 1,
order: [["MatchTime", "desc"]]
});
if (old_match != null) {
if (lotId == 72 && old_match.IssueName != moment().format(`YYYY-MM-DD`)) {
sql = `select * from core_issue where LotteryId=${lotId}
and (EndTime<'${moment().add(3, `hour`).format(`YYYY-MM-DD HH:mm:ss`)}')
order by Name desc limit ${args.limit || 30}
`;
}
else {
sql = `select * from core_issue where LotteryId=${lotId}
and Name<='${old_match.IssueName}'
order by StartTime desc limit ${args.limit || 30}
`;
}
}
}
else if ([45, 72, 73, 74, 75].includes(lotId)) {
// 1 完场的期号 2 是未完场的期号 3不限制是否完场 0 代表当前期号
switch (args.is_end) {
case 2:
sql = `select * from core_issue where LotteryId=${lotId}
and EndTime>'${moment().format(`YYYY-MM-DD HH:mm`)}'
order by Name desc limit ${args.limit || 30}
`;
break;
case 3:
sql = `select * from core_issue where LotteryId=${lotId}
and StartTime>'${moment().add(-100, `day`).format(`YYYY-MM-DD HH:mm:ss`)}'
order by Name desc limit ${args.limit || 30}
`;
break;
case 0:
sql = `select * from core_issue where LotteryId=${lotId}
and StartTime>'${moment().add(-3, `hour`).format(`YYYY-MM-DD HH:mm:ss`)}'
order by Name asc limit 1
`;
break;
}
}
// console.info(sql);
let t = await Core.sequelize.query(sql);
t = checkList(t);
return t;
}, { lotId, is_end: args.is_end }, 5, "pginfo_issue:vy5", 60, 100);
};
exports.Issues = Issues;
const MatchTimes = async (root, args, context, isUpdateCache = false) => {
let lotId = 72;
if (parseInt(args.lotId) > 0) {
lotId = parseInt(args.lotId);
}
let key = `${config.CachePrefix}match:matchMatchDates:v1_${args.lotId}`;
let reply = await cache_1.redis.get(key);
try {
if (reply && reply.length > 0 && !isUpdateCache) {
return JSON.parse(reply);
}
}
catch (e) {
console.info(e);
}
let sql = `
select distinct to_char("MatchTime",'YYYY-MM-DD') as "MatchTime"
from core_match
where "LotteryId"=${lotId} and "MatchTime">'${moment().add(-20, 'day').format('YYYY-MM-DD')}'
ORDER BY "MatchTime" desc limit 13
`;
let t = await Core.sequelize.query(sql);
t = checkList(t);
t = _.map(t, o => o.MatchTime);
await cache_1.redis.set(key, JSON.stringify(t));
cache_1.redis.expire(key, 60);
return t;
};
exports.MatchTimes = MatchTimes;
function checkList(list) {
if (list && list.length > 0) {
return list[0];
}
return [];
}
//# sourceMappingURL=issue.js.map