dividends_order.go 2.5 KB
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(dividendsOrderModel *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.DividendsReturnedOrderNumber,
			DividendsReturnedOrderNumber: good.DividendsOrderNumber,
			CooperationContractNumber:    good.CooperationContractNumber,
			OrderGoodDividendsStatus:     good.OrderGoodDividendsStatus,
			OrderGoodExpense:             good.OrderGoodExpense,
			CreatedAt:                    good.CreatedAt,
			DeletedAt:                    good.DeletedAt,
			UpdatedAt:                    good.UpdatedAt,
		})
	}
	dividendsOrderAmount, _ := decimal.NewFromFloatWithExponent(dividendsOrderModel.DividendsOrderAmount, -2).Float64()
	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
}