作者 陈志颖

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

@@ -10,7 +10,8 @@ type EmployeesRankingListStatisticsCommand struct { @@ -10,7 +10,8 @@ type EmployeesRankingListStatisticsCommand struct {
10 CompanyId int `json:"companyId" valid:"Required"` // 公司id 10 CompanyId int `json:"companyId" valid:"Required"` // 公司id
11 StartTime time.Time `json:"startTime"` // 年榜开始时间 11 StartTime time.Time `json:"startTime"` // 年榜开始时间
12 EndTime time.Time `json:"endTime"` // 年榜结束时间 12 EndTime time.Time `json:"endTime"` // 年榜结束时间
13 - 13 + Offset int `json:"offset,omitempty"` // 查询偏离量
  14 + Limit int `json:"limit,omitempty"` // 查询限制
14 } 15 }
15 16
16 func (employeesRankingListStatisticsCommand *EmployeesRankingListStatisticsCommand) ValidateCommand() error { 17 func (employeesRankingListStatisticsCommand *EmployeesRankingListStatisticsCommand) ValidateCommand() error {
@@ -391,7 +391,7 @@ func (statisticsService *StatisticsService) EmployeesRankingListStatistics(emplo @@ -391,7 +391,7 @@ func (statisticsService *StatisticsService) EmployeesRankingListStatistics(emplo
391 employeesRankingListStatisticsCommand.EndTime = time.Now().Local() 391 employeesRankingListStatisticsCommand.EndTime = time.Now().Local()
392 } 392 }
393 393
394 - if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime); err != nil { 394 + if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); err != nil {
395 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 395 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
396 } else { 396 } else {
397 if err := transactionContext.CommitTransaction(); err != nil { 397 if err := transactionContext.CommitTransaction(); err != nil {
@@ -1042,7 +1042,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1042,7 +1042,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1042 exchangeActivityRepository = value 1042 exchangeActivityRepository = value
1043 } 1043 }
1044 1044
1045 - if _, activities, err := exchangeActivityRepository.Find(map[string]interface{}{ 1045 + // TODO 需要改为获取所有活动,去除分页
  1046 + if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
1046 "companyId": listExchangeCashPersonQuery.CompanyId, 1047 "companyId": listExchangeCashPersonQuery.CompanyId,
1047 }); err != nil { 1048 }); err != nil {
1048 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1049 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -283,8 +283,8 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. @@ -283,8 +283,8 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
283 // }, nil 283 // }, nil
284 //} 284 //}
285 285
286 -// 排行榜统计  
287 -func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) { 286 +// TODO 排行榜统计,增加分页
  287 +func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
288 var retWealth []struct { 288 var retWealth []struct {
289 Uid int 289 Uid int
290 EmployeeName string 290 EmployeeName string
@@ -302,6 +302,12 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t @@ -302,6 +302,12 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
302 } 302 }
303 tx := dao.transactionContext.PgTx 303 tx := dao.transactionContext.PgTx
304 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 304 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  305 + if limit < -1 {
  306 + limit = 20
  307 + }
  308 + if offset < -1 {
  309 + offset = 0
  310 + }
305 // 员工财富值 311 // 员工财富值
306 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). 312 if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
307 ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid"). 313 ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
@@ -314,6 +320,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t @@ -314,6 +320,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
314 Where(`su_money_transaction_record.create_time < ?`, endTime). 320 Where(`su_money_transaction_record.create_time < ?`, endTime).
315 Group("su_money_transaction_record.employee"). 321 Group("su_money_transaction_record.employee").
316 Order("employee_su_money DESC"). 322 Order("employee_su_money DESC").
  323 + Limit(limit).
  324 + Offset(offset).
317 Select(&retWealth); err != nil { 325 Select(&retWealth); err != nil {
318 return nil, err 326 return nil, err
319 } 327 }
@@ -329,6 +337,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t @@ -329,6 +337,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
329 Where(`su_money_transaction_record.create_time < ?`, endTime). 337 Where(`su_money_transaction_record.create_time < ?`, endTime).
330 Group("su_money_transaction_record.employee"). 338 Group("su_money_transaction_record.employee").
331 Order("employees_contributions DESC"). 339 Order("employees_contributions DESC").
  340 + Limit(limit).
  341 + Offset(offset).
332 Select(&retContributions); err != nil { 342 Select(&retContributions); err != nil {
333 return nil, err 343 return nil, err
334 } 344 }
@@ -344,6 +354,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t @@ -344,6 +354,8 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t
344 Where(`su_money_transaction_record.create_time < ?`, endTime). 354 Where(`su_money_transaction_record.create_time < ?`, endTime).
345 Group("su_money_transaction_record.employee"). 355 Group("su_money_transaction_record.employee").
346 Order("employees_contributions DESC"). 356 Order("employees_contributions DESC").
  357 + Limit(limit).
  358 + Offset(offset).
347 Select(&retContributionDecrease); err != nil { 359 Select(&retContributionDecrease); err != nil {
348 return nil, err 360 return nil, err
349 } 361 }