|
@@ -6,17 +6,19 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.store.StoreBookingCategory;
|
|
import shop.alien.entity.store.StoreBookingCategory;
|
|
|
|
|
+import shop.alien.entity.store.StoreBookingSettings;
|
|
|
import shop.alien.entity.store.StoreBookingTable;
|
|
import shop.alien.entity.store.StoreBookingTable;
|
|
|
import shop.alien.entity.store.UserReservation;
|
|
import shop.alien.entity.store.UserReservation;
|
|
|
import shop.alien.mapper.StoreBookingCategoryMapper;
|
|
import shop.alien.mapper.StoreBookingCategoryMapper;
|
|
|
import shop.alien.mapper.UserReservationMapper;
|
|
import shop.alien.mapper.UserReservationMapper;
|
|
|
import shop.alien.store.service.StoreBookingCategoryService;
|
|
import shop.alien.store.service.StoreBookingCategoryService;
|
|
|
|
|
+import shop.alien.store.service.StoreBookingSettingsService;
|
|
|
import shop.alien.store.service.StoreBookingTableService;
|
|
import shop.alien.store.service.StoreBookingTableService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
|
@@ -31,11 +33,20 @@ import java.util.List;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
@Transactional
|
|
@Transactional
|
|
|
-@RequiredArgsConstructor
|
|
|
|
|
public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCategoryMapper, StoreBookingCategory> implements StoreBookingCategoryService {
|
|
public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCategoryMapper, StoreBookingCategory> implements StoreBookingCategoryService {
|
|
|
|
|
|
|
|
private final StoreBookingTableService storeBookingTableService;
|
|
private final StoreBookingTableService storeBookingTableService;
|
|
|
private final UserReservationMapper userReservationMapper;
|
|
private final UserReservationMapper userReservationMapper;
|
|
|
|
|
+ private final StoreBookingSettingsService storeBookingSettingsService;
|
|
|
|
|
+
|
|
|
|
|
+ public StoreBookingCategoryServiceImpl(
|
|
|
|
|
+ StoreBookingTableService storeBookingTableService,
|
|
|
|
|
+ UserReservationMapper userReservationMapper,
|
|
|
|
|
+ @Lazy StoreBookingSettingsService storeBookingSettingsService) {
|
|
|
|
|
+ this.storeBookingTableService = storeBookingTableService;
|
|
|
|
|
+ this.userReservationMapper = userReservationMapper;
|
|
|
|
|
+ this.storeBookingSettingsService = storeBookingSettingsService;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<StoreBookingCategory> getCategoryList(Integer storeId) {
|
|
public List<StoreBookingCategory> getCategoryList(Integer storeId) {
|
|
@@ -92,6 +103,23 @@ public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCat
|
|
|
throw new RuntimeException("最长预订时间必须大于0");
|
|
throw new RuntimeException("最长预订时间必须大于0");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 校验:如果当前门店有信息设置,分类中的最长预订时间要超过信息设置的保留时间
|
|
|
|
|
+ // 如果没有信息设置,分类的最长预订时间可随意设置
|
|
|
|
|
+ StoreBookingSettings settings = storeBookingSettingsService.getByStoreId(category.getStoreId());
|
|
|
|
|
+ if (settings != null) {
|
|
|
|
|
+ // 如果门店有信息设置,且设置了保留位置(retain_position_flag = 1)
|
|
|
|
|
+ if (settings.getRetainPositionFlag() != null && settings.getRetainPositionFlag() == 1) {
|
|
|
|
|
+ // 如果设置了保留时长,则分类的最长预订时间要超过保留时长
|
|
|
|
|
+ if (settings.getRetentionDuration() != null && settings.getRetentionDuration() > 0) {
|
|
|
|
|
+ if (category.getMaxBookingTime() <= settings.getRetentionDuration()) {
|
|
|
|
|
+ log.warn("新增预订服务分类失败:分类的最长预订时间要超过信息设置的保留时间,maxBookingTime={}, retentionDuration={}",
|
|
|
|
|
+ category.getMaxBookingTime(), settings.getRetentionDuration());
|
|
|
|
|
+ throw new RuntimeException("分类的最长预订时间要超过信息设置的保留时间(" + settings.getRetentionDuration() + "分钟)");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 验证图片数量(最多9张)
|
|
// 验证图片数量(最多9张)
|
|
|
String[] images = category.getFloorPlanImages().split(",");
|
|
String[] images = category.getFloorPlanImages().split(",");
|
|
|
if (images.length > 9) {
|
|
if (images.length > 9) {
|
|
@@ -230,16 +258,32 @@ public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCat
|
|
|
throw new RuntimeException("分类不存在");
|
|
throw new RuntimeException("分类不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 校验:检查当前分类下是否有桌号,如果有则不允许删除
|
|
|
|
|
|
|
+ // 查询当前分类下的所有桌号
|
|
|
LambdaQueryWrapper<StoreBookingTable> tableWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StoreBookingTable> tableWrapper = new LambdaQueryWrapper<>();
|
|
|
tableWrapper.eq(StoreBookingTable::getCategoryId, id);
|
|
tableWrapper.eq(StoreBookingTable::getCategoryId, id);
|
|
|
- long tableCount = storeBookingTableService.count(tableWrapper);
|
|
|
|
|
- if (tableCount > 0) {
|
|
|
|
|
- log.warn("删除预订服务分类失败:当前分类下存在桌号,需要先删除桌号才能删除该分类,categoryId={}, tableCount={}", id, tableCount);
|
|
|
|
|
- throw new RuntimeException("当前分类下存在桌号,需要先删除桌号才能删除该分类");
|
|
|
|
|
|
|
+ // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
|
|
+ List<StoreBookingTable> tables = storeBookingTableService.list(tableWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果存在桌号,先批量删除这些桌号
|
|
|
|
|
+ if (tables != null && !tables.isEmpty()) {
|
|
|
|
|
+ List<Integer> tableIds = tables.stream()
|
|
|
|
|
+ .map(StoreBookingTable::getId)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ log.info("删除分类时同时删除该分类下的所有桌号,categoryId={}, tableCount={}, tableIds={}",
|
|
|
|
|
+ id, tables.size(), tableIds);
|
|
|
|
|
+
|
|
|
|
|
+ // 批量逻辑删除桌号
|
|
|
|
|
+ boolean deleteTablesResult = storeBookingTableService.removeByIds(tableIds);
|
|
|
|
|
+ if (!deleteTablesResult) {
|
|
|
|
|
+ log.warn("删除分类下的桌号失败,categoryId={}, tableIds={}", id, tableIds);
|
|
|
|
|
+ throw new RuntimeException("删除分类下的桌号失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("成功删除分类下的所有桌号,categoryId={}, tableCount={}", id, tables.size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 逻辑删除
|
|
|
|
|
|
|
+ // 逻辑删除分类
|
|
|
return this.removeById(id);
|
|
return this.removeById(id);
|
|
|
}
|
|
}
|
|
|
|
|
|