作者 陈志颖

feat:增加确认业绩分红激励预算服务

@@ -3,10 +3,12 @@ package service @@ -3,10 +3,12 @@ package service
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 7 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/event/subscriber"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
@@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
368 defer func() { 370 defer func() {
369 _ = transactionContext.RollbackTransaction() 371 _ = transactionContext.RollbackTransaction()
370 }() 372 }()
371 - if err := transactionContext.CommitTransaction(); err != nil {  
372 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 373 + // 分红订单仓储初始化
  374 + var dividendsOrderRepository domain.DividendsOrderRepository
  375 + if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
  376 + "transactionContext": transactionContext,
  377 + }); err != nil {
  378 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  379 + } else {
  380 + dividendsOrderRepository = value
  381 + }
  382 +
  383 + // 分红退货单仓储初始化
  384 + var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
  385 + if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
  386 + "transactionContext": transactionContext,
  387 + }); err != nil {
  388 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  389 + } else {
  390 + dividendsReturnedOrderRepository = value
  391 + }
  392 +
  393 + // 订单产品仓储初始化
  394 + var orderGoodRepository domain.OrderGoodRepository
  395 + if value, err := factory.CreateOrderGoodRepository(map[string]interface{}{
  396 + "transactionContext": transactionContext,
  397 + }); err != nil {
  398 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  399 + } else {
  400 + orderGoodRepository = value
  401 + }
  402 +
  403 + // 分红预算仓储初始化
  404 + var dividendsEstimateRepository domain.DividendsEstimateRepository
  405 + if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
  406 + "transactionContext": transactionContext,
  407 + }); err != nil {
  408 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  409 + } else {
  410 + dividendsEstimateRepository = value
  411 + }
  412 +
  413 + // 初始化确认业绩激励分红预算领域服务
  414 + var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
  415 + if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
  416 + "transactionContext": transactionContext,
  417 + }); err != nil {
  418 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  419 + } else {
  420 + confirmDividendsIncentivesEstimateService = value
  421 + _ = confirmDividendsIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
  422 + TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
  423 + })
  424 + }
  425 +
  426 + // 获取订单产品
  427 + if _, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(confirmDividendsIncentivesEstimateCommand)); err != nil {
  428 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  429 + } else {
  430 + var dividendsEstimates []*domain.DividendsEstimate
  431 + for _, orderGood := range orderGoods {
  432 + dividendsEstimate := &domain.DividendsEstimate{}
  433 + if orderGood.DividendsOrderNumber != "" { // 查询分红订单
  434 + dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
  435 + if err != nil {
  436 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  437 + }
  438 + if dividendsOrder == nil {
  439 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
  440 + }
  441 + // 分红订单产品预算
  442 + if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
  443 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  444 + } else {
  445 + dividendsEstimate = &domain.DividendsEstimate{
  446 + DividendsEstimateId: 0,
  447 + DividendsAccountStatus: 0,
  448 + DividendsAmount: dividendsAmount,
  449 + DividendsEstimateOrderNumber: "",
  450 + DividendsEstimateTime: time.Time{},
  451 + DividendsParticipateType: 0,
  452 + DividendsType: 0,
  453 + OrderOrReturnedOrderNum: "",
  454 + CooperationContractNumber: "",
  455 + DividendsUser: nil,
  456 + DividendsStage: 0,
  457 + Org: nil,
  458 + Company: nil,
  459 + Operator: nil,
  460 + OperateTime: time.Time{},
  461 + IsCanceled: false,
  462 + CreatedAt: time.Time{},
  463 + DeletedAt: time.Time{},
  464 + UpdatedAt: time.Time{},
  465 + }
  466 + }
  467 + } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
  468 + dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
  469 + if err != nil {
  470 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  471 + }
  472 + if dividendsReturnedOrder == nil {
  473 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
  474 + }
  475 + // 分红退货单产品预算
  476 + if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
  477 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  478 + } else {
  479 + dividendsEstimate = &domain.DividendsEstimate{
  480 + DividendsEstimateId: 0,
  481 + DividendsAccountStatus: 0,
  482 + DividendsAmount: dividendsAmount,
  483 + DividendsEstimateOrderNumber: "",
  484 + DividendsEstimateTime: time.Time{},
  485 + DividendsParticipateType: 0,
  486 + DividendsType: 0,
  487 + OrderOrReturnedOrderNum: "",
  488 + CooperationContractNumber: "",
  489 + DividendsUser: nil,
  490 + DividendsStage: 0,
  491 + Org: nil,
  492 + Company: nil,
  493 + Operator: nil,
  494 + OperateTime: time.Time{},
  495 + IsCanceled: false,
  496 + CreatedAt: time.Time{},
  497 + DeletedAt: time.Time{},
  498 + UpdatedAt: time.Time{},
  499 + }
  500 + }
  501 + }
  502 + dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
  503 + }
  504 + var dividendsEstimatesSaved []*domain.DividendsEstimate
  505 + for _, dividendsEstimate := range dividendsEstimates {
  506 + if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
  507 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  508 + } else {
  509 + dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
  510 + }
  511 + }
  512 +
  513 + if err := transactionContext.CommitTransaction(); err != nil {
  514 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  515 + }
  516 + return dividendsEstimatesSaved, nil
