|
|
@@ -18,6 +18,8 @@ import shop.alien.mapper.StoreStaffConfigMapper;
|
|
|
import shop.alien.store.service.BarPerformanceService;
|
|
|
import shop.alien.store.util.ai.AiContentModerationUtil;
|
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -115,13 +117,22 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
if (barPerformance.getDailyStartDate().after(barPerformance.getDailyEndDate())) {
|
|
|
throw new IllegalArgumentException("开始日期不能晚于结束日期");
|
|
|
}
|
|
|
- // 验证时间字段(复用single_start_datetime和single_end_datetime,只使用时间部分)
|
|
|
+ // 验证时间字段(使用single_start_datetime和single_end_datetime,提取时间部分)
|
|
|
if (barPerformance.getSingleStartDatetime() == null) {
|
|
|
throw new IllegalArgumentException("每天定时演出必须填写开始时间");
|
|
|
}
|
|
|
if (barPerformance.getSingleEndDatetime() == null) {
|
|
|
throw new IllegalArgumentException("每天定时演出必须填写结束时间");
|
|
|
}
|
|
|
+ // 从single_start_datetime和single_end_datetime中提取时间部分,存到daily_start_time和daily_end_time
|
|
|
+ LocalTime startTime = barPerformance.getSingleStartDatetime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalTime();
|
|
|
+ LocalTime endTime = barPerformance.getSingleEndDatetime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalTime();
|
|
|
+ barPerformance.setDailyStartTime(startTime);
|
|
|
+ barPerformance.setDailyEndTime(endTime);
|
|
|
// 每天定时不需要周天数据,清除周天字段(设置为空字符串,确保数据库插入时包含该字段)
|
|
|
barPerformance.setPerformanceWeek("");
|
|
|
break;
|
|
|
@@ -144,13 +155,22 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
if (StringUtils.isEmpty(barPerformance.getPerformanceWeek())) {
|
|
|
throw new IllegalArgumentException("每周定时演出必须选择演出日期");
|
|
|
}
|
|
|
- // 验证时间字段(复用single_start_datetime和single_end_datetime,只使用时间部分)
|
|
|
+ // 验证时间字段(使用single_start_datetime和single_end_datetime,提取时间部分)
|
|
|
if (barPerformance.getSingleStartDatetime() == null) {
|
|
|
throw new IllegalArgumentException("每周定时演出必须填写开始时间");
|
|
|
}
|
|
|
if (barPerformance.getSingleEndDatetime() == null) {
|
|
|
throw new IllegalArgumentException("每周定时演出必须填写结束时间");
|
|
|
}
|
|
|
+ // 从single_start_datetime和single_end_datetime中提取时间部分,存到daily_start_time和daily_end_time
|
|
|
+ LocalTime weeklyStartTime = barPerformance.getSingleStartDatetime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalTime();
|
|
|
+ LocalTime weeklyEndTime = barPerformance.getSingleEndDatetime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalTime();
|
|
|
+ barPerformance.setDailyStartTime(weeklyStartTime);
|
|
|
+ barPerformance.setDailyEndTime(weeklyEndTime);
|
|
|
break;
|
|
|
default:
|
|
|
throw new IllegalArgumentException("演出频次类型无效");
|
|
|
@@ -341,11 +361,34 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ // 检查并更新已删除的员工配置ID
|
|
|
+ String originalStaffConfigIds = barPerformance.getStaffConfigIds();
|
|
|
+ String updatedStaffConfigIds = checkAndUpdateDeletedStaff(originalStaffConfigIds);
|
|
|
+
|
|
|
+ // 如果员工配置ID有变化,更新数据库
|
|
|
+ if (updatedStaffConfigIds != null && !updatedStaffConfigIds.equals(originalStaffConfigIds)) {
|
|
|
+ try {
|
|
|
+ LambdaUpdateWrapper<BarPerformance> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(BarPerformance::getId, id);
|
|
|
+ updateWrapper.set(BarPerformance::getStaffConfigIds, updatedStaffConfigIds);
|
|
|
+ int updateResult = barPerformanceMapper.update(null, updateWrapper);
|
|
|
+ if (updateResult > 0) {
|
|
|
+ // 更新成功,同步更新本地对象
|
|
|
+ barPerformance.setStaffConfigIds(updatedStaffConfigIds);
|
|
|
+ log.info("酒吧演出ID={}的演出嘉宾字段已更新,原值:{},新值:{}",
|
|
|
+ id, originalStaffConfigIds, updatedStaffConfigIds);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新酒吧演出ID={}的演出嘉宾字段失败,异常信息:{}",
|
|
|
+ id, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 转换为VO对象
|
|
|
BarPerformanceDetailVo detailVo = new BarPerformanceDetailVo();
|
|
|
BeanUtils.copyProperties(barPerformance, detailVo);
|
|
|
|
|
|
- // 查询并设置表演嘉宾列表
|
|
|
+ // 查询并设置表演嘉宾列表(使用更新后的staffConfigIds)
|
|
|
List<PerformerVo> performers = queryPerformersByStaffConfigIds(barPerformance.getStaffConfigIds());
|
|
|
detailVo.setPerformers(performers);
|
|
|
|
|
|
@@ -353,6 +396,76 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 检查并更新已删除的员工配置ID
|
|
|
+ * 如果发现员工被删除,从staffConfigIds中移除这些已删除的员工ID
|
|
|
+ *
|
|
|
+ * @param staffConfigIds 员工配置ID字符串,逗号分隔,如 "41,25"
|
|
|
+ * @return 更新后的员工配置ID字符串,如果无变化则返回原值
|
|
|
+ */
|
|
|
+ private String checkAndUpdateDeletedStaff(String staffConfigIds) {
|
|
|
+ if (StringUtils.isEmpty(staffConfigIds)) {
|
|
|
+ return staffConfigIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析员工ID字符串
|
|
|
+ String[] idArray = staffConfigIds.split(",");
|
|
|
+ List<Integer> originalStaffIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (String idStr : idArray) {
|
|
|
+ if (StringUtils.isNotEmpty(idStr.trim())) {
|
|
|
+ try {
|
|
|
+ Integer staffId = Integer.parseInt(idStr.trim());
|
|
|
+ if (staffId > 0) {
|
|
|
+ originalStaffIdList.add(staffId);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("解析员工配置ID失败,无效的ID:{}", idStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (originalStaffIdList.isEmpty()) {
|
|
|
+ return staffConfigIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询员工配置信息(MyBatis-Plus的selectBatchIds会自动过滤已删除的记录)
|
|
|
+ List<StoreStaffConfig> staffList = storeStaffConfigMapper.selectBatchIds(originalStaffIdList);
|
|
|
+
|
|
|
+ // 获取实际查询到的员工ID列表(未删除的员工)
|
|
|
+ final List<Integer> existingStaffIdList;
|
|
|
+ if (staffList != null && !staffList.isEmpty()) {
|
|
|
+ existingStaffIdList = staffList.stream()
|
|
|
+ .filter(staff -> staff != null && staff.getDeleteFlag() != null && staff.getDeleteFlag() == 0)
|
|
|
+ .map(StoreStaffConfig::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ existingStaffIdList = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 比较原始ID列表和查询到的ID列表,找出被删除的员工ID
|
|
|
+ List<Integer> deletedStaffIdList = originalStaffIdList.stream()
|
|
|
+ .filter(id -> !existingStaffIdList.contains(id))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 如果有员工被删除,更新staffConfigIds字段
|
|
|
+ if (!deletedStaffIdList.isEmpty()) {
|
|
|
+ log.info("发现酒吧演出关联的员工被删除,员工ID列表:{}", deletedStaffIdList);
|
|
|
+ // 构建新的staffConfigIds字符串(只包含未删除的员工ID)
|
|
|
+ String updatedStaffConfigIds = existingStaffIdList.stream()
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ return updatedStaffConfigIds;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("检查并更新已删除的员工配置ID异常,staffConfigIds={},异常信息:{}",
|
|
|
+ staffConfigIds, e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return staffConfigIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据员工配置ID字符串查询表演嘉宾列表
|
|
|
*
|
|
|
* @param staffConfigIds 员工配置ID字符串,逗号分隔,如 "41,25"
|
|
|
@@ -387,7 +500,7 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
return performerList;
|
|
|
}
|
|
|
|
|
|
- // 批量查询员工配置信息
|
|
|
+ // 批量查询员工配置信息(MyBatis-Plus的selectBatchIds会自动过滤已删除的记录)
|
|
|
List<StoreStaffConfig> staffList = storeStaffConfigMapper.selectBatchIds(staffIdList);
|
|
|
|
|
|
if (staffList != null && !staffList.isEmpty()) {
|