...
|
...
|
@@ -2,13 +2,14 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"time"
|
|
|
|
|
|
"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"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -16,93 +17,104 @@ import ( |
|
|
type CashPoolService struct {
|
|
|
}
|
|
|
|
|
|
// 投入现金
|
|
|
func (cashPoolService *CashPoolService) OperationCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
|
|
|
// 投入现金池
|
|
|
func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *command.CreateCashPoolCommand) (interface{}, error) {
|
|
|
// 校验命令
|
|
|
if err := createCashPoolCommand.ValidateCommand(); 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 employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
// 新建现金池数据访问对象
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
// 获取系统已兑换现金值
|
|
|
var systemExchangedCash float64
|
|
|
if value, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
|
|
|
if value, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
systemExchangedCash = value
|
|
|
}
|
|
|
|
|
|
// 获取系统素币兑换情况
|
|
|
var (
|
|
|
systemChangedSuMoney float64
|
|
|
systemUnChangeSuMoney float64
|
|
|
)
|
|
|
if value1, value2, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId); err != nil {
|
|
|
if value1, value2, err := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
systemChangedSuMoney = value1
|
|
|
systemUnChangeSuMoney = value2
|
|
|
}
|
|
|
|
|
|
var inputCashPoolService service.InputCashPoolService
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
UnExchangeCash: 0,
|
|
|
ExchangedSuMoney: systemChangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnChangeSuMoney,
|
|
|
Rate: 0,
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
if value, err := factory.CreateInputCashPoolService(map[string]interface{}{
|
|
|
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 {
|
|
|
inputCashPoolService = value
|
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
if task, err := inputCashPoolService.Input(createCashPoolCommand.CompanyId, createCashPoolCommand.Operator, createCashPoolCommand.Cash, systemChangedSuMoney, systemUnChangeSuMoney, systemExchangedCash); err != nil {
|
|
|
if activity, err := cashPoolRepository.Save(newCashPool); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return task, nil
|
|
|
return activity, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回现金池
|
|
|
func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
|
|
|
func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetCashPoolQuery) (interface{}, error) {
|
|
|
if err := getCashPoolQuery.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 cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -111,274 +123,457 @@ func (cashPoolService *CashPoolService) CashPool(getCashPoolQuery *query.GetCash |
|
|
} else {
|
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
cashPool, err := cashPoolRepository.FindOne(map[string]interface{}{})
|
|
|
|
|
|
if err != nil {
|
|
|
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); 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
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"cashPools": cashPools,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 返回兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
|
|
|
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
|
|
|
// 新增兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
|
|
|
// 校验新增任务命令
|
|
|
if err := createExchangeCashActivityCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// TODO 新增兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
|
|
|
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
// 创建兑换活动
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
|
|
ExchangedCash: createExchangeCashActivityCommand.ExchangedCash,
|
|
|
ExchangedSuMoney: createExchangeCashActivityCommand.ExchangedSuMoney,
|
|
|
Deadline: createExchangeCashActivityCommand.Deadline,
|
|
|
CountDown: createExchangeCashActivityCommand.CountDown,
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
// 兑换活动资源库
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
return activity, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 返回兑换现金活动列表
|
|
|
func (cashPoolService *CashPoolService) ExchangeCashActivityList(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
|
|
|
// 返回兑换现金活动列表
|
|
|
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
|
|
|
if err := listExchangeCashActivityQuery.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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
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
|
|
|
}
|
|
|
|
|
|
if count, activities, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"activities": activities,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 移除兑换现金活动
|
|
|
// 移除兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchangeCashActivityCommand *command.RemoveExchangeCashActivityCommand) (interface{}, error) {
|
|
|
if err := removeExchangeCashActivityCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activityDeleted, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 返回兑换现金活动
|
|
|
// 返回兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashActivityQuery *query.GetExchangeCashActivityQuery) (interface{}, error) {
|
|
|
if err := getExchangeCashActivityQuery.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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activity, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 更新兑换现金活动
|
|
|
// 更新兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchangeCashActivityCommand *command.UpdateExchangeCashActivityCommand) (interface{}, error) {
|
|
|
if err := updateExchangeCashActivityCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 新建兑换现金人员
|
|
|
// 新建兑换现金人员
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := createExchangeCashPersonCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
// 创建兑换清单
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
CompanyId: createExchangeCashPersonCommand.ExchangeCashPerson.CompanyId,
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangeCashPerson: createExchangeCashPersonCommand.ExchangeCashPerson,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedCash,
|
|
|
}
|
|
|
|
|
|
// 兑换活动资源库
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 返回兑换现金人员
|
|
|
// 返回兑换现金人员
|
|
|
func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPersonQuery *query.GetExchangeCashPersonQuery) (interface{}, error) {
|
|
|
if err := getExchangeCashPersonQuery.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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": getExchangeCashPersonQuery.ExchangeCashPersonId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashPersonQuery.ExchangeCashPersonId)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 返回兑换现金人员列表
|
|
|
// 返回兑换现金人员列表
|
|
|
func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) {
|
|
|
if err := listExchangeCashPersonQuery.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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
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
|
|
|
}
|
|
|
|
|
|
if count, people, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"people": people,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 移除兑换现金人员
|
|
|
// 移除兑换现金人员
|
|
|
func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := removeExchangeCashPersonCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
return nil, nil
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": removeExchangeCashPersonCommand.ExchangeCashPersonId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ExchangeCashPersonId)))
|
|
|
}
|
|
|
|
|
|
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personDeleted, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 更新兑换现金人员
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := updateExchangeCashCommand.ValidateCommand(); err != nil {
|
|
|
// 更新兑换现金人员
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := updateExchangeCashPersonCommand.ValidateCommand(); 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()
|
|
|
}()
|
|
|
|
|
|
// TODO 新增流水记录
|
|
|
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
return nil, nil
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"personId": updateExchangeCashPersonCommand.ExchangeCashPersonId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ExchangeCashPersonId)))
|
|
|
}
|
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func NewCashPoolService(options map[string]interface{}) *CashPoolService {
|
...
|
...
|
|