作者 陈志颖

fix:排行榜管理

@@ -440,31 +440,51 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -440,31 +440,51 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
440 "companyId": contributionsWealthRankingQuery.CompanyId, 440 "companyId": contributionsWealthRankingQuery.CompanyId,
441 } 441 }
442 442
443 - if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil { 443 + if _, listIntervals, err := listIntervalRepository.FindAll(listListIntervalQuery); err != nil {
444 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 444 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
445 } else { 445 } else {
446 if len(listIntervals) == 0 { // 未配置年榜 446 if len(listIntervals) == 0 { // 未配置年榜
447 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local) 447 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
448 - contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local) 448 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
449 } else if len(listIntervals) == 1 { // 只配置了一个年榜 449 } else if len(listIntervals) == 1 { // 只配置了一个年榜
450 - currentTime := time.Now().Local()  
451 - if currentTime.After(listIntervals[0].IntervalStartTime.Local()) && currentTime.Before(listIntervals[0].IntervalEndTime.Local()) || currentTime.Equal(listIntervals[0].IntervalStartTime.Local()) || currentTime.Equal(listIntervals[0].IntervalEndTime.Local()) { // 当前时间在榜单内 450 + //currentTime := time.Now().Local()
  451 + //if currentTime.After(listIntervals[0].IntervalStartTime.Local()) && currentTime.Before(listIntervals[0].IntervalEndTime.Local()) || currentTime.Equal(listIntervals[0].IntervalStartTime.Local()) || currentTime.Equal(listIntervals[0].IntervalEndTime.Local()) { // 当前时间在榜单内
  452 + // contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime.Local()
  453 + // contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime.Local()
  454 + //} else { // 当前时间处于空档期
  455 + // contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  456 + // contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
  457 + //}
  458 + currentTime := time.Now().Local().Unix()
  459 + if currentTime >= listIntervals[0].IntervalStartTime.Unix() && currentTime <= listIntervals[0].IntervalEndTime.Local().Unix() {
452 contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime.Local() 460 contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime.Local()
453 contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime.Local() 461 contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime.Local()
454 } else { // 当前时间处于空档期 462 } else { // 当前时间处于空档期
455 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local) 463 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
456 - contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local) 464 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
457 } 465 }
458 } else { // 配置了多个年榜,判断当前时间是否在榜单里 466 } else { // 配置了多个年榜,判断当前时间是否在榜单里
459 - currentTime := time.Now().Local() 467 + //currentTime := time.Now().Local()
  468 + //for _, listInterval := range listIntervals {
  469 + // if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内
  470 + // contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime.Local()
  471 + // contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime.Local()
  472 + // break
  473 + // } else { // 当前时间处于空档期
  474 + // contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
  475 + // contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
  476 + // break
  477 + // }
  478 + //}
  479 + currentTime := time.Now().Local().Unix()
460 for _, listInterval := range listIntervals { 480 for _, listInterval := range listIntervals {
461 - if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内 481 + if currentTime >= listInterval.IntervalStartTime.Local().Unix() && currentTime <= listInterval.IntervalEndTime.Local().Unix() {
462 contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime.Local() 482 contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime.Local()
463 contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime.Local() 483 contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime.Local()
464 break 484 break
465 } else { // 当前时间处于空档期 485 } else { // 当前时间处于空档期
466 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local) 486 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
467 - contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local) 487 + contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
468 break 488 break
469 } 489 }
470 } 490 }
@@ -17,6 +17,7 @@ type ListIntervalRepository interface { @@ -17,6 +17,7 @@ type ListIntervalRepository interface {
17 Remove(listInterval *ListInterval) (*ListInterval, error) 17 Remove(listInterval *ListInterval) (*ListInterval, error)
18 FindOne(queryOptions map[string]interface{}) (*ListInterval, error) 18 FindOne(queryOptions map[string]interface{}) (*ListInterval, error)
19 Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error) 19 Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
  20 + FindAll(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
20 } 21 }
21 22
22 func (listInterval *ListInterval) Identify() interface{} { 23 func (listInterval *ListInterval) Identify() interface{} {
@@ -63,6 +63,28 @@ func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interf @@ -63,6 +63,28 @@ func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interf
63 } 63 }
64 } 64 }
65 65
  66 +func (repository *ListIntervalRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
  67 + tx := repository.transactionContext.PgTx
  68 + var listIntervalModels []*models.ListInterval
  69 + listIntervals := make([]*domain.ListInterval, 0)
  70 + query := tx.Model(&listIntervalModels)
  71 + if companyId, ok := queryOptions["companyId"]; ok {
  72 + query = query.Where("list_interval.company_id = ?", companyId)
  73 + }
  74 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  75 + return 0, listIntervals, err
  76 + } else {
  77 + for _, listIntervalModel := range listIntervalModels {
  78 + if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
  79 + return 0, listIntervals, err
  80 + } else {
  81 + listIntervals = append(listIntervals, listInterval)
  82 + }
  83 + }
  84 + return int64(count), listIntervals, nil
  85 + }
  86 +}
  87 +
66 func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) { 88 func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
67 tx := repository.transactionContext.PgTx 89 tx := repository.transactionContext.PgTx
68 var listIntervalModels []*models.ListInterval 90 var listIntervalModels []*models.ListInterval