Commit 3ca33305 by zhangquan

日志提醒

1 parent aeff93d1
......@@ -2,7 +2,7 @@
const Controller = require("egg").Controller;
const { SENTRY_HOOKS } = require("../utils/const");
const { fmtDateTime, genProjectOwners } = require("../utils/utils");
const { dateFormat, genProjectOwners } = require("../utils/utils");
class SentryController extends Controller {
/**
......@@ -13,10 +13,7 @@ class SentryController extends Controller {
params,
request: { body },
} = this.ctx;
console.log(params);
console.log(body);
let bodyJson = JSON.stringify(body);
let paramsJson = JSON.stringify(params);
let data = body && body.data && body.data.issue ? body.data.issue : {};
const ROBOT_DATA = {
msgtype: "markdown",
......@@ -26,18 +23,14 @@ class SentryController extends Controller {
}</font>发生错误:
> 错误原因: <font color=\"info\">${data.title}</font>
> 错误目录: <font color=\"info\">${data.culprit}</font>
> 错误时间: <font color=\"info\">${fmtDateTime()}</font>
> 错误级别: <font color=\"info\">${data.level}</font>
> 错误链接: [查看日志](${data.url || data.permalink})
> 错误body: <font color=\"info\">${bodyJson}</font>
\n
请以下同事注意:${genProjectOwners(SENTRY_HOOKS.SCRM.owners)}`,
> 错误时间: <font color=\"info\">${dateFormat(new Date(), 'YYYY-MM-DD mm:ss')}</font>
> 查看详情: [http://sentry.glsx.com.cn/auth/login/sentry/](http://sentry.glsx.com.cn/auth/login/sentry/)
> 错误body: <font color=\"info\">${bodyJson}</font>`,
},
};
const result = await this.ctx.curl(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f2ba84b-1b7f-4556-8508-e6c605e2671c",
{
// url: SENTRY_HOOKS[params.name].sentry_hook,
method: "POST",
headers: {
"content-type": "application/json",
......@@ -52,6 +45,14 @@ class SentryController extends Controller {
msg: "提醒成功",
};
}
async test(){
const result = await this.ctx.curl(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=file-uploader"
);
console.log(result)
}
}
module.exports = SentryController;
const Subscription = require('egg').Subscription;
const { dateFormat } = require("../utils/utils");
module.exports = {
schedule: {
cron: '0 0 9 * * *',
type: 'all', // 指定所有的 worker 都需要执行
},
async task(ctx) {
let plist=['胡悦','陈婉清','匡雅琴','李伟康','陆宇天','王琦琳','王志慧','吴文祥','徐忆琳','杨北旺','杨明','张杰','张立顺','张权','张晓玮']
let idx = parseInt((new Date().getTime() - new Date('2022-10-24').getTime()) / (86400000*7))
let includeList = ['2022-12-31', '2023-01-01', '2023-01-02',
'2023-01-21','2023-01-22', '2023-01-23', '2023-01-24', '2023-01-25', '2023-01-26', '2023-01-27',
'2023-04-05',
'2023-05-01','2023-05-02','2023-05-03','2023-05-04','2023-05-05',
'2023-06-23','2023-06-24','2023-06-25',
'2023-06-23','2023-06-24','2023-06-25',
'2023-09-29','2023-09-30','2023-10-01','2023-10-02','2023-10-03','2023-10-04','2023-10-05','2023-10-06'
]
let excludeList = ['2023-01-28','2023-01-29','2023-04-29','2023-04-30','2023-06-25','2023-10-07','2023-10-08']
let curDay = dateFormat(new Date())
let isWeekend = new Date().getDay() == 0 || new Date().getDay() == 6
if(includeList.includes(curDay) || (!excludeList.includes(curDay) && isWeekend)) return;
const ROBOT_DATA = {
msgtype: "markdown",
markdown: {
content: `请各位填写日报,[https://www.kdocs.cn/l/crp55HhT7R9b](https://www.kdocs.cn/l/crp55HhT7R9b), 麻烦${plist[idx]}同学提交日报${new Date().getDay()==1 ? ',并创建日报菜单':''}`,
},
};
const result = await ctx.curl(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5d90c43a-87e0-454c-8cc6-39db43cf9e2c",
{
method: "POST",
headers: {
"content-type": "application/json",
},
data: JSON.stringify(ROBOT_DATA),
}
);
ctx.app.cache = {
code: "0",
data: result,
msg: "提醒成功",
};
},
};
\ No newline at end of file
/**
* 对当前时间进行格式化
*/
const fmtDateTime = () => {
let date = new Date();
const dateFormat = function(dateTime, format = 'YYYY-MM-DD') {
const date = new Date(dateTime)
const config = {
YYYY: date.getFullYear(),
MM: appendZero(date.getMonth() + 1), //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
DD: appendZero(date.getDate()),
HH: appendZero(date.getHours()),
mm: appendZero(date.getMinutes()),
ss: appendZero(date.getSeconds())
}
for (const key in config) {
format = format.replace(key, config[key])
}
return format
}
let year = date.getFullYear();
let month = date.getMonth() + 1;
let hour = date.getHours();
let min = date.getMinutes();
month = month < 10 ? `0${month}` : month;
hour = hour < 10 ? `0${hour}` : hour;
min = min < 10 ? `0${min}` : min;
return `${year}-${month}-${date.getDate()} ${hour}:${min}`;
};
function appendZero(int) {
if (int < 10) {
return '0' + `${int}`
} else {
return int
}
}
/**
* 生成项目负责人
......@@ -24,6 +34,6 @@ const genProjectOwners = (owners) => {
};
module.exports = {
fmtDateTime,
dateFormat,
genProjectOwners,
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!