作者 陈志颖

fix:增加新增兑换素币清单时对员工的判断

... ... @@ -21,6 +21,7 @@ func (configService *ConfigService) ListTaskStatus(listTaskStatusQuery *query.Li
4: "待验收",
5: "已完成",
7: "待确认",
8: "已过期",
}
var list []map[string]interface{}
for key, value := range taskStatusMap {
... ...
... ... @@ -6,12 +6,16 @@ import (
)
type UpdateCashPoolCommand struct {
CashPoolId int64 `json:"cashPoolId"` // 现金池编号
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金
UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换素币
Rate float64 `json:"rate"` // 平均兑换汇率
CashPoolId int64 `json:"cashPoolId"` // 现金池编号
ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金
UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换素币
Rate float64 `json:"rate"` // 平均兑换汇率
Cash float64 `json:"cash"`
//CompanyId int64 `json:"companyId"`
LastRate float64 `json:"lastRate"`
//CreateTime time.Time `json:"createTime"`
}
func (updateCashPoolCommand *UpdateCashPoolCommand) ValidateCommand() error {
... ...
... ... @@ -99,6 +99,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
UnExchangeCash: createCashPoolCommand.Cash,
ExchangedSuMoney: 0,
UnExchangeSuMoney: systemUnExchangeSuMoney,
LastRate: 0,
Rate: 0,
CreateTime: time.Now(),
}
... ... @@ -123,6 +124,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: cashPools[0].Rate,
LastRate: cashPools[0].LastRate,
CreateTime: time.Now(),
}
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
... ... @@ -610,11 +612,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
}
//var timeNow = time.Now()
//var deadline = activityFound.Deadline
//var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
var t1 = time.Now()
//var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
var t2 = activityFound.Deadline
// 更新兑换现金活动倒计时命令
... ... @@ -790,6 +788,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// 获取平台现金状况
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
... ... @@ -812,14 +811,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
Rate: rate,
CashPoolId: cashPoolsFound[0].CashPoolId,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: rate,
}
fmt.Printf("更新现金池命令:%+v\n", updateCashPoolCommand)
// 更新现金池
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -854,8 +853,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
// 更新兑换活动命令已兑换素币
updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
fmt.Printf("更新兑换活动命令:%+v\n", updateExchangeCashActivityCommand)
// 更新兑换活动
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -868,7 +865,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activityUpdated, nil
}
}
... ... @@ -970,10 +966,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if createExchangeCashPersonCommand.PersonAccount == "" {
getEmployee = map[string]interface{}{
"uid": createExchangeCashPersonCommand.Uid,
"companyId": activityFound.CompanyId,
}
} else {
getEmployee = map[string]interface{}{
"account": createExchangeCashPersonCommand.PersonAccount,
"companyId": activityFound.CompanyId,
}
}
... ... @@ -1030,6 +1028,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
// 更新兑换活动命令
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
ExchangeActivityName: activityFound.ExchangeActivityName,
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
Deadline: activityFound.Deadline,
... ... @@ -1052,7 +1051,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
}
// 获取兑换活动素币兑换情况
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId)
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1110,11 +1109,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
Cash: cashPoolsFound[0].Cash,
//CompanyId: cashPoolsFound[0].CompanyId,
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: newRate,
LastRate: cashPoolsFound[0].LastRate,
//CreateTime: time.Now(),
}
// 更新现金池
... ... @@ -1459,17 +1462,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
}
// 重新获取系统现金兑换情况
//newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if newSystemCashStatistics == nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
//}
//newSystemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
//newSystemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
// 获取当前现金池
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": activityUpdated.CompanyId,
... ... @@ -1497,6 +1489,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
Rate: newRate,
ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
UnExchangeSuMoney: systemUnExchangeSuMoney,
LastRate: cashPoolsFound[0].LastRate,
//CompanyId: cashPoolsFound[0].CompanyId,
//CreateTime: time.Now(),
}
// 更新现金池
... ... @@ -1743,6 +1738,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
transactionContext.RollbackTransaction()
}()
// 兑换素币清单仓储初始化
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1752,10 +1748,11 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
exchangeCashPersonListRepository = value
}
if len(exportExchangeCashListCommand.IDs) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
}
//if len(exportExchangeCashListCommand.IDs) == 0 {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
//}
// 获取兑换清单
if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1782,6 +1779,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
transactionContext.RollbackTransaction()
}()
// 现金池DAO初始化
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1791,6 +1789,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
cashPoolDao = value
}
// 素币兑换清单榜单
if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -177,7 +177,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
systemUnExchangeCash float64
systemExchangedCash float64
)
// 系统兑换现金
// 系统兑换现金
cashPool := new(models.CashPool)
if err := tx.Model(cashPool).
Column("exchanged_cash").
... ... @@ -187,6 +187,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
Select(&systemExchangedCash) ; err != nil {
return nil, err
}
// 系统未兑换现金
if err := tx.Model(cashPool).
Column("un_exchange_cash").
Where("cash_pool.company_id = ?", companyId).
... ...
... ... @@ -66,6 +66,10 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
if account, ok := queryOptions["account"]; ok {
query = query.Where("employee.employee_account = ?", account)
}
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("employee.company_id = ?", companyId)
}
query = query.Where(`employee.status = ?`, 1)
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此员工")
... ...