作者 陈志颖

fix:修复兑换清单个人排行

@@ -114,6 +114,10 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -114,6 +114,10 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
114 } 114 }
115 queryPeople = queryPeople.Group("exchange_cash_person_list.uid") 115 queryPeople = queryPeople.Group("exchange_cash_person_list.uid")
116 queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name") 116 queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
  117 +
  118 + // 子清单查询
  119 + queryPeopleWith := queryPeople.Order("su_money DESC")
  120 +
117 if offset, ok := queryOptions["offset"]; ok { 121 if offset, ok := queryOptions["offset"]; ok {
118 offset := offset.(int) 122 offset := offset.(int)
119 if offset > -1 { 123 if offset > -1 {
@@ -130,31 +134,23 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -130,31 +134,23 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
130 } else { 134 } else {
131 queryPeople = queryPeople.Limit(20) 135 queryPeople = queryPeople.Limit(20)
132 } 136 }
133 - //queryPeopleWith := queryPeople.Order("su_money DESC") // 子查询  
134 if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil { 137 if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil {
135 return nil, err 138 return nil, err
136 } 139 }
137 140
138 - // 个人排名  
139 - queryEmployee := tx.Model(exchangeCashPersonListModels)  
140 - queryEmployee = queryEmployee.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")  
141 - queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.uid AS uid")  
142 - queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")  
143 - queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")  
144 - queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")  
145 - queryEmployee = queryEmployee.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")  
146 - if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {  
147 - queryEmployee = queryEmployee.Where("e.company_id = ?", companyId)  
148 - }  
149 - if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) {  
150 - queryEmployee = queryEmployee.Where("exchange_cash_person_list.activity_id = ?", activityId)  
151 - } 141 + // 个人清单排名
  142 + queryEmployee := tx.Model()
  143 + queryEmployee = queryEmployee.With("t", queryPeopleWith)
  144 + queryEmployee = queryEmployee.Table("t")
  145 + queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid")
  146 + queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
  147 + queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash")
  148 + queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money")
  149 + queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking")
152 if uid, ok := queryOptions["uid"]; ok { 150 if uid, ok := queryOptions["uid"]; ok {
153 - queryEmployee = queryEmployee.Where("exchange_cash_person_list.uid = ?", uid) 151 + queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid)
154 } 152 }
155 - queryEmployee = queryEmployee.Group("exchange_cash_person_list.uid")  
156 - queryEmployee = queryEmployee.Group("exchange_cash_person_list.employee_name")  
157 - if err := queryEmployee.Order("su_money DESC").Select(&retEmployee); err != nil { 153 + if err := queryEmployee.Select(&retEmployee); err != nil {
158 return nil, err 154 return nil, err
159 } 155 }
160 var currentEmployee interface{} 156 var currentEmployee interface{}
@@ -365,7 +365,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -365,7 +365,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
365 queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime) 365 queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
366 } 366 }
367 queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 367 queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
368 - queryWealthWith := queryWealth.Order("employee_su_money DESC") // 个人财富值子查询 368 +
  369 + // 个人财富值子查询
  370 + queryWealthWith := queryWealth.Order("employee_su_money DESC")
  371 +
369 if offset, ok := queryOptions["offset"]; ok { 372 if offset, ok := queryOptions["offset"]; ok {
370 offset := offset.(int) 373 offset := offset.(int)
371 if offset > -1 { 374 if offset > -1 {
@@ -450,7 +453,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -450,7 +453,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
450 queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime) 453 queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
451 } 454 }
452 queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease") 455 queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
453 - //queryContributionsWith := queryContributions.Order("employees_contributions DESC") // 个人贡献值子查询 456 +
  457 + // 个人贡献值子查询
  458 + queryContributionsWith := queryContributions.Order("employees_contributions DESC")
  459 +
454 if offset, ok := queryOptions["offset"]; ok { 460 if offset, ok := queryOptions["offset"]; ok {
455 offset := offset.(int) 461 offset := offset.(int)
456 if offset > -1 { 462 if offset > -1 {
@@ -471,52 +477,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -471,52 +477,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
471 return nil, err 477 return nil, err
472 } 478 }
473 479
474 - // 个人贡献值子查询-减少的贡献值排名  
475 - queryEmployeeContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)  
476 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")  
477 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")  
478 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")  
479 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")  
480 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")  
481 - if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {  
482 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where("e.company_id = ?", companyId)  
483 - }  
484 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`e.status = ?`, 1)  
485 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)  
486 - if startTime, ok := queryOptions["startTime"]; ok {  
487 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)  
488 - }  
489 - if endTime, ok := queryOptions["endTime"]; ok {  
490 - queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)  
491 - }  
492 - employeeContributionsDecrease := queryEmployeeContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")  
493 -  
494 - // 个人贡献值排名 480 + // 个人贡献值
495 queryEmployeeContributions := tx.Model() 481 queryEmployeeContributions := tx.Model()
496 - queryEmployeeContributions = queryEmployeeContributions.With("t", employeeContributionsDecrease) 482 + queryEmployeeContributions = queryEmployeeContributions.With("t", queryContributionsWith)
497 queryEmployeeContributions = queryEmployeeContributions.Table("t") 483 queryEmployeeContributions = queryEmployeeContributions.Table("t")
498 - queryEmployeeContributions = queryEmployeeContributions.Table("su_money_transaction_records")  
499 - queryEmployeeContributions = queryEmployeeContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")  
500 - queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")  
501 - queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")  
502 - queryEmployeeContributions = queryEmployeeContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)  
503 - queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")  
504 - if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {  
505 - queryEmployeeContributions = queryContributions.Where("e.company_id = ?", companyId)  
506 - }  
507 - queryEmployeeContributions = queryEmployeeContributions.Where(`e.status = ?`, 1)  
508 - queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))  
509 - if startTime, ok := queryOptions["startTime"]; ok {  
510 - queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.create_time > ?`, startTime)  
511 - }  
512 - if endTime, ok := queryOptions["endTime"]; ok {  
513 - queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)  
514 - } 484 + queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.uid AS uid")
  485 + queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.employee_name AS employee_name")
  486 + queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.employees_contributions AS employees_contributions")
  487 + queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.ranking AS ranking")
515 if uid, ok := queryOptions["uid"]; ok { 488 if uid, ok := queryOptions["uid"]; ok {
516 - queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.employee @> '{"uid":?}'`, uid) 489 + queryEmployeeContributions = queryEmployeeContributions.Where("t.uid::bigint = ?", uid)
517 } 490 }
518 - queryEmployeeContributions = queryEmployeeContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")  
519 - if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil { 491 + if err := queryEmployeeContributions.Select(&retEmployeeContributions); err != nil {
520 return nil, err 492 return nil, err
521 } 493 }
522 var retCurrentEmployeeContributions interface{} 494 var retCurrentEmployeeContributions interface{}