作者 陈志颖

fix:调整统计

... ... @@ -384,46 +384,6 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp
}
}
// 员工排行榜统计 (弃用)
//func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {
// if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, err.Error())
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// var employeeDao *dao.EmployeeDao
// if value, err := factory.CreateEmployeeDao(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// } else {
// employeeDao = value
// }
//
// if employeesRankingListStatisticsCommand.StartTime.IsZero() && employeesRankingListStatisticsCommand.EndTime.IsZero() {
// employeesRankingListStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
// employeesRankingListStatisticsCommand.EndTime = time.Now().Local()
// }
//
// if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); 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 employeesRankingListStatistics, nil
// }
//}
// 贡献值、财富值榜单
func (statisticsService *StatisticsService) ContributionsWealthRanking(contributionsWealthRankingQuery *query.ContributionsWealthRankingQuery) (interface{}, error) {
if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil {
... ...
... ... @@ -184,7 +184,7 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
}
}
// 素币事务记录统计
// 素币事务记录统计(个人素币)
func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) {
if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -219,7 +219,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
}
}
// 贡献值事务记录统计
// 贡献值事务记录统计(个人贡献值)
func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand *command.ContributionsTransactionRecordStatisticsCommand) (interface{}, error) {
if err := contributionsTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ...
... ... @@ -98,17 +98,17 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
yesterday := time.Now().AddDate(0, 0, -1)
// 昨日收益
// 昨日收益
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
Select(&incomeSuMoneyOfYesterday); err != nil {
return nil, err
}
// 昨日支出
// 昨日支出
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -122,7 +122,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
Select(&incomeSuMoney); err != nil {
return nil, err
}
... ... @@ -180,7 +180,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
},nil
}
// 计算系统已兑换现金、未兑换现金
// 计算现金池已兑换现金、未兑换现金
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
tx := dao.transactionContext.PgTx
var (
... ... @@ -220,7 +220,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 收入素币
// 收入素币
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -230,7 +230,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
Select(&incomeSuMoney); err != nil {
return nil, err
}
// 支出素币
// 支出素币
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -241,20 +241,20 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
return nil, err
}
return map[string]interface{}{
"incomeSuMoney": incomeSuMoney,
"expendSuMoney": expendSuMoney,
"incomeSuMoney": incomeSuMoney - expendSuMoney, // 个人素币盈利
"expendSuMoney": expendSuMoney, // 个人素币支出
}, nil
}
// 计算个人贡献值收支
func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
var (
incomeContributions float64 // 增加的贡献值(2:任务奖励,3:增加)
expendContributions float64 // 扣除的贡献值 (4: 扣除)
incomeContributions float64 // 收入的贡献值(2:任务奖励,3:增加)
expendContributions float64 // 支出的贡献值 (4: 扣除)
)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 增加的贡献值
// 总收入的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -264,7 +264,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
Select(&incomeContributions); err != nil {
return nil, err
}
// 扣除的贡献值
// 总支出的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -275,8 +275,8 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
return nil, err
}
return map[string]interface{}{
"incomeContributions": incomeContributions,
"expendContributions": expendContributions,
"incomeContributions": incomeContributions - expendContributions, // 个人贡献值盈利
"expendContributions": expendContributions, // 个人贡献支出
}, nil
}
... ...