作者 陈志颖

fix:排行榜管理

... ... @@ -440,31 +440,51 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
"companyId": contributionsWealthRankingQuery.CompanyId,
}
if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
if _, listIntervals, err := listIntervalRepository.FindAll(listListIntervalQuery); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if len(listIntervals) == 0 { // 未配置年榜
contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
} else if len(listIntervals) == 1 { // 只配置了一个年榜
currentTime := time.Now().Local()
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()) { // 当前时间在榜单内
//currentTime := time.Now().Local()
//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()) { // 当前时间在榜单内
// contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime.Local()
// contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime.Local()
//} else { // 当前时间处于空档期
// contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
// contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
//}
currentTime := time.Now().Local().Unix()
if currentTime >= listIntervals[0].IntervalStartTime.Unix() && currentTime <= listIntervals[0].IntervalEndTime.Local().Unix() {
contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime.Local()
contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime.Local()
} else { // 当前时间处于空档期
contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
}
} else { // 配置了多个年榜,判断当前时间是否在榜单里
currentTime := time.Now().Local()
//currentTime := time.Now().Local()
//for _, listInterval := range listIntervals {
// if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内
// contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime.Local()
// contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime.Local()
// break
// } else { // 当前时间处于空档期
// contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
// contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
// break
// }
//}
currentTime := time.Now().Local().Unix()
for _, listInterval := range listIntervals {
if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内
if currentTime >= listInterval.IntervalStartTime.Local().Unix() && currentTime <= listInterval.IntervalEndTime.Local().Unix() {
contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime.Local()
contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime.Local()
break
} else { // 当前时间处于空档期
contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
break
}
}
... ...
... ... @@ -17,6 +17,7 @@ type ListIntervalRepository interface {
Remove(listInterval *ListInterval) (*ListInterval, error)
FindOne(queryOptions map[string]interface{}) (*ListInterval, error)
Find(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
FindAll(queryOptions map[string]interface{}) (int64, []*ListInterval, error)
}
func (listInterval *ListInterval) Identify() interface{} {
... ...
... ... @@ -63,6 +63,28 @@ func (repository *ListIntervalRepository) FindOne(queryOptions map[string]interf
}
}
func (repository *ListIntervalRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
var listIntervalModels []*models.ListInterval
listIntervals := make([]*domain.ListInterval, 0)
query := tx.Model(&listIntervalModels)
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("list_interval.company_id = ?", companyId)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, listIntervals, err
} else {
for _, listIntervalModel := range listIntervalModels {
if listInterval, err := repository.transformPgModelToDomainModel(listIntervalModel); err != nil {
return 0, listIntervals, err
} else {
listIntervals = append(listIntervals, listInterval)
}
}
return int64(count), listIntervals, nil
}
}
func (repository *ListIntervalRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ListInterval, error) {
tx := repository.transactionContext.PgTx
var listIntervalModels []*models.ListInterval
... ...