...
|
...
|
@@ -605,6 +605,26 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
dividendsEstimateDao = value
|
|
|
}
|
|
|
|
|
|
// 分红订单仓储初始化
|
|
|
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 confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
|
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
...
|
...
|
@@ -750,9 +770,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("新增的分红预算单", map[string]interface{}{
|
|
|
"dividendsEstimates": dividendsEstimates,
|
|
|
})
|
|
|
|
|
|
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -780,39 +802,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 完成第一阶段事务提交
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 分析成功和失败原因
|
|
|
successfullyCount := len(dividendsEstimatesSaved)
|
|
|
|
|
|
// 错误原因收集,返回第一个可能的原因
|
|
|
failedReason := make([]string, 0)
|
|
|
for _, v := range estimateFailedDividendsOrders {
|
|
|
failedReason = append(failedReason, v)
|
|
|
}
|
|
|
|
|
|
var failedReasonStr string
|
|
|
if len(failedReason) > 0 {
|
|
|
failedReasonStr = failedReason[0]
|
|
|
} else {
|
|
|
failedReasonStr = "无"
|
|
|
}
|
|
|
|
|
|
// 开启第二阶段事务:处理订单和产品状态
|
|
|
newTransactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := newTransactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = newTransactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 分离分红订单和退货单
|
|
|
dividendsOrderNumbers := make([]string, 0)
|
|
|
dividendsReturnedOrderNumbers := make([]string, 0)
|
...
|
...
|
@@ -826,15 +815,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 分红订单仓储初始化
|
|
|
var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": newTransactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsOrderRepository = value
|
|
|
}
|
|
|
log.Logger.Info("分红订单", map[string]interface{}{
|
|
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
|
|
})
|
|
|
|
|
|
log.Logger.Info("分红退货单", map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
|
})
|
|
|
|
|
|
// 查找分红订单
|
|
|
if len(dividendsOrderNumbers) > 0 {
|
...
|
...
|
@@ -869,16 +856,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 分红退货单仓储初始化
|
|
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": newTransactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsReturnedOrderRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找分红退货单
|
|
|
if len(dividendsReturnedOrderNumbers) > 0 {
|
|
|
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
...
|
...
|
@@ -912,11 +889,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 完成第二阶段事务提交
|
|
|
if err := newTransactionContext.CommitTransaction(); err != nil {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 统计成功的分红预算
|
|
|
successfullyCount := len(dividendsEstimatesSaved)
|
|
|
|
|
|
// 错误原因收集,返回第一个可能的原因
|
|
|
failedReason := make([]string, 0)
|
|
|
for _, v := range estimateFailedDividendsOrders {
|
|
|
failedReason = append(failedReason, v)
|
|
|
}
|
|
|
var failedReasonStr string
|
|
|
if len(failedReason) > 0 {
|
|
|
failedReasonStr = failedReason[0]
|
|
|
} else {
|
|
|
failedReasonStr = "无"
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
|
|
|
}, nil
|
...
|
...
|
@@ -1414,6 +1405,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
|
|
|
}
|
|
|
|
|
|
// TODO 校验当前时间和激励阶段是否匹配
|
|
|
|
|
|
log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
|
|
|
"stageUndertakerMap": stageUndertakerMap,
|
|
|
})
|
...
|
...
|
@@ -1440,7 +1433,6 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
if countDividendsEstimates > 0 { // 已有分红预算
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
|
if !dividendsEstimate.IsCanceled { // 分红预算单状态为非取消状态
|
|
|
//stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker)
|
|
|
for i, undertakerAppended := range stageUndertakerMap[dividendsEstimate.DividendsStage] {
|
|
|
if undertakerAppended.UndertakerId == undertaker.UndertakerId {
|
|
|
// 将删除点前后的元素连接起来
|
...
|
...
|
@@ -1450,14 +1442,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励
|
|
|
// for i, _ := range stageUndertakerMap {
|
|
|
// stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker)
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 去除没有承接人的阶段
|
|
|
|
|
|
log.Logger.Info("阶段承接人map", map[string]interface{}{
|
|
|
"stageUndertakerMap": stageUndertakerMap,
|
|
|
})
|
...
|
...
|
|