作者 陈志颖

feat:增加共创合约暂停恢复日志记录

@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 type OperateCooperationContractCommand struct { 10 type OperateCooperationContractCommand struct {
11 // 共创合约id 11 // 共创合约id
12 CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"` 12 CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
13 - // 操作 13 + // 操作,1暂停,2恢复
14 Action int32 `cname:"操作" json:"action" valid:"Required"` 14 Action int32 `cname:"操作" json:"action" valid:"Required"`
15 // 公司ID,通过集成REST上下文获取 15 // 公司ID,通过集成REST上下文获取
16 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"` 16 CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
@@ -563,6 +563,24 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -563,6 +563,24 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
563 defer func() { 563 defer func() {
564 _ = transactionContext.RollbackTransaction() 564 _ = transactionContext.RollbackTransaction()
565 }() 565 }()
  566 +
  567 + // 用户REST服务初始化
  568 + var userService service.UserService
  569 + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
  570 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  571 + } else {
  572 + userService = value
  573 + }
  574 +
  575 + // 获取操作人
  576 + var operator *domain.User
  577 + if data, err := userService.OperatorFrom(operateCooperationContractCommand.CompanyId, operateCooperationContractCommand.OrgId, operateCooperationContractCommand.UserId); err != nil {
  578 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  579 + } else {
  580 + operator = data
  581 + }
  582 +
  583 + // 共创合约仓储初始化
566 var cooperationContractRepository domain.CooperationContractRepository 584 var cooperationContractRepository domain.CooperationContractRepository
567 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 585 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
568 "transactionContext": transactionContext, 586 "transactionContext": transactionContext,
@@ -571,6 +589,18 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -571,6 +589,18 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
571 } else { 589 } else {
572 cooperationContractRepository = value 590 cooperationContractRepository = value
573 } 591 }
  592 +
  593 + // 共创合约变更记录仓储初始化
  594 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  595 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  596 + "transactionContext": transactionContext,
  597 + }); err != nil {
  598 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  599 + } else {
  600 + cooperationContractChangeLogRepository = value
  601 + }
  602 +
  603 + // 获取共创合约
574 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": operateCooperationContractCommand.CooperationContractId}) 604 cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": operateCooperationContractCommand.CooperationContractId})
575 if err != nil { 605 if err != nil {
576 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 606 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -578,18 +608,42 @@ func (cooperationContractService *CooperationContractService) OperateCooperation @@ -578,18 +608,42 @@ func (cooperationContractService *CooperationContractService) OperateCooperation
578 if cooperationContract == nil { 608 if cooperationContract == nil {
579 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operateCooperationContractCommand.CooperationContractId))) 609 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operateCooperationContractCommand.CooperationContractId)))
580 } 610 }
  611 +
  612 + // 更新共创合约
581 if err := cooperationContract.Update(map[string]interface{}{ 613 if err := cooperationContract.Update(map[string]interface{}{
582 "action": operateCooperationContractCommand.Action, 614 "action": operateCooperationContractCommand.Action,
583 }); err != nil { 615 }); err != nil {
584 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 616 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
585 } 617 }
586 - if cooperationContract, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil { 618 + if cooperationContractUpdated, err := cooperationContractRepository.UpdateOne(cooperationContract); err != nil {
587 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 619 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
588 } else { 620 } else {
  621 + // 新增共创合约变更记录
  622 + var operationType int32
  623 + if operateCooperationContractCommand.Action == 1 {
  624 + operationType = domain.PAUSE
  625 + } else if operateCooperationContractCommand.Action == 2 {
  626 + operationType = domain.RECOVER
  627 + }
  628 + newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
  629 + IncentivesRule: "",
  630 + IncentivesRuleDetail: "",
  631 + OperationType: operationType,
  632 + Undertakers: "",
  633 + CooperationContractNumber: cooperationContractUpdated.CooperationContractNumber,
  634 + Company: cooperationContractUpdated.Company,
  635 + Operator: operator,
  636 + CreatedAt: time.Now(),
  637 + }
  638 +
  639 + // 保存共创合约变更记录
  640 + if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
  641 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
  642 + }
589 if err := transactionContext.CommitTransaction(); err != nil { 643 if err := transactionContext.CommitTransaction(); err != nil {
590 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 644 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
591 } 645 }
592 - return cooperationContract, nil 646 + return cooperationContractUpdated, nil
593 } 647 }
594 } 648 }
595 649
@@ -608,6 +662,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -608,6 +662,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
608 defer func() { 662 defer func() {
609 _ = transactionContext.RollbackTransaction() 663 _ = transactionContext.RollbackTransaction()
610 }() 664 }()
  665 +
