作者 陈志颖

feat:移除账期结算单,同时更新分红预算单结算状态

@@ -150,6 +150,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred @@ -150,6 +150,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
150 var goodAmountCount float64 150 var goodAmountCount float64
151 for _, dividendsEstimate := range dividendsEstimates { 151 for _, dividendsEstimate := range dividendsEstimates {
152 accountDetail = append(accountDetail, &domain.AccountDetail{ 152 accountDetail = append(accountDetail, &domain.AccountDetail{
  153 + DividendsEstimateOrderId: dividendsEstimate.DividendsEstimateId,
153 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, 154 DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
154 DividendsType: dividendsEstimate.DividendsType, 155 DividendsType: dividendsEstimate.DividendsType,
155 DividendsAmount: dividendsEstimate.DividendsAmount, 156 DividendsAmount: dividendsEstimate.DividendsAmount,
@@ -393,6 +394,7 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred @@ -393,6 +394,7 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred
393 defer func() { 394 defer func() {
394 _ = transactionContext.RollbackTransaction() 395 _ = transactionContext.RollbackTransaction()
395 }() 396 }()
  397 + // 账期结算单仓储初始化
396 var creditAccountRepository domain.CreditAccountRepository 398 var creditAccountRepository domain.CreditAccountRepository
397 if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{ 399 if value, err := factory.CreateCreditAccountRepository(map[string]interface{}{
398 "transactionContext": transactionContext, 400 "transactionContext": transactionContext,
@@ -401,20 +403,55 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred @@ -401,20 +403,55 @@ func (creditAccountService *CreditAccountService) RemoveCreditAccount(removeCred
401 } else { 403 } else {
402 creditAccountRepository = value 404 creditAccountRepository = value
403 } 405 }
404 - creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": removeCreditAccountCommand.CreditAccountId}) 406 +
  407 + // 分红预算单仓储初始化
  408 + var dividendsEstimateRepository domain.DividendsEstimateRepository
  409 + if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
  410 + "transactionContext": transactionContext,
  411 + }); err != nil {
  412 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  413 + } else {
  414 + dividendsEstimateRepository = value
  415 + }
  416 +
  417 + // 获取账期阶段单
  418 + creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{
  419 + "creditAccountId": removeCreditAccountCommand.CreditAccountId,
  420 + })
405 if err != nil { 421 if err != nil {
406 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 422 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
407 } 423 }
408 if creditAccount == nil { 424 if creditAccount == nil {
409 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCreditAccountCommand.CreditAccountId, 10))) 425 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCreditAccountCommand.CreditAccountId, 10)))
410 } 426 }
411 - if creditAccount, err := creditAccountRepository.Remove(creditAccount); err != nil { 427 + if creditAccountRemoved, err := creditAccountRepository.Remove(creditAccount); err != nil {
412 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 428 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
413 } else { 429 } else {
  430 + // 更新相关分红预算单结算状态
  431 + dividendsEstimateIds := make([]int64, 0)
  432 + if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
  433 + "dividendsEstimateIds": dividendsEstimateIds,
  434 + }); err != nil {
  435 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  436 + } else {
  437 + if count > 0 {
  438 + for i, dividendsEstimate := range dividendsEstimates {
  439 + if !dividendsEstimate.IsCanceled {
  440 + dividendsEstimates[i].DividendsAccountStatus = int32(1)
  441 + }
  442 + }
  443 + // 保存分红预算单
  444 + _, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimates)
  445 + if err3 != nil {
  446 + return nil, err3
  447 + }
  448 + }
  449 + }
  450 +
414 if err := transactionContext.CommitTransaction(); err != nil { 451 if err := transactionContext.CommitTransaction(); err != nil {
415 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 452 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
416 } 453 }
417 - return creditAccount, nil 454 + return creditAccountRemoved, nil
418 } 455 }
419 } 456 }
420 457
1 package domain 1 package domain
2 2
3 type AccountDetail struct { 3 type AccountDetail struct {
4 - // 分红预算单号 4 + // 分红预算单号ID
  5 + DividendsEstimateOrderId int64 `json:"dividendsEstimateOrderId"`
  6 + // 分红预算单编号
5 DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"` 7 DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"`
6 // 分红类型,1订单分红,2退货冲销,3金额激励 8 // 分红类型,1订单分红,2退货冲销,3金额激励
7 DividendsType int32 `json:"dividendsType"` 9 DividendsType int32 `json:"dividendsType"`