zhangqian
2024-08-01 fc3313955a083c9480e4ea74398f72f9ba6addcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}