Compare commits
6 Commits
0d688ccae5
...
master
Author | SHA1 | Date | |
---|---|---|---|
e40e23f091 | |||
2728a32064 | |||
61c0aaa35a | |||
39191484e5 | |||
8aa2b355d9 | |||
4bb385b766 |
@@ -1,4 +1,4 @@
|
||||
FROM golang:alpine as builder
|
||||
FROM dockerproxy.com/library/golang:alpine as builder
|
||||
|
||||
WORKDIR /go/src/miniapp
|
||||
COPY . .
|
||||
@@ -10,7 +10,7 @@ RUN go env -w GO111MODULE=on \
|
||||
&& go mod tidy \
|
||||
&& go build -o server .
|
||||
|
||||
FROM alpine:latest
|
||||
FROM dockerproxy.com/library/alpine:latest
|
||||
WORKDIR /go/src/miniapp
|
||||
|
||||
COPY --from=0 /go/src/miniapp/server ./
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"miniapp/model/common/request"
|
||||
r "miniapp/model/common/response"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TodosApi struct{}
|
||||
@@ -56,3 +57,50 @@ func (t TodosApi) UpdateTodo(ctx *gin.Context) {
|
||||
}
|
||||
r.Ok(ctx)
|
||||
}
|
||||
|
||||
// GetTodayTodos 获取今日待办
|
||||
func (t TodosApi) GetTodayTodos(ctx *gin.Context) {
|
||||
var p request.GetUserNotes
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage("参数错误:"+err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
var ue app.User
|
||||
if api.GetUser(ctx, &ue, false, true); ctx.IsAborted() {
|
||||
return
|
||||
}
|
||||
|
||||
p.UserId = strconv.Itoa(int(ue.ID))
|
||||
list, err := todosService.GetTodayTodos(&p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取Todo列表失败:"+err.Error(), ctx)
|
||||
global.GVA_LOG.Error("获取Todo列表失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
todos := make([]common.UserTodo, 0)
|
||||
hour := time.Now().Hour()
|
||||
for i := range list {
|
||||
//将remind_time截取前两位 转为int
|
||||
rt, _ := strconv.Atoi(list[i].RemindTime[:2])
|
||||
rt2 := 24
|
||||
|
||||
if i+1 == len(list) {
|
||||
rt2, _ = strconv.Atoi(list[len(list)-1].RemindTime[:2])
|
||||
} else {
|
||||
rt2, _ = strconv.Atoi(list[i+1].RemindTime[:2])
|
||||
}
|
||||
if hour >= rt && hour <= rt2 {
|
||||
todos = append(todos, list[i])
|
||||
}
|
||||
}
|
||||
|
||||
//删除todos第一个元素
|
||||
if len(todos) > 0 {
|
||||
todos = todos[1:]
|
||||
}
|
||||
|
||||
r.OkWithData(todos, ctx)
|
||||
}
|
||||
|
@@ -55,8 +55,7 @@ func Routers() *gin.Engine {
|
||||
r.OkWithData(len(jobs), c)
|
||||
})
|
||||
PublicGroup.GET("/task/send", func(c *gin.Context) {
|
||||
tag, _ := task.WxTask.FindJobsByTag("sendMsg")
|
||||
r.OkWithData(tag[0].NextRun(), c)
|
||||
task.SendMsg2User()
|
||||
})
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package request
|
||||
|
||||
type GetUserNotes struct {
|
||||
UserId string `json:"userId" form:"userId" binding:"required"`
|
||||
IsFinish string `json:"isFinish" form:"isFinish" binding:"required"`
|
||||
IsFinish string `json:"isFinish" form:"isFinish"`
|
||||
}
|
||||
|
||||
type TodoTask struct {
|
||||
|
@@ -24,7 +24,7 @@ func (s *LoginRouter) InitUserRouter(Router *gin.RouterGroup) {
|
||||
userRouter.GET("", baseApi.GetUser)
|
||||
userRouter.GET("todo", todoApi.GetUserTodos)
|
||||
userRouter.PUT("todo", todoApi.UpdateTodo)
|
||||
|
||||
userRouter.GET("todo/today", todoApi.GetTodayTodos)
|
||||
userRouter.POST("msg", baseApi.SendMedicineRemind)
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"miniapp/global"
|
||||
"miniapp/model/common"
|
||||
"miniapp/model/common/request"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TodesService struct{}
|
||||
@@ -18,3 +19,12 @@ func (t TodesService) UpdateTodoById(c *common.UserTodo) error {
|
||||
|
||||
return global.GVA_DB.Table("t_user_todo").Where("id = ?", c.ID).Update("is_finish", c.IsFinish).Error
|
||||
}
|
||||
|
||||
// GetTodayTodos 获取今日待办
|
||||
func (t TodesService) GetTodayTodos(notes *request.GetUserNotes) (list []common.UserTodo, err error) {
|
||||
// 获取当前时间
|
||||
nowTime := time.Now().Format("2006-01-02")
|
||||
|
||||
err = global.GVA_DB.Where("user_id = ? and is_finish = 0 and remind_day = ?", notes.UserId, nowTime).Find(&list).Error
|
||||
return
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ func CheckUserSurgeryDate() {
|
||||
global.GVA_DB.Model(&app.User{}).Find(&users)
|
||||
for _, user := range users {
|
||||
parse, _ := time.Parse("2006-01-02", user.SurgeryTime)
|
||||
if time.Now().Sub(parse).Hours()/24 == 0 {
|
||||
if time.Now().Local().Sub(parse.Local()).Hours()/24 <= 1 {
|
||||
global.GVA_DB.Model(&app.User{}).Where("id = ?", user.ID).Updates(app.User{IsSurgery: 1})
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func CheckUserSurgeryDate() {
|
||||
|
||||
func SendMsg2User() {
|
||||
go func() {
|
||||
global.GVA_LOG.Info("执行发送消息定时任务")
|
||||
global.GVA_LOG.Info("创建发送消息定时任务")
|
||||
var ut []common.UserTodo
|
||||
err := global.GVA_DB.Model(&common.UserTodo{}).Find(&ut).Error
|
||||
if err != nil {
|
||||
@@ -47,7 +47,7 @@ func SendMsg2User() {
|
||||
}
|
||||
|
||||
// 根据用户手术信息 发送提醒消息
|
||||
if todo.RemindPeriod == 0 && todo.IsFinish == 0 {
|
||||
if todo.RemindPeriod == user.IsSurgery && todo.IsFinish == 0 {
|
||||
// 根据年月日时发送消息
|
||||
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)))
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/medivhzhan/weapp/v3"
|
||||
msg "github.com/medivhzhan/weapp/v3/subscribemessage"
|
||||
"go.uber.org/zap"
|
||||
@@ -67,6 +66,7 @@ func MiniappSendMsg(userId string, utId string) {
|
||||
err = global.GVA_DB.Model(&common.UserTodo{}).Where("id = ?", utId).First(&ut).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("定时任务获取用户Todo列表失败:", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
var msgDatas []msg.SendRequest
|
||||
@@ -74,17 +74,19 @@ func MiniappSendMsg(userId string, utId string) {
|
||||
//判断context是否超过20个字符
|
||||
if len(ut.Content)/3 >= 19 {
|
||||
text := strings.Split(ut.Content, "药品")
|
||||
text = text[1:]
|
||||
for i := 1; i < len(text); i++ {
|
||||
msgData := msg.SendRequest{
|
||||
ToUser: user.WechatOpenId,
|
||||
TemplateID: "PgxoZOOSDgBcmIGd_EVLDnYUmL3eu6NQTAZCsHQeuWY",
|
||||
TemplateID: "BKyIwkt7HHEQoQ9ByrHqnHaGO5jq8d-MCp9YYGK23TE",
|
||||
Page: "/pages/index/done",
|
||||
MiniprogramState: msg.MiniprogramStateTrial,
|
||||
Data: msg.SendData{
|
||||
"thing1": msg.SendValue{Value: text[i]},
|
||||
"time2": msg.SendValue{Value: ut.RemindTime},
|
||||
"short_thing17": msg.SendValue{Value: ut.Frequency},
|
||||
"time15": msg.SendValue{Value: time.Now().Format("2006-01-02 15:04:05")},
|
||||
"thing2": msg.SendValue{Value: text[i]},
|
||||
"time6": msg.SendValue{Value: ut.RemindTime},
|
||||
"thing8": msg.SendValue{Value: ut.Frequency},
|
||||
"thing3": msg.SendValue{Value: "用药详情请进入小程序待完成事项中查看"},
|
||||
//"time15": msg.SendValue{Value: time.Now().Format("2006-01-02 15:04:05")},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -93,7 +95,7 @@ func MiniappSendMsg(userId string, utId string) {
|
||||
} else {
|
||||
msgData := msg.SendRequest{
|
||||
ToUser: user.WechatOpenId,
|
||||
TemplateID: "PgxoZOOSDgBcmIGd_EVLDnYUmL3eu6NQTAZCsHQeuWY",
|
||||
TemplateID: "BKyIwkt7HHEQoQ9ByrHqnHaGO5jq8d-MCp9YYGK23TE",
|
||||
Page: "/pages/index/done",
|
||||
MiniprogramState: msg.MiniprogramStateTrial,
|
||||
Data: msg.SendData{
|
||||
@@ -111,7 +113,7 @@ func MiniappSendMsg(userId string, utId string) {
|
||||
|
||||
err = send.GetResponseError()
|
||||
if err != nil {
|
||||
fmt.Printf("微信返回错误: %#v", err)
|
||||
global.GVA_LOG.Error("发送失败: %#v", zap.Any("返回结果: %#v", send))
|
||||
return
|
||||
}
|
||||
global.GVA_LOG.Info("发送成功: %#v", zap.Any("返回结果: %#v", send))
|
||||
@@ -125,7 +127,7 @@ func MiniappSendMsg(userId string, utId string) {
|
||||
|
||||
err = send.GetResponseError()
|
||||
if err != nil {
|
||||
fmt.Printf("微信返回错误: %#v", err)
|
||||
global.GVA_LOG.Error("发送失败: %#v", zap.Any("返回结果: %#v", send))
|
||||
return
|
||||
}
|
||||
global.GVA_LOG.Info("发送成功: %#v", zap.Any("返回结果: %#v", send))
|
||||
|
Reference in New Issue
Block a user