Calendar calendar = Calendar.getInstance();
String dataTime =(String) params.get("dataTime");
if (StringUtils.isBlank((String)params.get("dataTime"))){
dataTime=String.valueOf(calendar.get(Calendar.YEAR));
}
List<Map<String,Object>> resutList = new ArrayList<>();
String userId = StpUtil.getLoginIdAsString();
for (int i = 1; i <=12 ; i++) {
Map<String,Object> monthMap = new HashMap<>();
String data = dataTime + "-" + (i>9?i:"0"+i);
params.put("dataTime",data);
List<Map<String, Object>> infoList = baseMapper.getInfoList(params);
Integer myContribute=0;
// 获取我的贡献总数
for (Map<String,Object> map:infoList ){
if (map.containsValue(userId)){
myContribute++;
}
}
Map<String, List<Map>> map = infoList .stream().collect(Collectors.groupingBy(e -> e.get("addUserId").toString()));
List<String> result = new ArrayList<String>();
for(Map.Entry<String, List<Map>> entry : map.entrySet()) {
List<Map> mapValue = entry.getValue();
result.add(String.valueOf(mapValue.size()));
}
String max = "0";
if (!CollectionUtils.isEmpty(result)){
max = Collections.max(result);
}
monthMap.put("monthMax",max);
monthMap.put("month",i+"月");
// 我的贡献条数
monthMap.put("myContribute",myContribute);
resutList.add(monthMap);
}
return resutList;
获取上个月
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Date date = new Date();
Calendar calendar = Calendar.getInstance();
// 设置为当前时间
calendar.setTime(date);
calendar.add(Calendar.MONTH, -1);
// 设置为上一个月
//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
date = calendar.getTime();
String dateTime = format.format(date);
指定月份,有多少天
public class Main {
public static int getDaysInMonth(int year, int month) {
YearMonth yearMonthObject = YearMonth.of(year, month);
return yearMonthObject.lengthOfMonth();
}
public static void main(String[] args) {
int year = 2021;
int month = 6;
int days = getDaysInMonth(year, month);
System.out.println("Days in month " + month + " of year " + year + " is " + days);
}
}
该代码段使用Java进行月份数据处理,包括获取当前年份、遍历12个月并计算指定日期或上个月的数据。通过baseMapper查询数据,统计每个用户在各个月份的贡献次数,并找出每月最大贡献数。同时,计算指定年份和月份的总天数。

1025

被折叠的 条评论
为什么被折叠?



