mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-74-76-78-278):adjustment project flock,recording,purchase getall
This commit is contained in:
+36
@@ -23,6 +23,7 @@ type ProductWarehouseRepository interface {
|
||||
GetLatestByCategoryCodeAndWarehouseID(ctx context.Context, categoryCode string, warehouseId uint, db *gorm.DB) (*entity.ProductWarehouse, error)
|
||||
GetByFlagAndWarehouseID(ctx context.Context, flagName string, warehouseId uint) ([]entity.ProductWarehouse, error)
|
||||
GetFirstProductByFlag(ctx context.Context, flagName string) (*entity.Product, error)
|
||||
ListProductIDsByFlagPrefixes(ctx context.Context, prefixes []string, visibleStatus *bool) ([]uint, error)
|
||||
ApplyFlagsFilter(db *gorm.DB, flags []string) *gorm.DB
|
||||
AdjustQuantities(ctx context.Context, deltas map[uint]float64, modifier func(*gorm.DB) *gorm.DB) error
|
||||
GetDetailByID(ctx context.Context, id uint) (*entity.ProductWarehouse, error)
|
||||
@@ -380,3 +381,38 @@ func (r *ProductWarehouseRepositoryImpl) GetFirstProductByFlag(ctx context.Conte
|
||||
}
|
||||
return &product, nil
|
||||
}
|
||||
|
||||
func (r *ProductWarehouseRepositoryImpl) ListProductIDsByFlagPrefixes(ctx context.Context, prefixes []string, visibleStatus *bool) ([]uint, error) {
|
||||
if len(prefixes) == 0 {
|
||||
return []uint{}, nil
|
||||
}
|
||||
|
||||
db := r.DB().WithContext(ctx).
|
||||
Model(&entity.Product{}).
|
||||
Distinct("products.id").
|
||||
Joins("JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = ?", entity.FlagableTypeProduct)
|
||||
|
||||
applied := false
|
||||
for _, prefix := range prefixes {
|
||||
if prefix == "" {
|
||||
continue
|
||||
}
|
||||
like := prefix + "%"
|
||||
if !applied {
|
||||
db = db.Where("flags.name LIKE ?", like)
|
||||
applied = true
|
||||
continue
|
||||
}
|
||||
db = db.Or("flags.name LIKE ?", like)
|
||||
}
|
||||
|
||||
if visibleStatus != nil {
|
||||
db = db.Where("products.is_visible = ?", *visibleStatus)
|
||||
}
|
||||
|
||||
var ids []uint
|
||||
if err := db.Pluck("products.id", &ids).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user