event_estimate_dividends_service.go 1.9 KB
package domain_service

import (
	coreDomain "github.com/linmadan/egglib-go/core/domain"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
)

type EstimateDividendsService struct {
	coreDomain.BaseEventPublisher
	//transactionContext *pgTransaction.TransactionContext
}

// 账期结算
func (service *EstimateDividendsService) Estimate(data []service.EstimateData) error {
	dividendsEstimatedEvent := new(event.DividendsEstimated)
	for _, dividendsEstimatedData := range data {
		dividendsEstimatedEvent.DividendsEstimatedData = append(dividendsEstimatedEvent.DividendsEstimatedData, event.DividendsEstimatedData{
			CreditAccountOrderNum:        dividendsEstimatedData.CreditAccountOrderNum,
			SettlementAmount:             dividendsEstimatedData.SettlementAmount,
			CreditAccountId:              dividendsEstimatedData.CreditAccountId,
			DividendsEstimateId:          dividendsEstimatedData.DividendsEstimateId,
			DividendsEstimateOrderNumber: dividendsEstimatedData.DividendsEstimateOrderNumber,
			UserId:                       dividendsEstimatedData.UserId,
			UserBaseId:                   dividendsEstimatedData.UserBaseId,
			OrgId:                        dividendsEstimatedData.OrgId,
			CompanyId:                    dividendsEstimatedData.CompanyId,
		})
	}
	if err := service.Publish(dividendsEstimatedEvent); err != nil {
		return err
	}
	return nil
}

func NewEstimateDividendsService(transactionContext *pgTransaction.TransactionContext) (*EstimateDividendsService, error) {
	//if transactionContext == nil {
	//	return nil, fmt.Errorf("transactionContext参数不能为nil")
	//} else {
	//	return &EstimateDividendsService{
	//		transactionContext: transactionContext,
	//	}, nil
	//}
	return &EstimateDividendsService{}, nil
}