package service
|
|
import (
|
"github.com/shopspring/decimal"
|
"wms/models"
|
)
|
|
func GetLocationAmounts(productIds []string, locationIds []int) (locationAmountMap map[string]map[int]decimal.Decimal, err error) {
|
locationAmounts, err := models.NewLocationProductAmountSearch().
|
SetProductIds(productIds).SetLocationIds(locationIds).
|
SetFields("product_id, location_id, amount").
|
Find()
|
if err != nil {
|
return nil, err
|
}
|
locationAmountMap = make(map[string]map[int]decimal.Decimal)
|
for _, locationAmount := range locationAmounts {
|
if locationAmountMap[locationAmount.ProductId] == nil {
|
locationAmountMap[locationAmount.ProductId] = make(map[int]decimal.Decimal)
|
}
|
locationAmountMap[locationAmount.ProductId][locationAmount.LocationId] = locationAmount.Amount
|
}
|
return
|
}
|