611 // 共创合约仓储初始化 666 // 共创合约仓储初始化
612 var cooperationContractRepository domain.CooperationContractRepository 667 var cooperationContractRepository domain.CooperationContractRepository
613 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 668 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
@@ -617,7 +672,37 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -617,7 +672,37 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
617 } else { 672 } else {
618 cooperationContractRepository = value 673 cooperationContractRepository = value
619 } 674 }
620 - cooperationContractIds, _ := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds) 675 +
  676 + // 共创合约变更记录仓储初始化
  677 + var cooperationContractChangeLogRepository domain.CooperationContractChangeLogRepository
  678 + if value, err := factory.CreateCooperationContractChangeLogRepository(map[string]interface{}{
  679 + "transactionContext": transactionContext,
  680 + }); err != nil {
  681 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  682 + } else {
  683 + cooperationContractChangeLogRepository = value
  684 + }
  685 +
  686 + // 用户REST服务初始化
  687 + var userService service.UserService
  688 + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
  689 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  690 + } else {
  691 + userService = value
  692 + }
  693 +
  694 + // 获取操作人
  695 + var operator *domain.User
  696 + if data, err := userService.OperatorFrom(batchOperateCooperationContractCommand.CompanyId, batchOperateCooperationContractCommand.OrgId, batchOperateCooperationContractCommand.UserId); err != nil {
  697 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  698 + } else {
  699 + operator = data
  700 + }
  701 +
  702 + cooperationContractIds, err := utils.SliceAtoi(batchOperateCooperationContractCommand.CooperationContractIds)
  703 + if err != nil {
  704 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "转换共创合约ID列表错误")
  705 + }
