作者 陈志颖

fix:完善贡献值、财富值榜单参数

@@ -28,11 +28,13 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt @@ -28,11 +28,13 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
28 defer func() { 28 defer func() {
29 transactionContext.RollbackTransaction() 29 transactionContext.RollbackTransaction()
30 }() 30 }()
  31 +
31 newListInterval := &domain.ListInterval { 32 newListInterval := &domain.ListInterval {
32 CompanyId: createListIntervalCommand.CompanyId, 33 CompanyId: createListIntervalCommand.CompanyId,
33 IntervalStartTime: createListIntervalCommand.ListIntervalStartTime, 34 IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
34 IntervalEndTime: createListIntervalCommand.ListIntervalEndTime, 35 IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
35 } 36 }
  37 +
36 var listIntervalRepository domain.ListIntervalRepository 38 var listIntervalRepository domain.ListIntervalRepository
37 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 39 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
38 "transactionContext": transactionContext, 40 "transactionContext": transactionContext,
@@ -41,6 +43,7 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt @@ -41,6 +43,7 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
41 } else { 43 } else {
42 listIntervalRepository = value 44 listIntervalRepository = value
43 } 45 }
  46 +
44 if listInterval, err := listIntervalRepository.Save(newListInterval); err != nil { 47 if listInterval, err := listIntervalRepository.Save(newListInterval); err != nil {
45 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 48 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
46 } else { 49 } else {
@@ -66,6 +69,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva @@ -66,6 +69,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva
66 defer func() { 69 defer func() {
67 transactionContext.RollbackTransaction() 70 transactionContext.RollbackTransaction()
68 }() 71 }()
  72 +
69 var listIntervalRepository domain.ListIntervalRepository 73 var listIntervalRepository domain.ListIntervalRepository
70 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 74 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
71 "transactionContext": transactionContext, 75 "transactionContext": transactionContext,
@@ -74,6 +78,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva @@ -74,6 +78,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva
74 } else { 78 } else {
75 listIntervalRepository = value 79 listIntervalRepository = value
76 } 80 }
  81 +
77 if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); err != nil { 82 if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); err != nil {
78 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 83 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
79 } else { 84 } else {
@@ -102,6 +107,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ @@ -102,6 +107,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ
102 defer func() { 107 defer func() {
103 transactionContext.RollbackTransaction() 108 transactionContext.RollbackTransaction()
104 }() 109 }()
  110 +
105 var listIntervalRepository domain.ListIntervalRepository 111 var listIntervalRepository domain.ListIntervalRepository
106 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 112 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
107 "transactionContext": transactionContext, 113 "transactionContext": transactionContext,
@@ -110,6 +116,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ @@ -110,6 +116,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ
110 } else { 116 } else {
111 listIntervalRepository = value 117 listIntervalRepository = value
112 } 118 }
  119 +
113 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId}) 120 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId})
114 if err != nil { 121 if err != nil {
115 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 122 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -139,6 +146,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -139,6 +146,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
139 defer func() { 146 defer func() {
140 transactionContext.RollbackTransaction() 147 transactionContext.RollbackTransaction()
141 }() 148 }()
  149 +
142 var listIntervalRepository domain.ListIntervalRepository 150 var listIntervalRepository domain.ListIntervalRepository
143 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 151 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
144 "transactionContext": transactionContext, 152 "transactionContext": transactionContext,
@@ -147,6 +155,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -147,6 +155,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
147 } else { 155 } else {
148 listIntervalRepository = value 156 listIntervalRepository = value
149 } 157 }
  158 +
