作者 陈志颖

refactor:优化分红预算

... ... @@ -640,6 +640,26 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
dividendsReturnedOrderRepository = value
}
// 共创合约仓储初始化
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
}
// 共创项目仓储初始化
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
// 初始化确认业绩激励分红预算领域服务
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
... ... @@ -653,6 +673,38 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
})
}
// 查询共创合约
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
if count > 0 {
for _, cooperationContractFound := range cooperationContractsFound {
cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
}
}
}
// 查询共创项目
cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
if count > 0 {
for _, cooperationProjectFound := range cooperationProjectsFound {
cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
}
}
}
// 统计成功预算的分红订单
estimateSuccessfullyDividendsOrders := make(map[string]string)
... ... @@ -684,7 +736,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
// 分红订单产品预算
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap, cooperationProjectsMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
... ... @@ -740,7 +792,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
// 分红退货单产品预算
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap, cooperationProjectsMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
... ...
... ... @@ -43,5 +43,5 @@ func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividend
type ConfirmDividendsIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64) ([]*DividendsEstimateDetail, error)
Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract, cooperationProjectsMap map[string]*domain.CooperationProject) ([]*DividendsEstimateDetail, error)
}
... ...
... ... @@ -17,25 +17,25 @@ type ConfirmDividendsIncentivesEstimateService struct {
}
// Confirm 确认业绩分红预算
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64) ([]*service.DividendsEstimateDetail, error) {
var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract, cooperationProjectsMap map[string]*domain.CooperationProject) ([]*service.DividendsEstimateDetail, error) {
//var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
//var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
// 共创合约仓储初始化
if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationContractRepository = repo
}
//if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// cooperationContractRepository = repo
//}
// 共创项目仓储初始化
if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationProjectRepository = repo
}
//if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// cooperationProjectRepository = repo
//}
// 分红订单仓储初始化
if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
... ... @@ -52,36 +52,36 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
// 查询共创合约
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": companyId,
"orgId": orgId,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
if count > 0 {
for _, cooperationContractFound := range cooperationContractsFound {
cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
}
}
}
//cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
//if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
// "companyId": companyId,
// "orgId": orgId,
// "offsetLimit": false,
//}); err != nil {
// return nil, err
//} else {
// if count > 0 {
// for _, cooperationContractFound := range cooperationContractsFound {
// cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
// }
// }
//}
// 查询共创项目
cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
"companyId": companyId,
"orgId": orgId,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
if count > 0 {
for _, cooperationProjectFound := range cooperationProjectsFound {
cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
}
}
}
//cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
//if count, cooperationProjectsFound, err := cooperationProjectRepository.Find(map[string]interface{}{
// "companyId": companyId,
// "orgId": orgId,
// "offsetLimit": false,
//}); err != nil {
// return nil, err
//} else {
// if count > 0 {
// for _, cooperationProjectFound := range cooperationProjectsFound {
// cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
// }
// }
//}
// 确认业绩分红预算
var dividendsEstimateDetails []*service.DividendsEstimateDetail
... ...