zhangqian
2024-03-19 16fd3076723f820aa079ff2863f7ab054ab4d0a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package service
 
import (
    "github.com/shopspring/decimal"
    "time"
    "wms/constvar"
    "wms/models"
)
 
type OutputInfo struct {
    LocationID   int
    WarehouseID  int
    Products     []*ProductInfo
    OperationID  int
    SourceNumber string
}
 
type ProductInfo struct {
    ProductID string
    Amount    decimal.Decimal
}
 
func AddOutputOperations(outputList []*OutputInfo) (err error) {
    //查找operationID
    warehouseIds := make([]int, 0)
    for _, output := range outputList {
        warehouseIds = append(warehouseIds, output.WarehouseID)
    }
    opTypes, err := models.NewOperationTypeSearch().SetWarehouseIds(warehouseIds).SetBaseOperationType(constvar.BaseOperationTypeOutgoing).FindNotTotal()
    if err != nil {
        return err
    }
    opTypeMap := make(map[int]*models.OperationType, len(opTypes))
    for _, opType := range opTypes {
        opTypeMap[opType.WarehouseId] = opType
    }
    operations := make([]*models.Operation, 0, len(outputList))
    for _, output := range outputList {
        details := make([]*models.OperationDetails, 0, len(output.Products))
        for _, product := range output.Products {
            details = append(details, &models.OperationDetails{
                OperationID:    0,
                ProductId:      product.ProductID,
                Amount:         product.Amount,
                FromLocationID: output.LocationID,
            })
        }
        if opTypeMap[output.WarehouseID] == nil {
            continue
        }
        operation := &models.Operation{
            Id:                0,
            Number:            "",
            SourceNumber:      output.SourceNumber,
            OperationTypeId:   opTypeMap[output.WarehouseID].Id,
            OperationTypeName: opTypeMap[output.WarehouseID].Name,
            Status:            constvar.OperationStatus_Ready,
            OperationDate:     time.Now().Format("2006-01-02 15:04:05"),
            ContacterID:       0,
            ContacterName:     "",
            CompanyID:         0,
            CompanyName:       "",
            Comment:           "crm发货申请",
            LogisticCompanyId: "",
            LogisticCompany:   models.LogisticCompany{},
            WaybillNumber:     "",
            Weight:            decimal.Decimal{},
            LogisticWeight:    decimal.Decimal{},
            Source:            "crm",
            Details:           details,
            BaseOperationType: constvar.BaseOperationTypeOutgoing,
            LocationID:        output.LocationID,
        }
        operations = append(operations, operation)
    }
 
    return models.NewOperationSearch().CreateBatch(operations)
}