可直接使用,定期维护数据。如数据错误为跳过节假日,请及时提醒。
接口地址:http://222.210.127.164:81/holiday/api/day/holiday/addDaysSkipHoliday/{ymdDateString}/{days}
# ymdDateString:日期字符串 2020-01-01
# days:天数
核心代码
1. 跳过周末
public String addDaysSkipWeekend(String ymdDate, int days) throws BusinessException {
Calendar nowTime = Calendar.getInstance();
nowTime.setTime(DateTimeUtil.parseDate(ymdDate));
// 增加天数
for (int i = 0; i < days; i++) {
// 增加天数
nowTime.add(Calendar.DATE, 1);
// 判断日期类型,是否周末
String isWeek = judgeDateIsHoliday(DateTimeUtil.dateFormat2YmdInteger(nowTime.getTime()));
log.info("是否周末==={}", isWeek);
if ("2".equals(isWeek)) {
i--;
}
}
Date nowTimeTime = nowTime.getTime();
return DateTimeUtil.dateFormat2YmdString(nowTimeTime);
}
2. 跳过节假日
public String addDaysSkipHoliday(String ymdDate, int days) throws BusinessException {
Calendar nowTime = Calendar.getInstance();
nowTime.setTime(DateTimeUtil.parseDate(ymdDate));
// 增加天数
for (int i = 0; i < days; i++) {
// 增加天数
nowTime.add(Calendar.DATE, 1);
// 判断日期类型,是否工作日
String isWork = judgeDateIsHoliday(DateTimeUtil.dateFormat2YmdInteger(nowTime.getTime()));
if (!"0".equals(isWork)) {
i--;
}
}
Date nowTimeTime = nowTime.getTime();
return DateTimeUtil.dateFormat2YmdString(nowTimeTime);
}
3. 判断日期类型
public String judgeDateIsHoliday(String ymdDate) throws BusinessException {
String ymdString = DateTimeUtil.dateFormat2YmdString(DateTimeUtil.parseDate(ymdDate));
HolidayBDayEntity dayEntity = holidayBDayMapper
.selectOne(new QueryWrapper<HolidayBDayEntity>().eq("day_ymd", ymdString));
return dayEntity.getDayType();
}
网友评论