支持跨天预约并新增员工全天排班SQL
This commit is contained in:
+6
-4
@@ -24,6 +24,8 @@ public final class ArtistScheduleRuleSupport {
|
||||
public static final String EXCEPTION_REST = "REST";
|
||||
public static final String EXCEPTION_EXTRA_WORK = "EXTRA_WORK";
|
||||
public static final String EXCEPTION_CHANGE_SHIFT = "CHANGE_SHIFT";
|
||||
public static final LocalTime FULL_DAY_START_TIME = LocalTime.MIN;
|
||||
public static final LocalTime FULL_DAY_END_TIME = LocalTime.of(23, 59, 59);
|
||||
|
||||
private static final List<Integer> EVERYDAY_WORK_DAYS = List.of(1, 2, 3, 4, 5, 6, 7);
|
||||
|
||||
@@ -109,10 +111,10 @@ public final class ArtistScheduleRuleSupport {
|
||||
ArtistScheduleRuleDO rule = new ArtistScheduleRuleDO();
|
||||
rule.setShopId(shopId);
|
||||
rule.setArtistId(artistId);
|
||||
rule.setPresetType(PRESET_DOUBLE_REST);
|
||||
rule.setWorkDays(encodeWorkDays(List.of(1, 2, 3, 4, 5)));
|
||||
rule.setStartTime(LocalTime.of(9, 0));
|
||||
rule.setEndTime(LocalTime.of(17, 0));
|
||||
rule.setPresetType(PRESET_EVERYDAY);
|
||||
rule.setWorkDays(encodeWorkDays(EVERYDAY_WORK_DAYS));
|
||||
rule.setStartTime(FULL_DAY_START_TIME);
|
||||
rule.setEndTime(FULL_DAY_END_TIME);
|
||||
rule.setSlotMinutes(DEFAULT_SLOT_MINUTES);
|
||||
rule.setCapacity(DEFAULT_CAPACITY);
|
||||
rule.setStatus(1);
|
||||
|
||||
+64
-10
@@ -15,8 +15,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -28,6 +31,7 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
private static final String STATUS_RELEASED = "RELEASED";
|
||||
private static final String UNAVAILABLE_MESSAGE = "涓嶅彲棰勭害";
|
||||
private static final String FULL_MESSAGE = "褰撳墠缇庣敳甯堣鏃堕棿娈靛凡绾︽弧锛岃閲嶆柊閫夋嫨棰勭害鏃堕棿";
|
||||
private static final LocalTime FULL_DAY_QUERY_END_TIME = LocalTime.of(23, 59);
|
||||
|
||||
private final AppointmentReservationMapper reservationMapper;
|
||||
private final ArtistScheduleMapper scheduleMapper;
|
||||
@@ -145,21 +149,33 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
}
|
||||
|
||||
private int resolveCapacity(Long shopId, Long artistId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
List<AppointmentTimeSegment> segments = splitAppointmentSegments(startTime, endTime);
|
||||
int capacity = Integer.MAX_VALUE;
|
||||
for (AppointmentTimeSegment segment : segments) {
|
||||
capacity = Math.min(capacity, resolveSegmentCapacity(shopId, artistId, segment));
|
||||
}
|
||||
if (capacity == Integer.MAX_VALUE) {
|
||||
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
private int resolveSegmentCapacity(Long shopId, Long artistId, AppointmentTimeSegment segment) {
|
||||
ArtistScheduleDO schedule = scheduleMapper.selectCoveringSchedule(
|
||||
shopId,
|
||||
artistId,
|
||||
startTime.toLocalDate(),
|
||||
startTime.toLocalTime(),
|
||||
endTime.toLocalTime()
|
||||
segment.workDate(),
|
||||
segment.startTime(),
|
||||
toCoverageQueryEndTime(segment.endTime())
|
||||
);
|
||||
if (schedule != null && isManualScheduleOverride(schedule)) {
|
||||
return resolveExplicitScheduleCapacity(schedule);
|
||||
}
|
||||
ArtistScheduleDO daySchedule = scheduleMapper.selectDayScheduleForUpdate(shopId, artistId, startTime.toLocalDate());
|
||||
ArtistScheduleDO daySchedule = scheduleMapper.selectDayScheduleForUpdate(shopId, artistId, segment.workDate());
|
||||
if (daySchedule != null && isManualScheduleOverride(daySchedule)) {
|
||||
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
||||
}
|
||||
return resolveRuleCapacity(shopId, artistId, startTime, endTime);
|
||||
return resolveRuleCapacity(shopId, artistId, segment);
|
||||
}
|
||||
|
||||
private int resolveExplicitScheduleCapacity(ArtistScheduleDO schedule) {
|
||||
@@ -171,7 +187,7 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
return schedule.getCapacity();
|
||||
}
|
||||
|
||||
private int resolveRuleCapacity(Long shopId, Long artistId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
private int resolveRuleCapacity(Long shopId, Long artistId, AppointmentTimeSegment segment) {
|
||||
ArtistScheduleRuleDO rule = ruleMapper.selectOne(new QueryWrapper<ArtistScheduleRuleDO>()
|
||||
.eq("shop_id", shopId)
|
||||
.eq("artist_id", artistId)
|
||||
@@ -183,17 +199,17 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
ArtistScheduleExceptionDO exception = exceptionMapper.selectOne(new QueryWrapper<ArtistScheduleExceptionDO>()
|
||||
.eq("shop_id", shopId)
|
||||
.eq("artist_id", artistId)
|
||||
.eq("work_date", startTime.toLocalDate())
|
||||
.eq("work_date", segment.workDate())
|
||||
.eq("is_delete", 0)
|
||||
.last("LIMIT 1"));
|
||||
ArtistScheduleRuleSupport.ResolvedSchedule resolved = ArtistScheduleRuleSupport.resolveGeneratedSchedule(
|
||||
rule,
|
||||
exception,
|
||||
startTime.toLocalDate()
|
||||
segment.workDate()
|
||||
);
|
||||
if (!resolved.working()
|
||||
|| resolved.capacity() == null || resolved.capacity() < MIN_CAPACITY
|
||||
|| !isTimeCovered(resolved.startTime(), resolved.endTime(), startTime.toLocalTime(), endTime.toLocalTime())) {
|
||||
|| !isTimeCovered(resolved.startTime(), resolved.endTime(), segment.startTime(), segment.endTime())) {
|
||||
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
||||
}
|
||||
return resolved.capacity();
|
||||
@@ -204,7 +220,42 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
if (scheduleStartTime == null || scheduleEndTime == null || appointmentStartTime == null || appointmentEndTime == null) {
|
||||
return false;
|
||||
}
|
||||
return !appointmentStartTime.isBefore(scheduleStartTime) && !appointmentEndTime.isAfter(scheduleEndTime);
|
||||
return !appointmentStartTime.isBefore(scheduleStartTime) && isEndTimeCovered(appointmentEndTime, scheduleEndTime);
|
||||
}
|
||||
|
||||
private boolean isEndTimeCovered(LocalTime appointmentEndTime, LocalTime scheduleEndTime) {
|
||||
if (!appointmentEndTime.isAfter(scheduleEndTime)) {
|
||||
return true;
|
||||
}
|
||||
return LocalTime.MAX.equals(appointmentEndTime) && isFullDayEndTime(scheduleEndTime);
|
||||
}
|
||||
|
||||
private boolean isFullDayEndTime(LocalTime endTime) {
|
||||
return endTime != null && !endTime.isBefore(FULL_DAY_QUERY_END_TIME);
|
||||
}
|
||||
|
||||
private LocalTime toCoverageQueryEndTime(LocalTime endTime) {
|
||||
if (LocalTime.MAX.equals(endTime)) {
|
||||
return FULL_DAY_QUERY_END_TIME;
|
||||
}
|
||||
return endTime;
|
||||
}
|
||||
|
||||
private List<AppointmentTimeSegment> splitAppointmentSegments(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
if (startTime == null || endTime == null || !startTime.isBefore(endTime)) {
|
||||
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
||||
}
|
||||
List<AppointmentTimeSegment> segments = new ArrayList<>();
|
||||
LocalDateTime cursor = startTime;
|
||||
while (cursor.isBefore(endTime)) {
|
||||
LocalDate workDate = cursor.toLocalDate();
|
||||
LocalDateTime nextDayStart = workDate.plusDays(1L).atStartOfDay();
|
||||
LocalDateTime segmentEndDateTime = endTime.isBefore(nextDayStart) ? endTime : nextDayStart;
|
||||
LocalTime segmentEndTime = segmentEndDateTime.equals(nextDayStart) ? LocalTime.MAX : segmentEndDateTime.toLocalTime();
|
||||
segments.add(new AppointmentTimeSegment(workDate, cursor.toLocalTime(), segmentEndTime));
|
||||
cursor = segmentEndDateTime;
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
private boolean isManualScheduleOverride(ArtistScheduleDO schedule) {
|
||||
@@ -214,4 +265,7 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
||||
String remark = schedule.getRemark().trim();
|
||||
return !"规则生成排班".equals(remark) && !remark.startsWith("例外排班:");
|
||||
}
|
||||
|
||||
private record AppointmentTimeSegment(LocalDate workDate, LocalTime startTime, LocalTime endTime) {
|
||||
}
|
||||
}
|
||||
|
||||
+50
-8
@@ -1138,16 +1138,55 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
LocalDate workDate = startTime.toLocalDate();
|
||||
ShopScheduleSupport.LocalTimeRange hours = ShopScheduleSupport.resolveOpenRange(shop, selectShopScheduleException(shopId, workDate), workDate);
|
||||
if (!hours.open()) {
|
||||
throw new RuntimeException("当前日期为店铺休息日,不能预约:" + workDate);
|
||||
List<AppointmentTimeSegment> segments = splitAppointmentSegments(startTime, endTime);
|
||||
for (AppointmentTimeSegment segment : segments) {
|
||||
ShopScheduleSupport.LocalTimeRange hours = ShopScheduleSupport.resolveOpenRange(
|
||||
shop,
|
||||
selectShopScheduleException(shopId, segment.workDate()),
|
||||
segment.workDate()
|
||||
);
|
||||
if (!hours.open()) {
|
||||
throw new RuntimeException("当前日期为店铺休息日,不能预约:" + segment.workDate());
|
||||
}
|
||||
if (!isSegmentWithinBusinessHours(segment, hours)) {
|
||||
throw new RuntimeException("预约时间超出店铺营业时间:" + segment.workDate());
|
||||
}
|
||||
}
|
||||
LocalTime start = startTime.toLocalTime();
|
||||
LocalTime end = endTime.toLocalTime();
|
||||
if (start.isBefore(hours.startTime()) || end.isAfter(hours.endTime()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
|
||||
throw new RuntimeException("预约时间超出店铺营业时间");
|
||||
}
|
||||
|
||||
private boolean isSegmentWithinBusinessHours(AppointmentTimeSegment segment, ShopScheduleSupport.LocalTimeRange hours) {
|
||||
if (segment == null || hours == null || hours.startTime() == null || hours.endTime() == null) {
|
||||
return false;
|
||||
}
|
||||
return !segment.startTime().isBefore(hours.startTime()) && isSegmentEndCovered(segment.endTime(), hours.endTime());
|
||||
}
|
||||
|
||||
private boolean isSegmentEndCovered(LocalTime segmentEndTime, LocalTime businessEndTime) {
|
||||
if (!segmentEndTime.isAfter(businessEndTime)) {
|
||||
return true;
|
||||
}
|
||||
return LocalTime.MAX.equals(segmentEndTime) && isFullDayBusinessEndTime(businessEndTime);
|
||||
}
|
||||
|
||||
private boolean isFullDayBusinessEndTime(LocalTime businessEndTime) {
|
||||
return businessEndTime != null && !businessEndTime.isBefore(LocalTime.of(23, 59));
|
||||
}
|
||||
|
||||
private List<AppointmentTimeSegment> splitAppointmentSegments(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
if (startTime == null || endTime == null || !startTime.isBefore(endTime)) {
|
||||
throw new RuntimeException("预约时间范围不正确");
|
||||
}
|
||||
List<AppointmentTimeSegment> segments = new ArrayList<>();
|
||||
LocalDateTime cursor = startTime;
|
||||
while (cursor.isBefore(endTime)) {
|
||||
LocalDate workDate = cursor.toLocalDate();
|
||||
LocalDateTime nextDayStart = workDate.plusDays(1L).atStartOfDay();
|
||||
LocalDateTime segmentEndDateTime = endTime.isBefore(nextDayStart) ? endTime : nextDayStart;
|
||||
LocalTime segmentEndTime = segmentEndDateTime.equals(nextDayStart) ? LocalTime.MAX : segmentEndDateTime.toLocalTime();
|
||||
segments.add(new AppointmentTimeSegment(workDate, cursor.toLocalTime(), segmentEndTime));
|
||||
cursor = segmentEndDateTime;
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
private ShopScheduleExceptionDO selectShopScheduleException(Long shopId, LocalDate workDate) {
|
||||
@@ -1224,6 +1263,9 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
.collect(Collectors.toMap(UserDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private record AppointmentTimeSegment(LocalDate workDate, LocalTime startTime, LocalTime endTime) {
|
||||
}
|
||||
|
||||
private String resolveArtistColor(NailArtistInfoDO info, Long artistId, int index) {
|
||||
if (info != null && hasText(info.getColor()) && info.getColor().trim().matches("^#[0-9a-fA-F]{6}$")) {
|
||||
return info.getColor().trim().toUpperCase();
|
||||
|
||||
+20
@@ -8,6 +8,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.jayucloud.core.config.BrandProperties;
|
||||
import com.xiaowang.jayucloud.core.common.dto.*;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.dto.*;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleRuleMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.support.ArtistScheduleRuleSupport;
|
||||
import com.xiaowang.jayucloud.core.modules.auth.dto.*;
|
||||
import com.xiaowang.jayucloud.core.modules.content.dto.*;
|
||||
import com.xiaowang.jayucloud.core.modules.file.dto.*;
|
||||
@@ -180,6 +183,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
* Variable `nailArtistInfoService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
*/
|
||||
private final NailArtistInfoService nailArtistInfoService;
|
||||
private final ArtistScheduleRuleMapper artistScheduleRuleMapper;
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
/**
|
||||
* Variable `verificationCodeService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||
@@ -471,10 +475,26 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
nailArtistInfoDTO.setStatus(1); // 默认状态为营业中
|
||||
nailArtistInfoDTO.setPortfolio(""); // 默认作品集为空
|
||||
nailArtistInfoService.saveOrUpdateNailArtistInfo(nailArtistInfoDTO);
|
||||
ensureDefaultArtistScheduleRule(validatedShopId, userDO.getId());
|
||||
}
|
||||
|
||||
return userDO.getId();
|
||||
}
|
||||
|
||||
private void ensureDefaultArtistScheduleRule(Long shopId, Long artistId) {
|
||||
if (shopId == null || artistId == null) {
|
||||
throw new RuntimeException("创建员工默认排班缺少店铺或员工ID");
|
||||
}
|
||||
ArtistScheduleRuleDO existingRule = artistScheduleRuleMapper.selectOne(new LambdaQueryWrapper<ArtistScheduleRuleDO>()
|
||||
.eq(ArtistScheduleRuleDO::getShopId, shopId)
|
||||
.eq(ArtistScheduleRuleDO::getArtistId, artistId)
|
||||
.eq(ArtistScheduleRuleDO::getIsDelete, 0)
|
||||
.last("LIMIT 1"));
|
||||
if (existingRule != null) {
|
||||
return;
|
||||
}
|
||||
artistScheduleRuleMapper.insert(ArtistScheduleRuleSupport.defaultRule(shopId, artistId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配默认权限
|
||||
|
||||
+41
@@ -192,6 +192,47 @@ class AppointmentCapacityServiceImplTest {
|
||||
verify(reservationMapper, never()).insert(any(AppointmentReservationDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reserveAllowsCrossDayWhenEveryTouchedRuleDayWorks() {
|
||||
LocalDateTime start = LocalDateTime.of(2026, 7, 2, 23, 30);
|
||||
LocalDateTime end = LocalDateTime.of(2026, 7, 3, 7, 50);
|
||||
ArtistScheduleRuleDO rule = rule("EVERYDAY", "1,2,3,4,5,6,7", LocalTime.MIN, LocalTime.of(23, 59, 59));
|
||||
when(scheduleMapper.selectCoveringSchedule(9L, 30L, LocalDate.of(2026, 7, 2), LocalTime.of(23, 30), LocalTime.of(23, 59)))
|
||||
.thenReturn(null);
|
||||
when(scheduleMapper.selectCoveringSchedule(9L, 30L, LocalDate.of(2026, 7, 3), LocalTime.MIN, LocalTime.of(7, 50)))
|
||||
.thenReturn(null);
|
||||
when(scheduleMapper.selectDayScheduleForUpdate(9L, 30L, LocalDate.of(2026, 7, 2))).thenReturn(null);
|
||||
when(scheduleMapper.selectDayScheduleForUpdate(9L, 30L, LocalDate.of(2026, 7, 3))).thenReturn(null);
|
||||
when(ruleMapper.selectOne(any())).thenReturn(rule);
|
||||
when(exceptionMapper.selectOne(any())).thenReturn(null);
|
||||
when(reservationMapper.countOverlappingActiveForUpdate(30L, start, end)).thenReturn(0);
|
||||
|
||||
service.reserveOrThrow(1L, 10L, 9L, 30L, "French", start, end);
|
||||
|
||||
verify(reservationMapper).insert(any(AppointmentReservationDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reserveRejectsCrossDayWhenNextDayRuleExceptionRests() {
|
||||
LocalDateTime start = LocalDateTime.of(2026, 7, 2, 23, 30);
|
||||
LocalDateTime end = LocalDateTime.of(2026, 7, 3, 7, 50);
|
||||
ArtistScheduleRuleDO rule = rule("EVERYDAY", "1,2,3,4,5,6,7", LocalTime.MIN, LocalTime.of(23, 59, 59));
|
||||
when(scheduleMapper.selectCoveringSchedule(9L, 30L, LocalDate.of(2026, 7, 2), LocalTime.of(23, 30), LocalTime.of(23, 59)))
|
||||
.thenReturn(null);
|
||||
when(scheduleMapper.selectCoveringSchedule(9L, 30L, LocalDate.of(2026, 7, 3), LocalTime.MIN, LocalTime.of(7, 50)))
|
||||
.thenReturn(null);
|
||||
when(scheduleMapper.selectDayScheduleForUpdate(9L, 30L, LocalDate.of(2026, 7, 2))).thenReturn(null);
|
||||
when(scheduleMapper.selectDayScheduleForUpdate(9L, 30L, LocalDate.of(2026, 7, 3))).thenReturn(null);
|
||||
when(ruleMapper.selectOne(any())).thenReturn(rule);
|
||||
when(exceptionMapper.selectOne(any())).thenReturn(null).thenReturn(restException(LocalDate.of(2026, 7, 3)));
|
||||
|
||||
assertThatThrownBy(() -> service.reserveOrThrow(1L, 10L, 9L, 30L, "French", start, end))
|
||||
.isInstanceOf(RuntimeException.class)
|
||||
.hasMessageContaining("涓嶅彲棰勭害");
|
||||
|
||||
verify(reservationMapper, never()).insert(any(AppointmentReservationDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reserveRejectsWhenCoveringScheduleIsDisabled() {
|
||||
LocalDateTime start = LocalDateTime.of(2026, 6, 1, 10, 0);
|
||||
|
||||
+110
@@ -24,6 +24,7 @@ import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.entity.ShopScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
@@ -379,6 +380,115 @@ class PlanningServiceImplTest {
|
||||
.hasMessageContaining("当前日期为店铺休息日");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAppointmentAllowsCrossDayWhenTouchedDaysAreOpen() {
|
||||
UserDO manager = user(2, 8L);
|
||||
UserDO artist = user(3, 8L);
|
||||
artist.setId(20L);
|
||||
UserDO customer = user(0, 8L);
|
||||
customer.setId(30L);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setBusinessHours("00:00-23:59:59");
|
||||
shop.setSchedulePresetType("EVERYDAY");
|
||||
shop.setScheduleWorkDays("1,2,3,4,5,6,7");
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerUserId(30L);
|
||||
dto.setArtistId(20L);
|
||||
dto.setAppointmentDate("2026-07-02");
|
||||
dto.setAppointmentTime("23:30");
|
||||
dto.setDurationMinutes(500);
|
||||
dto.setManualProductTitle("跨天测试");
|
||||
dto.setManualProductPrice(new BigDecimal("100.00"));
|
||||
|
||||
OrderItemDO[] storedItem = new OrderItemDO[1];
|
||||
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
|
||||
when(userMapper.selectById(20L)).thenReturn(artist);
|
||||
when(userMapper.selectById(30L)).thenReturn(customer);
|
||||
when(shopMapper.selectById(8L)).thenReturn(shop);
|
||||
when(shopScheduleExceptionMapper.selectOne(any())).thenReturn(null);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("202607020001");
|
||||
when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> {
|
||||
OrderDO order = invocation.getArgument(0);
|
||||
order.setId(200L);
|
||||
return 1;
|
||||
});
|
||||
when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> {
|
||||
OrderItemDO item = invocation.getArgument(0);
|
||||
item.setId(300L);
|
||||
storedItem[0] = item;
|
||||
return 1;
|
||||
});
|
||||
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]);
|
||||
when(orderMapper.selectById(200L)).thenReturn(order(200L, 8L, 30L));
|
||||
AppointmentReservationDO reservation = reservation(
|
||||
20L,
|
||||
200L,
|
||||
300L,
|
||||
LocalDateTime.of(2026, 7, 2, 23, 30),
|
||||
LocalDateTime.of(2026, 7, 3, 7, 50)
|
||||
);
|
||||
reservation.setProductTitle("跨天测试");
|
||||
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
|
||||
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
|
||||
when(userMapper.selectList(any())).thenReturn(List.of(artist));
|
||||
when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of());
|
||||
when(artistScheduleRuleMapper.selectList(any()))
|
||||
.thenReturn(List.of(scheduleRule(20L, "EVERYDAY", "1,2,3,4,5,6,7", LocalTime.MIN, LocalTime.of(23, 59, 59))));
|
||||
|
||||
var appointment = planningService.createAppointment(manager, dto);
|
||||
|
||||
assertThat(storedItem[0].getAppointmentTime()).isEqualTo(LocalDateTime.of(2026, 7, 2, 23, 30));
|
||||
assertThat(appointment.getStartTime()).isEqualTo("2026-07-02 23:30:00");
|
||||
assertThat(appointment.getEndTime()).isEqualTo("2026-07-03 07:50:00");
|
||||
org.mockito.Mockito.verify(appointmentCapacityService).reserveConfirmedOrThrow(
|
||||
200L,
|
||||
300L,
|
||||
8L,
|
||||
20L,
|
||||
"跨天测试",
|
||||
LocalDateTime.of(2026, 7, 2, 23, 30),
|
||||
LocalDateTime.of(2026, 7, 3, 7, 50),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAppointmentRejectsCrossDayWhenNextDayIsStoreRest() {
|
||||
UserDO manager = user(2, 8L);
|
||||
UserDO artist = user(3, 8L);
|
||||
artist.setId(20L);
|
||||
UserDO customer = user(0, 8L);
|
||||
customer.setId(30L);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setBusinessHours("00:00-23:59:59");
|
||||
shop.setSchedulePresetType("EVERYDAY");
|
||||
shop.setScheduleWorkDays("1,2,3,4,5,6,7");
|
||||
ShopScheduleExceptionDO restException = new ShopScheduleExceptionDO();
|
||||
restException.setShopId(8L);
|
||||
restException.setWorkDate(LocalDate.of(2026, 7, 3));
|
||||
restException.setExceptionType("REST");
|
||||
restException.setIsDelete(0);
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerUserId(30L);
|
||||
dto.setArtistId(20L);
|
||||
dto.setAppointmentDate("2026-07-02");
|
||||
dto.setAppointmentTime("23:30");
|
||||
dto.setDurationMinutes(500);
|
||||
dto.setManualProductTitle("跨天休息测试");
|
||||
dto.setManualProductPrice(new BigDecimal("100.00"));
|
||||
|
||||
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
|
||||
when(userMapper.selectById(20L)).thenReturn(artist);
|
||||
when(userMapper.selectById(30L)).thenReturn(customer);
|
||||
when(shopMapper.selectById(8L)).thenReturn(shop);
|
||||
when(shopScheduleExceptionMapper.selectOne(any())).thenReturn(null).thenReturn(restException);
|
||||
|
||||
assertThatThrownBy(() -> planningService.createAppointment(manager, dto))
|
||||
.hasMessageContaining("当前日期为店铺休息日")
|
||||
.hasMessageContaining("2026-07-03");
|
||||
org.mockito.Mockito.verify(orderMapper, org.mockito.Mockito.never()).insert(any(OrderDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppointmentRejectsCompletedOrder() {
|
||||
UserDO manager = user(2, 8L);
|
||||
|
||||
+16
@@ -1,6 +1,8 @@
|
||||
package com.xiaowang.jayucloud.core.modules.user.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleRuleMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.security.mapper.PermissionMapper;
|
||||
import com.xiaowang.jayucloud.core.config.BrandProperties;
|
||||
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper;
|
||||
@@ -28,6 +30,7 @@ import com.xiaowang.jayucloud.core.utils.JwtUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -79,6 +82,9 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
@Mock
|
||||
private NailArtistInfoService nailArtistInfoService;
|
||||
|
||||
@Mock
|
||||
private ArtistScheduleRuleMapper artistScheduleRuleMapper;
|
||||
|
||||
@Mock
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
@@ -121,6 +127,7 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
brandProperties,
|
||||
userShopRoleMapper,
|
||||
nailArtistInfoService,
|
||||
artistScheduleRuleMapper,
|
||||
verificationCodeService,
|
||||
userShopBindingSupport,
|
||||
objectStorageUrlSupport,
|
||||
@@ -201,6 +208,7 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
when(userShopBindingSupport.isShopActive(8L)).thenReturn(true);
|
||||
when(permissionMapper.selectList(any())).thenReturn(existingManagedPermissionsFromCatalog());
|
||||
when(userPermissionMapper.selectList(any())).thenReturn(List.of());
|
||||
when(artistScheduleRuleMapper.selectOne(any())).thenReturn(null);
|
||||
doAnswer(invocation -> {
|
||||
UserDO userDO = invocation.getArgument(0);
|
||||
assertThat(userDO.getPhone()).isNull();
|
||||
@@ -214,6 +222,14 @@ class UserServiceImplPermissionAssignmentTest {
|
||||
assertThat(userId).isEqualTo(43L);
|
||||
verify(userShopBindingSupport).syncUserShopBindings(43L, List.of(8L));
|
||||
verify(nailArtistInfoService).saveOrUpdateNailArtistInfo(any());
|
||||
ArgumentCaptor<ArtistScheduleRuleDO> ruleCaptor = ArgumentCaptor.forClass(ArtistScheduleRuleDO.class);
|
||||
verify(artistScheduleRuleMapper).insert(ruleCaptor.capture());
|
||||
assertThat(ruleCaptor.getValue().getShopId()).isEqualTo(8L);
|
||||
assertThat(ruleCaptor.getValue().getArtistId()).isEqualTo(43L);
|
||||
assertThat(ruleCaptor.getValue().getPresetType()).isEqualTo("EVERYDAY");
|
||||
assertThat(ruleCaptor.getValue().getWorkDays()).isEqualTo("1,2,3,4,5,6,7");
|
||||
assertThat(ruleCaptor.getValue().getStartTime()).isEqualTo(java.time.LocalTime.MIN);
|
||||
assertThat(ruleCaptor.getValue().getEndTime()).isEqualTo(java.time.LocalTime.of(23, 59, 59));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user