作者 陈志颖

feat:修改现金池服务

... ... @@ -118,3 +118,5 @@ func CreateInputCashPoolService(options map[string]interface{}) (service.InputCa
return domainService.NewCashPoolService(transactionContext)
}
... ...
... ... @@ -85,3 +85,27 @@ func CreateSentNotificationRepository(options map[string]interface{}) (domain.Se
}
return repository.NewSentNotificationRepository(transactionContext)
}
func CreateCashPoolRepository(options map[string]interface{}) (domain.CashPoolRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCashPoolRepository(transactionContext)
}
func CreateExchangeCashActivityRepository(options map[string]interface{}) (domain.ExchangeActivityRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewExchangeCashActivityRepository(transactionContext)
}
func CreateExchangeCashPersonListRepository(options map[string]interface{}) (domain.ExchangeCashPersonListRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewExchangeCashPersonListRepository(transactionContext)
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
)
... ... @@ -80,7 +83,7 @@ func (cashPoolService *CashPoolService) OperationCashPool(createCashPoolCommand
}
}
// TODO 返回现金池
// 返回现金池
func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
if err := getCashPoolQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -100,8 +103,26 @@ func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCash
transactionContext.RollbackTransaction()
}()
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cashPoolRepository = value
}
return nil, nil
cashPool, err := cashPoolRepository.FindOne(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cashPool == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCashPoolQuery.CompanyId)))
} else {
return cashPool, nil
}
}
// TODO 返回兑换现金活动
... ...
... ... @@ -2,6 +2,8 @@ package service
import (
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
... ... @@ -13,7 +15,6 @@ import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"time"
)
// 任务服务
... ... @@ -908,16 +909,21 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
if err := getTaskQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -926,14 +932,18 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
taskRepository = value
}
task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if task == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId)))
} else {
var projectBelongRepository domain.ProjectBelongRepository
if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -941,7 +951,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
projectBelongRepository = value
}
projectBelongMap := make(map[int]*domain.ProjectBelong)
if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -951,7 +963,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
}
}
var customerValueRepository domain.CustomerValueRepository
if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -959,7 +973,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
customerValueRepository = value
}
customerValueMap := make(map[int]*domain.CustomerValue)
if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -969,7 +985,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
customerValueMap[customerValue.CustomerValueId] = customerValue
}
}
var taskNatureRepository domain.TaskNatureRepository
if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -977,7 +995,9 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
} else {
taskNatureRepository = value
}
taskNatureMap := make(map[int]*domain.TaskNature)
if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
}); err != nil {
... ... @@ -987,13 +1007,16 @@ func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (inter
taskNatureMap[taskNature.TaskNatureId] = taskNature
}
}
taskDto := &dto.TaskDto{}
if err := taskDto.LoadDto(task, projectBelongMap, customerValueMap, taskNatureMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return taskDto, nil
}
}
... ...
... ... @@ -117,7 +117,7 @@ func (repository *ExchangeCashPersonListRepository) transformPgModelToDomainMode
ExchangedSuMoney: exchangeCashList.ExchangedSuMoney,
}, nil
}
func NewExchangeCashListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
func NewExchangeCashPersonListRepository(transactionContext *pgTransaction.TransactionContext) (*ExchangeCashPersonListRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
... ...