作者 陈志颖

feat:修改现金池服务

@@ -118,3 +118,5 @@ func CreateInputCashPoolService(options map[string]interface{}) (service.InputCa @@ -118,3 +118,5 @@ func CreateInputCashPoolService(options map[string]interface{}) (service.InputCa
118 return domainService.NewCashPoolService(transactionContext) 118 return domainService.NewCashPoolService(transactionContext)
119 } 119 }
120 120
  121 +
  122 +
@@ -85,3 +85,27 @@ func CreateSentNotificationRepository(options map[string]interface{}) (domain.Se @@ -85,3 +85,27 @@ func CreateSentNotificationRepository(options map[string]interface{}) (domain.Se
85 } 85 }
86 return repository.NewSentNotificationRepository(transactionContext) 86 return repository.NewSentNotificationRepository(transactionContext)
87 } 87 }
  88 +
  89 +func CreateCashPoolRepository(options map[string]interface{}) (domain.CashPoolRepository, error) {
  90 + var transactionContext *pg.TransactionContext
  91 + if value, ok := options["transactionContext"]; ok {
  92 + transactionContext = value.(*pg.TransactionContext)
  93 + }
  94 + return repository.NewCashPoolRepository(transactionContext)
  95 +}
  96 +
  97 +func CreateExchangeCashActivityRepository(options map[string]interface{}) (domain.ExchangeActivityRepository, error) {
  98 + var transactionContext *pg.TransactionContext
  99 + if value, ok := options["transactionContext"]; ok {
  100 + transactionContext = value.(*pg.TransactionContext)
  101 + }
  102 + return repository.NewExchangeCashActivityRepository(transactionContext)
  103 +}
  104 +
  105 +func CreateExchangeCashPersonListRepository(options map[string]interface{}) (domain.ExchangeCashPersonListRepository, error) {
  106 + var transactionContext *pg.TransactionContext
  107 + if value, ok := options["transactionContext"]; ok {
  108 + transactionContext = value.(*pg.TransactionContext)
  109 + }
  110 + return repository.NewExchangeCashPersonListRepository(transactionContext)
  111 +}
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 +
4 "github.com/linmadan/egglib-go/core/application" 6 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" 11 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 12 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
10 ) 13 )
@@ -80,7 +83,7 @@ func (cashPoolService *CashPoolService) OperationCashPool(createCashPoolCommand @@ -80,7 +83,7 @@ func (cashPoolService *CashPoolService) OperationCashPool(createCashPoolCommand
80 } 83 }
81 } 84 }
82 85
83 -// TODO 返回现金池 86 +// 返回现金池
84 func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) { 87 func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
85 if err := getCashPoolQuery.ValidateQuery(); err != nil { 88 if err := getCashPoolQuery.ValidateQuery(); err != nil {
86 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 89 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -100,8 +103,26 @@ func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCash @@ -100,8 +103,26 @@ func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCash
100 transactionContext.RollbackTransaction() 103 transactionContext.RollbackTransaction()
101 }() 104 }()
102 105
  106 + var cashPoolRepository domain.CashPoolRepository
  107 + if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
  108 + "transactionContext": transactionContext,
  109 + }); err != nil {
  110 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  111 + } else {
  112 + cashPoolRepository = value
  113 + }
103 114
104 - return nil, nil 115 + cashPool, err := cashPoolRepository.FindOne(map[string]interface{}{})
  116 +
  117 + if err != nil {
  118 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  119 + }
  120 +
  121 + if cashPool == nil {
  122 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCashPoolQuery.CompanyId)))
  123 + } else {
  124 + return cashPool, nil
  125 + }
105 } 126 }
106 127
107 // TODO 返回兑换现金活动 128 // TODO 返回兑换现金活动
@@ -2,6 +2,8 @@ package service @@ -2,6 +2,8 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "time"
  6 +
5 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 9 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -13,7 +15,6 @@ import ( @@ -13,7 +15,6 @@ import (
13 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 15 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
14 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" 16 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
15 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 17 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
16 - "time"  
17 ) 18 )
18 19
19 // 任务服务 20 // 任务服务
@@ -908,16 +909,21 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -908,16 +909,21 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
908 if err := getTaskQuery.ValidateQuery(); err != nil { 909 if err := getTaskQuery.ValidateQuery(); err != nil {
909 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 910 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
910 } 911 }
  912 +
911 transactionContext, err := factory.CreateTransactionContext(nil) 913 transactionContext, err := factory.CreateTransactionContext(nil)
  914 +
912 if err != nil { 915 if err != nil {
913 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 916 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
914 } 917 }
  918 +
915 if err := transactionContext.StartTransaction(); err != nil { 919 if err := transactionContext.StartTransaction(); err != nil {
916 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 920 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
917 } 921 }
  922 +