621 if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ 706 if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
622 "cooperationContractIds": cooperationContractIds, 707 "cooperationContractIds": cooperationContractIds,
623 }); err != nil { 708 }); err != nil {
@@ -631,6 +716,31 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper @@ -631,6 +716,31 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
631 if err != nil { 716 if err != nil {
632 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 717 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
633 } 718 }
  719 + for _, cooperationContractOperated := range cooperationContractsOperated {
  720 + // 新增共创合约变更记录
  721 + var operationType int32
  722 + if batchOperateCooperationContractCommand.Action == 1 {
  723 + operationType = domain.PAUSE
  724 + } else if batchOperateCooperationContractCommand.Action == 2 {
  725 + operationType = domain.RECOVER
  726 + }
  727 + newCooperationContractChangeLog := &domain.CooperationContractChangeLog{
  728 + IncentivesRule: "",
  729 + IncentivesRuleDetail: "",
  730 + OperationType: operationType,
  731 + Undertakers: "",
  732 + CooperationContractNumber: cooperationContractOperated.CooperationContractNumber,
  733 + Company: cooperationContractOperated.Company,
  734 + Operator: operator,
  735 + CreatedAt: time.Now(),
  736 + }
  737 +
  738 + // 保存共创合约变更记录
  739 + if _, err20 := cooperationContractChangeLogRepository.Save(newCooperationContractChangeLog); err20 != nil {
  740 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
  741 + }
  742 + }
  743 +
634 if err := transactionContext.CommitTransaction(); err != nil { 744 if err := transactionContext.CommitTransaction(); err != nil {
635 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 745 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
636 } 746 }
@@ -24,6 +24,8 @@ type CooperationContractChangeLog struct { @@ -24,6 +24,8 @@ type CooperationContractChangeLog struct {
24 Undertakers string `json:"undertakers"` 24 Undertakers string `json:"undertakers"`
25 // 公司 25 // 公司
26 Company *Company `json:"company"` 26 Company *Company `json:"company"`
  27 + // 组织机构
  28 + Org *Org `json:"org"`
27 // 操作人 29 // 操作人
28 Operator *User `json:"operator"` 30 Operator *User `json:"operator"`
29 // 操作时间 31 // 操作时间
@@ -21,6 +21,8 @@ type CooperationContractChangeLog struct { @@ -21,6 +21,8 @@ type CooperationContractChangeLog struct {
21 Undertakers string `comment:"承接人"` 21 Undertakers string `comment:"承接人"`
22 // 公司 22 // 公司
23 Company *domain.Company `comment:"公司"` 23 Company *domain.Company `comment:"公司"`
  24 + // 组织机构
  25 + Org *domain.Org `comment:"组织"`
24 // 操作人 26 // 操作人
25 Operator *domain.User `comment:"操作人"` 27 Operator *domain.User `comment:"操作人"`
26 // 操作时间 28 // 操作时间
@@ -13,7 +13,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC @@ -13,7 +13,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC
13 CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber, 13 CooperationContractNumber: cooperationContractChangeLogModel.CooperationContractNumber,
14 Undertakers: cooperationContractChangeLogModel.Undertakers, 14 Undertakers: cooperationContractChangeLogModel.Undertakers,
15 Company: cooperationContractChangeLogModel.Company, 15 Company: cooperationContractChangeLogModel.Company,
  16 + Org: cooperationContractChangeLogModel.Org,
16 Operator: cooperationContractChangeLogModel.Operator, 17 Operator: cooperationContractChangeLogModel.Operator,
  18 + OperatorTime: cooperationContractChangeLogModel.OperatorTime,
17 UpdatedAt: cooperationContractChangeLogModel.UpdatedAt, 19 UpdatedAt: cooperationContractChangeLogModel.UpdatedAt,
18 DeletedAt: cooperationContractChangeLogModel.DeletedAt, 20 DeletedAt: cooperationContractChangeLogModel.DeletedAt,
19 CreatedAt: cooperationContractChangeLogModel.CreatedAt, 21 CreatedAt: cooperationContractChangeLogModel.CreatedAt,
@@ -33,6 +33,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -33,6 +33,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
33 "cooperation_contract_number", 33 "cooperation_contract_number",
34 "undertakers", 34 "undertakers",
35 "company", 35 "company",
  36 + "org",
36 "operator", 37 "operator",
37 "operator_time", 38 "operator_time",
38 "updated_at", 39 "updated_at",
@@ -60,6 +61,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -60,6 +61,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
60 &cooperationContractChangeLog.CooperationContractNumber, 61 &cooperationContractChangeLog.CooperationContractNumber,
61 &cooperationContractChangeLog.Undertakers, 62 &cooperationContractChangeLog.Undertakers,
62 &cooperationContractChangeLog.Company, 63 &cooperationContractChangeLog.Company,
  64 + &cooperationContractChangeLog.Org,
63 &cooperationContractChangeLog.Operator, 65 &cooperationContractChangeLog.Operator,
64 &cooperationContractChangeLog.OperatorTime, 66 &cooperationContractChangeLog.OperatorTime,
65 &cooperationContractChangeLog.UpdatedAt, 67 &cooperationContractChangeLog.UpdatedAt,
@@ -73,6 +75,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -73,6 +75,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
73 cooperationContractChangeLog.CooperationContractNumber, 75 cooperationContractChangeLog.CooperationContractNumber,
74 cooperationContractChangeLog.Undertakers, 76 cooperationContractChangeLog.Undertakers,
75 cooperationContractChangeLog.Company, 77 cooperationContractChangeLog.Company,
  78 + cooperationContractChangeLog.Org,
76 cooperationContractChangeLog.Operator, 79 cooperationContractChangeLog.Operator,
77 cooperationContractChangeLog.OperatorTime, 80 cooperationContractChangeLog.OperatorTime,
78 cooperationContractChangeLog.UpdatedAt, 81 cooperationContractChangeLog.UpdatedAt,
@@ -90,6 +93,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -90,6 +93,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
90 &cooperationContractChangeLog.CooperationContractNumber, 93 &cooperationContractChangeLog.CooperationContractNumber,
91 &cooperationContractChangeLog.Undertakers, 94 &cooperationContractChangeLog.Undertakers,
92 &cooperationContractChangeLog.Company, 95 &cooperationContractChangeLog.Company,
  96 + &cooperationContractChangeLog.Org,
93 &cooperationContractChangeLog.Operator, 97 &cooperationContractChangeLog.Operator,
94 &cooperationContractChangeLog.OperatorTime, 98 &cooperationContractChangeLog.OperatorTime,
95 &cooperationContractChangeLog.UpdatedAt, 99 &cooperationContractChangeLog.UpdatedAt,
@@ -103,6 +107,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra @@ -103,6 +107,7 @@ func (repository *CooperationContractChangeLogRepository) Save(cooperationContra
103 cooperationContractChangeLog.CooperationContractNumber, 107 cooperationContractChangeLog.CooperationContractNumber,
104 cooperationContractChangeLog.Undertakers, 108 cooperationContractChangeLog.Undertakers,
105 cooperationContractChangeLog.Company, 109 cooperationContractChangeLog.Company,
  110 + cooperationContractChangeLog.Org,
106 cooperationContractChangeLog.Operator, 111 cooperationContractChangeLog.Operator,
107 cooperationContractChangeLog.OperatorTime, 112 cooperationContractChangeLog.OperatorTime,
108 cooperationContractChangeLog.UpdatedAt, 113 cooperationContractChangeLog.UpdatedAt,