150 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId}) 159 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
151 if err != nil { 160 if err != nil {
152 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 161 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -157,6 +166,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -157,6 +166,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
157 if err := listInterval.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil { 166 if err := listInterval.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
158 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 167 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
159 } 168 }
  169 +
160 if listInterval, err := listIntervalRepository.Save(listInterval); err != nil { 170 if listInterval, err := listIntervalRepository.Save(listInterval); err != nil {
161 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 171 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
162 } else { 172 } else {
@@ -182,6 +192,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt @@ -182,6 +192,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
182 defer func() { 192 defer func() {
183 transactionContext.RollbackTransaction() 193 transactionContext.RollbackTransaction()
184 }() 194 }()
  195 +
185 var listIntervalRepository domain.ListIntervalRepository 196 var listIntervalRepository domain.ListIntervalRepository
186 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 197 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
187 "transactionContext": transactionContext, 198 "transactionContext": transactionContext,
@@ -190,6 +201,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt @@ -190,6 +201,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
190 } else { 201 } else {
191 listIntervalRepository = value 202 listIntervalRepository = value
192 } 203 }
  204 +
193 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId}) 205 listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId})
194 if err != nil { 206 if err != nil {
195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 207 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -197,6 +209,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt @@ -197,6 +209,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
197 if listInterval == nil { 209 if listInterval == nil {
198 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId))) 210 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId)))
199 } 211 }
  212 +
200 if listInterval, err := listIntervalRepository.Remove(listInterval); err != nil { 213 if listInterval, err := listIntervalRepository.Remove(listInterval); err != nil {
201 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 214 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
202 } else { 215 } else {
@@ -384,7 +384,7 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp @@ -384,7 +384,7 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp
384 } 384 }
385 } 385 }
386 386
387 -// TODO 员工排行榜统计 387 +// 员工排行榜统计 (弃用)
388 func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) { 388 func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {
389 if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil { 389 if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil {
390 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 390 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -449,6 +449,44 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -449,6 +449,44 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
449 employeeDao = value 449 employeeDao = value
450 } 450 }
451 451
  452 + // 返回年榜开始时间、结束时间
  453 + if contributionsWealthRankingQuery.RankingType == 2 {
  454 + // 获取公司最新年榜
  455 + var listIntervalRepository domain.ListIntervalRepository
  456 + if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
  457 + "transactionContext": transactionContext,
  458 + }); err != nil {
  459 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  460 + } else {
  461 + listIntervalRepository = value
  462 + }
  463 +
  464 + listListIntervalQuery := map[string]interface{} {
  465 + "companyId": contributionsWealthRankingQuery.CompanyId,
  466 + "offset": 0,
  467 + "limit": 1,
  468 + }
  469 +
  470 + if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
  471 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  472 + } else {
  473 + if len(listIntervals) == 0 {
  474 + contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  475 + contributionsWealthRankingQuery.EndTime = time.Now()
  476 + } else {
  477 + contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime
  478 + contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime
  479 + }
  480 + }
  481 + }
  482 +
  483 + // 返回总榜
  484 + if contributionsWealthRankingQuery.RankingType == 1 {
  485 + contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  486 + contributionsWealthRankingQuery.EndTime = time.Now()
  487 + }
  488 +
  489 + // 默认返回总榜
