This commit is contained in:
2026-09-15 16:02:45 +08:00
parent 112c5f8e46
commit ade2453083
70 changed files with 1441 additions and 707 deletions
+42
View File
@@ -55,6 +55,48 @@ func (d *ClothesDao) ClothesUpdateByUUID(ctx context.Context, clothesUUID string
return nil
}
// ClothesUpdateByUUIDIfStatusIn 条件更新衣物:仅当当前图片处理状态在 statuses 内时才更新,返回是否更新成功。
// 用于「处理成功回填」这类必须与状态守卫绑定的写操作:恢复任务可能已把该记录置为失败并回退额度,
// 无条件写回会把状态改回成功,造成「额度已退但衣物成功」的不一致。
func (d *ClothesDao) ClothesUpdateByUUIDIfStatusIn(ctx context.Context, clothesUUID string, statuses []int8, updates map[string]any) (bool, error) {
ctx, span := global.Tracer.Start(ctx, "mysqldao.ClothesUpdateByUUIDIfStatusIn")
defer span.End()
res := d.db.WithContext(ctx).Model(&mysqlmodel.Clothes{}).
Where("clothes_uuid = ? AND image_process_status IN ?", clothesUUID, statuses).
Updates(updates)
if res.Error != nil {
span.RecordError(res.Error)
return false, res.Error
}
return res.RowsAffected > 0, nil
}
// ClothesReferencedCount 统计衣物被「穿搭明细 / 衣柜分享明细」引用的数量(删除前校验,>0 表示不可删除)。
// 删除被引用的衣物会留下悬挂引用,公开穿搭与分享会变成空壳(明细里查不到衣物,前端静默跳过)。
func (d *ClothesDao) ClothesReferencedCount(ctx context.Context, clothesUUID string) (int64, error) {
ctx, span := global.Tracer.Start(ctx, "mysqldao.ClothesReferencedCount")
defer span.End()
subQuery := "clothes_id IN (SELECT id FROM clothes WHERE clothes_uuid = ? AND deleted_at = 0)"
var total int64
if err := d.db.WithContext(ctx).Model(&mysqlmodel.OutfitItem{}).
Where(subQuery, clothesUUID).Count(&total).Error; err != nil {
span.RecordError(err)
return 0, err
}
if total > 0 {
return total, nil
}
if err := d.db.WithContext(ctx).Model(&mysqlmodel.ClosetShareItem{}).
Where(subQuery, clothesUUID).Count(&total).Error; err != nil {
span.RecordError(err)
return 0, err
}
return total, nil
}
// ClothesGetByUUID 按 UUID 查询衣物
func (d *ClothesDao) ClothesGetByUUID(ctx context.Context, clothesUUID string) (*mysqlmodel.Clothes, error) {
ctx, span := global.Tracer.Start(ctx, "mysqldao.ClothesGetByUUID")