2024-03-21 21:08:45 +08:00
|
|
|
|
package task
|
|
|
|
|
|
|
|
|
|
import (
|
2024-03-29 02:32:26 +08:00
|
|
|
|
"go.uber.org/zap"
|
2024-03-21 21:08:45 +08:00
|
|
|
|
"miniapp/global"
|
|
|
|
|
"miniapp/model/app"
|
2024-03-29 02:32:26 +08:00
|
|
|
|
"miniapp/model/common"
|
2024-03-30 22:58:42 +08:00
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2024-03-21 21:08:45 +08:00
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CheckUserSurgeryDate 检查用户是否已到手术日期
|
|
|
|
|
func CheckUserSurgeryDate() {
|
2024-03-30 22:58:42 +08:00
|
|
|
|
go func() {
|
|
|
|
|
global.GVA_LOG.Info("检查用户是否已到手术日期")
|
|
|
|
|
var users []app.User
|
|
|
|
|
global.GVA_DB.Model(&app.User{}).Find(&users)
|
|
|
|
|
for _, user := range users {
|
|
|
|
|
parse, _ := time.Parse("2006-01-02", user.SurgeryTime)
|
2024-04-26 13:23:20 +08:00
|
|
|
|
if time.Now().Local().Sub(parse.Local()).Hours()/24 <= 1 {
|
2024-03-30 22:58:42 +08:00
|
|
|
|
global.GVA_DB.Model(&app.User{}).Where("id = ?", user.ID).Updates(app.User{IsSurgery: 1})
|
|
|
|
|
}
|
2024-03-21 21:08:45 +08:00
|
|
|
|
}
|
2024-03-30 22:58:42 +08:00
|
|
|
|
}()
|
2024-03-21 21:08:45 +08:00
|
|
|
|
}
|
2024-03-29 02:32:26 +08:00
|
|
|
|
|
|
|
|
|
func SendMsg2User() {
|
2024-03-30 22:58:42 +08:00
|
|
|
|
go func() {
|
2024-04-02 15:02:46 +08:00
|
|
|
|
global.GVA_LOG.Info("创建发送消息定时任务")
|
2024-03-30 22:58:42 +08:00
|
|
|
|
var ut []common.UserTodo
|
|
|
|
|
err := global.GVA_DB.Model(&common.UserTodo{}).Find(&ut).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
global.GVA_LOG.Error("定时任务获取用户Todo列表失败:", zap.Error(err))
|
|
|
|
|
}
|
2024-03-29 02:32:26 +08:00
|
|
|
|
|
2024-03-30 22:58:42 +08:00
|
|
|
|
for _, todo := range ut {
|
|
|
|
|
if strings.Compare(todo.RemindDay, time.Now().Format("2006-01-02")) == 0 {
|
|
|
|
|
// 创建定时任务
|
|
|
|
|
//WxTask := gocron.NewScheduler(time.Local)
|
|
|
|
|
//Send(todo.UserId, todo.Content, todo.RemindTime, todo.Frequency)
|
|
|
|
|
user := app.User{}
|
|
|
|
|
err := global.GVA_DB.Model(&app.User{}).Where("id = ?", todo.UserId).Find(&user).Error
|
2024-03-29 02:32:26 +08:00
|
|
|
|
if err != nil {
|
2024-03-30 22:58:42 +08:00
|
|
|
|
global.GVA_LOG.Error("定时任务获取用户信息失败:%s", zap.Error(err))
|
2024-03-29 02:32:26 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2024-03-30 22:58:42 +08:00
|
|
|
|
|
|
|
|
|
// 根据用户手术信息 发送提醒消息
|
2024-04-02 15:02:46 +08:00
|
|
|
|
if todo.RemindPeriod == user.IsSurgery && todo.IsFinish == 0 {
|
2024-03-30 22:58:42 +08:00
|
|
|
|
// 根据年月日时发送消息
|
2024-03-30 23:51:35 +08:00
|
|
|
|
job, err := WxTask.Every(1).Day().At(todo.RemindTime).LimitRunsTo(1).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
|
|
|
|
|
//job, err := WxTask.Cron("0 30 23 30 3 2024").Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
|
|
|
|
|
//job, err := WxTask.Every(1).Day().At("23:51").LimitRunsTo(1).Do(MiniappSendMsg, strconv.Itoa(int(user.ID)), strconv.Itoa(int(todo.ID)))
|
2024-03-31 03:45:17 +08:00
|
|
|
|
job.Tag("sendMsg")
|
2024-03-30 22:58:42 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
global.GVA_LOG.Error("定时任务创建失败:%s", zap.Error(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-03-31 06:00:19 +08:00
|
|
|
|
|
|
|
|
|
global.GVA_LOG.Info("定时发送消息任务创建成功", zap.Any("任务TodoId:", todo.ID))
|
2024-03-30 22:58:42 +08:00
|
|
|
|
}
|
2024-03-29 02:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-30 22:58:42 +08:00
|
|
|
|
}()
|
2024-03-29 02:32:26 +08:00
|
|
|
|
|
|
|
|
|
}
|