From dacdd812fdd7b64a60e1d45c464efe7d4efd7794 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Wed, 22 Jan 2025 15:34:42 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=EF=BC=8C=E5=8F=91=E9=80=81=E9=92=9F=E5=93=A5?= =?UTF-8?q?=E7=9A=84=E6=8E=92=E7=8F=AD=E9=80=9A=E7=9F=A5=EF=BC=9B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9B=B8=E5=85=B3=E6=96=87=E4=BB=B6=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 ++- schedule/index.ts | 4 ++++ schedule/zhongNotify.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 schedule/zhongNotify.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 0bb386f..82ea997 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -40,7 +40,8 @@ "Xname", "Yingbo", "Yoav", - "zhaoyingbo" + "zhaoyingbo", + "Zhong" ], // The path to the `bun` executable. "bun.runtime": "/home/node/.bun/bin/bun", diff --git a/schedule/index.ts b/schedule/index.ts index 8a4448a..5e4dd47 100644 --- a/schedule/index.ts +++ b/schedule/index.ts @@ -1,6 +1,7 @@ import schedule from "node-schedule" import report from "../controller/groupAgent/report" +import sendZhongNotify from "./zhongNotify" export const initSchedule = async () => { // 定时任务,每周一到周四晚上 8 点 0 分 0 秒执行 @@ -8,4 +9,7 @@ export const initSchedule = async () => { // 定时任务,每周五晚上 8 点 0 分 0 秒执行 schedule.scheduleJob("0 20 * * 5", () => report.genAllReport("weekly")) + + // 定时任务,每天早上 6 点 0 分 0 秒执行 + schedule.scheduleJob("0 6 * * *", sendZhongNotify) } diff --git a/schedule/zhongNotify.ts b/schedule/zhongNotify.ts new file mode 100644 index 0000000..b58e4b8 --- /dev/null +++ b/schedule/zhongNotify.ts @@ -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} + */ +const sendZhongNotify = async () => { + const ctx = await genContextManually() + const status = getScheduleStatus() + await ctx.larkService.message.sendText2Chat( + ctx.appInfo.errChatId, + `钟哥今天是${status}哦~` + ) +} + +export default sendZhongNotify