dividends_order.go
4.3 KB
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
79
80
81
82
83
84
85
86
87
package transform
import (
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModels []*models.DividendsOrder, goods []*models.OrderGood) ([]*domain.DividendsOrder, error) {
var orderGoods []*domain.OrderGood
for _, good := range goods {
orderGoodAmount, _ := decimal.NewFromFloatWithExponent(good.OrderGoodAmount, -2).Float64()
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: good.OrderGoodId,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsOrderNumber,
DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodDividendsStatus: good.OrderGoodDividendsStatus,
OrderGoodExpense: good.OrderGoodExpense,
OrgId: good.OrgId,
CompanyId: good.CompanyId,
CreatedAt: good.CreatedAt,
DeletedAt: good.DeletedAt,
UpdatedAt: good.UpdatedAt,
})
}
var dividendsOrders []*domain.DividendsOrder
for _, dividendsOrderModel := range dividendsOrderModels {
dividendsOrderAmount, _ := decimal.NewFromFloatWithExponent(dividendsOrderModel.DividendsOrderAmount, -2).Float64()
dividendsOrder := &domain.DividendsOrder{
DividendsOrderId: dividendsOrderModel.DividendsOrderId,
DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum,
DividendsOrderAmount: dividendsOrderAmount,
OrderTime: dividendsOrderModel.OrderTime,
DividendTime: dividendsOrderModel.DividendTime,
DividendStatus: dividendsOrderModel.DividendStatus,
Region: dividendsOrderModel.Region,
CustomerName: dividendsOrderModel.CustomerName,
Org: dividendsOrderModel.Org,
Company: dividendsOrderModel.Company,
CreatedAt: dividendsOrderModel.CreatedAt,
DeletedAt: dividendsOrderModel.DeletedAt,
UpdatedAt: dividendsOrderModel.UpdatedAt,
OperateTime: dividendsOrderModel.OperateTime,
Operator: dividendsOrderModel.Operator,
Remarks: dividendsOrderModel.Remarks,
}
var newOrderGoods []*domain.OrderGood
for _, orderGood := range orderGoods {
if orderGood.CompanyId == dividendsOrder.Company.CompanyId && orderGood.DividendsOrderNumber == dividendsOrder.DividendsOrderNumber {
newOrderGoods = append(newOrderGoods, orderGood)
}
}
dividendsOrder.Goods = newOrderGoods
dividendsOrders = append(dividendsOrders, dividendsOrder)
}
return dividendsOrders, nil
//return &domain.DividendsOrder{
// DividendsOrderId: dividendsOrderModel.DividendsOrderId,
// DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
// DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum,
// DividendsOrderAmount: dividendsOrderAmount,
// OrderTime: dividendsOrderModel.OrderTime,
// DividendTime: dividendsOrderModel.DividendTime,
// DividendStatus: dividendsOrderModel.DividendStatus,
// Region: dividendsOrderModel.Region,
// CustomerName: dividendsOrderModel.CustomerName,
// Org: dividendsOrderModel.Org,
// Goods: orderGoods,
// Company: dividendsOrderModel.Company,
// CreatedAt: dividendsOrderModel.CreatedAt,
// DeletedAt: dividendsOrderModel.DeletedAt,
// UpdatedAt: dividendsOrderModel.UpdatedAt,
// OperateTime: dividendsOrderModel.OperateTime,
// Operator: dividendsOrderModel.Operator,
// Remarks: dividendsOrderModel.Remarks,
//}, nil
}