|
@@ -283,22 +283,173 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
@@ -283,22 +283,173 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
283
|
// }, nil
|
283
|
// }, nil
|
284
|
//}
|
284
|
//}
|
285
|
|
285
|
|
286
|
-// TODO 排行榜统计,排名
|
286
|
+// TODO 贡献值、财富值排行榜
|
|
|
287
|
+func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
288
|
+ var retWealth []struct {
|
|
|
289
|
+ Uid int
|
|
|
290
|
+ EmployeeName string
|
|
|
291
|
+ EmployeeSuMoney float64
|
|
|
292
|
+ Ranking int
|
|
|
293
|
+ }
|
|
|
294
|
+ var retContributions []struct { // 员工贡献值
|
|
|
295
|
+ Uid int
|
|
|
296
|
+ EmployeeName string
|
|
|
297
|
+ EmployeesContributions float64
|
|
|
298
|
+ Ranking int
|
|
|
299
|
+ }
|
|
|
300
|
+
|
|
|
301
|
+ tx := dao.transactionContext.PgTx
|
|
|
302
|
+ suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
303
|
+
|
|
|
304
|
+ // 财富值排名
|
|
|
305
|
+ queryWealth := tx.Model(suMoneyTransactionRecordModel)
|
|
|
306
|
+ queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
307
|
+ queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
308
|
+ queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
309
|
+ queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
|
|
|
310
|
+ queryWealth = queryWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
|
|
|
311
|
+ queryWealth = queryWealth.Where(`e.status = ?`, 1)
|
|
|
312
|
+ queryWealth = queryWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
313
|
+ if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
314
|
+ queryWealth = queryWealth.Where("e.company_id = ?", companyId)
|
|
|
315
|
+ }
|
|
|
316
|
+ if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
317
|
+ queryWealth = queryWealth.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
318
|
+ }
|
|
|
319
|
+ if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
320
|
+ queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
321
|
+ }
|
|
|
322
|
+ queryWealth = queryWealth.Group("su_money_transaction_record.employee")
|
|
|
323
|
+ if offset, ok := queryOptions["offset"]; ok {
|
|
|
324
|
+ offset := offset.(int)
|
|
|
325
|
+ if offset > -1 {
|
|
|
326
|
+ queryWealth = queryWealth.Offset(offset)
|
|
|
327
|
+ }
|
|
|
328
|
+ } else {
|
|
|
329
|
+ queryWealth = queryWealth.Offset(0)
|
|
|
330
|
+ }
|
|
|
331
|
+ if limit, ok := queryOptions["limit"]; ok {
|
|
|
332
|
+ limit := limit.(int)
|
|
|
333
|
+ if limit > -1 {
|
|
|
334
|
+ queryWealth = queryWealth.Limit(limit)
|
|
|
335
|
+ }
|
|
|
336
|
+ } else {
|
|
|
337
|
+ queryWealth = queryWealth.Limit(20)
|
|
|
338
|
+ }
|
|
|
339
|
+ if err := queryWealth.Order("employee_su_money DESC").Select(&retWealth); err != nil {
|
|
|
340
|
+ return nil, err
|
|
|
341
|
+ }
|
|
|
342
|
+
|
|
|
343
|
+ // 当前员工财富值排名
|
|
|
344
|
+
|
|
|
345
|
+ // 扣除的贡献值子查询
|
|
|
346
|
+ queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
|
|
|
347
|
+ queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
348
|
+ queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
349
|
+ queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
350
|
+ queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")
|
|
|
351
|
+ queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
|
|
|
352
|
+ if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
353
|
+ queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
|
|
|
354
|
+ }
|
|
|
355
|
+ queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
|
|
|
356
|
+ queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
|
|
|
357
|
+ if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
358
|
+ queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
359
|
+ }
|
|
|
360
|
+ if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
361
|
+ queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
362
|
+ }
|
|
|
363
|
+ contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee")
|
|
|
364
|
+
|
|
|
365
|
+ //if offset, ok := queryOptions["offset"]; ok {
|
|
|
366
|
+ // offset := offset.(int)
|
|
|
367
|
+ // if offset > -1 {
|
|
|
368
|
+ // queryContributionsDecrease = queryContributionsDecrease.Offset(offset)
|
|
|
369
|
+ // }
|
|
|
370
|
+ //} else {
|
|
|
371
|
+ // queryContributionsDecrease = queryContributionsDecrease.Offset(0)
|
|
|
372
|
+ //}
|
|
|
373
|
+ //if limit, ok := queryOptions["limit"]; ok {
|
|
|
374
|
+ // limit := limit.(int)
|
|
|
375
|
+ // if limit > -1 {
|
|
|
376
|
+ // queryContributionsDecrease = queryContributionsDecrease.Limit(limit)
|
|
|
377
|
+ // }
|
|
|
378
|
+ //} else {
|
|
|
379
|
+ // queryContributionsDecrease = queryContributionsDecrease.Limit(20)
|
|
|
380
|
+ //}
|
|
|
381
|
+ //contributionsDecrease := queryWealth.Order("employee_contributions_decrease DESC")
|
|
|
382
|
+
|
|
|
383
|
+ // 贡献值排名
|
|
|
384
|
+ queryContributions := tx.Model()
|
|
|
385
|
+ queryContributions = queryContributions.With("t", contributionsDecrease)
|
|
|
386
|
+ queryContributions = queryContributions.Table("t")
|
|
|
387
|
+ queryContributions = queryContributions.Table("su_money_transaction_records")
|
|
|
388
|
+ queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
|
|
|
389
|
+ queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
|
|
|
390
|
+ queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
|
|
|
391
|
+ queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
|
|
|
392
|
+ queryContributions = queryContributions.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
|
|
|
393
|
+ if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
394
|
+ queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
|
|
395
|
+ }
|
|
|
396
|
+ queryContributions = queryContributions.Where(`e.status = ?`, 1)
|
|
|
397
|
+ queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
398
|
+ if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
399
|
+ queryContributions = queryContributions.Where(`su_money_transaction_records.create_time > ?`, startTime)
|
|
|
400
|
+ }
|
|
|
401
|
+ if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
402
|
+ queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
|
|
|
403
|
+ }
|
|
|
404
|
+ queryContributions = queryContributions.Group("su_money_transaction_records.employee")
|
|
|
405
|
+ queryContributions = queryContributions.Group("t.employee_contributions_decrease")
|
|
|
406
|
+ if offset, ok := queryOptions["offset"]; ok {
|
|
|
407
|
+ offset := offset.(int)
|
|
|
408
|
+ if offset > -1 {
|
|
|
409
|
+ queryContributions = queryContributions.Offset(offset)
|
|
|
410
|
+ }
|
|
|
411
|
+ } else {
|
|
|
412
|
+ queryContributions = queryContributions.Offset(0)
|
|
|
413
|
+ }
|
|
|
414
|
+ if limit, ok := queryOptions["limit"]; ok {
|
|
|
415
|
+ limit := limit.(int)
|
|
|
416
|
+ if limit > -1 {
|
|
|
417
|
+ queryContributions = queryContributions.Limit(limit)
|
|
|
418
|
+ }
|
|
|
419
|
+ } else {
|
|
|
420
|
+ queryContributions = queryContributions.Limit(20)
|
|
|
421
|
+ }
|
|
|
422
|
+ if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
|
|
|
423
|
+ return nil, err
|
|
|
424
|
+ }
|
|
|
425
|
+
|
|
|
426
|
+ // 当前员工贡献值排名
|
|
|
427
|
+
|
|
|
428
|
+ return map[string]interface{}{
|
|
|
429
|
+ "employeesWealth": retWealth,
|
|
|
430
|
+ "employeesContributions": retContributions,
|
|
|
431
|
+ }, nil
|
|
|
432
|
+}
|
|
|
433
|
+
|
|
|
434
|
+// 排行榜统计,排名
|
287
|
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
|
435
|
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
|
288
|
var retWealth []struct {
|
436
|
var retWealth []struct {
|
289
|
Uid int
|
437
|
Uid int
|
290
|
EmployeeName string
|
438
|
EmployeeName string
|
291
|
EmployeeSuMoney float64
|
439
|
EmployeeSuMoney float64
|
|
|
440
|
+ Ranking int
|
292
|
}
|
441
|
}
|
293
|
var retContributions []struct { // 员工贡献值
|
442
|
var retContributions []struct { // 员工贡献值
|
294
|
Uid int
|
443
|
Uid int
|
295
|
EmployeeName string
|
444
|
EmployeeName string
|
296
|
EmployeesContributions float64
|
445
|
EmployeesContributions float64
|
|
|
446
|
+ Ranking int
|
297
|
}
|
447
|
}
|
298
|
var retContributionDecrease []struct { // 员工减少的贡献值
|
448
|
var retContributionDecrease []struct { // 员工减少的贡献值
|
299
|
Uid int
|
449
|
Uid int
|
300
|
EmployeeName string
|
450
|
EmployeeName string
|
301
|
EmployeesContributions float64
|
451
|
EmployeesContributions float64
|
|
|
452
|
+ Ranking int
|
302
|
}
|
453
|
}
|
303
|
tx := dao.transactionContext.PgTx
|
454
|
tx := dao.transactionContext.PgTx
|
304
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
455
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|