This commit is contained in:
duyu 2024-08-21 18:54:34 +08:00
parent f86624aa1b
commit e2bd32c96c
3 changed files with 14 additions and 11 deletions

View File

@ -379,8 +379,8 @@ func (m *ordersModel) GetRechargeTimeoutOrder(
var args []interface{}
sql += " and transfer_status = 2"
sql += " and (fail_reason = '' or fail_reason IS NULL)"
// sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)"
sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 MINUTE)"
sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)"
// sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 MINUTE)"
err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders)
return
}

View File

@ -137,10 +137,10 @@ func DingSend(title string, content string, retry bool) (err error) {
logger.Error(context.TODO(), "dingding", err)
return
}
// fmt.Println("响应状态码:", resp.StatusCode)
// fmt.Println("响应内容:", string(body))
// fmt.Println("参数:", data)
if resp.StatusCode != 200 {
logger.Error(context.TODO(), "dingding", "钉钉发送公告失败")
logger.Error(context.TODO(), "dingding", string(body))

View File

@ -8,15 +8,14 @@ import (
models "com.snow.auto_monitor/app/models/orders"
dingServ "com.snow.auto_monitor/app/services/dingding"
orderServ "com.snow.auto_monitor/app/services/orders"
"github.com/qit-team/snow-core/log/logger"
)
func DoRechargeTimeout() {
fmt.Println("开始执行周期任务DoTimeout")
fmt.Println("开始执行周期任务DoRechargeTimeout")
// 创建一个新的Ticker每分钟触发一次
ticker := time.NewTicker(60 * time.Second)
ticker := time.NewTicker(3 * time.Second)
defer ticker.Stop() // 在函数结束时停止Ticker
for range ticker.C {
res, err := models.GetInstance().GetRechargeTimeoutOrder(10)
@ -25,21 +24,25 @@ func DoRechargeTimeout() {
continue
}
for i := 0; i < len(res); i++ {
orderServ.Update(&models.Orders{
models.GetInstance().Update(&models.Orders{
Id: res[i].Id,
FailReason: "超时",
})
logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10))
}
if len(res) > 0 {
dingStr := fmt.Sprintf(
`
系统出现了超时7分钟的订单啦快去后台查看
- 异常单号: %s;
- 充值账号: %s;
`,
res[i].OutTradeNo,
res[i].RechargeAccount,
res[0].OutTradeNo,
res[0].RechargeAccount,
)
dingServ.DingSend("订单超时", dingStr, true)
logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10))
err = dingServ.DingSend("订单超时", dingStr, true)
fmt.Println(err)
}
}
}