|
|
@@ -361,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);
|
|
|
|
|
|
@@ -373,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"
|
|
|
@@ -407,7 +500,7 @@ public class BarPerformanceServiceImpl implements BarPerformanceService {
|
|
|
return performerList;
|
|
|
}
|
|
|
|
|
|
- // 批量查询员工配置信息
|
|
|
+ // 批量查询员工配置信息(MyBatis-Plus的selectBatchIds会自动过滤已删除的记录)
|
|
|
List<StoreStaffConfig> staffList = storeStaffConfigMapper.selectBatchIds(staffIdList);
|
|
|
|
|
|
if (staffList != null && !staffList.isEmpty()) {
|