修复预约客户与员工管理问题

This commit is contained in:
2026-07-24 23:11:23 +08:00
parent cef84e0d01
commit cb14f3fe4a
11 changed files with 213 additions and 12 deletions
@@ -33,6 +33,7 @@ import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper;
import com.xiaowang.jayucloud.core.modules.product.mapper.ProductMapper;
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopMapper;
import com.xiaowang.jayucloud.core.modules.shop.mapper.ShopScheduleExceptionMapper;
import com.xiaowang.jayucloud.core.modules.shop.support.UserShopBindingSupport;
import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.core.modules.planning.service.AppointmentCapacityService;
import com.xiaowang.jayucloud.core.modules.order.service.OrderService;
@@ -105,6 +106,7 @@ public class PlanningServiceImpl implements PlanningService {
private final ObjectStorageUrlSupport objectStorageUrlSupport;
private final ShopMapper shopMapper;
private final ShopScheduleExceptionMapper shopScheduleExceptionMapper;
private final UserShopBindingSupport userShopBindingSupport;
private final AppointmentCapacityService appointmentCapacityService;
private final OrderService orderService;
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
@@ -168,7 +170,7 @@ public class PlanningServiceImpl implements PlanningService {
}
Long shopId = requirePlanningShopId(currentUser);
requireAppointmentDuration(dto.getDurationMinutes());
ProductDO product = resolveAppointmentProduct(dto, shopId);
ProductDO product = resolveCreateAppointmentProduct(dto, shopId);
UserDO artist = requireActiveArtist(dto.getArtistId(), shopId);
UserDO customer = resolveCustomer(shopId, dto);
@@ -1084,6 +1086,30 @@ public class PlanningServiceImpl implements PlanningService {
return product;
}
private ProductDO resolveCreateAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
if (dto.getProductId() != null) {
return requireActiveProduct(dto.getProductId(), shopId);
}
requireManualAppointmentProduct(dto);
ProductDO product = new ProductDO();
product.setShopId(shopId);
product.setTitle(trimToNull(dto.getManualProductTitle()));
product.setDescription(trimToNull(dto.getManualProductDescription()));
product.setPrice(dto.getManualProductPrice());
product.setTags(trimToNull(dto.getManualProductTags()));
product.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
product.setApproximateDuration(String.valueOf(dto.getDurationMinutes()));
product.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId()));
product.setFrontVisible(0);
product.setSourceType("MANAGER_APPOINTMENT");
product.setLikeCount(0);
product.setCollectCount(0);
product.setIsDelete(0);
productMapper.insert(product);
return product;
}
private ProductDO resolveAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
if (dto.getProductId() != null) {
return requireActiveProduct(dto.getProductId(), shopId);
@@ -1184,12 +1210,13 @@ public class PlanningServiceImpl implements PlanningService {
customer.setNickname(firstNonBlank(customerName, phone, "到店客户"));
customer.setPhone(phone);
customer.setContactPhone(phone);
customer.setAccount("guest" + snowflakeIdGenerator.nextIdString());
customer.setAccount("tmp" + snowflakeIdGenerator.nextIdString());
customer.setPassword(ENCODED_UNSET_PASSWORD);
customer.setType(0);
customer.setStatus(1);
customer.setIsDelete(0);
userMapper.insert(customer);
userShopBindingSupport.ensureUserBoundToShop(customer.getId(), shopId);
return customer;
}
@@ -1927,7 +1927,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
throw new RuntimeException("用户类型错误");
}
if (currentUserType <= targetUserType) {
if (currentUserType < targetUserType) {
/**
* Run business method `RuntimeException`.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
@@ -29,6 +29,7 @@ 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.shop.support.UserShopBindingSupport;
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.core.support.id.TimeOrderedSnowflakeIdGenerator;
@@ -96,6 +97,9 @@ class PlanningServiceImplTest {
@Mock
private ShopScheduleExceptionMapper shopScheduleExceptionMapper;
@Mock
private UserShopBindingSupport userShopBindingSupport;
@Mock
private AppointmentCapacityService appointmentCapacityService;
@@ -124,6 +128,7 @@ class PlanningServiceImplTest {
objectStorageUrlSupport,
shopMapper,
shopScheduleExceptionMapper,
userShopBindingSupport,
appointmentCapacityService,
orderService,
snowflakeIdGenerator
@@ -131,7 +136,7 @@ class PlanningServiceImplTest {
}
@Test
void createAppointmentShouldStoreManualProductSnapshotWithoutCreatingProduct() {
void createAppointmentShouldCreateManualProductAndStoreSnapshot() {
UserDO manager = user(2, 8L);
UserDO artist = user(3, 8L);
artist.setId(20L);
@@ -160,6 +165,11 @@ class PlanningServiceImplTest {
when(userMapper.selectById(30L)).thenReturn(customer);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(snowflakeIdGenerator.nextIdString()).thenReturn("202606260001");
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
return 1;
});
when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> {
OrderDO order = invocation.getArgument(0);
order.setId(200L);
@@ -203,8 +213,11 @@ class PlanningServiceImplTest {
var appointment = planningService.createAppointment(manager, dto);
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class));
assertThat(storedItem[0].getProductId()).isNull();
ArgumentCaptor<ProductDO> productCaptor = ArgumentCaptor.forClass(ProductDO.class);
org.mockito.Mockito.verify(productMapper).insert(productCaptor.capture());
assertThat(productCaptor.getValue().getSourceType()).isEqualTo("MANAGER_APPOINTMENT");
assertThat(productCaptor.getValue().getFrontVisible()).isZero();
assertThat(storedItem[0].getProductId()).isEqualTo(productCaptor.getValue().getId());
assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("日落贝壳");
assertThat(storedItem[0].getAppointmentProductDescription()).isEqualTo("轻透贝壳款");
assertThat(storedItem[0].getAppointmentProductTags()).isEqualTo("贝壳");
@@ -245,6 +258,11 @@ class PlanningServiceImplTest {
when(userMapper.selectById(20L)).thenReturn(artist);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(snowflakeIdGenerator.nextIdString()).thenReturn("202607200001", "202607200002");
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
return 1;
});
when(userMapper.insert(any(UserDO.class))).thenAnswer(invocation -> {
UserDO customer = invocation.getArgument(0);
customer.setId(30L);
@@ -279,9 +297,12 @@ class PlanningServiceImplTest {
assertThat(customerCaptor.getValue().getNickname()).isEqualTo("到店王女士");
assertThat(customerCaptor.getValue().getPhone()).isNull();
assertThat(customerCaptor.getValue().getContactPhone()).isNull();
assertThat(customerCaptor.getValue().getAccount()).isEqualTo("guest202607200001");
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class));
assertThat(storedItem[0].getProductId()).isNull();
ArgumentCaptor<ProductDO> productCaptor = ArgumentCaptor.forClass(ProductDO.class);
org.mockito.Mockito.verify(productMapper).insert(productCaptor.capture());
assertThat(customerCaptor.getValue().getAccount()).isEqualTo("tmp202607200001");
assertThat(productCaptor.getValue().getSourceType()).isEqualTo("MANAGER_APPOINTMENT");
assertThat(storedItem[0].getProductId()).isEqualTo(productCaptor.getValue().getId());
org.mockito.Mockito.verify(userShopBindingSupport).ensureUserBoundToShop(30L, 8L);
assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("净色护理");
assertThat(storedItem[0].getDepositPaid()).isTrue();
assertThat(storedItem[0].getNeedRemoval()).isTrue();