feat: 添加定时任务,发送钟哥的排班通知;更新相关文件以支持新功能
This commit is contained in:
parent
4990ffb3a4
commit
dacdd812fd
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -40,7 +40,8 @@
|
|||||||
"Xname",
|
"Xname",
|
||||||
"Yingbo",
|
"Yingbo",
|
||||||
"Yoav",
|
"Yoav",
|
||||||
"zhaoyingbo"
|
"zhaoyingbo",
|
||||||
|
"Zhong"
|
||||||
],
|
],
|
||||||
// The path to the `bun` executable.
|
// The path to the `bun` executable.
|
||||||
"bun.runtime": "/home/node/.bun/bin/bun",
|
"bun.runtime": "/home/node/.bun/bin/bun",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import schedule from "node-schedule"
|
import schedule from "node-schedule"
|
||||||
|
|
||||||
import report from "../controller/groupAgent/report"
|
import report from "../controller/groupAgent/report"
|
||||||
|
import sendZhongNotify from "./zhongNotify"
|
||||||
|
|
||||||
export const initSchedule = async () => {
|
export const initSchedule = async () => {
|
||||||
// 定时任务,每周一到周四晚上 8 点 0 分 0 秒执行
|
// 定时任务,每周一到周四晚上 8 点 0 分 0 秒执行
|
||||||
@ -8,4 +9,7 @@ export const initSchedule = async () => {
|
|||||||
|
|
||||||
// 定时任务,每周五晚上 8 点 0 分 0 秒执行
|
// 定时任务,每周五晚上 8 点 0 分 0 秒执行
|
||||||
schedule.scheduleJob("0 20 * * 5", () => report.genAllReport("weekly"))
|
schedule.scheduleJob("0 20 * * 5", () => report.genAllReport("weekly"))
|
||||||
|
|
||||||
|
// 定时任务,每天早上 6 点 0 分 0 秒执行
|
||||||
|
schedule.scheduleJob("0 6 * * *", sendZhongNotify)
|
||||||
}
|
}
|
||||||
|
28
schedule/zhongNotify.ts
Normal file
28
schedule/zhongNotify.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { genContextManually } from "../utils/genContext"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前的排班文本
|
||||||
|
* @returns {string} 排班文本
|
||||||
|
*/
|
||||||
|
const getScheduleStatus = () => {
|
||||||
|
const anchorTime = new Date("2023/03/20")
|
||||||
|
const now = new Date()
|
||||||
|
const diffTime = Math.floor(((now as any) - (anchorTime as any)) / 86400000)
|
||||||
|
const scheduleMap = ["休班", "白班", "白班", "夜班", "夜班", "休班"]
|
||||||
|
return scheduleMap[diffTime % 6]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送钟哥的排班通知
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const sendZhongNotify = async () => {
|
||||||
|
const ctx = await genContextManually()
|
||||||
|
const status = getScheduleStatus()
|
||||||
|
await ctx.larkService.message.sendText2Chat(
|
||||||
|
ctx.appInfo.errChatId,
|
||||||
|
`钟哥今天是${status}哦~`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default sendZhongNotify
|
Loading…
x
Reference in New Issue
Block a user