作者 陈志颖

feat:金额激励领域服务开发

... ... @@ -10,10 +10,10 @@ import (
// ConfirmMoneyIncentivesEstimateCommand 确定金额激励分红预算
type ConfirmMoneyIncentivesEstimateCommand struct {
// 共创合约ID列表
CooperationContractIds []string `cname:"共创合约ID列表" json:"cooperationContractIds" valid:"Required"`
// 共创合约ID
CooperationContractId string `cname:"共创合约ID" json:"cooperationContractId" valid:"Required"`
// 分红阶段
DividendsIncentivesStage int64 `cname:"分红阶段" json:"dividendsIncentivesStage,string" valid:"Required"`
DividendsIncentivesStage int32 `cname:"分红阶段" json:"dividendsIncentivesStage,string" valid:"Required"`
// 承接人UID
UndertakerUids []string `cname:"承接人UID列表" json:"undertakerUids" valid:"Required"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -604,10 +604,51 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// 初始化确认金额激励分红预算领域服务
var confirmMoneyIncentivesEstimateService service.ConfirmMoneyIncentivesEstimateService
if value, err := factory.CreateConfirmMoneyIncentivesEstimateService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
confirmMoneyIncentivesEstimateService = value
_ = confirmMoneyIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
// 获取共创合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": cooperationContractId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationContractId, 10)))
}
// 共创合约预算
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, int64(confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage), undertakerUIDs); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsEstimateDetails, nil
}
return nil, nil
}
// GetDividendsEstimate 返回分红预算单详情
... ...
package service
import coreDomain "github.com/linmadan/egglib-go/core/domain"
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
type ConfirmMoneyIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm()
Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*DividendsEstimateDetail, error)
}
... ...
... ... @@ -4,6 +4,9 @@ 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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"time"
)
type ConfirmMoneyIncentivesEstimateService struct {
... ... @@ -11,6 +14,25 @@ type ConfirmMoneyIncentivesEstimateService struct {
transactionContext *pgTransaction.TransactionContext
}
func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
var dividendsEstimateDetails []*service.DividendsEstimateDetail
// 获取金额激励规则
var moneyIncentivesRuleMatched *domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range contract.MoneyIncentivesRules {
if moneyIncentivesRule.MoneyIncentivesStage == stage {
moneyIncentivesRuleMatched = moneyIncentivesRule
break
}
}
// 判断分红阶段时间
currentTime := time.Now()
if moneyIncentivesRuleMatched.MoneyIncentivesStageStart.After(currentTime) {
return nil, fmt.Errorf("还未到分红时间")
}
// TODO 判断承接人在当前阶段是否已经分红
return dividendsEstimateDetails, nil
}
func NewConfirmMoneyIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmMoneyIncentivesEstimateService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...