作者 陈志颖

fix:贡献值、财富值排行榜

@@ -2,16 +2,12 @@ package command @@ -2,16 +2,12 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "time"  
6 -  
7 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
8 ) 6 )
9 7
10 type RemoveEmployeeCommand struct { 8 type RemoveEmployeeCommand struct {
11 // 统一用户UID 9 // 统一用户UID
12 Uid int64 `json:"uid" valid:"Required"` 10 Uid int64 `json:"uid" valid:"Required"`
13 - // 创建时间  
14 - CreateTime time.Time `json:"createTime"`  
15 } 11 }
16 12
17 func (removeEmployeeCommand *RemoveEmployeeCommand) ValidateCommand() error { 13 func (removeEmployeeCommand *RemoveEmployeeCommand) ValidateCommand() error {
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 + "time"
11 ) 12 )
12 13
13 // 员工服务 14 // 员工服务
@@ -36,6 +37,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co @@ -36,6 +37,7 @@ func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *co
36 EmployeeAccount: createEmployeeCommand.EmployeeAccount, 37 EmployeeAccount: createEmployeeCommand.EmployeeAccount,
37 }, 38 },
38 SuMoney: 0, 39 SuMoney: 0,
  40 + CreateTime: time.Now(),
39 } 41 }
40 var employeeRepository domain.EmployeeRepository 42 var employeeRepository domain.EmployeeRepository
41 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 43 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
@@ -122,6 +124,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co @@ -122,6 +124,7 @@ func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *co
122 if employee == nil { 124 if employee == nil {
123 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateEmployeeCommand.Uid))) 125 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateEmployeeCommand.Uid)))
124 } 126 }
  127 + updateEmployeeCommand.CreateTime = time.Now()
125 if err := employee.Update(tool_funs.SimpleStructToMap(updateEmployeeCommand)); err != nil { 128 if err := employee.Update(tool_funs.SimpleStructToMap(updateEmployeeCommand)); err != nil {
126 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 129 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
127 } 130 }
@@ -402,15 +402,15 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -402,15 +402,15 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
402 transactionContext.RollbackTransaction() 402 transactionContext.RollbackTransaction()
403 }() 403 }()
404 404
405 - //// 员工仓储初始化  
406 - //var employeeRepository domain.EmployeeRepository  
407 - //if value, err := factory.CreateEmployeeRepository(map[string]interface{}{  
408 - // "transactionContext": transactionContext,  
409 - //}); err != nil {  
410 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
411 - //} else {  
412 - // employeeRepository = value  
413 - //} 405 + // 员工仓储初始化
  406 + var employeeRepository domain.EmployeeRepository
  407 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  408 + "transactionContext": transactionContext,
  409 + }); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + } else {
  412 + employeeRepository = value
  413 + }
414 414
415 // 员工DAO初始化 415 // 员工DAO初始化
416 var employeeDao *dao.EmployeeDao 416 var employeeDao *dao.EmployeeDao
@@ -476,23 +476,52 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -476,23 +476,52 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
476 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil { 476 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil {
477 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 477 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
478 } else { 478 } else {
479 - if err := transactionContext.CommitTransaction(); err != nil {  
480 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 479 + uidName := map[int64]interface{}{}
  480 + if _, employees, err := employeeRepository.Find(map[string]interface{}{
  481 + "companyId": contributionsWealthRankingQuery.CompanyId,
  482 + }); err != nil {
  483 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  484 + } else {
  485 + for _, employee := range employees {
  486 + uidName[employee.EmployeeInfo.Uid] = employee.EmployeeInfo.EmployeeName
  487 + }
481 } 488 }
482 489
483 - // TODO 排行榜姓名获取  
484 - //if count, employees, err := employeeRepository.Find(map[string]interface{}{  
485 - // "companyId": contributionsWealthRankingQuery.CompanyId,  
486 - // "offset": contributionsWealthRankingQuery.Offset,  
487 - // "limit": contributionsWealthRankingQuery.Limit,  
488 - //}); err != nil {  
489 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
490 - //}  
491 // 财富值排行榜 490 // 财富值排行榜
  491 + for i, _ := range contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int}) {
  492 + uid := contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})[i].Uid
  493 + if uidName[uid] != nil {
  494 + contributionsWealthRankingStatistics.(map[string]interface{})["employeesWealth"].([]struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})[i].EmployeeName = uidName[uid].(string)
  495 + }
  496 + }
492 497
  498 + // 个人财富值
  499 + currentEmployeeWealth := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"].(struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int})
  500 + uidWealth := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"].(struct{Uid int64;EmployeeName string;EmployeeSuMoney float64;Ranking int}).Uid
  501 + if uidName[uidWealth] != nil {
  502 + currentEmployeeWealth.EmployeeName = uidName[uidWealth].(string)
  503 + }
  504 + contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeWealth"] = currentEmployeeWealth
