|
@@ -328,6 +328,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -328,6 +328,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
328
|
}
|
328
|
}
|
329
|
|
329
|
|
330
|
tx := dao.transactionContext.PgTx
|
330
|
tx := dao.transactionContext.PgTx
|
|
|
331
|
+
|
331
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
332
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
332
|
|
333
|
|
333
|
// 财富值排行榜
|
334
|
// 财富值排行榜
|
|
@@ -338,6 +339,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -338,6 +339,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
338
|
queryWealth = queryWealth.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
|
339
|
queryWealth = queryWealth.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
|
339
|
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
340
|
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
340
|
queryWealth = queryWealth.Where(`e.status = ?`, 1)
|
341
|
queryWealth = queryWealth.Where(`e.status = ?`, 1)
|
|
|
342
|
+ queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
341
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
343
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
342
|
queryWealth = queryWealth.Where("e.company_id = ?", companyId)
|
344
|
queryWealth = queryWealth.Where("e.company_id = ?", companyId)
|
343
|
}
|
345
|
}
|
|
@@ -347,8 +349,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -347,8 +349,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
347
|
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
349
|
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
348
|
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
350
|
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
349
|
}
|
351
|
}
|
350
|
- // 财富值排行榜子查询
|
|
|
351
|
- queryWealthRestoreWith := queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
352
|
if offset, ok := queryOptions["offset"]; ok {
|
352
|
if offset, ok := queryOptions["offset"]; ok {
|
353
|
offset := offset.(int)
|
353
|
offset := offset.(int)
|
354
|
if offset > -1 {
|
354
|
if offset > -1 {
|
|
@@ -369,7 +369,25 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -369,7 +369,25 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
369
|
if err := queryWealth.Select(&retWealth); err != nil {
|
369
|
if err := queryWealth.Select(&retWealth); err != nil {
|
370
|
return nil, err
|
370
|
return nil, err
|
371
|
}
|
371
|
}
|
|
|
372
|
+
|
372
|
// 个人财富值排名
|
373
|
// 个人财富值排名
|
|
|
374
|
+ queryWealthWith := tx.Model(suMoneyTransactionRecordModel)
|
|
|
375
|
+ queryWealthWith = queryWealthWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
376
|
+ queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
377
|
+ queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
378
|
+ queryWealthWith = queryWealthWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
|
|
|
379
|
+ queryWealthWith = queryWealthWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
|
|
380
|
+ queryWealthWith = queryWealthWith.Where(`e.status = ?`, 1)
|
|
|
381
|
+ if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
382
|
+ queryWealthWith = queryWealthWith.Where("e.company_id = ?", companyId)
|
|
|
383
|
+ }
|
|
|
384
|
+ if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
|
|
|
385
|
+ queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
386
|
+ }
|
|
|
387
|
+ if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
|
|
388
|
+ queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
389
|
+ }
|
|
|
390
|
+ queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
373
|
querySelfWealth := tx.Model()
|
391
|
querySelfWealth := tx.Model()
|
374
|
querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
|
392
|
querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
|
375
|
querySelfWealth = querySelfWealth.Table("t")
|
393
|
querySelfWealth = querySelfWealth.Table("t")
|
|
@@ -383,7 +401,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -383,7 +401,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
383
|
if err := querySelfWealth.Select(&retEmployeeWealth); err != nil {
|
401
|
if err := querySelfWealth.Select(&retEmployeeWealth); err != nil {
|
384
|
return nil, err
|
402
|
return nil, err
|
385
|
}
|
403
|
}
|
386
|
-
|
|
|
387
|
var retCurrentEmployeeWealth interface{}
|
404
|
var retCurrentEmployeeWealth interface{}
|
388
|
if len(retEmployeeWealth) == 0 {
|
405
|
if len(retEmployeeWealth) == 0 {
|
389
|
retCurrentEmployeeWealth = nil
|
406
|
retCurrentEmployeeWealth = nil
|
|
@@ -391,14 +408,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -391,14 +408,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
391
|
retCurrentEmployeeWealth = retEmployeeWealth[0]
|
408
|
retCurrentEmployeeWealth = retEmployeeWealth[0]
|
392
|
}
|
409
|
}
|
393
|
|
410
|
|
394
|
- // 贡献值
|
411
|
+ // 贡献值排行榜
|
395
|
queryContributions := tx.Model(suMoneyTransactionRecordModel)
|
412
|
queryContributions := tx.Model(suMoneyTransactionRecordModel)
|
396
|
queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
413
|
queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
397
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
414
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
398
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
415
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
399
|
queryContributions = queryContributions.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
|
416
|
queryContributions = queryContributions.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
|
400
|
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
417
|
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
401
|
- queryContributions = queryContributions.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
418
|
+ //queryContributions = queryContributions.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
402
|
queryContributions = queryContributions.Where(`e.status = ?`, 1)
|
419
|
queryContributions = queryContributions.Where(`e.status = ?`, 1)
|
403
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
420
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
404
|
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
421
|
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
|
@@ -409,8 +426,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -409,8 +426,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
409
|
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
426
|
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
410
|
queryContributions = queryContributions.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
427
|
queryContributions = queryContributions.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
411
|
}
|
428
|
}
|
412
|
- // 贡献值子查询
|
|
|
413
|
- contributions := queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
429
|
+ queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
414
|
if offset, ok := queryOptions["offset"]; ok {
|
430
|
if offset, ok := queryOptions["offset"]; ok {
|
415
|
offset := offset.(int)
|
431
|
offset := offset.(int)
|
416
|
if offset > -1 {
|
432
|
if offset > -1 {
|
|
@@ -430,9 +446,28 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
@@ -430,9 +446,28 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
430
|
if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
|
446
|
if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
|
431
|
return nil, err
|
447
|
return nil, err
|
432
|
}
|
448
|
}
|
433
|
- // 个人贡献值
|
449
|
+
|
|
|
450
|
+ // 个人贡献值排名
|
|
|
451
|
+ queryContributionsWith := tx.Model(suMoneyTransactionRecordModel)
|
|
|
452
|
+ queryContributionsWith = queryContributionsWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
453
|
+ queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
454
|
+ queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
455
|
+ queryContributionsWith = queryContributionsWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
|
|
|
456
|
+ queryContributionsWith = queryContributionsWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
|
|
|
457
|
+ //queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
458
|
+ queryContributionsWith = queryContributionsWith.Where(`e.status = ?`, 1)
|
|
|
459
|
+ if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
460
|
+ queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId)
|
|
|
461
|
+ }
|
|
|
462
|
+ if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
|
|
|
463
|
+ queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
464
|
+ }
|
|
|
465
|
+ if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
|
|
466
|
+ queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
467
|
+ }
|
|
|
468
|
+ contributionsWith := queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
434
|
querySelfContributions := tx.Model()
|
469
|
querySelfContributions := tx.Model()
|
435
|
- querySelfContributions = querySelfContributions.With("t", contributions)
|
470
|
+ querySelfContributions = querySelfContributions.With("t", contributionsWith)
|
436
|
querySelfContributions = querySelfContributions.Table("t")
|
471
|
querySelfContributions = querySelfContributions.Table("t")
|
437
|
querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid")
|
472
|
querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid")
|
438
|
querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
|
473
|
querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
|