Explorar el Código

fix(app): 修复预约库存计算逻辑

- 严格匹配有交集的时间段(不包含端点相接)
- 修复了之前可能导致库存计算不准确的问题
- 优化了代码结构,提高了可读性
SheepHy hace 3 semanas
padre
commit
a126b9f025

+ 3 - 6
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -209,17 +209,15 @@ public class OrderServiceImpl implements IOrderService {
             LocalTime slotStart = LocalTime.parse(DateUtil.format(a.getStartTime(), "HH:mm"));
             LocalTime slotEnd = LocalTime.parse(DateUtil.format(a.getEndTime(), "HH:mm"));
             boolean isTeaching = a.getIsTeaching() == 0;
-
             List<OrderVO.TimeSlotData> targetList = isTeaching ? teachingList : nonTeachingList;
-
             Optional<OrderVO.TimeSlotData> matchedSlot = targetList.stream()
                     .filter(t -> {
                         LocalTime invStart = LocalTime.parse(t.getStartTime());
                         LocalTime invEnd = LocalTime.parse(t.getEndTime());
-                        return !slotStart.isAfter(invEnd) && !slotEnd.isBefore(invStart);
+                        // 严格匹配有交集的时间段(不包含端点相接)
+                        return invStart.isBefore(invEnd) && slotStart.isBefore(invEnd) && slotEnd.isAfter(invStart);
                     })
                     .findFirst();
-
             matchedSlot.ifPresent(timeSlotData -> {
                 int totalInventory = Integer.parseInt(timeSlotData.getTicketNum());
                 int bookedCount = appOrderMapper.queryBookedCount(
@@ -228,8 +226,7 @@ public class OrderServiceImpl implements IOrderService {
                         timeSlotData.getStartTime(),
                         timeSlotData.getEndTime()
                 );
-                int availableInventory = totalInventory - bookedCount;
-                a.setInventory(availableInventory);
+                a.setInventory(totalInventory - bookedCount);
             });
         });
         AppSitePlace appSitePlace = appSitePlaceMapper.selectById(placeId);