|
|
@@ -1,14 +1,19 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.izouma.nineth.config.MetaConstants;
|
|
|
import com.izouma.nineth.domain.MetaUserGoldRecord;
|
|
|
+import com.izouma.nineth.dto.MetaRankDTO;
|
|
|
+import com.izouma.nineth.dto.MetaRestResult;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.repo.MetaUserGoldRecordRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -24,9 +29,28 @@ public class MetaUserGoldRecordService {
|
|
|
return metaUserGoldRecordRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaUserGoldRecord.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public List<Map<String, String>> rank() {
|
|
|
+ public MetaRestResult<List<MetaRankDTO>> top() {
|
|
|
+ List<Map<String, String>> rank = rank(true);
|
|
|
+ if (CollectionUtils.isEmpty(rank)) {
|
|
|
+ return MetaRestResult.returnSuccess(new ArrayList<>());
|
|
|
+ }
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ jsonArray.addAll(rank);
|
|
|
+ return MetaRestResult.returnSuccess(jsonArray.toJavaList(MetaRankDTO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计规定时间内用户获取金币的榜单
|
|
|
+ *
|
|
|
+ * @param limit 是否查询全部
|
|
|
+ * @return 榜单数据
|
|
|
+ */
|
|
|
+ public List<Map<String, String>> rank(boolean limit) {
|
|
|
String beginTime = metaParamsConfigService.getString(MetaConstants.META_GOLD_TOP_BEGIN_TIME);
|
|
|
String endTime = metaParamsConfigService.getString(MetaConstants.META_GOLD_TOP_END_TIME);
|
|
|
+ if (limit) {
|
|
|
+ return metaUserGoldRecordRepo.rankLimit(beginTime, endTime, MetaConstants.META_GOLD_RECEIVED_RANK_LIMIT_NUM);
|
|
|
+ }
|
|
|
return metaUserGoldRecordRepo.rank(beginTime, endTime);
|
|
|
}
|
|
|
}
|