...
|
...
|
@@ -3,7 +3,6 @@ package service |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
|
...
|
...
|
@@ -542,6 +541,17 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 预算消息推送领域服务初始化
|
|
|
var informDividendsExpectedService service.InformDividendsExpectedService
|
|
|
if value, err := factory.CreateInformDividendsExpectedService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
informDividendsExpectedService = value
|
|
|
_ = informDividendsExpectedService.Subscribe(&subscriber.MessageServiceSubscriber{
|
|
|
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
...
|
...
|
@@ -656,6 +666,16 @@ 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{}{
|
...
|
...
|
@@ -664,9 +684,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
confirmDividendsIncentivesEstimateService = value
|
|
|
_ = confirmDividendsIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
|
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 统计成功预算的分红订单
|
...
|
...
|
@@ -689,14 +706,21 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
var cooperationContractNumbers []string
|
|
|
|
|
|
orderGoodsMap := make(map[int64]*domain.OrderGood, 0)
|
|
|
|
|
|
// 获取订单产品合约编号
|
|
|
for _, orderGood := range orderGoods {
|
|
|
cooperationContractNumbers = append(cooperationContractNumbers, orderGood.CooperationContractNumber)
|
|
|
orderGoodsMap[orderGood.OrderGoodId] = orderGood
|
|
|
}
|
|
|
|
|
|
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
|
|
|
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
|
|
|
cooperationProjectsMap := make(map[string]*domain.CooperationProject, 0)
|
|
|
|
|
|
// 共创项目编号
|
|
|
var cooperationProjectNumbers []string
|
|
|
|
|
|
// 查询共创合约
|
|
|
startQueryContracts := time.Now()
|
...
|
...
|
@@ -712,6 +736,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
if count > 0 {
|
|
|
for _, cooperationContractFound := range cooperationContractsFound {
|
|
|
cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
|
|
|
cooperationProjectNumbers = append(cooperationProjectNumbers, cooperationContractFound.CooperationProjectNumber)
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -720,6 +745,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
"report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
newCooperationProjectNumbers := utils.RemoveDuplicationString(cooperationProjectNumbers)
|
|
|
|
|
|
fmt.Println("查询共创合约耗时:", time.Since(startQueryContracts))
|
|
|
|
|
|
// 统计当前企业分红预算单数
|
...
|
...
|
@@ -996,6 +1024,24 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
fmt.Println("更新退货单耗时:", time.Since(startUpdateReturnedOrder))
|
|
|
|
|
|
// 查询共创项目
|
|
|
if len(newCooperationProjectNumbers) > 0 {
|
|
|
if countProject, cooperationProjectsFound, errFind := cooperationProjectRepository.Find(map[string]interface{}{
|
|
|
"cooperationProjectNumbers": newCooperationProjectNumbers,
|
|
|
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
|
|
|
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
|
|
|
"offsetLimit": false,
|
|
|
}); errFind != nil {
|
|
|
return nil, errFind
|
|
|
} else {
|
|
|
if countProject > 0 {
|
|
|
for _, cooperationProjectFound := range cooperationProjectsFound {
|
|
|
cooperationProjectsMap[cooperationProjectFound.CooperationProjectNumber] = cooperationProjectFound
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
startCommit := time.Now()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -1019,6 +1065,31 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
|
|
|
fmt.Println("函数执行完毕:", time.Since(start))
|
|
|
|
|
|
// 消息通知
|
|
|
var expectedData []service.ExpectedData
|
|
|
for _, dividendsEstimateSaved := range dividendsEstimatesSaved {
|
|
|
if dividendsEstimateSaved.DividendsParticipateType == 1 {
|
|
|
expectedData = append(expectedData, service.ExpectedData{
|
|
|
CreationContractId: cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationContractId,
|
|
|
CreationContractName: cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationContractName,
|
|
|
CreationContractNumber: cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationContractNumber,
|
|
|
CreationProjectId: cooperationProjectsMap[cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationProjectNumber].CooperationProjectId,
|
|
|
CreationProjectName: cooperationProjectsMap[cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationProjectNumber].CooperationProjectName,
|
|
|
CreationProjectNumber: cooperationProjectsMap[cooperationContractsMap[dividendsEstimateSaved.CooperationContractNumber].CooperationProjectNumber].CooperationProjectNumber,
|
|
|
ProductName: orderGoodsMap[dividendsEstimateSaved.OrderGoodId].OrderGoodName,
|
|
|
UserId: dividendsEstimateSaved.DividendsUser.UserId,
|
|
|
UserBaseId: dividendsEstimateSaved.DividendsUser.UserBaseId,
|
|
|
OrgId: dividendsEstimateSaved.Org.OrgId,
|
|
|
CompanyId: dividendsEstimateSaved.Company.CompanyId,
|
|
|
DividendsEstimateId: dividendsEstimateSaved.DividendsEstimateId,
|
|
|
DividendsAmount: fmt.Sprint(dividendsEstimateSaved.DividendsAmount),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
if err := informDividendsExpectedService.Expect(expectedData); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
|
|
|
}, nil
|
...
|
...
|
@@ -1050,8 +1121,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
confirmMoneyIncentivesEstimateService = value
|
|
|
_ = confirmMoneyIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
|
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
}
|
|
|
|
|
|
// 预算消息推送领域服务初始化
|
|
|
var informDividendsExpectedService service.InformDividendsExpectedService
|
|
|
if value, err := factory.CreateInformDividendsExpectedService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
informDividendsExpectedService = value
|
|
|
_ = informDividendsExpectedService.Subscribe(&subscriber.MessageServiceSubscriber{
|
|
|
//TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1065,6 +1144,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
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
|
|
|
}
|
|
|
|
|
|
// 分红预算单DAO初始化
|
|
|
var dividendsEstimateDao *dao.DividendsEstimateDao
|
|
|
if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
|
...
|
...
|
@@ -1138,6 +1227,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationContractId, 10)))
|
|
|
}
|
|
|
|
|
|
// 获取共创项目
|
|
|
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
|
|
|
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
|
|
|
"orgId": organization.OrgId,
|
|
|
"companyId": company.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationProject == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", cooperationContract.CooperationProjectNumber))
|
|
|
}
|
|
|
|
|
|
// 分红预算单
|
|
|
var dividendsEstimates []*domain.DividendsEstimate
|
|
|
|
|
|
// 统计当前分红预算单数
|
...
|
...
|
@@ -1203,6 +1306,32 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 消息通知
|
|
|
var expectedData []service.ExpectedData
|
|
|
for _, dividendsEstimateSaved := range dividendsEstimatesSaved {
|
|
|
if dividendsEstimateSaved.DividendsParticipateType == 1 {
|
|
|
expectedData = append(expectedData, service.ExpectedData{
|
|
|
CreationContractId: cooperationContract.CooperationContractId,
|
|
|
CreationContractName: cooperationContract.CooperationContractName,
|
|
|
CreationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
CreationProjectId: cooperationProject.CooperationProjectId,
|
|
|
CreationProjectName: cooperationProject.CooperationProjectName,
|
|
|
CreationProjectNumber: cooperationProject.CooperationProjectNumber,
|
|
|
ProductName: "",
|
|
|
UserId: dividendsEstimateSaved.DividendsUser.UserId,
|
|
|
UserBaseId: dividendsEstimateSaved.DividendsUser.UserBaseId,
|
|
|
OrgId: dividendsEstimateSaved.Org.OrgId,
|
|
|
CompanyId: dividendsEstimateSaved.Company.CompanyId,
|
|
|
DividendsEstimateId: dividendsEstimateSaved.DividendsEstimateId,
|
|
|
DividendsAmount: fmt.Sprint(dividendsEstimateSaved.DividendsAmount),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
if err := informDividendsExpectedService.Expect(expectedData); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return dividendsEstimatesSaved, nil
|
|
|
}
|
|
|
return dividendsEstimatesSaved, nil
|
...
|
...
|
|