373 } 517 }
374 - return nil, nil  
375 } 518 }
376 519
377 // ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算 520 // ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
@@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g @@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g
410 defer func() { 553 defer func() {
411 _ = transactionContext.RollbackTransaction() 554 _ = transactionContext.RollbackTransaction()
412 }() 555 }()
  556 + // 分红预算单仓储初始化
413 var dividendsEstimateRepository domain.DividendsEstimateRepository 557 var dividendsEstimateRepository domain.DividendsEstimateRepository
414 if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{ 558 if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
415 "transactionContext": transactionContext, 559 "transactionContext": transactionContext,
  1 +package subscriber
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 +)
  7 +
  8 +type DividendsEstimateSubscriber struct {
  9 + TransactionContext *pgTransaction.TransactionContext
  10 +}
  11 +
  12 +func (subscriber *DividendsEstimateSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
  13 + return nil
  14 +}
  15 +
  16 +func (subscriber *DividendsEstimateSubscriber) SubscribedToEventTypes() []string {
  17 + return []string{
  18 + //event.CONFERENCE_MESSAGE, // 日程预约消息通知
  19 + }
  20 +}
1 package service 1 package service
2 2
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  6 +)
  7 +
3 type ConfirmDividendsIncentivesEstimateService interface { 8 type ConfirmDividendsIncentivesEstimateService interface {
4 - Confirm() 9 + coreDomain.DomainEventPublisher
  10 + Confirm(orderGoods []*domain.OrderGood) (float64, error)
5 } 11 }
1 package service 1 package service
2 2
  3 +import coreDomain "github.com/linmadan/egglib-go/core/domain"
  4 +
3 type ConfirmMoneyIncentivesEstimateService interface { 5 type ConfirmMoneyIncentivesEstimateService interface {
  6 + coreDomain.DomainEventPublisher
4 Confirm() 7 Confirm()
5 } 8 }
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
7 ) 8 )
8 9
9 type ConfirmDividendsIncentivesEstimateService struct { 10 type ConfirmDividendsIncentivesEstimateService struct {
@@ -11,6 +12,11 @@ type ConfirmDividendsIncentivesEstimateService struct { @@ -11,6 +12,11 @@ type ConfirmDividendsIncentivesEstimateService struct {
11 transactionContext *pgTransaction.TransactionContext 12 transactionContext *pgTransaction.TransactionContext
12 } 13 }
13 14
  15 +// Confirm TODO 确认业绩分红预算
  16 +func (c ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) (float64, error) {
  17 + panic("implement me")
  18 +}
  19 +
14 func NewConfirmDividendsIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmDividendsIncentivesEstimateService, error) { 20 func NewConfirmDividendsIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmDividendsIncentivesEstimateService, error) {
15 if transactionContext == nil { 21 if transactionContext == nil {
16 return nil, fmt.Errorf("transactionContext参数不能为空") 22 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -175,6 +175,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{}) @@ -175,6 +175,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{})
175 return q, nil 175 return q, nil
176 }) 176 })
177 } 177 }
  178 + if orderGoodIds, ok := queryOptions["orderGoodIds"]; ok && len(orderGoodIds.([]int64)) > 0 {
  179 + query.Where("order_good_id IN (?)", pg.In(orderGoodIds))
  180 + }
178 offsetLimitFlag := true 181 offsetLimitFlag := true
179 if offsetLimit, ok := queryOptions["offsetLimit"]; ok { 182 if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
180 offsetLimitFlag = offsetLimit.(bool) 183 offsetLimitFlag = offsetLimit.(bool)