...
|
...
|
@@ -343,6 +343,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
|
|
// 获取分红预算
|
|
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"dividendsEstimateIds": dividendsEstimateIds,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -520,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat |
|
|
|
|
|
// ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算
|
|
|
func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) {
|
|
|
start := time.Now()
|
|
|
if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -549,12 +551,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
startGetCompany := time.Now()
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(confirmDividendsIncentivesEstimateCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
fmt.Println("获取公司信息耗时:", time.Since(startGetCompany))
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
...
|
...
|
@@ -565,12 +569,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
startGetOrg := time.Now()
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
fmt.Println("获取组织机构数据耗时:", time.Since(startGetOrg))
|
|
|
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
...
|
...
|
@@ -581,12 +587,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 获取操作人
|
|
|
startGetOperator := time.Now()
|
|
|
var operator *domain.User
|
|
|
if data, err := userService.OperatorFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, confirmDividendsIncentivesEstimateCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
fmt.Println("获取操作人耗时:", time.Since(startGetOperator))
|
|
|
|
|
|
// 订单产品仓储初始化
|
|
|
var orderGoodRepository domain.OrderGoodRepository
|
...
|
...
|
@@ -638,6 +646,16 @@ 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 confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
|
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
...
|
...
|
@@ -658,13 +676,52 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
estimateFailedDividendsOrders := make(map[string]string)
|
|
|
|
|
|
// 获取订单产品
|
|
|
startGetOrderGoods := time.Now()
|
|
|
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"orderGoodIds": orderGoodIds,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
fmt.Println("获取订单产品耗时:", time.Since(startGetOrderGoods))
|
|
|
|
|
|
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
|
|
|
|
|
|
var cooperationContractNumbers []string
|
|
|
|
|
|
// 获取订单产品合约编号
|
|
|
for _, orderGood := range orderGoods {
|
|
|
cooperationContractNumbers = append(cooperationContractNumbers, orderGood.CooperationContractNumber)
|
|
|
}
|
|
|
|
|
|
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
|
|
|
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
|
|
|
|
|
// 查询共创合约
|
|
|
startQueryContracts := time.Now()
|
|
|
if len(newCooperationContractNumbers) > 0 {
|
|
|
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"cooperationContractNumbers": newCooperationContractNumbers,
|
|
|
"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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
|
|
|
}, nil
|
|
|
}
|
|
|
fmt.Println("查询共创合约耗时:", time.Since(startQueryContracts))
|
|
|
|
|
|
// 统计当前企业分红预算单数
|
|
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
...
|
...
|
@@ -674,131 +731,133 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
var countDividendsEstimate int64
|
|
|
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
|
|
|
for _, orderGood := range orderGoods {
|
|
|
dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
// 临时方案
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红订单产品预算
|
|
|
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
if dividendsEstimateDetail.IsSuccessfully {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" {
|
|
|
returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 记录成功的订单号
|
|
|
estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
|
|
|
// 统计分红预算单数目
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
|
|
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
DividendsEstimateTime: time.Now(),
|
|
|
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
DividendsTypeName: "订单分红",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsEstimateDetail.DividendsStage,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
|
|
startConfirm := time.Now()
|
|
|
if len(orderGoodsToConfirm) > 0 { // 分红订单产品预算
|
|
|
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
|
|
|
if dividendsEstimateDetail.IsSuccessfully {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的订单号和原因
|
|
|
estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
|
|
// 记录成功的订单号
|
|
|
estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
|
|
|
// 统计分红预算单数目
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
|
|
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
DividendsEstimateTime: time.Now(),
|
|
|
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
DividendsTypeName: "订单分红",
|
|
|
OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsEstimateDetail.DividendsStage,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: dividendsEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的订单号和原因
|
|
|
estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
if dividendsReturnedEstimateDetail.IsSuccessfully {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 记录成功的退货单号
|
|
|
estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
|
|
|
// 统计生成的预算单数量
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
|
|
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
DividendsEstimateTime: time.Now(),
|
|
|
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
DividendsTypeName: "退货冲销",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
|
|
}
|
|
|
} else if len(returnedOrderGoodsToConfirm) > 0 { // 退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(returnedOrderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
|
|
|
if dividendsReturnedEstimateDetail.IsSuccessfully {
|
|
|
// 生成分红预算单号
|
|
|
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的退货单号和原因
|
|
|
estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
|
|
// 记录成功的退货单号
|
|
|
estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
|
|
|
|
|
|
// 统计生成的预算单数量
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
|
|
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
|
|
|
DividendsEstimateTime: time.Now(),
|
|
|
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
DividendsTypeName: "退货冲销",
|
|
|
OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
|
|
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
} else {
|
|
|
// 记录失败的退货单号和原因
|
|
|
estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fmt.Println("订单分红耗时:", time.Since(startConfirm))
|
|
|
|
|
|
log.Logger.Info("新增的分红预算单", map[string]interface{}{
|
|
|
"dividendsEstimates": dividendsEstimates,
|
|
|
})
|
|
|
|
|
|
startInsert := time.Now()
|
|
|
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
fmt.Println("插入预算单耗时:", time.Since(startInsert))
|
|
|
// 获取产品ID
|
|
|
orderGoodSavedIds := make([]int64, 0)
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
...
|
...
|
@@ -806,10 +865,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 更新订单产品分红状态
|
|
|
startUpdateGoodStatus := time.Now()
|
|
|
var orderGoodsSaved []*domain.OrderGood
|
|
|
if len(orderGoodSavedIds) > 0 {
|
|
|
// 订单产品ID去重
|
|
|
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodSavedIds)
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"orderGoodIds": orderGoodSavedIds,
|
|
|
"orderGoodIds": newOrderGoodIds,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -824,6 +887,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fmt.Println("更新订单产品分红状态耗时:", time.Since(startUpdateGoodStatus))
|
|
|
|
|
|
// 分离分红订单和退货单
|
|
|
dividendsOrderNumbers := make([]string, 0)
|
...
|
...
|
@@ -840,20 +904,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("分红订单", map[string]interface{}{
|
|
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
|
|
})
|
|
|
|
|
|
log.Logger.Info("分红退货单", map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
|
})
|
|
|
|
|
|
// 查找分红订单
|
|
|
startUpdateOrder := time.Now()
|
|
|
if len(dividendsOrderNumbers) > 0 {
|
|
|
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
"dividendsOrderNumbers": dividendsOrderNumbers,
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -890,13 +948,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fmt.Println("更新订单耗时:", time.Since(startUpdateOrder))
|
|
|
|
|
|
// 查找分红退货单
|
|
|
startUpdateReturnedOrder := time.Now()
|
|
|
if len(dividendsReturnedOrderNumbers) > 0 {
|
|
|
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
|
|
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
"offsetLimit": false,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -933,9 +994,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
|
|
|
fmt.Println("更新退货单耗时:", time.Since(startUpdateReturnedOrder))
|
|
|
|
|
|
startCommit := time.Now()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
fmt.Println("提交事务耗时:", time.Since(startCommit))
|
|
|
|
|
|
// 统计成功的分红预算
|
|
|
successfullyCount := len(dividendsEstimatesSaved)
|
...
|
...
|
@@ -952,6 +1017,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
failedReasonStr = "无"
|
|
|
}
|
|
|
|
|
|
fmt.Println("函数执行完毕:", time.Since(start))
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
|
|
|
}, nil
|
...
|
...
|
@@ -1166,7 +1233,10 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g |
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId})
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId,
|
|
|
"isCanceled": false,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1283,6 +1353,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimat |
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
searchDividendsEstimateQuery.IsCanceled = false
|
|
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(searchDividendsEstimateQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
|