duidui_fiber/internal/camp/dao/reset_history_dao.go
2026-03-27 10:34:03 +08:00

40 lines
1.0 KiB
Go

package dao
import (
"fmt"
"dd_fiber_api/pkg/database"
"github.com/didi/gendry/builder"
)
// ResetHistoryDAO 打卡营重置历史 DAO
type ResetHistoryDAO struct {
client *database.MySQLClient
}
// NewResetHistoryDAO 创建重置历史 DAO
func NewResetHistoryDAO(client *database.MySQLClient) *ResetHistoryDAO {
return &ResetHistoryDAO{client: client}
}
// Create 写入一条重置历史
func (d *ResetHistoryDAO) Create(id, userID, campID string, clearedProgressCount int, note string) error {
table := "camp_reset_history"
data := []map[string]any{{
"id": id,
"user_id": userID,
"camp_id": campID,
"cleared_progress_count": clearedProgressCount,
"note": nullString(note),
}}
cond, vals, err := builder.BuildInsert(table, data)
if err != nil {
return fmt.Errorf("构建插入语句失败: %v", err)
}
if _, err := d.client.DB.Exec(cond, vals...); err != nil {
return fmt.Errorf("写入重置历史失败: %v", err)
}
return nil
}