|
@@ -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
|
}
|