dividends_order.go 4.3 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(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
}