Commit 51d981b3 by zhangquan

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

1 parent 126dd612
......@@ -3,22 +3,45 @@ const { dateFormat } = require("../utils/utils");
module.exports = {
schedule: {
cron: "0 2 9,11 * * ?",
type: "all", // 指定所有的 worker 都需要执行
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'}
{ dataType: "json" }
);
let {includeList, excludeList, infoList, startDate, firstTipText, secondTipText, robotUrl} = reqRes.data.data
let idx = parseInt((new Date().getTime() - new Date(startDate).getTime()) / (86400000 * 7)) % infoList.length;
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) content = content + "并创建日报菜单";
if (new Date().getHours() == 11) content = secondTipText.replace(/@xxx/g,curPerson);
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: {
......@@ -26,15 +49,13 @@ module.exports = {
},
};
const result = await ctx.curl(robotUrl,
{
method: "POST",
headers: {
"content-type": "application/json",
},
data: JSON.stringify(ROBOT_DATA),
}
);
const result = await ctx.curl(robotUrl, {
method: "POST",
headers: {
"content-type": "application/json",
},
data: JSON.stringify(ROBOT_DATA),
});
ctx.app.cache = {
code: "0",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!