fix: send_stats task_id type
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
// SendStats 发送统计表
|
||||
type SendStats struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
TaskID *uint `json:"task_id" gorm:"type:bigint unsigned;index:idx_task_type_day_status"`
|
||||
TaskID string `json:"task_id" gorm:"type:varchar(12);default:'';index:idx_task_type_day_status"`
|
||||
TaskType string `json:"task_type" gorm:"type:varchar(20);default:'task';index:idx_task_type_day_status;comment:'任务类型:task-发信任务,template-模板任务'"`
|
||||
Day string `json:"day" gorm:"type:varchar(10);index:idx_task_type_day_status;index:idx_day_status"`
|
||||
Status string `json:"status" gorm:"type:varchar(20);index:idx_task_type_day_status;index:idx_day_status"`
|
||||
@@ -121,7 +121,7 @@ func GetSendStatsData(days int) (SendStatsData, error) {
|
||||
}
|
||||
|
||||
// GetSendStatsByTask 获取指定任务的统计数据
|
||||
func GetSendStatsByTask(taskID uint, days int) (SendStatsData, error) {
|
||||
func GetSendStatsByTask(taskID string, days int) (SendStatsData, error) {
|
||||
var result SendStatsData
|
||||
statsTable := GetSchema(SendStats{})
|
||||
currDay := util.GetNowTimeStr()[:10]
|
||||
@@ -185,7 +185,7 @@ func GetSendStatsByTask(taskID uint, days int) (SendStatsData, error) {
|
||||
}
|
||||
|
||||
// IncrementSendStats 增加发送统计(用于实时更新统计数据)
|
||||
func IncrementSendStats(taskID *uint, taskType string, day string, status string, num int64) error {
|
||||
func IncrementSendStats(taskID string, taskType string, day string, status string, num int64) error {
|
||||
statsTable := GetSchema(SendStats{})
|
||||
|
||||
// 使用 ON DUPLICATE KEY UPDATE 或 UPSERT 逻辑
|
||||
|
||||
@@ -347,18 +347,6 @@ func (sm *SendMessageService) UpdateSendStats() {
|
||||
// 获取当前日期
|
||||
currentDay := sm.getCurrentDay()
|
||||
|
||||
// 解析任务ID(如果是数字ID)
|
||||
var taskID *uint
|
||||
if sm.TaskID != "" {
|
||||
// 尝试将字符串ID转换为uint(如果是数字ID)
|
||||
var id uint64
|
||||
_, err := fmt.Sscanf(sm.TaskID, "%d", &id)
|
||||
if err == nil {
|
||||
taskIDValue := uint(id)
|
||||
taskID = &taskIDValue
|
||||
}
|
||||
}
|
||||
|
||||
// 确定任务类型
|
||||
taskType := "task"
|
||||
if sm.SendMode == SendModeTemplate {
|
||||
@@ -374,7 +362,7 @@ func (sm *SendMessageService) UpdateSendStats() {
|
||||
}
|
||||
|
||||
// 更新统计:每次任务执行记录为1次
|
||||
err := models.IncrementSendStats(taskID, taskType, currentDay, status, 1)
|
||||
err := models.IncrementSendStats(sm.TaskID, taskType, currentDay, status, 1)
|
||||
if err != nil {
|
||||
logrus.Errorf("更新发送统计失败:%s", err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package statistic_service
|
||||
|
||||
import (
|
||||
"message-nest/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type StatisticService struct {
|
||||
@@ -44,11 +43,6 @@ func (sw *StatisticService) GetSendStatsByTask() (models.SendStatsData, error) {
|
||||
if days <= 0 {
|
||||
days = 30 // 默认30天
|
||||
}
|
||||
|
||||
taskID, err := strconv.ParseUint(sw.TaskID, 10, 64)
|
||||
if err != nil {
|
||||
return models.SendStatsData{}, err
|
||||
}
|
||||
|
||||
return models.GetSendStatsByTask(uint(taskID), days)
|
||||
|
||||
return models.GetSendStatsByTask(sw.TaskID, days)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user