This commit is contained in:
2026-09-15 23:04:13 +08:00
parent ade2453083
commit 8c2ea84939
17 changed files with 749 additions and 161 deletions
+30
View File
@@ -187,6 +187,36 @@ func (d *OutfitDao) OutfitListCommunity(ctx context.Context, excludeUserID int64
return list, total, nil
}
// OutfitCleanupExpiredUnsavedAI 清理「超过保留期仍未保存」的 AI 穿搭(连带明细),返回清理条数。
// 状态字面量:source 2=AI 推荐;status 3=待用户保存。软删除后列表与详情立即不可见。
// 分批 + 限量:单次最多处理 limit 条,避免长事务持锁。
func (d *OutfitDao) OutfitCleanupExpiredUnsavedAI(ctx context.Context, createdBefore int64, limit int) (int64, error) {
ctx, span := global.Tracer.Start(ctx, "mysqldao.OutfitCleanupExpiredUnsavedAI")
defer span.End()
var ids []int64
if err := d.db.WithContext(ctx).Model(&mysqlmodel.Outfit{}).
Where("source = ? AND status = ? AND created_at < ?", int8(2), int8(3), createdBefore).
Order("id ASC").Limit(limit).Pluck("id", &ids).Error; err != nil {
span.RecordError(err)
return 0, err
}
if len(ids) == 0 {
return 0, nil
}
if err := d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if err := tx.Where("outfit_id IN ?", ids).Delete(&mysqlmodel.OutfitItem{}).Error; err != nil {
return err
}
return tx.Where("id IN ?", ids).Delete(&mysqlmodel.Outfit{}).Error
}); err != nil {
span.RecordError(err)
return 0, err
}
return int64(len(ids)), nil
}
// OutfitItemDao 穿搭明细数据访问
type OutfitItemDao struct {
db *gorm.DB