tyc-server/app/user/cmd/api/internal/queue/cleanQueryData.go
2025-04-09 15:58:06 +08:00

51 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package queue
import (
"context"
"fmt"
"tyc-server/app/user/cmd/api/internal/svc"
"github.com/hibiken/asynq"
)
const TASKTIME = "0 2 * * *"
type CleanQueryDataHandler struct {
svcCtx *svc.ServiceContext
}
func NewCleanQueryDataHandler(svcCtx *svc.ServiceContext) *CleanQueryDataHandler {
return &CleanQueryDataHandler{
svcCtx: svcCtx,
}
}
func (l *CleanQueryDataHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
fmt.Println(TASKTIME)
//// 计算 30 天前的时间
//threshold := time.Now().AddDate(0, 0, -30)
//
//// 1. 构造查询条件,查找创建时间小于 threshold 的记录
//// 假设表中“创建时间”字段为 create_time且字段类型对应数据库里实际的列名
//rowBuilder := l.svcCtx.QueryModel.SelectBuilder().
// Where(squirrel.Lt{"create_time": threshold})
//
//// 2. 调用 FindAll 获取所有符合条件的记录
//// orderBy 这里可传空字符串或你想要的排序字段
//records, err := l.svcCtx.QueryModel.FindAll(ctx, rowBuilder, "")
//if err != nil {
// return err
//}
//
//// 3. 遍历记录,逐条删除
//// 假设你的 Delete 方法签名是Delete(ctx context.Context, id int64) error
//// 并且 records[i] 中有一个字段 ID 用于表示主键
//for _, record := range records {
// if err := l.svcCtx.QueryModel.Delete(ctx, record.Id); err != nil {
// return err
// }
//}
return nil
}