...
|
...
|
@@ -3,7 +3,6 @@ package service |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
...
|
...
|
@@ -11,7 +10,6 @@ import ( |
|
|
"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/infrastructure/dao"
|
|
|
)
|
|
|
|
|
|
// 现金池服务
|
...
|
...
|
@@ -33,33 +31,28 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
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 {
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
var (
|
|
|
systemExchangedCash float64
|
|
|
systemUnExchangeCash float64
|
|
|
)
|
|
|
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 := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
systemChangedSuMoney = value1
|
|
|
systemUnChangeSuMoney = value2
|
|
|
}
|
|
|
|
|
|
// TODO 判断公司是否存在
|
|
|
//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 {
|
|
|
// cashPoolDao = value
|
|
|
//}
|
|
|
|
|
|
var systemUnExchangeCash float64
|
|
|
|
|
|
//systemExchangedCash, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
|
|
|
//systemChangedSuMoney, systemUnChangeSuMoney, err := cashPoolDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
...
|
...
|
@@ -83,15 +76,19 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
// systemUnExchangeCash = cashPools[0].UnExchangeCash
|
|
|
//}
|
|
|
|
|
|
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
|
|
|
//rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
//ExchangedCash: systemExchangedCash,
|
|
|
ExchangedCash: 0,
|
|
|
UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash,
|
|
|
ExchangedSuMoney: systemChangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnChangeSuMoney,
|
|
|
Rate: rate,
|
|
|
//ExchangedSuMoney: systemChangedSuMoney,
|
|
|
ExchangedSuMoney: 0,
|
|
|
//UnExchangeSuMoney: systemUnChangeSuMoney,
|
|
|
UnExchangeSuMoney: 0,
|
|
|
//Rate: rate,
|
|
|
Rate: 0,
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
|
...
|
...
|
@@ -142,10 +139,21 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
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 初始状态下,现金池返回默认值
|
|
|
if count == 0 {
|
|
|
return map[string]interface{}{
|
|
|
"cashPoolId": 4,
|
|
|
"cash": 0,
|
|
|
"companyId": 101,
|
|
|
"exchangedCash": 100,
|
|
|
"unExchangeCash": 1001,
|
|
|
"exchangedSuMoney": 50,
|
|
|
"unExchangeSuMoney": 11,
|
|
|
"rate": 2,
|
|
|
"createTime": "2020-11-03T17:23:00.848676+08:00",
|
|
|
}, nil
|
|
|
}
|
|
|
return cashPools[0], nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|