作者 陈志颖

fix:新增素币兑换清单时增加更新现金池

... ... @@ -373,12 +373,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
ExchangeCashActivityId: activity.ActivityId,
//ExchangeActivityName: activity.ExchangeActivityName,
//Deadline: activity.Deadline,
CountDown: int64(t2.Sub(t1).Hours() / 24),
//ExchangedSuMoney: activity.ExchangedSuMoney,
//ExchangedCash: activity.ExchangedCash,
//ExchangeRate: activity.Rate,
}
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -485,6 +480,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
// TODO 批量更新兑换清单中已兑换现金值
// 计算系统平均兑换汇率并更新现金池
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
... ... @@ -518,10 +515,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
} else {
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
}
// TODO 更新现金池
// 更新现金池
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
ExchangedCash: systemExchangedCash,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
Rate: rate,
}
... ... @@ -535,10 +532,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// TODO 批量更新兑换清单中已兑换现金值
}
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -672,7 +666,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if activityUpdated == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
}
// 判断清单中现金总额超过平台未兑换现金
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
... ... @@ -690,6 +683,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
}
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -699,12 +693,68 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
employeeDao = value
}
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
// TODO 更新现金池
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
// 更新现金池
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
}
// 获取现金池
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": activity.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cashPools == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
}
// 平均兑换汇率
var newRate float64
if systemExchangedSuMoney == 0 {
newRate = 0
} else {
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
}
// 更新现金池
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
Rate: newRate,
}
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cashPoolUpdated == 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())
}
... ...