作者 陈志颖

refactor:优化分红预算

... ... @@ -67,8 +67,25 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
}
// 查询共创项目
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
go func() {
for _, orderGood := range orderGoods {
log.Logger.Info("业绩分红预算产品", map[string]interface{}{
"orderGood": orderGood,
... ... @@ -93,9 +110,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
continue
}
var cooperationContract *domain.CooperationContract
// 获取合约
var cooperationContract *domain.CooperationContract
if _, ok := cooperationContractsMap[orderGood.CooperationContractNumber]; !ok {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
... ... @@ -115,6 +131,24 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
continue
} else {
cooperationContract = cooperationContractsMap[orderGood.CooperationContractNumber]
if cooperationContract.Status == 2 {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
})
continue
}
}
//cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
... ... @@ -140,73 +174,94 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// })
// continue
//}
if cooperationContract == nil {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
})
continue
} else {
log.Logger.Info("产品相关的合约", map[string]interface{}{
"cooperationContract": cooperationContract,
})
if cooperationContract.Status == 2 {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
})
continue
}
}
//if cooperationContract == nil {
// var orderNumber string
// if orderGood.DividendsOrderNumber != "" {
// orderNumber = orderGood.DividendsOrderNumber
// } else {
// orderNumber = orderGood.DividendsReturnedOrderNumber
// }
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
// DividendsUser: nil,
// DividendsParticipateType: 0,
// DividendsStage: 0,
// DividendsAmount: 0,
// OrderOrReturnedOrderNumber: orderNumber,
// IsSuccessfully: false,
// Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
// })
// continue
//} else {
// log.Logger.Info("产品相关的合约", map[string]interface{}{
// "cooperationContract": cooperationContract,
// })
// if cooperationContract.Status == 2 {
// var orderNumber string
// if orderGood.DividendsOrderNumber != "" {
// orderNumber = orderGood.DividendsOrderNumber
// } else {
// orderNumber = orderGood.DividendsReturnedOrderNumber
// }
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
// DividendsUser: nil,
// DividendsParticipateType: 0,
// DividendsStage: 0,
// DividendsAmount: 0,
// OrderOrReturnedOrderNumber: orderNumber,
// IsSuccessfully: false,
// Reason: "共创合约" + orderGood.CooperationContractNumber + "已暂停",
// })
// continue
// }
//}
// 获取共创项目
if cooperationContract.CooperationProjectNumber != "" {
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
"companyId": cooperationContract.Company.CompanyId,
"orgId": cooperationContract.Org.OrgId,
})
if err != nil {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "查询错误",
})
continue
}
if cooperationProject == nil {
//if cooperationContract.CooperationProjectNumber != "" {
// cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
// "cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
// "companyId": cooperationContract.Company.CompanyId,
// "orgId": cooperationContract.Org.OrgId,
// })
// if err != nil {
// var orderNumber string
// if orderGood.DividendsOrderNumber != "" {
// orderNumber = orderGood.DividendsOrderNumber
// } else {
// orderNumber = orderGood.DividendsReturnedOrderNumber
// }
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
// DividendsUser: nil,
// DividendsParticipateType: 0,
// DividendsStage: 0,
// DividendsAmount: 0,
// OrderOrReturnedOrderNumber: orderNumber,
// IsSuccessfully: false,
// Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "查询错误",
// })
// continue
// }
// if cooperationProject == nil {
// var orderNumber string
// if orderGood.DividendsOrderNumber != "" {
// orderNumber = orderGood.DividendsOrderNumber
// } else {
// orderNumber = orderGood.DividendsReturnedOrderNumber
// }
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
// DividendsUser: nil,
// DividendsParticipateType: 0,
// DividendsStage: 0,
// DividendsAmount: 0,
// OrderOrReturnedOrderNumber: orderNumber,
// IsSuccessfully: false,
// Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "已结束或不存在",
// })
// continue
// }
//}
// 判断共创项目是否存在
if _, ok := cooperationProjectsMap[cooperationContract.CooperationProjectNumber]; !ok {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
... ... @@ -224,7 +279,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
continue
}
}
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
// 获取分红订单
... ... @@ -497,6 +551,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
}
}
}()
return dividendsEstimateDetails, nil
}
... ...