918 defer func() { 923 defer func() {
919 transactionContext.RollbackTransaction() 924 transactionContext.RollbackTransaction()
920 }() 925 }()
  926 +
921 var taskRepository domain.TaskRepository 927 var taskRepository domain.TaskRepository
922 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 928 if value, err := factory.CreateTaskRepository(map[string]interface{}{
923 "transactionContext": transactionContext, 929 "transactionContext": transactionContext,
@@ -926,14 +932,18 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -926,14 +932,18 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
926 } else { 932 } else {
927 taskRepository = value 933 taskRepository = value
928 } 934 }
  935 +
929 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId}) 936 task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
  937 +
930 if err != nil { 938 if err != nil {
931 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 939 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
932 } 940 }
  941 +
933 if task == nil { 942 if task == nil {
934 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId))) 943 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId)))
935 } else { 944 } else {
936 var projectBelongRepository domain.ProjectBelongRepository 945 var projectBelongRepository domain.ProjectBelongRepository
  946 +
937 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 947 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
938 "transactionContext": transactionContext, 948 "transactionContext": transactionContext,
939 }); err != nil { 949 }); err != nil {
@@ -941,7 +951,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -941,7 +951,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
941 } else { 951 } else {
942 projectBelongRepository = value 952 projectBelongRepository = value
943 } 953 }
  954 +
944 projectBelongMap := make(map[int]*domain.ProjectBelong) 955 projectBelongMap := make(map[int]*domain.ProjectBelong)
  956 +
945 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 957 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
946 "companyId": task.CompanyId, 958 "companyId": task.CompanyId,
947 }); err != nil { 959 }); err != nil {
@@ -951,7 +963,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -951,7 +963,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
951 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 963 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
952 } 964 }
953 } 965 }
  966 +
954 var customerValueRepository domain.CustomerValueRepository 967 var customerValueRepository domain.CustomerValueRepository
  968 +
955 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 969 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
956 "transactionContext": transactionContext, 970 "transactionContext": transactionContext,
957 }); err != nil { 971 }); err != nil {
@@ -959,7 +973,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -959,7 +973,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
959 } else { 973 } else {
960 customerValueRepository = value 974 customerValueRepository = value
961 } 975 }
  976 +
962 customerValueMap := make(map[int]*domain.CustomerValue) 977 customerValueMap := make(map[int]*domain.CustomerValue)
  978 +
963 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 979 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
964 "companyId": task.CompanyId, 980 "companyId": task.CompanyId,
965 }); err != nil { 981 }); err != nil {
@@ -969,7 +985,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -969,7 +985,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
969 customerValueMap[customerValue.CustomerValueId] = customerValue 985 customerValueMap[customerValue.CustomerValueId] = customerValue
970 } 986 }
971 } 987 }
  988 +
972 var taskNatureRepository domain.TaskNatureRepository 989 var taskNatureRepository domain.TaskNatureRepository
  990 +
973 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 991 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
974 "transactionContext": transactionContext, 992 "transactionContext": transactionContext,
975 }); err != nil { 993 }); err != nil {
@@ -977,7 +995,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -977,7 +995,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
977 } else { 995 } else {
978 taskNatureRepository = value 996 taskNatureRepository = value
979 } 997 }
  998 +
980 taskNatureMap := make(map[int]*domain.TaskNature) 999 taskNatureMap := make(map[int]*domain.TaskNature)
  1000 +
981 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 1001 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
982 "companyId": task.CompanyId, 1002 "companyId": task.CompanyId,
983 }); err != nil { 1003 }); err != nil {
@@ -987,13 +1007,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter @@ -987,13 +1007,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
987 taskNatureMap[taskNature.TaskNatureId] = taskNature 1007 taskNatureMap[taskNature.TaskNatureId] = taskNature
988 } 1008 }
989 } 1009 }
  1010 +
990 taskDto := &dto.TaskDto{} 1011 taskDto := &dto.TaskDto{}
  1012 +
991 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil { 1013 if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
992 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1014 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
993 } 1015 }
994 if err := transactionContext.CommitTransaction(); err != nil { 1016 if err := transactionContext.CommitTransaction(); err != nil {
995 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1017 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
996 } 1018 }
  1019 +
997 return taskDto, nil 1020 return taskDto, nil
998 } 1021 }
999 } 1022 }
@@ -117,7 +117,7 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode @@ -117,7 +117,7 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode
117 ExchangedSuMoney: exchangeCashList.ExchangedSuMoney, 117 ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
118 }, nil 118 }, nil
119 } 119 }
120 -func NewExchangeCashListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) { 120 +func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
121 if transactionContext == nil { 121 if transactionContext == nil {
122 return nil, fmt.Errorf("transactionContext参数不能为nil") 122 return nil, fmt.Errorf("transactionContext参数不能为nil")
123 } else { 123 } else {