作者 陈志颖

fix:排行榜

... ... @@ -330,3 +330,39 @@
}
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
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
2020/11/22 13:51:35.028 [I] [???:0] http server Running on http://:8082
2020/11/22 13:51:39.531 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024299531630000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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\""}
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
2020/11/22 13:53:31.421 [I] [???:0] http server Running on http://:8082
2020/11/22 13:53:36.532 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024416532198000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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"}
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
2020/11/22 13:53:59.063 [I] [???:0] http server Running on http://:8082
2020/11/22 13:54:01.976 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606024441976713000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
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
/**********************************************贡献值排行榜****************************************/
// 减少的贡献值
// 贡献值
queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions")
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
}
queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
if startTime, ok := queryOptions["startTime"]; ok {
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
}
... ... @@ -454,19 +454,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
// 贡献值子查询
contributionsDecrease := queryContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
// 贡献值排行榜
// 减少的贡献值
queryContributions := tx.Model()
queryContributions = queryContributions.With("t", contributionsDecrease)
queryContributions = queryContributions.Table("t")
queryContributions = queryContributions.Table("su_money_transaction_records")
queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
queryContributions = queryContributions.ColumnExpr("t.uid AS uid")
queryContributions = queryContributions.ColumnExpr("t.employee_name AS employee_name")
queryContributions = queryContributions.ColumnExpr(`t.employee_contributions - sum(su_money_transaction_records.su_money) AS employees_contributions`)
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY t.employee_contributions - sum(su_money_transaction_records.su_money) DESC) AS ranking")
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type = ?`, 4)
queryContributions = queryContributions.Where(`e.status = ?`, 1)
queryContributions = queryContributions.Where("su_money_transaction_records.employee->>'uid' = t.uid")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
}
... ... @@ -476,7 +475,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
}
queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
queryContributions = queryContributions.GroupExpr("t.uid, t.employee_name, t.employee_contributions")
// 个人贡献值子查询
queryContributionsWith := queryContributions.Order("employees_contributions DESC")
... ...