package org.jeecg.common.util;
|
|
import com.nlf.calendar.Holiday;
|
import com.nlf.calendar.util.HolidayUtil;
|
|
import java.util.*;
|
|
/**
|
* 节假日工具类
|
*/
|
public class HolidayUtils {
|
public static void main(String[] args) {
|
Map<Integer, Integer> holidayWeek = getHolidayWeek(2024);
|
System.out.println(holidayWeek);
|
|
|
}
|
/**
|
* 获取指定年份的节假日
|
* @param year
|
* @return
|
*/
|
public static Map<Integer, Integer> getHolidayWeek(int year) {
|
//统计一周有几天,一周有5天假期则不计算绩效
|
Map<Integer, Integer> weekMap = new HashMap<>();
|
List<Holiday> holidays = HolidayUtil.getHolidays(year);
|
holidays.forEach(item -> {
|
if (item.getName().equals("春节") || item.getName().equals("劳动节") || item.getName().equals("国庆节")) {
|
if (item.isWork()) return;
|
String day = item.getDay();
|
Date date = DateUtils.str2Date(day, DateUtils.date_sdf.get());
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(date);
|
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 将星期日从1映射为0
|
|
Integer weekNoByDate = DateUtils.getWeekNoByDate(date);
|
// System.out.println("假期:" + item.getName() + "日期:" + item.getDay());
|
// System.out.println("星期 " + dayOfWeek);
|
// System.out.println("这一天是一年的第 " + weekNoByDate + " 周");
|
// System.out.println("-----------------------");
|
|
//排除周末(统计一周5天都是假期的周号)
|
if (dayOfWeek != 6 && dayOfWeek != 0) {
|
if (weekMap.containsKey(weekNoByDate)) {
|
weekMap.put(weekNoByDate, weekMap.get(weekNoByDate) + 1);
|
} else {
|
weekMap.put(weekNoByDate, 1);
|
}
|
}
|
}
|
});
|
weekMap.entrySet().removeIf(entry -> entry.getValue() < 5);
|
|
return weekMap;
|
}
|
|
|
}
|