mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
fix(BE): remove supplier price in master nonstock
This commit is contained in:
@@ -61,30 +61,20 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
|
||||
return err
|
||||
}
|
||||
|
||||
existingMap := make(map[uint]entity.NonstockSupplier, len(existing))
|
||||
existingMap := make(map[uint]struct{}, len(existing))
|
||||
for _, rel := range existing {
|
||||
existingMap[rel.SupplierId] = rel
|
||||
existingMap[rel.SupplierId] = struct{}{}
|
||||
}
|
||||
|
||||
incomingMap := make(map[uint]struct{}, len(suppliers))
|
||||
for _, rel := range suppliers {
|
||||
incomingMap[rel.SupplierId] = struct{}{}
|
||||
if existingRel, exists := existingMap[rel.SupplierId]; exists {
|
||||
if existingRel.Price != rel.Price {
|
||||
if err := db.WithContext(ctx).
|
||||
Model(&entity.NonstockSupplier{}).
|
||||
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierId).
|
||||
Update("price", rel.Price).
|
||||
Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, exists := existingMap[rel.SupplierId]; exists {
|
||||
continue
|
||||
}
|
||||
record := entity.NonstockSupplier{
|
||||
NonstockId: nonstockID,
|
||||
SupplierId: rel.SupplierId,
|
||||
Price: rel.Price,
|
||||
}
|
||||
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user