...
|
...
|
@@ -336,6 +336,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("查找合约数据", map[string]interface{}{
|
|
|
"cooperationContractsMap": cooperationContractsMap,
|
|
|
})
|
|
|
|
|
|
// 分红订单DAO初始化
|
|
|
var dividendsOrderDao *dao.DividendsOrderDao
|
|
|
if value, err := factory.CreateDividendsOrderDao(map[string]interface{}{
|
...
|
...
|
@@ -609,6 +613,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
DividendsOrderNumber: "",
|
|
|
CooperationContractNumber: dividendsOrder.CooperationContractNumber,
|
|
|
OrderGoodExpense: expense,
|
|
|
LineNumber: i,
|
|
|
},
|
|
|
},
|
|
|
CompanyId: importDividendsOrderCommand.CompanyId,
|
...
|
...
|
@@ -660,6 +665,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
DividendsOrderNumber: "",
|
|
|
CooperationContractNumber: dividendsOrder.CooperationContractNumber,
|
|
|
OrderGoodExpense: expense,
|
|
|
LineNumber: i, // 记录订单产品行号
|
|
|
})
|
|
|
|
|
|
// 记录聚合行号
|
...
|
...
|
@@ -667,6 +673,10 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("聚合订单", map[string]interface{}{
|
|
|
"dividendsOrderCommands": dividendsOrderCommands,
|
|
|
})
|
|
|
|
|
|
// 聚合订单错误返回
|
|
|
if len(aggregateErrorList) > 0 {
|
|
|
return map[string]interface{}{
|
...
|
...
|
@@ -698,7 +708,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.BUSINESS_ERROR, err.Error()), // 错误信息
|
|
|
LineNumbers: cmd.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
GoodLine: map[int]string{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
...
|
...
|
@@ -758,7 +768,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单号生成错误:%s", err)),
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
GoodLine: map[int]string{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
...
|
...
|
@@ -770,18 +780,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
GoodLine: map[int]string{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
orderGoodErrMap := make(map[int]interface{}, 0)
|
|
|
for i, orderGood := range dividendsOrder.OrderGoods {
|
|
|
orderGoodErrMap := make(map[int]string, 0)
|
|
|
for j, orderGood := range dividendsOrder.OrderGoods {
|
|
|
// 校验共创合约是否合法
|
|
|
contractNumberExist := false
|
|
|
for _, cooperationContract := range cooperationContracts {
|
...
|
...
|
@@ -791,18 +802,24 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
}
|
|
|
if !contractNumberExist {
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "订单产品关联的共创合约不存在"
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 计算产品金额
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64()
|
|
|
|
|
|
// 校验共创合约激励类型是否正确
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
// 校验共创合约激励类型是否正确
|
|
|
log.Logger.Info("订单产品匹配的合约", map[string]interface{}{
|
|
|
"contractMatched": cooperationContractsMap[orderGood.CooperationContractNumber],
|
|
|
})
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "分红订单不能关联金额激励规则"
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
...
|
...
|
@@ -814,7 +831,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[j].LineNumber] = "订单时间无法匹配分红激励规则"
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -838,9 +856,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
|
|
|
}
|
|
|
|
|
|
if len(orderGoodErrMap) > 0 {
|
|
|
log.Logger.Info("校验订单产品", map[string]interface{}{
|
|
|
"orderGoodErrMap": orderGoodErrMap,
|
|
|
})
|
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.BUSINESS_ERROR, "共创合约不存在"),
|
|
|
Error: nil,
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: orderGoodErrMap, // 错误产品行号记录
|
|
|
}
|
...
|
...
|
@@ -874,8 +896,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
|
|
|
creatDividendsOrder = append(creatDividendsOrder, newDividendsOrder)
|
|
|
}
|
|
|
/******************************************************************************************************************/
|
|
|
|
|
|
// 错误报告处理
|
|
|
/*********************************************** 错误报告处理 *******************************************************/
|
|
|
if len(errorDataList) <= 0 { // 成功返回
|
|
|
if _, err2 := dividendsOrderRepository.SaveMany(creatDividendsOrder); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
...
|
...
|
@@ -887,7 +910,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
if successDataCount == int64(rowCnt) {
|
|
|
return map[string]interface{}{
|
|
|
"successCount": successDataCount,
|
|
|
"fail": map[string]interface{}{},
|
|
|
"fail": make(map[string]interface{}),
|
|
|
}, nil
|
|
|
}
|
|
|
} else { // 失败返回
|
...
|
...
|
@@ -897,7 +920,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
if len(errorData.GoodLine) == 0 { // 订单错误
|
|
|
for _, line := range errorData.LineNumbers {
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
|
|
|
FailReason: errorData.Error.Error(),
|
|
|
}
|
|
|
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
|
|
|
failureDataList = append(failureDataList, tmpRow)
|
...
|
...
|
@@ -905,7 +928,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
|
|
|
for line := range errorData.GoodLine {
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
|
|
|
FailReason: errorData.GoodLine[line],
|
|
|
}
|
|
|
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[line]
|
|
|
failureDataList = append(failureDataList, tmpRow)
|
...
|
...
|
|