Commit 51d981b3 by zhangquan

修复bug,日报提醒两次的问题

1 parent 126dd612
...@@ -3,22 +3,45 @@ const { dateFormat } = require("../utils/utils"); ...@@ -3,22 +3,45 @@ const { dateFormat } = require("../utils/utils");
module.exports = { module.exports = {
schedule: { schedule: {
cron: "0 2 9,11 * * ?", cron: "0 2 9,11 * * ?",
type: "all", // 指定所有的 worker 都需要执行 type: "worker", // 指定所有的 worker 都需要执行
}, },
async task(ctx) { async task(ctx) {
const reqRes = await ctx.curl( const reqRes = await ctx.curl(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=test&env=llx", "https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=test&env=llx",
{dataType: 'json'} { dataType: "json" }
); );
let {includeList, excludeList, infoList, startDate, firstTipText, secondTipText, robotUrl} = reqRes.data.data let {
let idx = parseInt((new Date().getTime() - new Date(startDate).getTime()) / (86400000 * 7)) % infoList.length; 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 curDay = dateFormat(new Date()); //今天
let isWeekend = new Date().getDay() == 0 || new Date().getDay() == 6; //是否是周末 let isWeekend = new Date().getDay() == 0 || new Date().getDay() == 6; //是否是周末
if (includeList.includes(curDay) || (!excludeList.includes(curDay) && isWeekend)) return; //如果是节假日或者 不是调休日和周末 则不提醒 if (
let curPerson = `<@${infoList[idx]['id']}>` //当前日报的提醒人 includeList.includes(curDay) ||
let content = firstTipText.replace(/@xxx/g,curPerson); (!excludeList.includes(curDay) && isWeekend)
if(new Date().getDay() == 1) content = content + "并创建日报菜单"; ) {
if (new Date().getHours() == 11) content = secondTipText.replace(/@xxx/g,curPerson); 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 = { const ROBOT_DATA = {
msgtype: "markdown", msgtype: "markdown",
markdown: { markdown: {
...@@ -26,15 +49,13 @@ module.exports = { ...@@ -26,15 +49,13 @@ module.exports = {
}, },
}; };
const result = await ctx.curl(robotUrl, const result = await ctx.curl(robotUrl, {
{
method: "POST", method: "POST",
headers: { headers: {
"content-type": "application/json", "content-type": "application/json",
}, },
data: JSON.stringify(ROBOT_DATA), data: JSON.stringify(ROBOT_DATA),
} });
);
ctx.app.cache = { ctx.app.cache = {
code: "0", code: "0",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!