...
|
...
|
@@ -521,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())
|
|
|
}
|
...
|
...
|
@@ -550,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
|
...
|
...
|
@@ -566,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
|
...
|
...
|
@@ -582,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
|
...
|
...
|
@@ -649,16 +656,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
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{}{
|
...
|
...
|
@@ -672,26 +669,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
})
|
|
|
}
|
|
|
|
|
|
// 查询共创项目
|
|
|
//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
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//
|
|
|
//log.Logger.Info("查询共创项目", map[string]interface{}{
|
|
|
// "cooperationProjectsMap": cooperationProjectsMap,
|
|
|
//})
|
|
|
|
|
|
// 统计成功预算的分红订单
|
|
|
estimateSuccessfullyDividendsOrders := make(map[string]string)
|
|
|
|
...
|
...
|
@@ -699,12 +676,15 @@ 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
|
...
|
...
|
@@ -716,8 +696,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
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,
|
...
|
...
|
@@ -732,10 +715,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("查询共创合约", map[string]interface{}{
|
|
|
"cooperationContractsMap": cooperationContractsMap,
|
|
|
})
|
|
|
} else {
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
|
|
|
}, nil
|
|
|
}
|
|
|
fmt.Println("查询共创合约耗时:", time.Since(startQueryContracts))
|
|
|
|
|
|
// 统计当前企业分红预算单数
|
|
|
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
|
...
|
...
|
@@ -747,12 +732,19 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
var countDividendsEstimate int64
|
|
|
|
|
|
for _, orderGood := range orderGoods {
|
|
|
dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
|
|
|
for _, orderGood := range orderGoods {
|
|
|
if orderGood.DividendsOrderNumber != "" {
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红订单产品预算
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" {
|
|
|
returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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 {
|
...
|
...
|
@@ -770,7 +762,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
// 统计分红预算单数目
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
|
...
|
...
|
@@ -779,8 +771,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.ORDER_DIVIDENDS,
|
|
|
DividendsTypeName: "订单分红",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsEstimateDetail.DividendsStage,
|
...
|
...
|
@@ -792,8 +784,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodId: dividendsEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
...
|
...
|
@@ -805,11 +797,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
|
|
|
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
|
|
|
// 分红退货单产品预算
|
|
|
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
|
|
|
} 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 {
|
...
|
...
|
@@ -826,7 +815,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
// 统计生成的预算单数量
|
|
|
countDividendsEstimate = countDividendsEstimate + 1
|
|
|
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
dividendsEstimate := &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
|
|
|
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
|
...
|
...
|
@@ -835,8 +824,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
|
|
|
DividendsType: domain.RETURN_WRITE_OFF,
|
|
|
DividendsTypeName: "退货冲销",
|
|
|
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
|
|
|
CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
|
|
|
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
|
|
|
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
|
|
|
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
|
...
|
...
|
@@ -848,8 +837,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
OrderGoodId: orderGood.OrderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
|
|
|
OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
|
|
|
PaymentStatus: int32(1),
|
|
|
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
|
|
|
}
|
...
|
...
|
@@ -862,15 +851,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.Logger.Info("新增的分红预算单", map[string]interface{}{
|
|
|
"dividendsEstimates": dividendsEstimates,
|
|
|
})
|
|
|
fmt.Println("订单分红耗时:", time.Since(startConfirm))
|
|
|
|
|
|
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 {
|
...
|
...
|
@@ -878,6 +865,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
|
|
|
// 更新订单产品分红状态
|
|
|
startUpdateGoodStatus := time.Now()
|
|
|
var orderGoodsSaved []*domain.OrderGood
|
|
|
if len(orderGoodSavedIds) > 0 {
|
|
|
// 订单产品ID去重
|
...
|
...
|
@@ -899,6 +887,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fmt.Println("更新订单产品分红状态耗时:", time.Since(startUpdateGoodStatus))
|
|
|
|
|
|
// 分离分红订单和退货单
|
|
|
dividendsOrderNumbers := make([]string, 0)
|
...
|
...
|
@@ -915,15 +904,8 @@ 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,
|
...
|
...
|
@@ -966,8 +948,10 @@ 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,
|
...
|
...
|
@@ -1010,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)
|
...
|
...
|
@@ -1029,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
|
...
|
...
|
|