作者 陈志颖

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

... ... @@ -3,10 +3,12 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/event/subscriber"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
... ... @@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsReturnedOrderRepository = value
}
// 订单产品仓储初始化
var orderGoodRepository domain.OrderGoodRepository
if value, err := factory.CreateOrderGoodRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderGoodRepository = value
}
// 分红预算仓储初始化
var dividendsEstimateRepository domain.DividendsEstimateRepository
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimateRepository = value
}
// 初始化确认业绩激励分红预算领域服务
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
confirmDividendsIncentivesEstimateService = value
_ = confirmDividendsIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 获取订单产品
if _, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(confirmDividendsIncentivesEstimateCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var dividendsEstimates []*domain.DividendsEstimate
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
}
// 分红订单产品预算
if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: 0,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: "",
DividendsEstimateTime: time.Time{},
DividendsParticipateType: 0,
DividendsType: 0,
OrderOrReturnedOrderNum: "",
CooperationContractNumber: "",
DividendsUser: nil,
DividendsStage: 0,
Org: nil,
Company: nil,
Operator: nil,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Time{},
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
}
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
}
// 分红退货单产品预算
if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: 0,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: "",
DividendsEstimateTime: time.Time{},
DividendsParticipateType: 0,
DividendsType: 0,
OrderOrReturnedOrderNum: "",
CooperationContractNumber: "",
DividendsUser: nil,
DividendsStage: 0,
Org: nil,
Company: nil,
Operator: nil,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Time{},
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
}
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsEstimatesSaved, nil
}
return nil, nil
}
// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
... ... @@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 分红预算单仓储初始化
var dividendsEstimateRepository domain.DividendsEstimateRepository
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ...
package subscriber
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type DividendsEstimateSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *DividendsEstimateSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
return nil
}
func (subscriber *DividendsEstimateSubscriber) SubscribedToEventTypes() []string {
return []string{
//event.CONFERENCE_MESSAGE, // 日程预约消息通知
}
}
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
type ConfirmDividendsIncentivesEstimateService interface {
Confirm()
coreDomain.DomainEventPublisher
Confirm(orderGoods []*domain.OrderGood) (float64, error)
}
... ...
package service
import coreDomain "github.com/linmadan/egglib-go/core/domain"
type ConfirmMoneyIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm()
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
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"
)
type ConfirmDividendsIncentivesEstimateService struct {
... ... @@ -11,6 +12,11 @@ type ConfirmDividendsIncentivesEstimateService struct {
transactionContext *pgTransaction.TransactionContext
}
// Confirm TODO 确认业绩分红预算
func (c ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) (float64, error) {
panic("implement me")
}
func NewConfirmDividendsIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmDividendsIncentivesEstimateService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -175,6 +175,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{})
return q, nil
})
}
if orderGoodIds, ok := queryOptions["orderGoodIds"]; ok && len(orderGoodIds.([]int64)) > 0 {
query.Where("order_good_id IN (?)", pg.In(orderGoodIds))
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
offsetLimitFlag = offsetLimit.(bool)
... ...