新危大工程
This commit is contained in:
parent
d99914d445
commit
bbfa43e521
@ -813,6 +813,46 @@ public class DateUtils {
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends DateAware> List<T> fillDateByStartEndDate(
|
||||||
|
Map<String, Object> param,
|
||||||
|
List<T> list,
|
||||||
|
Supplier<T> instanceSupplier
|
||||||
|
) {
|
||||||
|
String startDate = MapUtils.getString(param, "startDate");
|
||||||
|
String endDate = MapUtils.getString(param, "endDate");
|
||||||
|
List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR);
|
||||||
|
Map<String, T> dateMap = list.stream().collect(Collectors.toMap(T::getDate, Function.identity(), (o1, o2) -> o1));
|
||||||
|
return dateTimes.stream().map(dateTime -> {
|
||||||
|
String dateStr = DateUtil.formatDate(dateTime);
|
||||||
|
T obj = dateMap.get(dateStr);
|
||||||
|
if (obj == null) {
|
||||||
|
obj = instanceSupplier.get();
|
||||||
|
obj.setDate(dateStr);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends YearMonthAware> List<T> fillYearMonthByStartEndMonth(
|
||||||
|
Map<String, Object> param,
|
||||||
|
List<T> list,
|
||||||
|
Supplier<T> instanceSupplier
|
||||||
|
) {
|
||||||
|
String startMonth = MapUtils.getString(param, "startMonth");
|
||||||
|
String endMonth = MapUtils.getString(param, "endMonth");
|
||||||
|
List<DateTime> months = DateUtil.rangeToList(DateUtil.parseDate(startMonth + "-01"), DateUtil.parseDate(endMonth + "-01"), DateField.MONTH);
|
||||||
|
Map<String, T> dateMap = list.stream().collect(Collectors.toMap(T::getYearMonth, Function.identity(), (o1, o2) -> o1));
|
||||||
|
return months.stream().map(dateTime -> {
|
||||||
|
String dateStr = DateUtil.format(dateTime, "yyyy-MM");
|
||||||
|
T obj = dateMap.get(dateStr);
|
||||||
|
if (obj == null) {
|
||||||
|
obj = instanceSupplier.get();
|
||||||
|
obj.setYearMonth(dateStr);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 补充空白的日期的接口
|
* 补充空白的日期的接口
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user