作者 陈志颖

feat:添加共创申请消息推送

... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationApplication/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"
... ... @@ -346,6 +347,32 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
cooperationApplicationRepository = value
}
// 同意共创申请消息推送领域服务初始化
var agreeContractApplicationService service.AgreeContractApplicationService
if value, err := factory.CreateAgreeContractApplicationService(map[string]interface{}{
//"transactionContext": transactionContext,
}); err != nil {
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
agreeContractApplicationService = value
_ = agreeContractApplicationService.Subscribe(&subscriber.MessageServiceSubscriber{
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 拒绝共创申请消息推送领域服务初始化
var rejectContractApplicationService service.RejectContractApplicationService
if value, err := factory.CreateRejectContractApplicationService(map[string]interface{}{
//"transactionContext": transactionContext,
}); err != nil {
return []interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rejectContractApplicationService = value
_ = rejectContractApplicationService.Subscribe(&subscriber.MessageServiceSubscriber{
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
// 共创申请ID类型转换
cooperationApplicationIds, err := utils.SliceAtoi(batchApprovalCooperationApplicationCommand.CooperationApplicationIds)
if err != nil {
... ... @@ -379,7 +406,7 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
for i, cooperationApplication := range cooperationApplications {
// 校验共创申请是否已经审核过
if cooperationApplication.CooperationApplicationStatus != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "申请已经审核过")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "申请已经审核过")
}
// 更新共创申请数据
cooperationApplications[i].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription
... ... @@ -392,13 +419,45 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
cooperationApplications[i].CooperationApplicationVerifyTime = time.Now()
cooperationApplications[i].IsCanceled = 1
}
cooperationApplicationsApproved, err := cooperationApplicationRepository.UpdateMany(cooperationApplications)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 推送消息
for _, cooperationApplicationApproved := range cooperationApplicationsApproved {
if cooperationApplicationApproved.CooperationApplicationStatus == 2 {
if err1 := agreeContractApplicationService.Agree(
cooperationApplicationApproved.CooperationProject.CooperationProjectId,
cooperationApplicationApproved.CooperationProject.CooperationProjectName,
cooperationApplicationApproved.CooperationProject.CooperationProjectNumber,
cooperationApplicationApproved.CooperationApplicationApplicant.UserId,
cooperationApplicationApproved.CooperationApplicationApplicant.UserBaseId,
cooperationApplicationApproved.CooperationProject.Org.OrgId,
cooperationApplicationApproved.CooperationProject.Company.CompanyId,
); err1 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err1.Error())
}
} else if cooperationApplicationApproved.CooperationApplicationStatus == 3 {
if err2 := rejectContractApplicationService.Reject(
cooperationApplicationApproved.CooperationProject.CooperationProjectId,
cooperationApplicationApproved.CooperationProject.CooperationProjectName,
cooperationApplicationApproved.CooperationProject.CooperationProjectNumber,
cooperationApplicationApproved.CooperationApplicationApplicant.UserId,
cooperationApplicationApproved.CooperationApplicationApplicant.UserBaseId,
cooperationApplicationApproved.CooperationProject.Org.OrgId,
cooperationApplicationApproved.CooperationProject.Company.CompanyId,
); err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
}
}
return map[string]interface{}{
"cooperationApplications": cooperationApplicationsApproved,
}, nil
... ...
... ... @@ -2,14 +2,13 @@ package subscriber
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/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type MessageServiceSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
//TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *MessageServiceSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
... ...
... ... @@ -53,3 +53,21 @@ func CreateCancelDividendsEstimateService(options map[string]interface{}) (*doma
}
return domain_service.NewCancelDividendsEstimateService(transactionContext)
}
func CreateAgreeContractApplicationService(options map[string]interface{}) (*domain_service.AgreeContractApplicationService, error) {
//var transactionContext *pgTransaction.TransactionContext
//if value, ok := options["transactionContext"]; ok {
// transactionContext = value.(*pgTransaction.TransactionContext)
//}
//return domain_service.NewAgreeContractApplicationService(transactionContext)
return domain_service.NewAgreeContractApplicationService(nil)
}
func CreateRejectContractApplicationService(options map[string]interface{}) (*domain_service.RejectContractApplicationService, error) {
//var transactionContext *pgTransaction.TransactionContext
//if value, ok := options["transactionContext"]; ok {
// transactionContext = value.(*pgTransaction.TransactionContext)
//}
//return domain_service.NewRejectContractApplicationService(transactionContext)
return domain_service.NewRejectContractApplicationService(nil)
}
... ...
... ... @@ -4,5 +4,5 @@ import coreDomain "github.com/linmadan/egglib-go/core/domain"
type AgreeContractApplicationService interface {
coreDomain.DomainEventPublisher
Agree() error
Agree(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error
}
... ...
... ... @@ -4,5 +4,5 @@ import coreDomain "github.com/linmadan/egglib-go/core/domain"
type RejectContractApplicationService interface {
coreDomain.DomainEventPublisher
Reject() error
Reject(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error
}
... ...
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"
)
type AgreeContractApplicationService struct {
coreDomain.BaseEventPublisher
//transactionContext *pgTransaction.TransactionContext
}
func (service *AgreeContractApplicationService) Agree(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error {
cooperationApplicationAgreedEvent := new(event.CooperationApplicationAgreed)
cooperationApplicationAgreedEvent.CreationProjectId = creationProjectId
cooperationApplicationAgreedEvent.CreationProjectName = creationProjectName
cooperationApplicationAgreedEvent.CreationProjectNumber = creationProjectNumber
cooperationApplicationAgreedEvent.UserId = userId
cooperationApplicationAgreedEvent.UserBaseId = userBaseId
cooperationApplicationAgreedEvent.OrgId = orgId
cooperationApplicationAgreedEvent.CompanyId = companyId
if err := service.Publish(cooperationApplicationAgreedEvent); err != nil {
return err
}
return nil
}
func NewAgreeContractApplicationService(transactionContext *pgTransaction.TransactionContext) (*AgreeContractApplicationService, error) {
//if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
//} else {
// return &AgreeContractApplicationService{
// transactionContext: transactionContext,
// }, nil
//}
return &AgreeContractApplicationService{}, nil
}
... ...
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"
)
type RejectContractApplicationService struct {
coreDomain.BaseEventPublisher
//transactionContext *pgTransaction.TransactionContext
}
func (service *RejectContractApplicationService) Reject(creationProjectId int64, creationProjectName string, creationProjectNumber string, userId int64, userBaseId int64, orgId int64, companyId int64) error {
cooperationApplicationRejectedEvent := new(event.CooperationApplicationRejected)
cooperationApplicationRejectedEvent.CreationProjectId = creationProjectId
cooperationApplicationRejectedEvent.CreationProjectName = creationProjectName
cooperationApplicationRejectedEvent.CreationProjectNumber = creationProjectNumber
cooperationApplicationRejectedEvent.UserId = userId
cooperationApplicationRejectedEvent.UserBaseId = userBaseId
cooperationApplicationRejectedEvent.OrgId = orgId
cooperationApplicationRejectedEvent.CompanyId = companyId
if err := service.Publish(cooperationApplicationRejectedEvent); err != nil {
return err
}
return nil
}
func NewRejectContractApplicationService(transactionContext *pgTransaction.TransactionContext) (*RejectContractApplicationService, error) {
//if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
//} else {
// return &RejectContractApplicationService{
// transactionContext: transactionContext,
// }, nil
//}
return &RejectContractApplicationService{}, nil
}
... ...