修复店务预约与小程序生产问题

This commit is contained in:
2026-07-20 01:22:37 +08:00
parent 92949f9368
commit d180880445
25 changed files with 565 additions and 70 deletions
@@ -34,6 +34,9 @@ public class OrderItemDO extends BaseEntity {
private BigDecimal referencePrice;
private BigDecimal quotedPrice;
private BigDecimal confirmedPrice;
private Boolean depositPaid;
private Boolean needRemoval;
private Boolean fromMeituan;
/**
* Field `artistId` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
*/
@@ -9,6 +9,9 @@ public class PlanningAppointmentCreateDTO {
private Long customerUserId;
private String customerName;
private String phone;
private Boolean depositPaid;
private Boolean needRemoval;
private Boolean fromMeituan;
private Long productId;
private Integer quantity;
private Long artistId;
@@ -117,8 +117,9 @@ public class PlanningServiceImpl implements PlanningService {
);
Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate = listShopScheduleExceptions(shopId, start, end);
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, artists, artistId);
List<PlanningArtistVO> artists = listArtists(shopId, null);
List<PlanningArtistVO> selectedArtists = selectCalendarArtists(artists, artistId);
List<ArtistScheduleDO> schedules = listSchedules(shopId, start, end, selectedArtists, artistId);
List<PlanningScheduleVO> scheduleVos = schedules.stream()
.map(schedule -> toScheduleVO(schedule, artists))
.sorted(Comparator.comparing(PlanningScheduleVO::getDate)
@@ -141,7 +142,8 @@ public class PlanningServiceImpl implements PlanningService {
vo.setArtists(artists);
vo.setSchedules(scheduleVos);
vo.setAppointments(appointments);
vo.setDaySummaries(buildDaySummaries(start, end, artists, schedules, appointments, shop, shopExceptionByDate));
vo.setDaySummaries(buildDaySummaries(start, end, selectedArtists, schedules, appointments, shop, shopExceptionByDate,
artistId != null && artistId > 0));
return vo;
}
@@ -195,6 +197,9 @@ public class PlanningServiceImpl implements PlanningService {
item.setPrice(unitPrice);
item.setArtistId(artist.getId());
item.setAppointmentTime(startTime);
item.setDepositPaid(Boolean.TRUE.equals(dto.getDepositPaid()));
item.setNeedRemoval(Boolean.TRUE.equals(dto.getNeedRemoval()));
item.setFromMeituan(Boolean.TRUE.equals(dto.getFromMeituan()));
item.setIsDelete(0);
orderItemMapper.insert(item);
@@ -282,6 +287,15 @@ public class PlanningServiceImpl implements PlanningService {
item.setPrice(unitPrice);
item.setArtistId(artist.getId());
item.setAppointmentTime(startTime);
if (dto.getDepositPaid() != null) {
item.setDepositPaid(dto.getDepositPaid());
}
if (dto.getNeedRemoval() != null) {
item.setNeedRemoval(dto.getNeedRemoval());
}
if (dto.getFromMeituan() != null) {
item.setFromMeituan(dto.getFromMeituan());
}
orderItemMapper.updateById(item);
return getAppointment(currentUser, item.getId());
}
@@ -662,6 +676,9 @@ public class PlanningServiceImpl implements PlanningService {
vo.setArtistId(artistId);
vo.setArtistName(artist == null ? "未分配" : artist.getName());
vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor());
vo.setDepositPaid(item != null && Boolean.TRUE.equals(item.getDepositPaid()));
vo.setNeedRemoval(item != null && Boolean.TRUE.equals(item.getNeedRemoval()));
vo.setFromMeituan(item != null && Boolean.TRUE.equals(item.getFromMeituan()));
vo.setDate(start == null ? null : start.toLocalDate().toString());
vo.setStartTime(start == null ? null : DATE_TIME_FORMATTER.format(start));
vo.setEndTime(end == null ? null : DATE_TIME_FORMATTER.format(end));
@@ -681,7 +698,8 @@ public class PlanningServiceImpl implements PlanningService {
private List<PlanningDaySummaryVO> buildDaySummaries(LocalDate start, LocalDate end, List<PlanningArtistVO> artists,
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments,
ShopDO shop, Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate) {
ShopDO shop, Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate,
boolean artistScoped) {
Map<String, List<PlanningAppointmentVO>> appointmentsByDate = appointments.stream()
.filter(appointment -> appointment.getDate() != null)
.collect(Collectors.groupingBy(PlanningAppointmentVO::getDate));
@@ -737,15 +755,30 @@ public class PlanningServiceImpl implements PlanningService {
ShopScheduleSupport.LocalTimeRange openRange = ShopScheduleSupport.resolveOpenRange(shop, shopExceptionByDate.get(cursor), cursor);
summary.setBusinessStartTime(openRange.startTime() == null ? null : openRange.startTime().toString());
summary.setBusinessEndTime(openRange.endTime() == null ? null : openRange.endTime().toString());
summary.setDayStatus(openRange.open()
? PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull)
: "rest");
summary.setDayStatus(resolveDaySummaryStatus(openRange, total, hasWorkingSchedule, allFull, artistScoped));
summaries.add(summary);
cursor = cursor.plusDays(1);
}
return summaries;
}
private String resolveDaySummaryStatus(ShopScheduleSupport.LocalTimeRange openRange, int totalCount,
boolean hasWorkingSchedule, boolean allFull, boolean artistScoped) {
if (!openRange.open()) {
return "rest";
}
if (artistScoped) {
return PlanningCalendarSupport.resolveDayStatus(totalCount, hasWorkingSchedule, allFull);
}
if (hasWorkingSchedule && allFull) {
return "full";
}
if (totalCount <= 0) {
return "free";
}
return "working";
}
private Map<LocalDate, ShopScheduleExceptionDO> listShopScheduleExceptions(Long shopId, LocalDate start, LocalDate end) {
return shopScheduleExceptionMapper.selectList(new QueryWrapper<ShopScheduleExceptionDO>()
.eq("shop_id", shopId)
@@ -884,23 +917,27 @@ public class PlanningServiceImpl implements PlanningService {
}
return customer;
}
if (!hasText(dto.getPhone())) {
throw new RuntimeException("客户手机号不能为空");
String customerName = trimToNull(dto.getCustomerName());
String phone = trimToNull(dto.getPhone());
if (hasText(phone)) {
QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0)
.and(query -> query.eq("phone", phone).or().eq("contact_phone", phone))
.last("LIMIT 1");
UserDO existing = userMapper.selectOne(wrapper);
if (existing != null) {
return existing;
}
}
QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0)
.and(query -> query.eq("phone", dto.getPhone()).or().eq("contact_phone", dto.getPhone()))
.last("LIMIT 1");
UserDO existing = userMapper.selectOne(wrapper);
if (existing != null) {
return existing;
if (!hasText(customerName)) {
throw new RuntimeException("客户姓名不能为空");
}
UserDO customer = new UserDO();
customer.setShopId(shopId);
customer.setNickname(firstNonBlank(dto.getCustomerName(), dto.getPhone()));
customer.setPhone(dto.getPhone());
customer.setContactPhone(dto.getPhone());
customer.setAccount(dto.getPhone());
customer.setNickname(firstNonBlank(customerName, phone, "到店客户"));
customer.setPhone(phone);
customer.setContactPhone(phone);
customer.setAccount("guest" + snowflakeIdGenerator.nextIdString());
customer.setPassword(ENCODED_UNSET_PASSWORD);
customer.setType(0);
customer.setStatus(1);
@@ -909,6 +946,15 @@ public class PlanningServiceImpl implements PlanningService {
return customer;
}
private List<PlanningArtistVO> selectCalendarArtists(List<PlanningArtistVO> artists, Long artistId) {
if (artistId == null || artistId <= 0) {
return artists;
}
return artists.stream()
.filter(artist -> Objects.equals(artist.getId(), artistId))
.toList();
}
private String buildOrderCustomerNameSnapshot(PlanningAppointmentCreateDTO dto, UserDO customer) {
return firstNonBlank(
dto.getCustomerName(),
@@ -25,6 +25,9 @@ public class PlanningAppointmentVO {
private Integer status;
private String statusText;
private String occupancyStatus;
private Boolean depositPaid;
private Boolean needRemoval;
private Boolean fromMeituan;
private Boolean canEdit;
private Boolean canCancel;
private String conflictReason;
@@ -211,6 +211,83 @@ class PlanningServiceImplTest {
assertThat(appointment.getCustomerName()).isEqualTo("王女士");
}
@Test
void createAppointmentShouldCreateWalkInCustomerWithoutPhoneAndStoreFlags() {
UserDO manager = user(2, 8L);
UserDO artist = user(3, 8L);
artist.setId(20L);
ShopDO shop = new ShopDO();
shop.setBusinessHours("10:00-22:00");
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setCustomerName(" 到店王女士 ");
dto.setArtistId(20L);
dto.setAppointmentDate("2026-07-20");
dto.setAppointmentTime("15:00");
dto.setDurationMinutes(60);
dto.setManualProductTitle("净色护理");
dto.setManualProductPrice(new BigDecimal("128.00"));
dto.setDepositPaid(true);
dto.setNeedRemoval(true);
dto.setFromMeituan(true);
ProductDO[] storedProduct = new ProductDO[1];
UserDO[] storedCustomer = new UserDO[1];
OrderDO[] storedOrder = new OrderDO[1];
OrderItemDO[] storedItem = new OrderItemDO[1];
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
storedProduct[0] = product;
return 1;
});
when(userMapper.selectById(20L)).thenReturn(artist);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(snowflakeIdGenerator.nextIdString()).thenReturn("202607200001", "202607200002");
when(userMapper.insert(any(UserDO.class))).thenAnswer(invocation -> {
UserDO customer = invocation.getArgument(0);
customer.setId(30L);
storedCustomer[0] = customer;
return 1;
});
when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> {
OrderDO order = invocation.getArgument(0);
order.setId(200L);
storedOrder[0] = order;
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)).thenAnswer(invocation -> storedOrder[0]);
when(productMapper.selectById(100L)).thenAnswer(invocation -> storedProduct[0]);
AppointmentReservationDO reservation = reservation(20L, 200L, 300L,
LocalDateTime.of(2026, 7, 20, 15, 0),
LocalDateTime.of(2026, 7, 20, 16, 0));
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
when(userMapper.selectBatchIds(any())).thenAnswer(invocation -> List.of(storedCustomer[0]));
var appointment = planningService.createAppointment(manager, dto);
ArgumentCaptor<UserDO> customerCaptor = ArgumentCaptor.forClass(UserDO.class);
org.mockito.Mockito.verify(userMapper).insert(customerCaptor.capture());
assertThat(customerCaptor.getValue().getNickname()).isEqualTo("到店王女士");
assertThat(customerCaptor.getValue().getPhone()).isNull();
assertThat(customerCaptor.getValue().getContactPhone()).isNull();
assertThat(customerCaptor.getValue().getAccount()).isEqualTo("guest202607200001");
assertThat(storedItem[0].getDepositPaid()).isTrue();
assertThat(storedItem[0].getNeedRemoval()).isTrue();
assertThat(storedItem[0].getFromMeituan()).isTrue();
assertThat(appointment.getCustomerName()).isEqualTo("到店王女士");
assertThat(appointment.getDepositPaid()).isTrue();
assertThat(appointment.getNeedRemoval()).isTrue();
assertThat(appointment.getFromMeituan()).isTrue();
}
@Test
void createAppointmentRejectsStoreRestDay() {
UserDO manager = user(2, 8L);
@@ -316,6 +393,73 @@ class PlanningServiceImplTest {
assertThat(calendar.getAppointments().get(0).getCustomerName()).isEqualTo("预约王女士");
}
@Test
void calendarUsesShopStatusWhenNoEmployeeScheduleInShopView() {
UserDO manager = user(2, 8L);
UserDO firstArtist = user(3, 8L);
firstArtist.setId(20L);
firstArtist.setNickname("小王");
UserDO secondArtist = user(3, 8L);
secondArtist.setId(21L);
secondArtist.setNickname("小李");
LocalDate date = LocalDate.of(2026, 7, 20);
ShopDO shop = new ShopDO();
shop.setBusinessHours("09:00-18:00");
shop.setSchedulePresetType("EVERYDAY");
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of());
when(userMapper.selectList(any())).thenReturn(List.of(firstArtist, secondArtist));
when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of());
when(artistScheduleMapper.selectList(any())).thenReturn(List.of());
when(artistScheduleRuleMapper.selectList(any())).thenReturn(List.of());
when(appointmentReservationMapper.selectList(any())).thenReturn(List.of());
when(orderItemMapper.selectList(any())).thenReturn(List.of());
var calendar = planningService.getCalendar(manager, date, date, null);
var summary = calendar.getDaySummaries().get(0);
assertThat(summary.getDayStatus()).isEqualTo("free");
assertThat(summary.getArtistCounts())
.extracting(count -> count.getArtistId() + ":" + count.getStatus())
.containsExactly("20:rest", "21:rest");
}
@Test
void calendarUsesEmployeeStatusWhenSingleArtistHasNoSchedule() {
UserDO manager = user(2, 8L);
UserDO firstArtist = user(3, 8L);
firstArtist.setId(20L);
firstArtist.setNickname("小王");
UserDO secondArtist = user(3, 8L);
secondArtist.setId(21L);
secondArtist.setNickname("小李");
LocalDate date = LocalDate.of(2026, 7, 20);
ShopDO shop = new ShopDO();
shop.setBusinessHours("09:00-18:00");
shop.setSchedulePresetType("EVERYDAY");
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of());
when(userMapper.selectList(any())).thenReturn(List.of(firstArtist, secondArtist));
when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of());
when(artistScheduleMapper.selectList(any())).thenReturn(List.of());
when(artistScheduleRuleMapper.selectList(any())).thenReturn(List.of());
when(appointmentReservationMapper.selectList(any())).thenReturn(List.of());
when(orderItemMapper.selectList(any())).thenReturn(List.of());
var calendar = planningService.getCalendar(manager, date, date, 20L);
assertThat(calendar.getArtists()).hasSize(2);
var summary = calendar.getDaySummaries().get(0);
assertThat(summary.getDayStatus()).isEqualTo("rest");
assertThat(summary.getArtistCounts())
.extracting(count -> count.getArtistId() + ":" + count.getStatus())
.containsExactly("20:rest");
}
@Test
void calendarUsesRuleWhenDailyScheduleMissing() {
UserDO manager = user(2, 8L);