作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
... ... @@ -351,6 +351,16 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
creditAccountRepository = value
}
// 分红预算单仓储初始化
var dividendsEstimateRepository domain.DividendsEstimateRepository
if value, err2 := factory.CreateDividendsEstimateRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
dividendsEstimateRepository = value
}
// 获取待支付的账期结算单
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{
"creditAccountId": creditAccountId,
... ... @@ -372,6 +382,27 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
} else {
// 更新账期结算单相关的分红预算单的分红结算状态
var dividendsEstimateIds []int64
for _, accountDetail := range creditAccount.AccountDetail {
dividendsEstimateIds = append(dividendsEstimateIds, accountDetail.DividendsEstimateOrderId)
}
if count, dividendsEstimates, err3 := dividendsEstimateRepository.Find(map[string]interface{}{
"dividendsEstimateIds": dividendsEstimateIds,
"offsetLimit": false,
}); err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
} else {
if count > 0 {
for i, _ := range dividendsEstimates {
dividendsEstimates[i].PaymentStatus = int32(2)
}
if _, err5 := dividendsEstimateRepository.UpdateMany(dividendsEstimates); err5 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err5.Error())
}
}
}
if err3 := transactionContext.CommitTransaction(); err3 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
}
... ...
... ... @@ -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,
})
... ...
... ... @@ -15,4 +15,6 @@ type AccountDetail struct {
OrderGoodAmount float64 `json:"orderGoodAmount"`
// 关联共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 参与类型
ParticipateType string `json:"participateType"`
}
... ...
... ... @@ -25,6 +25,8 @@ type DividendsEstimate struct {
DividendsEstimateId int64 `json:"dividendsEstimateId,string"`
// 分红结算状态,1待结算,2已结算
DividendsAccountStatus int32 `json:"dividendsAccountStatus"`
// 分红支付状态,1未支付,2已支付
PaymentStatus int32 `json:"paymentStatus"`
// 分红金额
DividendsAmount float64 `json:"dividendsAmount"`
// 承接人分红预算单号
... ...
... ... @@ -11,6 +11,8 @@ type DividendsEstimate struct {
DividendsEstimateId int64 `comment:"承接人分红预算记录ID" pg:",pk"`
// 分红结算状态
DividendsAccountStatus int32 `comment:"分红结算状态"`
// 支付状态 1未支付,2已支付
PaymentStatus int32 `comment:"支付状态" pg:",default:1"`
// 分红金额
DividendsAmount float64 `comment:"分红金额"`
// 承接人分红预算单号
... ...
... ... @@ -11,6 +11,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
return &domain.DividendsEstimate{
DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,
PaymentStatus: dividendsEstimateModel.PaymentStatus,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,
... ...
... ... @@ -28,6 +28,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
sqlBuildFields := []string{
"dividends_estimate_id",
"dividends_account_status",
"payment_status",
"dividends_amount",
"dividends_estimate_order_number",
"dividends_estimate_time",
... ... @@ -64,6 +65,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
pg.Scan(
&dividendsEstimate.DividendsEstimateId,
&dividendsEstimate.DividendsAccountStatus,
&dividendsEstimate.PaymentStatus,
&dividendsEstimate.DividendsAmount,
&dividendsEstimate.DividendsEstimateOrderNumber,
&dividendsEstimate.DividendsEstimateTime,
... ... @@ -86,6 +88,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
fmt.Sprintf("INSERT INTO dividends_estimates (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
dividendsEstimate.DividendsAccountStatus,
dividendsEstimate.PaymentStatus,
dividendsEstimate.DividendsAmount,
dividendsEstimate.DividendsEstimateOrderNumber,
dividendsEstimate.DividendsEstimateTime,
... ... @@ -112,6 +115,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
pg.Scan(
&dividendsEstimate.DividendsEstimateId,
&dividendsEstimate.DividendsAccountStatus,
&dividendsEstimate.PaymentStatus,
&dividendsEstimate.DividendsAmount,
&dividendsEstimate.DividendsEstimateOrderNumber,
&dividendsEstimate.DividendsEstimateTime,
... ... @@ -134,6 +138,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
fmt.Sprintf("UPDATE dividends_estimates SET %s WHERE dividends_estimate_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
dividendsEstimate.DividendsAccountStatus,
dividendsEstimate.PaymentStatus,
dividendsEstimate.DividendsAmount,
dividendsEstimate.DividendsEstimateOrderNumber,
dividendsEstimate.DividendsEstimateTime,
... ... @@ -175,6 +180,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
... ... @@ -219,6 +225,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
... ...
... ... @@ -165,10 +165,10 @@ func (controller *DividendsEstimateController) SearchMoneyIncentivesEstimate() {
searchMoneyIncentivesEstimateQuery.OrgId = header.OrgId
searchMoneyIncentivesEstimateQuery.UserId = header.UserId
searchMoneyIncentivesEstimateQuery.UserBaseId = header.UserBaseId
pageSize, _ := controller.GetInt64("pageSize")
searchMoneyIncentivesEstimateQuery.PageSize = pageSize
pageNumber, _ := controller.GetInt64("pageNumber")
searchMoneyIncentivesEstimateQuery.PageNumber = pageNumber
//pageSize, _ := controller.GetInt64("pageSize")
//searchMoneyIncentivesEstimateQuery.PageSize = pageSize
//pageNumber, _ := controller.GetInt64("pageNumber")
//searchMoneyIncentivesEstimateQuery.PageNumber = pageNumber
data, err := dividendsEstimateService.SearchMoneyIncentivesEstimate(searchMoneyIncentivesEstimateQuery)
controller.Response(data, err)
}
... ... @@ -200,10 +200,10 @@ func (controller *DividendsEstimateController) SearchDividendsIncentivesEstimate
searchDividendsIncentivesQuery.OrgId = header.OrgId
searchDividendsIncentivesQuery.UserId = header.UserId
searchDividendsIncentivesQuery.UserBaseId = header.UserBaseId
pageSize, _ := controller.GetInt64("pageSize")
searchDividendsIncentivesQuery.PageSize = pageSize
pageNumber, _ := controller.GetInt64("pageNumber")
searchDividendsIncentivesQuery.PageNumber = pageNumber
//pageSize, _ := controller.GetInt64("pageSize")
//searchDividendsIncentivesQuery.PageSize = pageSize
//pageNumber, _ := controller.GetInt64("pageNumber")
//searchDividendsIncentivesQuery.PageNumber = pageNumber
data, err := dividendsEstimateService.SearchDividendsIncentivesEstimate(searchDividendsIncentivesQuery)
controller.Response(data, err)
}
... ...