|
|
@@ -15,7 +15,9 @@ import vip.xiaonuo.disk.service.ResourceStatisticService;
|
|
|
import vip.xiaonuo.disk.util.AppUseAggregationUtil;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 资源统计分析Service接口实现类
|
|
|
@@ -170,13 +172,45 @@ public class ResourceStatisticServiceImpl extends ServiceImpl<ResourceStatisticM
|
|
|
@Override
|
|
|
public List<Map<String, Object>> selectResourceUpload(String collegeId, String type) {
|
|
|
Map<String, Object> map = getTime(type);
|
|
|
- Map<String,Object> rs=resourceStatisticMapper.selectResourceUpload(collegeId,map);
|
|
|
- List<Map<String, Object>> newList = new ArrayList<>();
|
|
|
- newList.add(createStatisticMap(1, MapUtils.getInteger(rs, "uploadNum", 0)));
|
|
|
- newList.add(createStatisticMap(2, MapUtils.getInteger(rs, "seeNum", 0)));
|
|
|
- return newList;
|
|
|
+
|
|
|
+ List<String> months =getMonthsUntilNow();
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> rs=resourceStatisticMapper.selectResourceUpload(collegeId,map);
|
|
|
+ List<String> validCrateMonths = rs.stream()
|
|
|
+ .map(item -> item.get("createMonth"))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(Object::toString)
|
|
|
+ .filter(months::contains)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> months1=months.stream().filter(month->!validCrateMonths.contains(month)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ months1.stream().forEach(month->{
|
|
|
+ Map<String, Object> monthMap=new HashMap<>(3);
|
|
|
+ monthMap.put("createMonth",month);
|
|
|
+ monthMap.put("uploadNum",0);
|
|
|
+ monthMap.put("seeNum",0);
|
|
|
+ rs.add(monthMap);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 使用 Comparator.comparing 进行排序
|
|
|
+ return rs.stream()
|
|
|
+ .sorted(Comparator.comparing(
|
|
|
+ map1 -> (String) map1.get("createMonth"),
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder())
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
+ public List<String> getMonthsUntilNow() {
|
|
|
+ int currentMonth = LocalDate.now().getMonthValue();
|
|
|
+ List<String> months = new ArrayList<>();
|
|
|
|
|
|
+ for (int month = 1; month <= currentMonth; month++) {
|
|
|
+ months.add(String.format("%02d", month));
|
|
|
+ }
|
|
|
+ return months;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 创建统计信息Map
|
|
|
@@ -185,7 +219,7 @@ public class ResourceStatisticServiceImpl extends ServiceImpl<ResourceStatisticM
|
|
|
* @return 统计信息Map
|
|
|
*/
|
|
|
private Map<String, Object> createStatisticMap(int type, int num) {
|
|
|
- Map<String, Object> map = new HashMap<>(2);
|
|
|
+ Map<String, Object> map = new HashMap<>(3);
|
|
|
map.put("type", type);
|
|
|
map.put("num", num);
|
|
|
return map;
|