作者 陈志颖

refactor:重构贡献值排行

@@ -234,3 +234,99 @@ @@ -234,3 +234,99 @@
234 } 234 }
235 2020/11/22 12:34:33.614 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606019673460431000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.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":86999,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeeSuMon 235 2020/11/22 12:34:33.614 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606019673460431000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.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":86999,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeeSuMon
236 2020/11/22 12:34:33.614 [D] [server.go:1925] | 127.0.0.1| 200 | 154.246858ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list 236 2020/11/22 12:34:33.614 [D] [server.go:1925] | 127.0.0.1| 200 | 154.246858ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  237 +2020/11/22 12:49:39.008 [I] [???:0] http server Running on http://:8082
  238 +2020/11/22 12:51:00.560 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606020660560139000
  239 + Auth=
  240 + BodyData:{
  241 + "companyId": 381,
  242 + "uid": 3259769336174592,
  243 + "rankingType": 1,
  244 + "offset": 0,
  245 + "limit": 20
  246 +}
  247 +2020/11/22 12:51:00.949 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606020660560139000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.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":86999,"Ranking":1},{"Uid":3259769336174592,"EmployeeName":"索超","EmployeeSuMoney":23819.3,"Ranking":2},{"Uid":3259769336137728,"EmployeeName":"杨志","EmployeeSuMon
  248 +2020/11/22 12:51:00.949 [D] [server.go:1925] | 127.0.0.1| 200 | 389.452774ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  249 +2020/11/22 13:17:38.053 [I] [???:0] http server Running on http://:8082
  250 +2020/11/22 13:17:45.425 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022265425319000
  251 + Auth=
  252 + BodyData:{
  253 + "companyId": 381,
  254 + "uid": 3259769336174592,
  255 + "rankingType": 1,
  256 + "offset": 0,
  257 + "limit": 20
  258 +}
  259 +2020/11/22 13:17:45.658 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606022265425319000 BodyData:{"code":501,"msg":"内部服务出错:ERROR #42703 column a.su_money_restore does not exist"}
  260 +2020/11/22 13:17:45.658 [D] [server.go:1925] | 127.0.0.1| 200 | 233.318686ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  261 +2020/11/22 13:18:50.955 [I] [???:0] http server Running on http://:8082
  262 +2020/11/22 13:18:55.080 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022335080698000
  263 + Auth=
  264 + BodyData:{
  265 + "companyId": 381,
  266 + "uid": 3259769336174592,
  267 + "rankingType": 1,
  268 + "offset": 0,
  269 + "limit": 20
  270 +}
  271 +2020/11/22 13:18:55.332 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606022335080698000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":null,"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":86995,"Ranking":8},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":25112.3,"Ranking":7},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":6127,"Ranking":6},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuM
  272 +2020/11/22 13:18:55.332 [D] [server.go:1925] | 127.0.0.1| 200 | 251.702717ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  273 +2020/11/22 13:21:18.006 [I] [???:0] http server Running on http://:8082
  274 +2020/11/22 13:21:21.586 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022481586961000
  275 + Auth=
  276 + BodyData:{
  277 + "companyId": 381,
  278 + "uid": 3259769336174592,
  279 + "rankingType": 1,
  280 + "offset": 0,
  281 + "limit": 20
  282 +}
  283 +2020/11/22 13:21:21.732 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606022481586961000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":null,"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":86995,"Ranking":1}]},"msg":"ok"}
  284 +2020/11/22 13:21:21.732 [D] [server.go:1925] | 127.0.0.1| 200 | 145.505463ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  285 +2020/11/22 13:21:54.796 [I] [???:0] http server Running on http://:8082
  286 +2020/11/22 13:21:57.754 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022517754296000
  287 + Auth=
  288 + BodyData:{
  289 + "companyId": 381,
  290 + "uid": 3259769336174592,
  291 + "rankingType": 1,
  292 + "offset": 0,
  293 + "limit": 20
  294 +}
  295 +2020/11/22 13:21:57.880 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606022517754296000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":null,"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":86995,"Ranking":5},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":23815.3,"Ranking":4},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":7030,"Ranking":3},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuM
  296 +2020/11/22 13:21:57.881 [D] [server.go:1925] | 127.0.0.1| 200 | 126.875779ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  297 +2020/11/22 13:22:54.610 [I] [???:0] http server Running on http://:8082
  298 +2020/11/22 13:22:57.798 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022577798058000
  299 + Auth=
  300 + BodyData:{
  301 + "companyId": 381,
  302 + "uid": 3259769336174592,
  303 + "rankingType": 1,
  304 + "offset": 0,
  305 + "limit": 20
  306 +}
  307 +2020/11/22 13:22:57.975 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606022577798058000 BodyData:{"code":0,"data":{"currentEmployeeContributions":{"Uid":3259769336174592,"EmployeeName":"索超","EmployeesContributions":26117.3,"Ranking":2},"currentEmployeeWealth":null,"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":86995,"Ranking":5},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":23815.3,"Ranking":4},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuMoney":7030,"Ranking":3},{"Uid":3259769335767040,"EmployeeName":"朱武","EmployeeSuM
  308 +2020/11/22 13:22:57.975 [D] [server.go:1925] | 127.0.0.1| 200 | 177.422062ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  309 +2020/11/22 13:41:14.183 [I] [???:0] http server Running on http://:8082
  310 +2020/11/22 13:41:18.208 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606023678207974000
  311 + Auth=
  312 + BodyData:{
  313 + "companyId": 381,
  314 + "uid": 3259769336174592,
  315 + "rankingType": 1,
  316 + "offset": 0,
  317 + "limit": 20
  318 +}
  319 +2020/11/22 13:41:18.284 [D] [server.go:2843] <====Send RequestId:POST./statistics/employees-ranking-list.1606023678207974000 BodyData:{"code":501,"msg":"内部服务出错:ERROR #42803 column \"b.uid\" must appear in the GROUP BY clause or be used in an aggregate function"}
  320 +2020/11/22 13:41:18.284 [D] [server.go:1925] | 127.0.0.1| 200 | 76.482421ms| match| POST  /statistics/employees-ranking-list r:/statistics/employees-ranking-list
  321 +2020/11/22 13:42:08.899 [I] [???:0] http server Running on http://:8082
  322 +2020/11/22 13:42:12.727 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606023732727892000
  323 + Auth=
  324 + BodyData:{
  325 + "companyId": 381,
  326 + "uid": 3259769336174592,
  327 + "rankingType": 1,
  328 + "offset": 0,
  329 + "limit": 20
  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
  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
@@ -312,14 +312,16 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -312,14 +312,16 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
312 tx := dao.transactionContext.PgTx 312 tx := dao.transactionContext.PgTx
313 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 313 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
314 314
315 - // 兑换现金退还素币 315 + /**********************************************财富值排行榜****************************************/
  316 +
  317 + // 素币增加
316 queryWealthRestore := tx.Model(suMoneyTransactionRecordModel) 318 queryWealthRestore := tx.Model(suMoneyTransactionRecordModel)
317 queryWealthRestore = queryWealthRestore.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 319 queryWealthRestore = queryWealthRestore.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
318 queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 320 queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
319 queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 321 queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
320 - queryWealthRestore = queryWealthRestore.ColumnExpr("sum(su_money_transaction_record.su_money) AS su_money_restore") 322 + queryWealthRestore = queryWealthRestore.ColumnExpr("sum(su_money_transaction_record.su_money) AS su_money")
321 queryWealthRestore = queryWealthRestore.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking") 323 queryWealthRestore = queryWealthRestore.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
322 - queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.record_type =?`, 6) 324 + queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
323 queryWealthRestore = queryWealthRestore.Where(`e.status = ?`, 1) // 离职员工过滤 325 queryWealthRestore = queryWealthRestore.Where(`e.status = ?`, 1) // 离职员工过滤
324 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 326 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
325 queryWealthRestore = queryWealthRestore.Where("e.company_id = ?", companyId) 327 queryWealthRestore = queryWealthRestore.Where("e.company_id = ?", companyId)
@@ -330,23 +332,21 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -330,23 +332,21 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
330 if endTime, ok := queryOptions["endTime"]; ok { 332 if endTime, ok := queryOptions["endTime"]; ok {
331 queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.create_time < ?`, endTime) 333 queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.create_time < ?`, endTime)
332 } 334 }
  335 + // 素币增加子查询
333 queryWealthRestoreWith := queryWealthRestore.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 336 queryWealthRestoreWith := queryWealthRestore.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
334 337
335 - // 兑换现金退还素币子查询  
336 - //queryWealthRestoreWith := queryWealthRestore.Order("su_money_restore DESC")  
337 -  
338 // 素币支出 338 // 素币支出
339 queryWealthExpend := tx.Model() 339 queryWealthExpend := tx.Model()
340 queryWealthExpend = queryWealthExpend.With("a", queryWealthRestoreWith) 340 queryWealthExpend = queryWealthExpend.With("a", queryWealthRestoreWith)
341 queryWealthExpend = queryWealthExpend.Table("a") 341 queryWealthExpend = queryWealthExpend.Table("a")
342 queryWealthExpend = queryWealthExpend.Table("su_money_transaction_records") 342 queryWealthExpend = queryWealthExpend.Table("su_money_transaction_records")
343 queryWealthExpend = queryWealthExpend.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint") 343 queryWealthExpend = queryWealthExpend.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
344 - queryWealthExpend = queryWealthExpend.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")  
345 - queryWealthExpend = queryWealthExpend.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")  
346 - queryWealthExpend = queryWealthExpend.ColumnExpr("sum(su_money_transaction_records.su_money) - a.su_money_restore AS su_money_expend")  
347 - queryWealthExpend = queryWealthExpend.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) DESC) AS ranking") 344 + queryWealthExpend = queryWealthExpend.ColumnExpr("a.uid AS uid")
  345 + queryWealthExpend = queryWealthExpend.ColumnExpr("a.employee_name AS employee_name")
  346 + queryWealthExpend = queryWealthExpend.ColumnExpr("a.su_money - sum(su_money_transaction_records.su_money) AS su_money_expend")
  347 + queryWealthExpend = queryWealthExpend.ColumnExpr("ROW_NUMBER() OVER (ORDER BY a.su_money - sum(su_money_transaction_records.su_money) DESC) AS ranking")
348 queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{4, 1, 5})) 348 queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{4, 1, 5}))
349 - queryWealthExpend = queryWealthExpend.Where(`e.status = ?`, 1) // 离职员工过滤 349 + queryWealthExpend = queryWealthExpend.Where(`e.status = ?`, 1)
350 //queryWealthExpend = queryWealthExpend.Where("su_money_transaction_records.employee->>'uid' = a.uid") 350 //queryWealthExpend = queryWealthExpend.Where("su_money_transaction_records.employee->>'uid' = a.uid")
351 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 351 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
352 queryWealthExpend = queryWealthExpend.Where("e.company_id = ?", companyId) 352 queryWealthExpend = queryWealthExpend.Where("e.company_id = ?", companyId)
@@ -357,24 +357,23 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -357,24 +357,23 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
357 if endTime, ok := queryOptions["endTime"]; ok { 357 if endTime, ok := queryOptions["endTime"]; ok {
358 queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.create_time < ?`, endTime) 358 queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.create_time < ?`, endTime)
359 } 359 }
360 - queryWealthExpendWith := queryWealthExpend.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',a.su_money_restore")  
361 360
362 // 素币支出子查询 361 // 素币支出子查询
363 - //queryWealthExpendWith := queryWealthRestore.Order("su_money_expend DESC") 362 + queryWealthExpendWith := queryWealthExpend.GroupExpr("a.uid, a.employee_name, a.su_money")
364 363
365 - // 素币值榜单 364 + // 素币退还
366 queryWealth := tx.Model() 365 queryWealth := tx.Model()
367 queryWealth = queryWealth.With("b", queryWealthExpendWith) 366 queryWealth = queryWealth.With("b", queryWealthExpendWith)
368 queryWealth = queryWealth.Table("b") 367 queryWealth = queryWealth.Table("b")
369 queryWealth = queryWealth.Table("su_money_transaction_records") 368 queryWealth = queryWealth.Table("su_money_transaction_records")
370 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint") 369 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
371 - queryWealth = queryWealth.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")  
372 - queryWealth = queryWealth.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")  
373 - queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_records.su_money) - b.su_money_expend AS employee_su_money")  
374 - queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) DESC) AS ranking")  
375 - queryWealth = queryWealth.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})) 370 + queryWealth = queryWealth.ColumnExpr("b.uid AS uid")
  371 + queryWealth = queryWealth.ColumnExpr("b.employee_name AS employee_name")
  372 + queryWealth = queryWealth.ColumnExpr("b.su_money_expend - sum(su_money_transaction_records.su_money) AS employee_su_money")
  373 + queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY b.su_money_expend - sum(su_money_transaction_records.su_money) DESC) AS ranking")
  374 + queryWealth = queryWealth.Where(`su_money_transaction_records.record_type = ?`, 6)
376 queryWealth = queryWealth.Where(`e.status = ?`, 1) // 离职员工过滤 375 queryWealth = queryWealth.Where(`e.status = ?`, 1) // 离职员工过滤
377 - queryWealth = queryWealth.Where("su_money_transaction_records.employee->>'uid' = b.uid") 376 + //queryWealth = queryWealth.Where("su_money_transaction_records.employee->>'uid' = b.uid")
378 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 377 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
379 queryWealth = queryWealth.Where("e.company_id = ?", companyId) 378 queryWealth = queryWealth.Where("e.company_id = ?", companyId)
380 } 379 }
@@ -384,10 +383,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -384,10 +383,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
384 if endTime, ok := queryOptions["endTime"]; ok { 383 if endTime, ok := queryOptions["endTime"]; ok {
385 queryWealth = queryWealth.Where(`su_money_transaction_records.create_time < ?`, endTime) 384 queryWealth = queryWealth.Where(`su_money_transaction_records.create_time < ?`, endTime)
386 } 385 }
387 - queryWealth = queryWealth.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',b.su_money_expend") 386 + queryWealth = queryWealth.GroupExpr("b.uid, b.employee_name ,b.su_money_expend")
388 387
389 // 个人素币值子查询 388 // 个人素币值子查询
390 - queryWealthWith := queryWealth.Order("employee_su_money DESC") 389 + queryWealthWith := queryWealth.Order("ranking ASC")
391 390
392 if offset, ok := queryOptions["offset"]; ok { 391 if offset, ok := queryOptions["offset"]; ok {
393 offset := offset.(int) 392 offset := offset.(int)
@@ -431,6 +430,8 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -431,6 +430,8 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
431 retCurrentEmployeeWealth = retEmployeeWealth[0] 430 retCurrentEmployeeWealth = retEmployeeWealth[0]
432 } 431 }
433 432
  433 + /**********************************************贡献值排行榜****************************************/
  434 +
434 // 减少的贡献值 435 // 减少的贡献值
435 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel) 436 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
436 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")