tip.js
1.81 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
const Subscription = require("egg").Subscription;
const { dateFormat } = require("../utils/utils");
module.exports = {
schedule: {
cron: "0 2 9,11 * * ?",
type: "worker", // 指定所有的 worker 都需要执行
},
async task(ctx) {
const reqRes = await ctx.curl(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=test&env=llx",
{ dataType: "json" }
);
let {
includeList,
excludeList,
infoList,
startDate,
firstTipText,
otherTipText,
secondTipText,
robotUrl,
} = reqRes.data.data;
let idx =
parseInt(
(new Date().getTime() - new Date(startDate).getTime()) / (86400000 * 7)
) % infoList.length;
let curDay = dateFormat(new Date()); //今天
let isWeekend = new Date().getDay() == 0 || new Date().getDay() == 6; //是否是周末
if (
includeList.includes(curDay) ||
(!excludeList.includes(curDay) && isWeekend)
) {
return;
}
//如果是节假日或者 不是调休日和周末 则不提醒
let curPerson = `<@${infoList[idx]["id"]}>`; //当前日报的提醒人
let content = firstTipText.replace(/@xxx/g, curPerson);
if (new Date().getDay() == 1 && otherTipText) {
let otherTip = otherTipText.replace(/@xxx/g, curPerson);
content = content + otherTip;
}
if (new Date().getHours() == 11) {
content = secondTipText.replace(/@xxx/g, curPerson);
}
const ROBOT_DATA = {
msgtype: "markdown",
markdown: {
content,
},
};
const result = await ctx.curl(robotUrl, {
method: "POST",
headers: {
"content-type": "application/json",
},
data: JSON.stringify(ROBOT_DATA),
});
ctx.app.cache = {
code: "0",
data: result,
msg: "提醒成功",
};
},
};