This commit is contained in:
zhengchiliu
2026-09-15 00:53:04 +08:00
parent 32a0b87e9e
commit 112c5f8e46
42 changed files with 1121 additions and 304 deletions
+18
View File
@@ -2,6 +2,7 @@ package mysqldao
import (
"context"
"time"
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/global"
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/mysqlmodel"
@@ -136,3 +137,20 @@ func (d *ClothesDao) ClothesListByUserID(ctx context.Context, userID int64, cate
}
return list, total, nil
}
// ClothesListStaleProcessing 查询超时未完成的图片任务。
func (d *ClothesDao) ClothesListStaleProcessing(ctx context.Context, before int64, limit int) ([]mysqlmodel.Clothes, error) {
var list []mysqlmodel.Clothes
err := d.db.WithContext(ctx).
Where("image_process_status IN ? AND updated_at < ?", []int8{1, 2, 3}, before).
Order("id ASC").Limit(limit).Find(&list).Error
return list, err
}
// ClothesClaimStaleProcessing 原子认领超时任务,避免多实例重复恢复。
func (d *ClothesDao) ClothesClaimStaleProcessing(ctx context.Context, clothesUUID string, before int64) (bool, error) {
res := d.db.WithContext(ctx).Model(&mysqlmodel.Clothes{}).
Where("clothes_uuid = ? AND image_process_status IN ? AND updated_at < ?", clothesUUID, []int8{1, 2, 3}, before).
Updates(map[string]any{"image_process_status": 3, "updated_at": time.Now().Unix()})
return res.RowsAffected > 0, res.Error
}