作者 陈志颖

refactor:重构贡献值排行

... ... @@ -234,3 +234,99 @@
}
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
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
2020/11/22 12:49:39.008 [I] [???:0] http server Running on http://:8082
2020/11/22 12:51:00.560 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606020660560139000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
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
2020/11/22 13:17:38.053 [I] [???:0] http server Running on http://:8082
2020/11/22 13:17:45.425 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022265425319000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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"}
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
2020/11/22 13:18:50.955 [I] [???:0] http server Running on http://:8082
2020/11/22 13:18:55.080 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022335080698000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
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
2020/11/22 13:21:18.006 [I] [???:0] http server Running on http://:8082
2020/11/22 13:21:21.586 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022481586961000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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"}
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
2020/11/22 13:21:54.796 [I] [???:0] http server Running on http://:8082
2020/11/22 13:21:57.754 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022517754296000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
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
2020/11/22 13:22:54.610 [I] [???:0] http server Running on http://:8082
2020/11/22 13:22:57.798 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606022577798058000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
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
2020/11/22 13:41:14.183 [I] [???:0] http server Running on http://:8082
2020/11/22 13:41:18.208 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606023678207974000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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"}
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
2020/11/22 13:42:08.899 [I] [???:0] http server Running on http://:8082
2020/11/22 13:42:12.727 [D] [server.go:2843] ====>Recv User:<nil> RequestId:POST./statistics/employees-ranking-list.1606023732727892000
Auth=
BodyData:{
"companyId": 381,
"uid": 3259769336174592,
"rankingType": 1,
"offset": 0,
"limit": 20
}
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
... ...
... ... @@ -312,14 +312,16 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 兑换现金退还素币
/**********************************************财富值排行榜****************************************/
// 素币增加
queryWealthRestore := tx.Model(suMoneyTransactionRecordModel)
queryWealthRestore = queryWealthRestore.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryWealthRestore = queryWealthRestore.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryWealthRestore = queryWealthRestore.ColumnExpr("sum(su_money_transaction_record.su_money) AS su_money_restore")
queryWealthRestore = queryWealthRestore.ColumnExpr("sum(su_money_transaction_record.su_money) AS su_money")
queryWealthRestore = queryWealthRestore.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.record_type =?`, 6)
queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
queryWealthRestore = queryWealthRestore.Where(`e.status = ?`, 1) // 离职员工过滤
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryWealthRestore = queryWealthRestore.Where("e.company_id = ?", companyId)
... ... @@ -330,23 +332,21 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryWealthRestore = queryWealthRestore.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
// 素币增加子查询
queryWealthRestoreWith := queryWealthRestore.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
// 兑换现金退还素币子查询
//queryWealthRestoreWith := queryWealthRestore.Order("su_money_restore DESC")
// 素币支出
queryWealthExpend := tx.Model()
queryWealthExpend = queryWealthExpend.With("a", queryWealthRestoreWith)
queryWealthExpend = queryWealthExpend.Table("a")
queryWealthExpend = queryWealthExpend.Table("su_money_transaction_records")
queryWealthExpend = queryWealthExpend.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
queryWealthExpend = queryWealthExpend.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
queryWealthExpend = queryWealthExpend.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
queryWealthExpend = queryWealthExpend.ColumnExpr("sum(su_money_transaction_records.su_money) - a.su_money_restore AS su_money_expend")
queryWealthExpend = queryWealthExpend.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) DESC) AS ranking")
queryWealthExpend = queryWealthExpend.ColumnExpr("a.uid AS uid")
queryWealthExpend = queryWealthExpend.ColumnExpr("a.employee_name AS employee_name")
queryWealthExpend = queryWealthExpend.ColumnExpr("a.su_money - sum(su_money_transaction_records.su_money) AS su_money_expend")
queryWealthExpend = queryWealthExpend.ColumnExpr("ROW_NUMBER() OVER (ORDER BY a.su_money - sum(su_money_transaction_records.su_money) DESC) AS ranking")
queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{4, 1, 5}))
queryWealthExpend = queryWealthExpend.Where(`e.status = ?`, 1) // 离职员工过滤
queryWealthExpend = queryWealthExpend.Where(`e.status = ?`, 1)
//queryWealthExpend = queryWealthExpend.Where("su_money_transaction_records.employee->>'uid' = a.uid")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryWealthExpend = queryWealthExpend.Where("e.company_id = ?", companyId)
... ... @@ -357,24 +357,23 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryWealthExpend = queryWealthExpend.Where(`su_money_transaction_records.create_time < ?`, endTime)
}
queryWealthExpendWith := queryWealthExpend.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',a.su_money_restore")
// 素币支出子查询
//queryWealthExpendWith := queryWealthRestore.Order("su_money_expend DESC")
queryWealthExpendWith := queryWealthExpend.GroupExpr("a.uid, a.employee_name, a.su_money")
// 素币值榜单
// 素币退还
queryWealth := tx.Model()
queryWealth = queryWealth.With("b", queryWealthExpendWith)
queryWealth = queryWealth.Table("b")
queryWealth = queryWealth.Table("su_money_transaction_records")
queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
queryWealth = queryWealth.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
queryWealth = queryWealth.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_records.su_money) - b.su_money_expend AS employee_su_money")
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) DESC) AS ranking")
queryWealth = queryWealth.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
queryWealth = queryWealth.ColumnExpr("b.uid AS uid")
queryWealth = queryWealth.ColumnExpr("b.employee_name AS employee_name")
queryWealth = queryWealth.ColumnExpr("b.su_money_expend - sum(su_money_transaction_records.su_money) AS employee_su_money")
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY b.su_money_expend - sum(su_money_transaction_records.su_money) DESC) AS ranking")
queryWealth = queryWealth.Where(`su_money_transaction_records.record_type = ?`, 6)
queryWealth = queryWealth.Where(`e.status = ?`, 1) // 离职员工过滤
queryWealth = queryWealth.Where("su_money_transaction_records.employee->>'uid' = b.uid")
//queryWealth = queryWealth.Where("su_money_transaction_records.employee->>'uid' = b.uid")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryWealth = queryWealth.Where("e.company_id = ?", companyId)
}
... ... @@ -384,10 +383,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok {
queryWealth = queryWealth.Where(`su_money_transaction_records.create_time < ?`, endTime)
}
queryWealth = queryWealth.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',b.su_money_expend")
queryWealth = queryWealth.GroupExpr("b.uid, b.employee_name ,b.su_money_expend")
// 个人素币值子查询
queryWealthWith := queryWealth.Order("employee_su_money DESC")
queryWealthWith := queryWealth.Order("ranking ASC")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
... ... @@ -431,6 +430,8 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
retCurrentEmployeeWealth = retEmployeeWealth[0]
}
/**********************************************贡献值排行榜****************************************/
// 减少的贡献值
queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
... ...