|
@@ -2,8 +2,10 @@ package com.zfjg.manage.service.impl.other;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.zfjg.common.core.exception.ServiceException;
|
|
|
import com.zfjg.common.core.interfaces.IHolidayCacheService;
|
|
|
import com.zfjg.common.core.utils.DateUtils;
|
|
|
+import com.zfjg.common.core.utils.SpringUtils;
|
|
|
import com.zfjg.common.redis.service.RedisService;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -11,9 +13,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.rmi.ServerException;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author xxd
|
|
@@ -47,10 +47,13 @@ public class IHolidayCacheServiceImpl implements IHolidayCacheService {
|
|
|
cacheObject.put(dayDate, false);
|
|
|
}
|
|
|
}
|
|
|
+ HashMap<String, Object> lastTwoYears = this.getLastTwoYears();
|
|
|
+ cacheObject.putAll(lastTwoYears);
|
|
|
redisService.setCacheMap(CACHE_KEY, cacheObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@SneakyThrows
|
|
|
@Override
|
|
|
public Boolean getHoliday(Date currentDay) {
|
|
@@ -62,6 +65,34 @@ public class IHolidayCacheServiceImpl implements IHolidayCacheService {
|
|
|
if (cacheMap.containsKey(dateFormat)) {
|
|
|
return (Boolean) cacheMap.get(dateFormat);
|
|
|
}
|
|
|
- throw new ServerException("获取节假日数据异常");
|
|
|
+ throw new ServerException("获取节假日数据异常: " + dateFormat);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取后两年的日期
|
|
|
+ */
|
|
|
+ private HashMap<String, Object> getLastTwoYears() {
|
|
|
+ HashMap<String, Object> objectHashMap = new HashMap<>();
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ Date time = instance.getTime();
|
|
|
+ String dateFormat = DateUtils.getDateFormat(time, "yyyy");
|
|
|
+ if (dateFormat == null) {
|
|
|
+ throw new ServiceException("获取当年yyyy出错" + time);
|
|
|
+ }
|
|
|
+ Integer i = Integer.parseInt(dateFormat);
|
|
|
+ String s1 = i + "-12-31 00:00:00";
|
|
|
+ Date date = DateUtils.transStrToDate(s1);
|
|
|
+ instance.setTime(date);
|
|
|
+ for (int j = 0; j < 750; j++) {
|
|
|
+ instance.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ int i1 = instance.get(Calendar.DAY_OF_WEEK);
|
|
|
+ String dateFormatMap = DateUtils.getDateFormat(instance.getTime(), "yyyy-MM-dd");
|
|
|
+ if (i1 == Calendar.SATURDAY || i1 == Calendar.SUNDAY) {
|
|
|
+ objectHashMap.put(dateFormatMap, true);
|
|
|
+ } else {
|
|
|
+ objectHashMap.put(dateFormatMap, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objectHashMap;
|
|
|
}
|
|
|
}
|