作者 陈志颖

test:测试现金池

... ... @@ -1266,8 +1266,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
}
fmt.Print(person.EmployeeInfo.Uid, "\n")
var exchangeCashActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1354,7 +1352,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
// 获取平台素币状况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
... ... @@ -1398,10 +1396,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
ExchangedCash: systemExchangedCash - person.ExchangedCash,
UnExchangeCash: systemUnExchangeCash + person.ExchangedCash,
ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
Rate: newRate,
ExchangedSuMoney: systemExchangedSuMoney - person.ExchangedSuMoney,
ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
}
... ... @@ -1481,15 +1479,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
}
// 更新兑换清单,个人已兑换现金计算
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
fmt.Print(updateExchangeCashPersonCommand.ExchangedCash, "\n")
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
ExchangeCashActivityId: person.ExchangeCashActivityId,
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
... ... @@ -1499,11 +1488,56 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
ExchangeRate: activityFound.Rate,
}
// 更新兑换清单,个人已兑换现金计算
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
personUpdated, err := exchangeCashPersonListRepository.Save(person)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新员工素币,生成素币兑换流水记录
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyService = value
}
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: updateExchangeCashPersonCommand.Operator,
SuMoney: 0,
OperationType: 0,
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
}
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 1
} else {
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 3
}
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
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(operationSuMoneyCommand.Uid)))
}
// 更新兑换活动
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -1512,6 +1546,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
}
// 更新现金池
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1543,44 +1578,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
}
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
// 判断是否超过平台未兑换现金
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
Uid: person.EmployeeInfo.Uid,
Operator: updateExchangeCashPersonCommand.Operator,
SuMoney: 0,
OperationType: 0,
OperationDescription: activityUpdated.ExchangeActivityName + "素币调整",
}
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 1
} else {
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
operationSuMoneyCommand.OperationType = 3
}
var operationSuMoneyService service.OperationSuMoneyService
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operationSuMoneyService = value
}
// 更新员工素币,生成素币兑换流水记录
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
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(operationSuMoneyCommand.Uid)))
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
// 判断是否超过平台未兑换现金
if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
// 重新获取系统现金兑换情况
... ... @@ -1593,7 +1600,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
}
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
//systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
// 获取平台素币状况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
... ... @@ -1637,10 +1644,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
Rate: newRate,
ExchangedSuMoney: systemExchangedSuMoney,
ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
UnExchangeSuMoney: systemUnExchangeSuMoney,
}
... ... @@ -1656,15 +1663,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_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
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return personUpdated, nil
}
// 根据id获取兑换清单
... ...
... ... @@ -23,6 +23,7 @@ type CashPoolRepository interface {
}
func (cashPool *CashPool) Update(data map[string]interface{}) error {
if exchangedCash, ok := data["exchangedCash"]; ok {
cashPool.ExchangedCash = exchangedCash.(float64)
}
... ...