issue.ts
3.8 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
123
124
125
126
127
128
129
130
131
132
133
import * as Core from '../table';
import Model = require('../model');
import moment = require('moment');
import _ = require('lodash');
const config = require("../../../../config");
import { cache,redis as client, redis, task_lock } from '../../../cache'
async function Issue(issueId: any) {
let t = await Model.Issue.findOne({
where: {
Id: issueId
}
});
return t;
};
const Issues = async (root: any, args: any, context: any, isUpdateCache: any = false) => {
let lotId = 72
if (parseInt(args.lotId) > 0) {
lotId = parseInt(args.lotId)
}
// console.info(args);
return cache(async ({lotId,limit}: any) => {
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: any = 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)
};
const MatchTimes = async (root: any, args: any, context: any, isUpdateCache: any = 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 client.get(key);
try {
if (reply && reply.length > 0 && !isUpdateCache) {
return JSON.parse(reply)
}
} catch (e:any) {
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 client.set(key, JSON.stringify(t))
client.expire(key, 60)
return t;
};
function checkList(list: any) {
if (list && list.length > 0) {
return list[0]
}
return []
}
export { Issue, Issues, MatchTimes }