作者 陈志颖

fix:修复现金池返回错误创建时间问题

... ... @@ -9,7 +9,7 @@ import (
type EmployeesContributionsStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
StartTime time.Time `json:"startTime"` // 年榜开始时间
EndTime time.Time `json:"EndTime"` // 年榜结束时间
EndTime time.Time `json:"endTime"` // 年榜结束时间
}
func (employeesContributionsStatisticsCommand *EmployeesContributionsStatisticsCommand) ValidateCommand() error {
... ...
... ... @@ -10,7 +10,7 @@ import (
type EmployeesSuMoneyStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
StartTime time.Time `json:"startTime"` // 年榜开始时间
EndTime time.Time `json:"EndTime"` // 年榜结束时间
EndTime time.Time `json:"endTime"` // 年榜结束时间
}
func (employeesSuMoneyStatisticsCommand *EmployeesSuMoneyStatisticsCommand) ValidateCommand() error {
... ...
... ... @@ -114,20 +114,6 @@ func (cashPoolService *CashPoolService) UpdateCashPool(updateCashPoolCommand *co
defer func() {
transactionContext.RollbackTransaction()
}()
//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
//}
//
//count, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
// "companyId":
//})
return nil , nil
}
... ... @@ -276,6 +262,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
for _, activity := range activities {
deadlines = append(deadlines, activity.Deadline)
}
if len(deadlines) == 0 {
deadlines = []interface{}{}
}
return map[string]interface{}{
"deadlines": deadlines,
}, nil
... ... @@ -431,19 +420,6 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
}
return activityFound, nil
}
// 返回兑换现金活动
//activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if activityFound == 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 activityFound, nil
//}
}
// 更新兑换现金活动,名称,截止日期、汇率
... ... @@ -497,7 +473,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cashPools == nil {
if len(cashPools) == 0 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
}
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
... ... @@ -521,7 +497,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
// 批量更新兑换清单中已兑换现金值
// 获取兑换清单列表
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -532,7 +507,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
}
_, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
"exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
});
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -627,15 +602,19 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
transactionContext.RollbackTransaction()
}()
// 获取兑换活动兑换汇率
var rate float64
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{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if activity != nil {
rate = activity.Rate
}
rate := activity.Rate
// 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
... ... @@ -645,10 +624,17 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
} else {
employeeRepository = value
}
employee, err := employeeRepository.FindOne(map[string]interface{}{
getEmployee := map[string]interface{}{}
if createExchangeCashPersonCommand.PersonName == "" {
getEmployee = map[string]interface{}{
"uid": createExchangeCashPersonCommand.Uid,
}
} else {
getEmployee = map[string]interface{}{
"account": createExchangeCashPersonCommand.PersonAccount,
})
}
}
employee, err := employeeRepository.FindOne(getEmployee)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -892,6 +878,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
} else {
exchangeCashPersonListRepository = value
}
// TODO 增加总榜单查询
if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -151,17 +151,6 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
systemUnExchangeCash float64
systemExchangedCash float64
)
// 系统已兑换现金
//suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
//if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
// ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash").
// Where("e.company_id = ?", companyId).
// //Where(`e.status = ?`, 1).
// Where(`su_money_transaction_record.record_type = ?`, 5).
// Select(&systemExchangedCash) ; err != nil {
// return nil, err
//}
// 系统未兑换现金
cashPool := new(models.CashPool)
if err := tx.Model(cashPool).
... ... @@ -169,7 +158,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
Where("cash_pool.company_id = ?", companyId).
Order("id DESC").
Limit(1).
Select(&systemUnExchangeCash) ; err != nil {
Select(&systemExchangedCash) ; err != nil {
return nil, err
}
if err := tx.Model(cashPool).
... ... @@ -223,13 +212,12 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
Uid int
EmployeeName string
EmployeesSuMoney float64
//Employee domain.Employee
}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
Column("(su_money_transaction_record.employee->>'employeeName')::text").
ColumnExpr("(su_money_transaction_record.employee->>'uid') AS uid, (su_money_transaction_record.employee->>'employeeName') AS employeeName, sum(su_money_transaction_record.su_money) AS employee_su_money").
//Column("su_money_transaction_record.employee").
//Column("su_money_transaction_record.employee->>'employeeName'").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employee_su_money").
Where(`e.company_id = ?`, companyId).
Where(`e.status = ?`, 1).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
... ... @@ -252,21 +240,16 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime
Uid int
EmployeeName string
EmployeesContributions float64
//Employee domain.Employee
}
var retDecrease []struct { // 员工减少的贡献值
Uid int
EmployeeName string
EmployeesContributions float64
//Employee domain.Employee
}
//var employeesContributionsIncrease []struct{} // 员工增加的贡献值列表
//var employeesContributionsDecrease []struct{} //
//var employeesContributions []struct{}
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
//Column("su_money_transaction_record.employee").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employees_contributions_increase").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
... ... @@ -280,8 +263,8 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime
}
// 减少的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
Column("su_money_transaction_record.employee").
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions_decrease").
//Column("su_money_transaction_record.employee").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employees_contributions_decrease").
Where(`e.company_id = ?`, companyId).
Where(`su_money_transaction_record.record_type = ?`, 4).
Where(`e.status = ?`, 1).
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type SuMoneyTransactionRecord struct {
TableName string `pg:"su_money_transaction_records,alias:su_money_transaction_record"`
TableName string `pg:"su_money_transaction_records,alias:su_money_transaction_record,discard_unknown_columns"`
// 素币事务记录ID
Id int64 `pg:",pk"`
// 记录类型
... ...
... ... @@ -16,9 +16,9 @@ func (repository *CashPoolRepository) Save(cashPool *domain.CashPool) (*domain.C
tx := repository.transactionContext.PgTx
if cashPool.Identity() == nil {
if _, err := tx.QueryOne(
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate),
"INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate); err != nil {
pg.Scan(&cashPool.CashPoolId, &cashPool.Cash, &cashPool.CompanyId, &cashPool.ExchangedCash, &cashPool.UnExchangeCash, &cashPool.ExchangedSuMoney, &cashPool.UnExchangeSuMoney, &cashPool.Rate, &cashPool.CreateTime),
"INSERT INTO cash_pools (cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, cash, company_id, exchanged_cash, un_exchange_cash, exchanged_su_money, un_exchange_su_money, rate, create_time",
cashPool.Cash, cashPool.CompanyId, cashPool.ExchangedCash, cashPool.UnExchangeCash, cashPool.ExchangedSuMoney, cashPool.UnExchangeSuMoney, cashPool.Rate, cashPool.CreateTime); err != nil {
return cashPool, err
}
} else {
... ... @@ -102,6 +102,7 @@ func (repository *CashPoolRepository) transformPgModelToDomainModel(cashPoolMode
ExchangedSuMoney: cashPoolModel.ExchangedSuMoney,
UnExchangeSuMoney: cashPoolModel.UnExchangeSuMoney,
Rate: cashPoolModel.Rate,
CreateTime: cashPoolModel.CreateTime,
}, nil
}
... ...
... ... @@ -103,6 +103,7 @@ func (controller *StatisticsController) SystemCashStatistics() {
controller.ServeJSON()
}
// 员工财富值
func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
... ... @@ -118,6 +119,7 @@ func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
controller.ServeJSON()
}
// 员工贡献值
func (controller *StatisticsController) EmployeesContributionsStatistics() {
statisticsService := service.NewStatisticsService(nil)
employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
... ...