egg_server/schedule/zhongNotify.ts

38 lines
1.1 KiB
TypeScript

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 { larkService, logger, appInfo } = await genContextManually()
logger.info("钟哥每日提醒开始")
try {
const status = getScheduleStatus()
await larkService.message.sendText2Chat(
appInfo.errChatId,
`钟哥今天是${status}哦~`,
"zhongNotify 每日提醒"
)
logger.info("钟哥每日提醒发送成功")
} catch (error: any) {
logger.error("钟哥每日提醒发送失败", { error: error.message })
const errorMessage = `sendZhongNotify error: ${error}`
await larkService.message.sendText2Chat(appInfo.errChatId, errorMessage)
}
}
export default sendZhongNotify