452 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil { 490 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil {
453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 491 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
454 } else { 492 } else {
@@ -3,13 +3,17 @@ package query @@ -3,13 +3,17 @@ package query
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/validation" 5 "github.com/astaxie/beego/validation"
  6 + "time"
6 ) 7 )
7 8
8 type ContributionsWealthRankingQuery struct { 9 type ContributionsWealthRankingQuery struct {
9 - CompanyId int64 `json:"companyId"` // 公司ID 10 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  11 + RankingType int `json:"rankingType" valid:"Required"` // 榜单类型,区分总榜和年榜 1:总榜,2:年榜
10 Offset int `json:"offset,omitempty"` // 查询偏离量 12 Offset int `json:"offset,omitempty"` // 查询偏离量
11 Limit int `json:"limit,omitempty"` // 查询限制 13 Limit int `json:"limit,omitempty"` // 查询限制
12 - Uid int64 `json:"uid"` // 统一用户id 14 + Uid int64 `json:"uid" valid:"Required"` // 统一用户id
  15 + StartTime time.Time `json:"startTime"` // 榜单开始时间,由后台根据榜单类型后去
  16 + EndTime time.Time `json:"endTime"` // 榜单结束更新,由后台根据榜单类型获取
13 } 17 }
14 18
15 func (contributionsWealthRankingQuery *ContributionsWealthRankingQuery) ValidateQuery() error { 19 func (contributionsWealthRankingQuery *ContributionsWealthRankingQuery) ValidateQuery() error {
@@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. @@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
283 // }, nil 283 // }, nil
284 //} 284 //}
285 285
286 -// 贡献值、财富值排行 286 +// 贡献值、财富值总榜和年
287 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) { 287 func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
288 var retWealth []struct { 288 var retWealth []struct {
289 Uid int 289 Uid int
@@ -313,7 +313,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -313,7 +313,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
313 tx := dao.transactionContext.PgTx 313 tx := dao.transactionContext.PgTx
314 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 314 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
315 315
316 - // 财富值排名 316 + // 财富值榜单
317 queryWealth := tx.Model(suMoneyTransactionRecordModel) 317 queryWealth := tx.Model(suMoneyTransactionRecordModel)
318 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 318 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
319 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 319 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
@@ -377,8 +377,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -377,8 +377,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
377 if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil { 377 if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil {
378 return nil, err 378 return nil, err
379 } 379 }
  380 + var retCurrentEmployeeWealth interface{}
  381 + if len(retEmployeeWealth) == 0 {
  382 + retCurrentEmployeeWealth = nil
  383 + } else {
  384 + retCurrentEmployeeWealth = retEmployeeWealth[0]
  385 + }
380 386
381 - // 贡献值排名 387 + // 贡献值榜单
382 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel) 388 queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
383 queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 389 queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
384 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 390 queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
@@ -506,12 +512,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -506,12 +512,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
506 if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil { 512 if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil {
507 return nil, err 513 return nil, err
508 } 514 }
  515 + var retCurrentEmployeeContributions interface{}
  516 + if len(retEmployeeContributions) == 0 {
  517 + retCurrentEmployeeContributions = nil
  518 + } else {
  519 + retCurrentEmployeeContributions = retEmployeeContributions[0]
  520 + }
509 521
510 return map[string]interface{}{ 522 return map[string]interface{}{
511 "employeesWealth": retWealth, 523 "employeesWealth": retWealth,
512 "employeesContributions": retContributions, 524 "employeesContributions": retContributions,
513 - "currentEmployeeContributions": retEmployeeContributions,  
514 - "currentEmployeeWealth": retEmployeeWealth, 525 + "currentEmployeeContributions": retCurrentEmployeeContributions,
  526 + "currentEmployeeWealth": retCurrentEmployeeWealth,
515 }, nil 527 }, nil
516 } 528 }
517 529
@@ -141,11 +141,8 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { @@ -141,11 +141,8 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() {
141 // 员工财富值、贡献值排行榜 141 // 员工财富值、贡献值排行榜
142 func (controller *StatisticsController) RankingListStatistics() { 142 func (controller *StatisticsController) RankingListStatistics() {
143 statisticsService := service.NewStatisticsService(nil) 143 statisticsService := service.NewStatisticsService(nil)
144 - //employeesRankingListStatisticsCommand := &command.EmployeesRankingListStatisticsCommand{}  
145 - //json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesRankingListStatisticsCommand)  
146 contributionsWealthRankingQuery := &query.ContributionsWealthRankingQuery{} 144 contributionsWealthRankingQuery := &query.ContributionsWealthRankingQuery{}
147 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsWealthRankingQuery) 145 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsWealthRankingQuery)
148 - //data, err := statisticsService.EmployeesRankingListStatistics(employeesRankingListStatisticsCommand)  
149 data, err := statisticsService.ContributionsWealthRanking(contributionsWealthRankingQuery) 146 data, err := statisticsService.ContributionsWealthRanking(contributionsWealthRankingQuery)
150 var response utils.JsonResponse 147 var response utils.JsonResponse
151 if err != nil { 148 if err != nil {