|
|
@@ -5742,304 +5742,8 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
result.setStoreBusinessInfos(storeBusinessInfos);
|
|
|
}
|
|
|
if(storeInfo.getBusinessStatus() == 0){
|
|
|
- // 优先判断当前时间是否是特殊日期
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- LocalTime currentTime = LocalTime.now();
|
|
|
-
|
|
|
- log.info("开始判断营业状态 - 当前日期: {}, 当前时间: {}, 店铺ID: {}", currentDate, currentTime, storeId);
|
|
|
-
|
|
|
- // 标记当前是否是特殊营业时间
|
|
|
- boolean isCurrentSpecialBusinessTime = false;
|
|
|
-
|
|
|
- // 查找特殊营业时间(businessType == 2)
|
|
|
- StoreBusinessInfo specialBusinessInfo = storeBusinessInfos.stream()
|
|
|
- .filter(item -> item.getBusinessType() != null && item.getBusinessType() == 2)
|
|
|
- .filter(item -> {
|
|
|
- // 判断当前日期是否匹配特殊日期
|
|
|
- if (StringUtils.isEmpty(item.getBusinessDate())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- String businessDate = item.getBusinessDate().trim();
|
|
|
-
|
|
|
- // 移除开头的数字和空格(如 "2 元旦、春节、儿童节" -> "元旦、春节、儿童节")
|
|
|
- String holidayNames = businessDate.replaceAll("^\\d+\\s*", "").trim();
|
|
|
-
|
|
|
- // 判断是否包含节假日名称(支持所有特殊日期:元旦、春节、情人节、元宵节、清明节、劳动节、儿童节、端午节、七夕、中秋节、国庆节、冬至、平安夜、圣诞节)
|
|
|
- boolean isHolidayName = holidayNames.contains("元旦") || holidayNames.contains("春节") ||
|
|
|
- holidayNames.contains("情人节") || holidayNames.contains("元宵") ||
|
|
|
- holidayNames.contains("七夕") || holidayNames.contains("冬至") ||
|
|
|
- holidayNames.contains("平安夜") || holidayNames.contains("圣诞") ||
|
|
|
- holidayNames.contains("清明") || holidayNames.contains("劳动") ||
|
|
|
- holidayNames.contains("端午") || holidayNames.contains("中秋") ||
|
|
|
- holidayNames.contains("国庆") || holidayNames.contains("儿童");
|
|
|
-
|
|
|
- if (isHolidayName) {
|
|
|
-
|
|
|
- List<LocalDate[]> holidayRanges = getHolidayDateRanges(currentDate.getYear(), holidayNames);
|
|
|
- for (LocalDate[] range : holidayRanges) {
|
|
|
- if (range != null && range.length == 2) {
|
|
|
- LocalDate startDate = range[0];
|
|
|
- LocalDate endDate = range[1];
|
|
|
- if (!currentDate.isBefore(startDate) && !currentDate.isAfter(endDate)) {
|
|
|
- log.info("特殊日期判断(节假日) - 节假日: {}, 日期范围: {}至{}, 当前日期: {}, 是否在范围内: true",
|
|
|
- holidayNames, startDate, endDate, currentDate);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("特殊日期判断(节假日) - 节假日: {}, 当前日期: {}, 是否在范围内: false",
|
|
|
- holidayNames, currentDate);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果不是节假日名称,尝试解析日期格式(兼容旧格式)
|
|
|
- String[] dateFormats = {"yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd"};
|
|
|
-
|
|
|
- // 先检查是否包含"至"(日期范围)
|
|
|
- if (businessDate.contains("至")) {
|
|
|
- String[] dateRange = businessDate.split("至");
|
|
|
- if (dateRange.length >= 2) {
|
|
|
- try {
|
|
|
- LocalDate startDate = null;
|
|
|
- LocalDate endDate = null;
|
|
|
- for (String format : dateFormats) {
|
|
|
- try {
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
- startDate = LocalDate.parse(dateRange[0].trim(), formatter);
|
|
|
- endDate = LocalDate.parse(dateRange[1].trim(), formatter);
|
|
|
- break;
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
- }
|
|
|
- if (startDate != null && endDate != null) {
|
|
|
- boolean inRange = !currentDate.isBefore(startDate) && !currentDate.isAfter(endDate);
|
|
|
- log.info("特殊日期范围判断 - 日期范围: {}至{}, 当前日期: {}, 是否在范围内: {}",
|
|
|
- startDate, endDate, currentDate, inRange);
|
|
|
- return inRange;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("解析特殊日期范围失败: {}", businessDate, e);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 尝试解析单个日期格式
|
|
|
- for (String format : dateFormats) {
|
|
|
- try {
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
- LocalDate specialDate = LocalDate.parse(businessDate, formatter);
|
|
|
- boolean matches = specialDate.equals(currentDate);
|
|
|
- log.info("特殊日期判断 - 特殊日期: {}, 当前日期: {}, 是否匹配: {}",
|
|
|
- specialDate, currentDate, matches);
|
|
|
- if (matches) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } catch (Exception ignored) {
|
|
|
- // 继续尝试下一个格式
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("解析特殊日期失败: {}", item.getBusinessDate(), e);
|
|
|
- }
|
|
|
- return false;
|
|
|
- })
|
|
|
- .findFirst()
|
|
|
- .orElse(null);
|
|
|
-
|
|
|
- // 如果找到匹配的特殊日期,判断是否在营业时间内
|
|
|
- if (specialBusinessInfo != null) {
|
|
|
- log.info("找到匹配的特殊日期营业时间 - 开始时间: {}, 结束时间: {}",
|
|
|
- specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
- if (StringUtils.isNotEmpty(specialBusinessInfo.getStartTime())
|
|
|
- && StringUtils.isNotEmpty(specialBusinessInfo.getEndTime())) {
|
|
|
- try {
|
|
|
- String[] startArr = specialBusinessInfo.getStartTime().split(":");
|
|
|
- String[] endArr = specialBusinessInfo.getEndTime().split(":");
|
|
|
- if (startArr.length >= 2 && endArr.length >= 2) {
|
|
|
- LocalTime start = LocalTime.of(
|
|
|
- Integer.parseInt(startArr[0]),
|
|
|
- Integer.parseInt(startArr[1])
|
|
|
- );
|
|
|
- LocalTime end = LocalTime.of(
|
|
|
- Integer.parseInt(endArr[0]),
|
|
|
- Integer.parseInt(endArr[1])
|
|
|
- );
|
|
|
-
|
|
|
- boolean isInBusiness;
|
|
|
- // 判断是否是全天营业(00:00到00:00)
|
|
|
- LocalTime midnight = LocalTime.of(0, 0);
|
|
|
- if (start.equals(midnight) && end.equals(midnight)) {
|
|
|
- // 全天营业
|
|
|
- isInBusiness = true;
|
|
|
- log.info("特殊日期营业时间判断 - 全天营业(00:00-00:00),当前时间: {},是否在营业时间内: true", currentTime);
|
|
|
- } else {
|
|
|
- // 处理跨天营业
|
|
|
- if (start.isBefore(end) || start.equals(end)) {
|
|
|
- // 同一天营业:包含边界值
|
|
|
- isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
- && (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
- } else {
|
|
|
- // 跨天营业:包含边界值
|
|
|
- isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
- || (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
- }
|
|
|
- log.info("特殊日期营业时间判断 - 开始时间: {}, 结束时间: {}, 当前时间: {}, 是否在营业时间内: {}",
|
|
|
- start, end, currentTime, isInBusiness);
|
|
|
- }
|
|
|
-
|
|
|
- result.setYyFlag(isInBusiness ? 1 : 0);
|
|
|
- isCurrentSpecialBusinessTime = isInBusiness;
|
|
|
- } else {
|
|
|
- log.warn("特殊日期营业时间格式错误 - 开始时间: {}, 结束时间: {}",
|
|
|
- specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
- result.setYyFlag(0);
|
|
|
- isCurrentSpecialBusinessTime = false;
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- log.warn("解析特殊日期营业时间失败 - 开始时间: {}, 结束时间: {}",
|
|
|
- specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime(), e);
|
|
|
- result.setYyFlag(0);
|
|
|
- isCurrentSpecialBusinessTime = false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.warn("特殊日期营业时间为空 - 开始时间: {}, 结束时间: {}",
|
|
|
- specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
- result.setYyFlag(0);
|
|
|
- isCurrentSpecialBusinessTime = false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 如果不是特殊日期,判断正常营业时间(businessType == 1)
|
|
|
- StoreBusinessInfo normalBusinessInfo = storeBusinessInfos.stream()
|
|
|
- .filter(item -> item.getBusinessType() != null && item.getBusinessType() == 1)
|
|
|
- .findFirst()
|
|
|
- .orElse(null);
|
|
|
-
|
|
|
- if (normalBusinessInfo != null) {
|
|
|
- log.info("判断正常营业时间 - 营业日期: {}, 开始时间: {}, 结束时间: {}",
|
|
|
- normalBusinessInfo.getBusinessDate(),
|
|
|
- normalBusinessInfo.getStartTime(),
|
|
|
- normalBusinessInfo.getEndTime());
|
|
|
- // 获取当前星期并转换为业务格式
|
|
|
-// Calendar calendar = Calendar.getInstance();
|
|
|
-// int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // 1=周日,2=周一...7=周六
|
|
|
-// String[] days = {"7", "1", "2", "3", "4", "5", "6"};
|
|
|
-// String day = days[dayOfWeek - 1];
|
|
|
-
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // 1=周日,2=周一...7=周六
|
|
|
- // 映射数组:索引对应dayOfWeek-1,值为中文星期
|
|
|
- String[] weekDaysCN = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
|
|
- String day = weekDaysCN[dayOfWeek - 1];
|
|
|
-
|
|
|
- log.info("当前星期: {}, 转换后: {}", dayOfWeek, day);
|
|
|
-
|
|
|
- // 判断当前日期是否在营业日期范围内
|
|
|
- if (StringUtils.isNotEmpty(normalBusinessInfo.getBusinessDate())
|
|
|
- && normalBusinessInfo.getBusinessDate().contains(day)) {
|
|
|
- log.info("当前星期在营业日期范围内");
|
|
|
- if (StringUtils.isNotEmpty(normalBusinessInfo.getStartTime())
|
|
|
- && StringUtils.isNotEmpty(normalBusinessInfo.getEndTime())) {
|
|
|
- try {
|
|
|
- String[] startArr = normalBusinessInfo.getStartTime().split(":");
|
|
|
- String[] endArr = normalBusinessInfo.getEndTime().split(":");
|
|
|
- if (startArr.length >= 2 && endArr.length >= 2) {
|
|
|
- LocalTime start = LocalTime.of(
|
|
|
- Integer.parseInt(startArr[0]),
|
|
|
- Integer.parseInt(startArr[1])
|
|
|
- );
|
|
|
- LocalTime end = LocalTime.of(
|
|
|
- Integer.parseInt(endArr[0]),
|
|
|
- Integer.parseInt(endArr[1])
|
|
|
- );
|
|
|
-
|
|
|
- boolean isInBusiness;
|
|
|
- // 判断是否是全天营业(00:00到00:00)
|
|
|
- LocalTime midnight = LocalTime.of(0, 0);
|
|
|
- if (start.equals(midnight) && end.equals(midnight)) {
|
|
|
- // 全天营业
|
|
|
- isInBusiness = true;
|
|
|
- log.info("正常营业时间判断 - 全天营业(00:00-00:00),当前时间: {},是否在营业时间内: true", currentTime);
|
|
|
- } else {
|
|
|
- // 处理跨天营业
|
|
|
- if (start.isBefore(end) || start.equals(end)) {
|
|
|
- // 同一天营业:包含边界值
|
|
|
- isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
- && (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
- } else {
|
|
|
- // 跨天营业:包含边界值
|
|
|
- isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
- || (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
- }
|
|
|
- log.info("正常营业时间判断 - 开始时间: {}, 结束时间: {}, 当前时间: {}, 是否在营业时间内: {}",
|
|
|
- start, end, currentTime, isInBusiness);
|
|
|
- }
|
|
|
-
|
|
|
- result.setYyFlag(isInBusiness ? 1 : 0);
|
|
|
- } else {
|
|
|
- log.warn("正常营业时间格式错误 - 开始时间: {}, 结束时间: {}",
|
|
|
- normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime());
|
|
|
- result.setYyFlag(0);
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- log.warn("解析正常营业时间失败 - 开始时间: {}, 结束时间: {}",
|
|
|
- normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime(), e);
|
|
|
- result.setYyFlag(0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.warn("正常营业时间为空 - 开始时间: {}, 结束时间: {}",
|
|
|
- normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime());
|
|
|
- result.setYyFlag(0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("当前星期不在营业日期范围内 - 营业日期: {}, 当前星期: {}",
|
|
|
- normalBusinessInfo.getBusinessDate(), day);
|
|
|
- result.setYyFlag(0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.warn("没有找到正常营业时间配置");
|
|
|
- result.setYyFlag(0);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("最终营业状态 - yyFlag: {}", result.getYyFlag());
|
|
|
-
|
|
|
- // 根据当前是否是特殊营业时间,对storeBusinessInfos进行排序
|
|
|
- if (ObjectUtils.isNotEmpty(storeBusinessInfos)) {
|
|
|
- final boolean isSpecial = isCurrentSpecialBusinessTime;
|
|
|
- List<StoreBusinessInfo> sortedBusinessInfos = storeBusinessInfos.stream()
|
|
|
- .sorted((a, b) -> {
|
|
|
- Integer typeA = a.getBusinessType() != null ? a.getBusinessType() : 0;
|
|
|
- Integer typeB = b.getBusinessType() != null ? b.getBusinessType() : 0;
|
|
|
-
|
|
|
- // 如果当前是特殊营业时间,businessType == 2 排在前面
|
|
|
- if (isSpecial) {
|
|
|
- if (typeA == 2 && typeB != 2) {
|
|
|
- return -1; // a排在前面
|
|
|
- } else if (typeA != 2 && typeB == 2) {
|
|
|
- return 1; // b排在前面
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 如果当前不是特殊营业时间,businessType == 1 排在前面
|
|
|
- if (typeA == 1 && typeB != 1) {
|
|
|
- return -1; // a排在前面
|
|
|
- } else if (typeA != 1 && typeB == 1) {
|
|
|
- return 1; // b排在前面
|
|
|
- }
|
|
|
- }
|
|
|
- // 相同类型,保持原有顺序
|
|
|
- return 0;
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 重新设置排序后的列表
|
|
|
- result.setStoreBusinessInfos(sortedBusinessInfos);
|
|
|
- if (!sortedBusinessInfos.isEmpty()) {
|
|
|
- result.setStoreBusinessInfo(sortedBusinessInfos.get(0));
|
|
|
- }
|
|
|
-
|
|
|
- log.info("营业时间列表排序完成 - 当前是特殊营业时间: {}, 排序后第一个businessType: {}",
|
|
|
- isSpecial, sortedBusinessInfos.isEmpty() ? "无" : sortedBusinessInfos.get(0).getBusinessType());
|
|
|
- }
|
|
|
+ // 调用提取的营业时间判断方法
|
|
|
+ calculateBusinessStatus(storeId, storeBusinessInfos, result);
|
|
|
} else {
|
|
|
log.info("店铺营业状态不为0,不判断营业时间 - businessStatus: {}", storeInfo.getBusinessStatus());
|
|
|
}
|
|
|
@@ -6084,6 +5788,395 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public StoreBusinessStatusVo getStoreBusinessStatus(String storeId) {
|
|
|
+ log.info("StoreInfoServiceImpl.getStoreBusinessStatus?storeId={}", storeId);
|
|
|
+ StoreBusinessStatusVo result = new StoreBusinessStatusVo();
|
|
|
+
|
|
|
+ StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
|
|
|
+ if (storeInfo == null) {
|
|
|
+ log.warn("店铺不存在,storeId={}", storeId);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ result.setBusinessStatus(storeInfo.getBusinessStatus());
|
|
|
+
|
|
|
+ // 查询营业时间
|
|
|
+ List<StoreBusinessInfo> storeBusinessInfos = storeBusinessInfoMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<StoreBusinessInfo>()
|
|
|
+ .eq(StoreBusinessInfo::getStoreId, storeId)
|
|
|
+ .eq(StoreBusinessInfo::getDeleteFlag, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 回显所有营业时间信息(特殊营业时间和正常营业时间)
|
|
|
+ if (ObjectUtils.isNotEmpty(storeBusinessInfos)) {
|
|
|
+ result.setStoreBusinessInfo(storeBusinessInfos.get(0));
|
|
|
+ result.setStoreBusinessInfos(storeBusinessInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断营业状态
|
|
|
+ if (storeInfo.getBusinessStatus() == 0) {
|
|
|
+ // 调用提取的营业时间判断方法
|
|
|
+ calculateBusinessStatus(storeId, storeBusinessInfos, result);
|
|
|
+ } else {
|
|
|
+ log.info("店铺营业状态不为0,不判断营业时间 - businessStatus: {}", storeInfo.getBusinessStatus());
|
|
|
+ result.setYyFlag(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算店铺营业状态
|
|
|
+ * 判断当前时间是否在营业时间内,并设置营业状态和排序后的营业时间列表
|
|
|
+ *
|
|
|
+ * @param storeId 店铺ID
|
|
|
+ * @param storeBusinessInfos 营业时间列表
|
|
|
+ * @param result 结果对象(StoreInfoVo或StoreBusinessStatusVo)
|
|
|
+ */
|
|
|
+ private void calculateBusinessStatus(String storeId, List<StoreBusinessInfo> storeBusinessInfos, Object result) {
|
|
|
+ // 优先判断当前时间是否是特殊日期
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ LocalTime currentTime = LocalTime.now();
|
|
|
+
|
|
|
+ log.info("开始判断营业状态 - 当前日期: {}, 当前时间: {}, 店铺ID: {}", currentDate, currentTime, storeId);
|
|
|
+
|
|
|
+ // 标记当前是否是特殊营业时间
|
|
|
+ boolean isCurrentSpecialBusinessTime = false;
|
|
|
+
|
|
|
+ // 查找特殊营业时间(businessType == 2)
|
|
|
+ StoreBusinessInfo specialBusinessInfo = storeBusinessInfos.stream()
|
|
|
+ .filter(item -> item.getBusinessType() != null && item.getBusinessType() == 2)
|
|
|
+ .filter(item -> {
|
|
|
+ // 判断当前日期是否匹配特殊日期
|
|
|
+ if (StringUtils.isEmpty(item.getBusinessDate())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String businessDate = item.getBusinessDate().trim();
|
|
|
+
|
|
|
+ // 移除开头的数字和空格(如 "2 元旦、春节、儿童节" -> "元旦、春节、儿童节")
|
|
|
+ String holidayNames = businessDate.replaceAll("^\\d+\\s*", "").trim();
|
|
|
+
|
|
|
+ // 判断是否包含节假日名称(支持所有特殊日期:元旦、春节、情人节、元宵节、清明节、劳动节、儿童节、端午节、七夕、中秋节、国庆节、冬至、平安夜、圣诞节)
|
|
|
+ boolean isHolidayName = holidayNames.contains("元旦") || holidayNames.contains("春节") ||
|
|
|
+ holidayNames.contains("情人节") || holidayNames.contains("元宵") ||
|
|
|
+ holidayNames.contains("七夕") || holidayNames.contains("冬至") ||
|
|
|
+ holidayNames.contains("平安夜") || holidayNames.contains("圣诞") ||
|
|
|
+ holidayNames.contains("清明") || holidayNames.contains("劳动") ||
|
|
|
+ holidayNames.contains("端午") || holidayNames.contains("中秋") ||
|
|
|
+ holidayNames.contains("国庆") || holidayNames.contains("儿童");
|
|
|
+
|
|
|
+ if (isHolidayName) {
|
|
|
+
|
|
|
+ List<LocalDate[]> holidayRanges = getHolidayDateRanges(currentDate.getYear(), holidayNames);
|
|
|
+ for (LocalDate[] range : holidayRanges) {
|
|
|
+ if (range != null && range.length == 2) {
|
|
|
+ LocalDate startDate = range[0];
|
|
|
+ LocalDate endDate = range[1];
|
|
|
+ if (!currentDate.isBefore(startDate) && !currentDate.isAfter(endDate)) {
|
|
|
+ log.info("特殊日期判断(节假日) - 节假日: {}, 日期范围: {}至{}, 当前日期: {}, 是否在范围内: true",
|
|
|
+ holidayNames, startDate, endDate, currentDate);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("特殊日期判断(节假日) - 节假日: {}, 当前日期: {}, 是否在范围内: false",
|
|
|
+ holidayNames, currentDate);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果不是节假日名称,尝试解析日期格式(兼容旧格式)
|
|
|
+ String[] dateFormats = {"yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd"};
|
|
|
+
|
|
|
+ // 先检查是否包含"至"(日期范围)
|
|
|
+ if (businessDate.contains("至")) {
|
|
|
+ String[] dateRange = businessDate.split("至");
|
|
|
+ if (dateRange.length >= 2) {
|
|
|
+ try {
|
|
|
+ LocalDate startDate = null;
|
|
|
+ LocalDate endDate = null;
|
|
|
+ for (String format : dateFormats) {
|
|
|
+ try {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
+ startDate = LocalDate.parse(dateRange[0].trim(), formatter);
|
|
|
+ endDate = LocalDate.parse(dateRange[1].trim(), formatter);
|
|
|
+ break;
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (startDate != null && endDate != null) {
|
|
|
+ boolean inRange = !currentDate.isBefore(startDate) && !currentDate.isAfter(endDate);
|
|
|
+ log.info("特殊日期范围判断 - 日期范围: {}至{}, 当前日期: {}, 是否在范围内: {}",
|
|
|
+ startDate, endDate, currentDate, inRange);
|
|
|
+ return inRange;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析特殊日期范围失败: {}", businessDate, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 尝试解析单个日期格式
|
|
|
+ for (String format : dateFormats) {
|
|
|
+ try {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
+ LocalDate specialDate = LocalDate.parse(businessDate, formatter);
|
|
|
+ boolean matches = specialDate.equals(currentDate);
|
|
|
+ log.info("特殊日期判断 - 特殊日期: {}, 当前日期: {}, 是否匹配: {}",
|
|
|
+ specialDate, currentDate, matches);
|
|
|
+ if (matches) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ // 继续尝试下一个格式
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析特殊日期失败: {}", item.getBusinessDate(), e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ // 如果找到匹配的特殊日期,判断是否在营业时间内
|
|
|
+ if (specialBusinessInfo != null) {
|
|
|
+ log.info("找到匹配的特殊日期营业时间 - 开始时间: {}, 结束时间: {}",
|
|
|
+ specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
+ if (StringUtils.isNotEmpty(specialBusinessInfo.getStartTime())
|
|
|
+ && StringUtils.isNotEmpty(specialBusinessInfo.getEndTime())) {
|
|
|
+ try {
|
|
|
+ String[] startArr = specialBusinessInfo.getStartTime().split(":");
|
|
|
+ String[] endArr = specialBusinessInfo.getEndTime().split(":");
|
|
|
+ if (startArr.length >= 2 && endArr.length >= 2) {
|
|
|
+ LocalTime start = LocalTime.of(
|
|
|
+ Integer.parseInt(startArr[0]),
|
|
|
+ Integer.parseInt(startArr[1])
|
|
|
+ );
|
|
|
+ LocalTime end = LocalTime.of(
|
|
|
+ Integer.parseInt(endArr[0]),
|
|
|
+ Integer.parseInt(endArr[1])
|
|
|
+ );
|
|
|
+
|
|
|
+ boolean isInBusiness;
|
|
|
+ // 判断是否是全天营业(00:00到00:00)
|
|
|
+ LocalTime midnight = LocalTime.of(0, 0);
|
|
|
+ if (start.equals(midnight) && end.equals(midnight)) {
|
|
|
+ // 全天营业
|
|
|
+ isInBusiness = true;
|
|
|
+ log.info("特殊日期营业时间判断 - 全天营业(00:00-00:00),当前时间: {},是否在营业时间内: true", currentTime);
|
|
|
+ } else {
|
|
|
+ // 处理跨天营业
|
|
|
+ if (start.isBefore(end) || start.equals(end)) {
|
|
|
+ // 同一天营业:包含边界值
|
|
|
+ isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
+ && (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
+ } else {
|
|
|
+ // 跨天营业:包含边界值
|
|
|
+ isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
+ || (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
+ }
|
|
|
+ log.info("特殊日期营业时间判断 - 开始时间: {}, 结束时间: {}, 当前时间: {}, 是否在营业时间内: {}",
|
|
|
+ start, end, currentTime, isInBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ setYyFlag(result, isInBusiness ? 1 : 0);
|
|
|
+ isCurrentSpecialBusinessTime = isInBusiness;
|
|
|
+ } else {
|
|
|
+ log.warn("特殊日期营业时间格式错误 - 开始时间: {}, 结束时间: {}",
|
|
|
+ specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ isCurrentSpecialBusinessTime = false;
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("解析特殊日期营业时间失败 - 开始时间: {}, 结束时间: {}",
|
|
|
+ specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime(), e);
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ isCurrentSpecialBusinessTime = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("特殊日期营业时间为空 - 开始时间: {}, 结束时间: {}",
|
|
|
+ specialBusinessInfo.getStartTime(), specialBusinessInfo.getEndTime());
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ isCurrentSpecialBusinessTime = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果不是特殊日期,判断正常营业时间(businessType == 1)
|
|
|
+ StoreBusinessInfo normalBusinessInfo = storeBusinessInfos.stream()
|
|
|
+ .filter(item -> item.getBusinessType() != null && item.getBusinessType() == 1)
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ if (normalBusinessInfo != null) {
|
|
|
+ log.info("判断正常营业时间 - 营业日期: {}, 开始时间: {}, 结束时间: {}",
|
|
|
+ normalBusinessInfo.getBusinessDate(),
|
|
|
+ normalBusinessInfo.getStartTime(),
|
|
|
+ normalBusinessInfo.getEndTime());
|
|
|
+ // 获取当前星期并转换为业务格式
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // 1=周日,2=周一...7=周六
|
|
|
+ // 映射数组:索引对应dayOfWeek-1,值为中文星期
|
|
|
+ String[] weekDaysCN = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
|
|
+ String day = weekDaysCN[dayOfWeek - 1];
|
|
|
+
|
|
|
+ log.info("当前星期: {}, 转换后: {}", dayOfWeek, day);
|
|
|
+
|
|
|
+ // 判断当前日期是否在营业日期范围内
|
|
|
+ if (StringUtils.isNotEmpty(normalBusinessInfo.getBusinessDate())
|
|
|
+ && normalBusinessInfo.getBusinessDate().contains(day)) {
|
|
|
+ log.info("当前星期在营业日期范围内");
|
|
|
+ if (StringUtils.isNotEmpty(normalBusinessInfo.getStartTime())
|
|
|
+ && StringUtils.isNotEmpty(normalBusinessInfo.getEndTime())) {
|
|
|
+ try {
|
|
|
+ String[] startArr = normalBusinessInfo.getStartTime().split(":");
|
|
|
+ String[] endArr = normalBusinessInfo.getEndTime().split(":");
|
|
|
+ if (startArr.length >= 2 && endArr.length >= 2) {
|
|
|
+ LocalTime start = LocalTime.of(
|
|
|
+ Integer.parseInt(startArr[0]),
|
|
|
+ Integer.parseInt(startArr[1])
|
|
|
+ );
|
|
|
+ LocalTime end = LocalTime.of(
|
|
|
+ Integer.parseInt(endArr[0]),
|
|
|
+ Integer.parseInt(endArr[1])
|
|
|
+ );
|
|
|
+
|
|
|
+ boolean isInBusiness;
|
|
|
+ // 判断是否是全天营业(00:00到00:00)
|
|
|
+ LocalTime midnight = LocalTime.of(0, 0);
|
|
|
+ if (start.equals(midnight) && end.equals(midnight)) {
|
|
|
+ // 全天营业
|
|
|
+ isInBusiness = true;
|
|
|
+ log.info("正常营业时间判断 - 全天营业(00:00-00:00),当前时间: {},是否在营业时间内: true", currentTime);
|
|
|
+ } else {
|
|
|
+ // 处理跨天营业
|
|
|
+ if (start.isBefore(end) || start.equals(end)) {
|
|
|
+ // 同一天营业:包含边界值
|
|
|
+ isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
+ && (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
+ } else {
|
|
|
+ // 跨天营业:包含边界值
|
|
|
+ isInBusiness = (currentTime.isAfter(start) || currentTime.equals(start))
|
|
|
+ || (currentTime.isBefore(end) || currentTime.equals(end));
|
|
|
+ }
|
|
|
+ log.info("正常营业时间判断 - 开始时间: {}, 结束时间: {}, 当前时间: {}, 是否在营业时间内: {}",
|
|
|
+ start, end, currentTime, isInBusiness);
|
|
|
+ }
|
|
|
+
|
|
|
+ setYyFlag(result, isInBusiness ? 1 : 0);
|
|
|
+ } else {
|
|
|
+ log.warn("正常营业时间格式错误 - 开始时间: {}, 结束时间: {}",
|
|
|
+ normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime());
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("解析正常营业时间失败 - 开始时间: {}, 结束时间: {}",
|
|
|
+ normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime(), e);
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("正常营业时间为空 - 开始时间: {}, 结束时间: {}",
|
|
|
+ normalBusinessInfo.getStartTime(), normalBusinessInfo.getEndTime());
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("当前星期不在营业日期范围内 - 营业日期: {}, 当前星期: {}",
|
|
|
+ normalBusinessInfo.getBusinessDate(), day);
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("没有找到正常营业时间配置");
|
|
|
+ setYyFlag(result, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer yyFlag = getYyFlag(result);
|
|
|
+ log.info("最终营业状态 - yyFlag: {}", yyFlag);
|
|
|
+
|
|
|
+ // 根据当前是否是特殊营业时间,对storeBusinessInfos进行排序
|
|
|
+ if (ObjectUtils.isNotEmpty(storeBusinessInfos)) {
|
|
|
+ final boolean isSpecial = isCurrentSpecialBusinessTime;
|
|
|
+ List<StoreBusinessInfo> sortedBusinessInfos = storeBusinessInfos.stream()
|
|
|
+ .sorted((a, b) -> {
|
|
|
+ Integer typeA = a.getBusinessType() != null ? a.getBusinessType() : 0;
|
|
|
+ Integer typeB = b.getBusinessType() != null ? b.getBusinessType() : 0;
|
|
|
+
|
|
|
+ // 如果当前是特殊营业时间,businessType == 2 排在前面
|
|
|
+ if (isSpecial) {
|
|
|
+ if (typeA == 2 && typeB != 2) {
|
|
|
+ return -1; // a排在前面
|
|
|
+ } else if (typeA != 2 && typeB == 2) {
|
|
|
+ return 1; // b排在前面
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果当前不是特殊营业时间,businessType == 1 排在前面
|
|
|
+ if (typeA == 1 && typeB != 1) {
|
|
|
+ return -1; // a排在前面
|
|
|
+ } else if (typeA != 1 && typeB == 1) {
|
|
|
+ return 1; // b排在前面
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 相同类型,保持原有顺序
|
|
|
+ return 0;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 重新设置排序后的列表
|
|
|
+ setStoreBusinessInfos(result, sortedBusinessInfos);
|
|
|
+ if (!sortedBusinessInfos.isEmpty()) {
|
|
|
+ setStoreBusinessInfo(result, sortedBusinessInfos.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("营业时间列表排序完成 - 当前是特殊营业时间: {}, 排序后第一个businessType: {}",
|
|
|
+ isSpecial, sortedBusinessInfos.isEmpty() ? "无" : sortedBusinessInfos.get(0).getBusinessType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置yyFlag(支持StoreInfoVo和StoreBusinessStatusVo)
|
|
|
+ */
|
|
|
+ private void setYyFlag(Object result, Integer yyFlag) {
|
|
|
+ if (result instanceof StoreInfoVo) {
|
|
|
+ ((StoreInfoVo) result).setYyFlag(yyFlag);
|
|
|
+ } else if (result instanceof StoreBusinessStatusVo) {
|
|
|
+ ((StoreBusinessStatusVo) result).setYyFlag(yyFlag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取yyFlag(支持StoreInfoVo和StoreBusinessStatusVo)
|
|
|
+ */
|
|
|
+ private Integer getYyFlag(Object result) {
|
|
|
+ if (result instanceof StoreInfoVo) {
|
|
|
+ return ((StoreInfoVo) result).getYyFlag();
|
|
|
+ } else if (result instanceof StoreBusinessStatusVo) {
|
|
|
+ return ((StoreBusinessStatusVo) result).getYyFlag();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置storeBusinessInfo(支持StoreInfoVo和StoreBusinessStatusVo)
|
|
|
+ */
|
|
|
+ private void setStoreBusinessInfo(Object result, StoreBusinessInfo storeBusinessInfo) {
|
|
|
+ if (result instanceof StoreInfoVo) {
|
|
|
+ ((StoreInfoVo) result).setStoreBusinessInfo(storeBusinessInfo);
|
|
|
+ } else if (result instanceof StoreBusinessStatusVo) {
|
|
|
+ ((StoreBusinessStatusVo) result).setStoreBusinessInfo(storeBusinessInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置storeBusinessInfos(支持StoreInfoVo和StoreBusinessStatusVo)
|
|
|
+ */
|
|
|
+ private void setStoreBusinessInfos(Object result, List<StoreBusinessInfo> storeBusinessInfos) {
|
|
|
+ if (result instanceof StoreInfoVo) {
|
|
|
+ ((StoreInfoVo) result).setStoreBusinessInfos(storeBusinessInfos);
|
|
|
+ } else if (result instanceof StoreBusinessStatusVo) {
|
|
|
+ ((StoreBusinessStatusVo) result).setStoreBusinessInfos(storeBusinessInfos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<LifeCouponVo> getStoreCouponList(String storeId) {
|
|
|
// 获取店铺代金券列表
|
|
|
LambdaUpdateWrapper<LifeCoupon> quanWrapper = new LambdaUpdateWrapper<>();
|