作者 陈志颖

fix:排行榜

@@ -330,3 +330,39 @@ @@ -330,3 +330,39 @@
330 } 330 }
331 2020/11/22 13:42:13.250 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606023732727892000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},"employeesContributions":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeesContributions":88000,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeesContributions":7132,"Ranking":3},{"Uid":3259769336137728,"EmployeeName":"杨志358","EmployeesContributions":3209.8,"Ranking":4},{"Uid":3259769336383488,"EmployeeName":"张三","EmployeesContributions":-10000,"Ranking":5}],"employeesWealth":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":71773,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeeSuMoney 331 2020/11/22 13:42:13.250 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606023732727892000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},"employeesContributions":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeesContributions":88000,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeesContributions":7132,"Ranking":3},{"Uid":3259769336137728,"EmployeeName":"杨志358","EmployeesContributions":3209.8,"Ranking":4},{"Uid":3259769336383488,"EmployeeName":"张三","EmployeesContributions":-10000,"Ranking":5}],"employeesWealth":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":71773,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeeSuMoney
332 2020/11/22 13:42:13.251 [D] [server.go:1925] | 127.0.0.1| 200 | 523.811858ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list 332 2020/11/22 13:42:13.251 [D] [server.go:1925] | 127.0.0.1| 200 | 523.811858ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  333 +2020/11/22 13:51:35.028 [I] [???:0] http server Running on http://:8082
  334 +2020/11/22 13:51:39.531 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024299531630000
  335 + Auth=
  336 + BodyData:{
  337 + "companyId": 381,
  338 + "uid": 3259769336174592,
  339 + "rankingType": 1,
  340 + "offset": 0,
  341 + "limit": 20
  342 +}
  343 +2020/11/22 13:51:39.656 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606024299531630000 BodyData:{"code":501,"msg":"内部服务出错:ERROR #42P01 invalid reference to FROM-clause entry for table \"su_money_transaction_records\""}
  344 +2020/11/22 13:51:39.656 [D] [server.go:1925] | 127.0.0.1| 200 | 125.170056ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  345 +2020/11/22 13:53:31.421 [I] [???:0] http server Running on http://:8082
  346 +2020/11/22 13:53:36.532 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024416532198000
  347 + Auth=
  348 + BodyData:{
  349 + "companyId": 381,
  350 + "uid": 3259769336174592,
  351 + "rankingType": 1,
  352 + "offset": 0,
  353 + "limit": 20
  354 +}
  355 +2020/11/22 13:53:36.671 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606024416532198000 BodyData:{"code":501,"msg":"内部服务出错:ERROR #42703 column t.employee_contributions_decrease does not exist"}
  356 +2020/11/22 13:53:36.671 [D] [server.go:1925] | 127.0.0.1| 200 | 139.41072ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  357 +2020/11/22 13:53:59.063 [I] [???:0] http server Running on http://:8082
  358 +2020/11/22 13:54:01.976 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024441976713000
  359 + Auth=
  360 + BodyData:{
  361 + "companyId": 381,
  362 + "uid": 3259769336174592,
  363 + "rankingType": 1,
  364 + "offset": 0,
  365 + "limit": 20
  366 +}
  367 +2020/11/22 13:54:02.083 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606024441976713000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":15917.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":9890.3,"Ranking":2},"employeesContributions":[{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeesContributions":77800,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":15917.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeesContributions":-3068,"Ranking":3},{"Uid":3259769336070144,"EmployeeName":"杜迁","EmployeesContributions":-6665,"Ranking":4},{"Uid":3259769336037376,"EmployeeName":"朱贵2","EmployeesContributions":-6975,"Ranking":5},{"Uid":3259769336137728,"EmployeeName":"杨志358","EmployeesContributions":-6990.2,"Ranking":6},{"Uid":3288265494991872,"EmployeeName":"李四","EmployeesContributions":-10289.5,"Ranking":7},{"Uid":3259769336317952,"EmployeeName":"陈达","EmployeesContribu
  368 +2020/11/22 13:54:02.083 [D] [server.go:1925] | 127.0.0.1| 200 | 106.60985ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
@@ -432,18 +432,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -432,18 +432,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
432 432
433 /**********************************************贡献值排行榜****************************************/ 433 /**********************************************贡献值排行榜****************************************/
434 434
435 - // 减少的贡献值 435 + // 贡献值
436 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel) 436 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
437 queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 437 queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
438 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 438 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
439 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 439 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
440 - queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease") 440 + queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions")
441 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking") 441 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
442 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 442 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
443 queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId) 443 queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
444 } 444 }
445 queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1) 445 queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
446 - queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4) 446 + queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
447 if startTime, ok := queryOptions["startTime"]; ok { 447 if startTime, ok := queryOptions["startTime"]; ok {
448 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime) 448 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
449 } 449 }
@@ -454,19 +454,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -454,19 +454,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
454 // 贡献值子查询 454 // 贡献值子查询
455 contributionsDecrease := queryContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 455 contributionsDecrease := queryContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
456 456
457 - // 贡献值排行榜 457 + // 减少的贡献值
458 queryContributions := tx.Model() 458 queryContributions := tx.Model()
459 queryContributions = queryContributions.With("t", contributionsDecrease) 459 queryContributions = queryContributions.With("t", contributionsDecrease)
460 queryContributions = queryContributions.Table("t") 460 queryContributions = queryContributions.Table("t")
461 queryContributions = queryContributions.Table("su_money_transaction_records") 461 queryContributions = queryContributions.Table("su_money_transaction_records")
462 queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint") 462 queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
463 - queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")  
464 - queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")  
465 - queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)  
466 - queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")  
467 - queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})) 463 + queryContributions = queryContributions.ColumnExpr("t.uid AS uid")
  464 + queryContributions = queryContributions.ColumnExpr("t.employee_name AS employee_name")
  465 + queryContributions = queryContributions.ColumnExpr(`t.employee_contributions - sum(su_money_transaction_records.su_money) AS employees_contributions`)
  466 + queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY t.employee_contributions - sum(su_money_transaction_records.su_money) DESC) AS ranking")
  467 + queryContributions = queryContributions.Where(`su_money_transaction_records.record_type = ?`, 4)
468 queryContributions = queryContributions.Where(`e.status = ?`, 1) 468 queryContributions = queryContributions.Where(`e.status = ?`, 1)
469 - queryContributions = queryContributions.Where("su_money_transaction_records.employee->>'uid' = t.uid")  
470 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 469 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
471 queryContributions = queryContributions.Where("e.company_id = ?", companyId) 470 queryContributions = queryContributions.Where("e.company_id = ?", companyId)
472 } 471 }
@@ -476,7 +475,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -476,7 +475,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
476 if endTime, ok := queryOptions["endTime"]; ok { 475 if endTime, ok := queryOptions["endTime"]; ok {
477 queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime) 476 queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
478 } 477 }
479 - queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease") 478 + queryContributions = queryContributions.GroupExpr("t.uid, t.employee_name, t.employee_contributions")
480 479
481 // 个人贡献值子查询 480 // 个人贡献值子查询
482 queryContributionsWith := queryContributions.Order("employees_contributions DESC") 481 queryContributionsWith := queryContributions.Order("employees_contributions DESC")