作者 陈志颖

feat:员工贡献值、财富值排行榜增加分页

... ... @@ -10,7 +10,8 @@ type EmployeesRankingListStatisticsCommand struct {
CompanyId int `json:"companyId" valid:"Required"` // 公司id
StartTime time.Time `json:"startTime"` // 年榜开始时间
EndTime time.Time `json:"endTime"` // 年榜结束时间
Offset int `json:"offset,omitempty"` // 查询偏离量
Limit int `json:"limit,omitempty"` // 查询限制
}
func (employeesRankingListStatisticsCommand *EmployeesRankingListStatisticsCommand) ValidateCommand() error {
... ...
... ... @@ -391,7 +391,7 @@ func (statisticsService *StatisticsService) EmployeesRankingListStatistics(emplo
employeesRankingListStatisticsCommand.EndTime = time.Now().Local()
}
if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime); err != nil {
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 {
... ...
... ... @@ -1042,7 +1042,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
exchangeActivityRepository = value
}
if _, activities, err := exchangeActivityRepository.Find(map[string]interface{}{
// TODO 需要改为获取所有活动,去除分页
if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
"companyId": listExchangeCashPersonQuery.CompanyId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -283,8 +283,8 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
// }, nil
//}
// 排行榜统计
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
// TODO 排行榜统计,增加分页
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
var retWealth []struct {
Uid int
EmployeeName string
... ... @@ -302,6 +302,12 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if limit < -1 {
limit = 20
}
if offset < -1 {
offset = 0
}
// 员工财富值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
... ... @@ -314,6 +320,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employee_su_money DESC").
Limit(limit).
Offset(offset).
Select(&retWealth); err != nil {
return nil, err
}
... ... @@ -329,6 +337,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Limit(limit).
Offset(offset).
Select(&retContributions); err != nil {
return nil, err
}
... ... @@ -344,6 +354,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
Where(`su_money_transaction_record.create_time < ?`, endTime).
Group("su_money_transaction_record.employee").
Order("employees_contributions DESC").
Limit(limit).
Offset(offset).
Select(&retContributionDecrease); err != nil {
return nil, err
}
... ...