493 505
494 // 贡献值排行版 506 // 贡献值排行版
  507 + for i, _ := range contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct { Uid int64; EmployeeName string; EmployeesContributions float64; Ranking int }) {
  508 + uid := contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})[i].Uid
  509 + if uidName[uid] != nil {
  510 + contributionsWealthRankingStatistics.(map[string]interface{})["employeesContributions"].([]struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})[i].EmployeeName = uidName[uid].(string)
  511 + }
  512 + }
  513 +
  514 + // 个人贡献值
  515 + currentEmployeeContributions := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"].(struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int})
  516 + uidContributions := contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"].(struct{Uid int64;EmployeeName string;EmployeesContributions float64;Ranking int}).Uid
  517 + if uidName[uidContributions] != nil {
  518 + currentEmployeeContributions.EmployeeName = uidName[uidContributions].(string)
  519 + }
  520 + contributionsWealthRankingStatistics.(map[string]interface{})["currentEmployeeContributions"] = currentEmployeeContributions
495 521
  522 + if err := transactionContext.CommitTransaction(); err != nil {
  523 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  524 + }
496 525
497 return contributionsWealthRankingStatistics, nil 526 return contributionsWealthRankingStatistics, nil
498 } 527 }
@@ -134,9 +134,6 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -134,9 +134,6 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
134 if value, ok := addEmployee["status"]; ok { 134 if value, ok := addEmployee["status"]; ok {
135 status = int(value.(float64)) 135 status = int(value.(float64))
136 } 136 }
137 -  
138 - // TODO 增加员工判断  
139 -  
140 employee := &domain.Employee{ 137 employee := &domain.Employee{
141 CompanyId: companyId, 138 CompanyId: companyId,
142 EmployeeInfo: &domain.EmployeeInfo{ 139 EmployeeInfo: &domain.EmployeeInfo{
@@ -309,25 +309,25 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -309,25 +309,25 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
309 // 贡献值、财富值总榜和年榜, 309 // 贡献值、财富值总榜和年榜,
310 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) { 310 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
311 var retWealth []struct { // 个人财富值 311 var retWealth []struct { // 个人财富值
312 - Uid int 312 + Uid int64
313 EmployeeName string 313 EmployeeName string
314 EmployeeSuMoney float64 314 EmployeeSuMoney float64
315 Ranking int 315 Ranking int
316 } 316 }
317 var retEmployeeWealth []struct { // 个人贡献值 317 var retEmployeeWealth []struct { // 个人贡献值
318 - Uid int 318 + Uid int64
319 EmployeeName string 319 EmployeeName string
320 EmployeeSuMoney float64 320 EmployeeSuMoney float64
321 Ranking int 321 Ranking int
322 } 322 }
323 var retContributions []struct { // 员工贡献值 323 var retContributions []struct { // 员工贡献值
324 - Uid int 324 + Uid int64
325 EmployeeName string 325 EmployeeName string
326 EmployeesContributions float64 326 EmployeesContributions float64
327 Ranking int 327 Ranking int
328 } 328 }
329 var retEmployeeContributions []struct { // 员工贡献值 329 var retEmployeeContributions []struct { // 员工贡献值
330 - Uid int 330 + Uid int64
331 EmployeeName string 331 EmployeeName string
332 EmployeesContributions float64 332 EmployeesContributions float64
333 Ranking int 333 Ranking int
@@ -342,7 +342,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -342,7 +342,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
342 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 342 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
343 //queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 343 //queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
344 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") 344 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")
345 - 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), e.create_time DESC) AS ranking") 345 + 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")
346 queryWealth = queryWealth.Where(`e.status = ?`, 1) 346 queryWealth = queryWealth.Where(`e.status = ?`, 1)
347 //queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 347 //queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
348 queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid'") 348 queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid'")
@@ -371,7 +371,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -371,7 +371,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
371 } else { 371 } else {
372 queryWealth = queryWealth.Limit(20) 372 queryWealth = queryWealth.Limit(20)
373 } 373 }
374 - queryWealth = queryWealth.Order("employee_su_money DESC") 374 + queryWealth = queryWealth.Order("ranking ASC")
375 if err := queryWealth.Select(&retWealth); err != nil { 375 if err := queryWealth.Select(&retWealth); err != nil {
376 return nil, err 376 return nil, err
377 } 377 }
@@ -380,9 +380,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -380,9 +380,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
380 queryWealthWith := tx.Model(suMoneyTransactionRecordModel) 380 queryWealthWith := tx.Model(suMoneyTransactionRecordModel)
381 queryWealthWith = queryWealthWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 381 queryWealthWith = queryWealthWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
382 queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 382 queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
383 - queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 383 + //queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
384 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") 384 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")
385 - 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), e.create_time DESC) AS ranking") 385 + 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")
386 queryWealthWith = queryWealthWith.Where(`e.status = ?`, 1) 386 queryWealthWith = queryWealthWith.Where(`e.status = ?`, 1)
387 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 387 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
388 queryWealthWith = queryWealthWith.Where("e.company_id = ?", companyId) 388 queryWealthWith = queryWealthWith.Where("e.company_id = ?", companyId)
@@ -393,12 +393,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -393,12 +393,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
393 if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() { 393 if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
394 queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time < ?`, endTime) 394 queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
395 } 395 }
396 - queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 396 + //queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
  397 + queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid'")
397 querySelfWealth := tx.Model() 398 querySelfWealth := tx.Model()
398 querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith) 399 querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
399 querySelfWealth = querySelfWealth.Table("t") 400 querySelfWealth = querySelfWealth.Table("t")
400 querySelfWealth = querySelfWealth.ColumnExpr("t.uid AS uid") 401 querySelfWealth = querySelfWealth.ColumnExpr("t.uid AS uid")
401 - querySelfWealth = querySelfWealth.ColumnExpr("t.employee_name AS employee_name") 402 + //querySelfWealth = querySelfWealth.ColumnExpr("t.employee_name AS employee_name")
402 querySelfWealth = querySelfWealth.ColumnExpr("t.employee_su_money AS employee_su_money") 403 querySelfWealth = querySelfWealth.ColumnExpr("t.employee_su_money AS employee_su_money")
403 querySelfWealth = querySelfWealth.ColumnExpr("t.ranking AS ranking") 404 querySelfWealth = querySelfWealth.ColumnExpr("t.ranking AS ranking")
404 if uid, ok := queryOptions["uid"]; ok { 405 if uid, ok := queryOptions["uid"]; ok {
@@ -420,7 +421,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -420,7 +421,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
420 queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 421 queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
421 //queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 422 //queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
422 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") 423 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")
423 - 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), e.create_time DESC) AS ranking") 424 + 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")
424 queryContributions = queryContributions.Where(`e.status = ?`, 1) 425 queryContributions = queryContributions.Where(`e.status = ?`, 1)
425 //queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 426 //queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
426 queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid'") 427 queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid'")
@@ -449,7 +450,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -449,7 +450,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
449 } else { 450 } else {
450 queryContributions = queryContributions.Limit(20) 451 queryContributions = queryContributions.Limit(20)
451 } 452 }
452 - if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil { 453 + if err := queryContributions.Order("ranking ASC").Select(&retContributions); err != nil {
453 return nil, err 454 return nil, err
454 } 455 }
455 456
@@ -457,9 +458,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -457,9 +458,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
457 queryContributionsWith := tx.Model(suMoneyTransactionRecordModel) 458 queryContributionsWith := tx.Model(suMoneyTransactionRecordModel)
458 queryContributionsWith = queryContributionsWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 459 queryContributionsWith = queryContributionsWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
459 queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 460 queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
460 - queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 461 + //queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
461 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") 462 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")
462 - 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), e.create_time AS ranking") 463 + 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")
463 queryContributionsWith = queryContributionsWith.Where(`e.status = ?`, 1) 464 queryContributionsWith = queryContributionsWith.Where(`e.status = ?`, 1)
464 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 465 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
465 queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId) 466 queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId)
@@ -470,12 +471,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -470,12 +471,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
470 if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() { 471 if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
471 queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime) 472 queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
472 } 473 }
473 - contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 474 + //contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
  475 + contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid'")
474 querySelfContributions := tx.Model() 476 querySelfContributions := tx.Model()
475 querySelfContributions = querySelfContributions.With("t", contributionsWith) 477 querySelfContributions = querySelfContributions.With("t", contributionsWith)
476 querySelfContributions = querySelfContributions.Table("t") 478 querySelfContributions = querySelfContributions.Table("t")
477 querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid") 479 querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid")
478 - querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name") 480 + //querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
479 querySelfContributions = querySelfContributions.ColumnExpr("t.employees_contributions AS employees_contributions") 481 querySelfContributions = querySelfContributions.ColumnExpr("t.employees_contributions AS employees_contributions")
480 querySelfContributions = querySelfContributions.ColumnExpr("t.ranking AS ranking") 482 querySelfContributions = querySelfContributions.ColumnExpr("t.ranking AS ranking")
481 if uid, ok := queryOptions["uid"]; ok { 483 if uid, ok := queryOptions["uid"]; ok {
@@ -34,6 +34,15 @@ func IsContain(items []interface{}, item string) bool { @@ -34,6 +34,15 @@ func IsContain(items []interface{}, item string) bool {
34 return false 34 return false
35 } 35 }
36 36
  37 +func IsContainInt(items map[int64]interface{}, item int64) bool {
  38 + for _, eachItem := range items {
  39 + if eachItem == item {
  40 + return true
  41 + }
  42 + }
  43 + return false
  44 +}
  45 +
37 type LocalTime time.Time 46 type LocalTime time.Time
38 47
39 // MarshalJSON satify the json marshal interface 48 // MarshalJSON satify the json marshal interface