|
|
@@ -21,8 +21,10 @@ import shop.alien.store.util.ai.AiContentModerationUtil;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -162,6 +164,12 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
if (barPerformance.getSingleEndDatetime() == null) {
|
|
|
throw new IllegalArgumentException("每周定时演出必须填写结束时间");
|
|
|
}
|
|
|
+ // 校验:选择的日期(singleStartDatetime 的星期几)必须是 performanceWeek 中的某一天
|
|
|
+ int startDayOfWeek = getDayOfWeekAsPerformanceWeek(barPerformance.getSingleStartDatetime());
|
|
|
+ Set<Integer> allowedWeekDays = parsePerformanceWeekToSet(barPerformance.getPerformanceWeek());
|
|
|
+ if (!allowedWeekDays.contains(startDayOfWeek)) {
|
|
|
+ throw new IllegalArgumentException("选择的开始日期对应的星期几必须在演出日期(周几)范围内");
|
|
|
+ }
|
|
|
// 从single_start_datetime和single_end_datetime中提取时间部分,存到daily_start_time和daily_end_time
|
|
|
LocalTime weeklyStartTime = barPerformance.getSingleStartDatetime().toInstant()
|
|
|
.atZone(ZoneId.systemDefault())
|
|
|
@@ -648,6 +656,44 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 将 Date 的星期几转换为 performanceWeek 编码(0=周一,1=周二,…,6=周日)
|
|
|
+ * 用于校验选择的日期是否在演出日期(周几)范围内
|
|
|
+ *
|
|
|
+ * @param date 日期时间
|
|
|
+ * @return 0-6,对应周一至周日
|
|
|
+ */
|
|
|
+ private int getDayOfWeekAsPerformanceWeek(Date date) {
|
|
|
+ if (date == null) {
|
|
|
+ throw new IllegalArgumentException("日期不能为空");
|
|
|
+ }
|
|
|
+ java.util.Calendar cal = java.util.Calendar.getInstance();
|
|
|
+ cal.setTime(date);
|
|
|
+ // Calendar: Sunday=1, Monday=2, ..., Saturday=7
|
|
|
+ int calendarDay = cal.get(java.util.Calendar.DAY_OF_WEEK);
|
|
|
+ // 转为 performanceWeek 编码:0=周一, 1=周二, ..., 6=周日
|
|
|
+ return calendarDay == java.util.Calendar.SUNDAY ? 6 : calendarDay - 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析 performanceWeek 字符串为允许的星期几集合(0-6)
|
|
|
+ * 格式:逗号分隔,如 "0,2,5" 表示周一、周三、周六
|
|
|
+ *
|
|
|
+ * @param performanceWeek 演出日期字符串
|
|
|
+ * @return 允许的星期几集合,空字符串或无效时返回空集合
|
|
|
+ */
|
|
|
+ private Set<Integer> parsePerformanceWeekToSet(String performanceWeek) {
|
|
|
+ if (StringUtils.isEmpty(performanceWeek)) {
|
|
|
+ return java.util.Collections.emptySet();
|
|
|
+ }
|
|
|
+ return Arrays.stream(performanceWeek.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .filter(s -> s.matches("^[0-6]$"))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 比较两个时间(只比较时间部分,忽略日期部分)
|
|
|
* 用于每天定时和每周定时演出的时间验证
|
|
|
*
|