修复管理师端预约与登录体验

This commit is contained in:
2026-06-26 11:07:54 +08:00
parent f1fdf6e5d3
commit 078a2b32cd
48 changed files with 1044 additions and 276 deletions
@@ -20,5 +20,5 @@ public class BrandProperties {
/**
* 管理师注册店铺的默认描述。
*/
private String managerRegisterShopDescription = "指尖管理师注册店铺";
private String managerRegisterShopDescription = "甲屿店务注册店铺";
}
@@ -27,6 +27,11 @@ public class JwtProperties {
*/
private long accessTokenExpirationSeconds = 2 * 60 * 60;
/**
* 记住登录 AccessToken 有效期,单位秒。
*/
private long rememberMeAccessTokenExpirationSeconds = 60 * 60;
/**
* RefreshToken 有效期,单位秒。
*/
@@ -34,6 +34,11 @@ public class PhoneLoginRequestDTO implements AgreementAwareRequest {
*/
private Long shopId;
/**
* 记住登录标志
*/
private Boolean rememberMe;
/**
* Purpose: agreementAccepted supports PhoneLoginRequestDTO.java by holding or executing the agreement accepted business role.
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
@@ -9,6 +9,7 @@ import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO;
import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService;
import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService;
import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO;
import com.xiaowang.fingertipdesigner.core.modules.manager.dto.ManagerCustomerCreateDTO;
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentCreateDTO;
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentMoveDTO;
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentStatusDTO;
@@ -125,6 +126,28 @@ public class AdminManagerController {
return Result.success(userService.getUserById(id));
}
@PostMapping("/customers")
@RequirePermission("user:create")
@OperationGuard(action = "manager-customer-create", ttlSeconds = 10, message = "客户创建处理中,请勿重复提交")
public Result<Long> createCustomer(HttpServletRequest request,
@Valid @RequestBody ManagerCustomerCreateDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requireShopContext(currentUser, "请先选择店铺后再新增客户");
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
String phone = dto.getPhone().trim();
UserDTO userDTO = new UserDTO();
userDTO.setNickname(dto.getNickname().trim());
userDTO.setPhone(phone);
userDTO.setContactPhone(phone);
userDTO.setAccount(phone);
userDTO.setType(0);
userDTO.setShopId(shopId);
userDTO.setShopIds(List.of(shopId));
userDTO.setLevel("普通");
userDTO.setVipId(0L);
return Result.success(userService.createUser(userDTO));
}
@GetMapping("/employees")
@RequirePermission("nail_artist:view")
public Result<List<NailArtistInfoDTO>> employees(HttpServletRequest request) {
@@ -164,6 +187,7 @@ public class AdminManagerController {
public Result<Long> createEmployeeUser(HttpServletRequest request,
@Valid @RequestBody UserDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
dto.setType(3);
adminScopeHelper.ensureAssignableUserType(currentUser, dto.getType());
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
Long managedShopId = adminScopeHelper.getManagedShopId(currentUser);
@@ -0,0 +1,17 @@
package com.xiaowang.fingertipdesigner.core.modules.manager.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
@Data
public class ManagerCustomerCreateDTO {
@NotBlank(message = "客户姓名不能为空")
private String nickname;
@NotBlank(message = "手机号不能为空")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
private String phone;
}
@@ -481,7 +481,7 @@ public class PlanningServiceImpl implements PlanningService {
vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId());
vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle())
? reservation.getProductTitle()
: product == null ? "预约项目" : product.getTitle());
: product == null ? "预约作品" : product.getTitle());
vo.setArtistId(artistId);
vo.setArtistName(artist == null ? "未分配" : artist.getName());
vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor());
@@ -578,11 +578,11 @@ public class PlanningServiceImpl implements PlanningService {
private ProductDO requireActiveProduct(Long productId, Long shopId) {
if (productId == null) {
throw new RuntimeException("请选择预约项目");
throw new RuntimeException("请选择预约作品");
}
ProductDO product = productMapper.selectById(productId);
if (product == null || Integer.valueOf(1).equals(product.getIsDelete()) || !shopId.equals(product.getShopId())) {
throw new RuntimeException("预约项目不存在或不属于当前店铺");
throw new RuntimeException("预约作品不存在或不属于当前店铺");
}
return product;
}
@@ -597,11 +597,11 @@ public class PlanningServiceImpl implements PlanningService {
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
String title = trimToNull(dto.getManualProductTitle());
if (!hasText(title)) {
throw new RuntimeException("请选择预约项目或填写手动项目名称");
throw new RuntimeException("请选择预约作品或填写手动作品名称");
}
BigDecimal price = dto.getManualProductPrice();
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("手动项目价格不能小于0");
throw new RuntimeException("手动作品价格不能小于0");
}
int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0
? DEFAULT_DURATION_MINUTES
@@ -1062,7 +1062,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* @param false parameter `false` supplied by the caller
* @return return result consumed by the caller or returned to the frontend
*/
return buildLoginResponse(userDO, resolvedShopId, false);
return buildLoginResponse(userDO, resolvedShopId, false, Boolean.TRUE.equals(loginRequestDTO.getRememberMe()));
}
@Override
@@ -1110,7 +1110,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
}
Long resolvedShopId = resolveUserLoginShopId(userDO, phoneLoginRequestDTO.getShopId());
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()));
return buildLoginResponse(userDO, resolvedShopId, ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()), Boolean.TRUE.equals(phoneLoginRequestDTO.getRememberMe()));
}
// 未设置密码的特殊标识
@@ -1279,7 +1279,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* @param false parameter `false` supplied by the caller
* @return return result consumed by the caller or returned to the frontend
*/
return buildLoginResponse(userDO, resolvedShopId, false);
return buildLoginResponse(userDO, resolvedShopId, false, Boolean.TRUE.equals(loginRequestDTO.getRememberMe()));
}
@Override
@@ -2751,6 +2751,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
return buildLoginResponse(userDO, currentShopId, needSetPassword, null);
}
private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, boolean rememberMe) {
return buildLoginResponse(userDO, currentShopId, needSetPassword, null, rememberMe);
}
/**
* Run business method `buildLoginResponse`.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
@@ -2761,6 +2765,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
* @return private LoginResponseVO result consumed by the caller or returned to the frontend
*/
private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, String previousSessionId) {
return buildLoginResponse(userDO, currentShopId, needSetPassword, previousSessionId, false);
}
private LoginResponseVO buildLoginResponse(UserDO userDO, Long currentShopId, boolean needSetPassword, String previousSessionId, boolean rememberMe) {
UserSessionService.SessionIssueResult sessionIssueResult = StringUtils.hasText(previousSessionId)
? userSessionService.rotateSession(previousSessionId, userDO.getId(), userDO.getAccount(), currentShopId, userDO.getType())
: userSessionService.issueSession(userDO.getId(), userDO.getAccount(), currentShopId, userDO.getType());
@@ -2769,7 +2777,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
userDO.getAccount(),
currentShopId,
sessionIssueResult.sessionId(),
sessionIssueResult.accessJti()
sessionIssueResult.accessJti(),
jwtUtil.resolveAccessTokenExpirationSeconds(rememberMe)
);
String refreshToken = jwtUtil.generateRefreshToken(
userDO.getId(),
@@ -41,6 +41,10 @@ public class JwtUtil {
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
*/
public String generateAccessToken(Long userId, String account, Long currentShopId, String sessionId, String jti) {
return generateAccessToken(userId, account, currentShopId, sessionId, jti, jwtProperties.getAccessTokenExpirationSeconds());
}
public String generateAccessToken(Long userId, String account, Long currentShopId, String sessionId, String jti, long expirationSeconds) {
Map<String, Object> claims = new HashMap<>();
claims.put("userId", userId);
claims.put("account", account);
@@ -50,7 +54,13 @@ public class JwtUtil {
if (currentShopId != null && currentShopId > 0) {
claims.put("shopId", currentShopId);
}
return createToken(claims, userId.toString(), jwtProperties.getAccessTokenExpirationSeconds() * 1000);
return createToken(claims, userId.toString(), expirationSeconds * 1000);
}
public long resolveAccessTokenExpirationSeconds(boolean rememberMe) {
return rememberMe
? jwtProperties.getRememberMeAccessTokenExpirationSeconds()
: jwtProperties.getAccessTokenExpirationSeconds();
}
/**
+2 -1
View File
@@ -28,11 +28,12 @@ mybatis:
fingertip-designer:
brand:
message-template-name: ${PLATFORM_MESSAGE_TEMPLATE_NAME:FingertipDesigner}
manager-register-shop-description: ${PLATFORM_MANAGER_REGISTER_SHOP_DESCRIPTION:指尖管理师注册店铺}
manager-register-shop-description: ${PLATFORM_MANAGER_REGISTER_SHOP_DESCRIPTION:甲屿店务注册店铺}
security:
jwt:
issuer: fingertip-designer
access-token-expiration-seconds: 7200
remember-me-access-token-expiration-seconds: 3600
refresh-token-expiration-seconds: 604800
clock-skew-seconds: 30
signature:
@@ -7,6 +7,7 @@ import com.xiaowang.fingertipdesigner.core.modules.artist.dto.NailArtistInfoDTO;
import com.xiaowang.fingertipdesigner.core.modules.artist.service.ArtistScheduleService;
import com.xiaowang.fingertipdesigner.core.modules.artist.service.NailArtistInfoService;
import com.xiaowang.fingertipdesigner.core.modules.artist.vo.ArtistScheduleVO;
import com.xiaowang.fingertipdesigner.core.modules.manager.dto.ManagerCustomerCreateDTO;
import com.xiaowang.fingertipdesigner.core.modules.planning.service.PlanningService;
import com.xiaowang.fingertipdesigner.core.modules.product.service.ProductService;
import com.xiaowang.fingertipdesigner.core.modules.product.vo.ProductVO;
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -109,6 +111,53 @@ class AdminManagerControllerTest {
verify(adminScopeHelper).ensureAssignableUserType(manager, 3);
}
@Test
void createEmployeeUserShouldForceNailArtistType() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
UserDTO dto = new UserDTO();
dto.setType(0);
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(true);
when(userService.createUser(dto)).thenReturn(102L);
Result<Long> result = controller.createEmployeeUser(request, dto);
assertThat(result.getData()).isEqualTo(102L);
assertThat(dto.getType()).isEqualTo(3);
verify(adminScopeHelper).ensureAssignableUserType(manager, 3);
}
@Test
void createCustomerShouldForceNormalUserInCurrentShop() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserDO manager = new UserDO();
manager.setType(2);
ManagerCustomerCreateDTO dto = new ManagerCustomerCreateDTO();
dto.setNickname(" 小王客户 ");
dto.setPhone(" 13800138000 ");
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(userService.createUser(any(UserDTO.class))).thenReturn(103L);
Result<Long> result = controller.createCustomer(request, dto);
assertThat(result.getData()).isEqualTo(103L);
verify(adminScopeHelper).requireShopContext(manager, "请先选择店铺后再新增客户");
verify(userService).createUser(org.mockito.ArgumentMatchers.argThat(userDTO ->
"小王客户".equals(userDTO.getNickname())
&& "13800138000".equals(userDTO.getPhone())
&& "13800138000".equals(userDTO.getContactPhone())
&& "13800138000".equals(userDTO.getAccount())
&& Integer.valueOf(0).equals(userDTO.getType())
&& Long.valueOf(8L).equals(userDTO.getShopId())
&& userDTO.getShopIds().equals(List.of(8L))
&& "普通".equals(userDTO.getLevel())
&& Long.valueOf(0L).equals(userDTO.getVipId())
));
}
@Test
void saveScheduleShouldResolveShopScopeBeforeSaving() {
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -0,0 +1,197 @@
package com.xiaowang.fingertipdesigner.core.modules.planning.service.impl;
import com.xiaowang.fingertipdesigner.core.modules.artist.mapper.ArtistScheduleMapper;
import com.xiaowang.fingertipdesigner.core.modules.artist.mapper.NailArtistInfoMapper;
import com.xiaowang.fingertipdesigner.core.modules.order.entity.OrderDO;
import com.xiaowang.fingertipdesigner.core.modules.order.entity.OrderItemDO;
import com.xiaowang.fingertipdesigner.core.modules.order.mapper.OrderItemMapper;
import com.xiaowang.fingertipdesigner.core.modules.order.mapper.OrderMapper;
import com.xiaowang.fingertipdesigner.core.modules.order.service.OrderService;
import com.xiaowang.fingertipdesigner.core.modules.planning.dto.PlanningAppointmentCreateDTO;
import com.xiaowang.fingertipdesigner.core.modules.planning.entity.AppointmentReservationDO;
import com.xiaowang.fingertipdesigner.core.modules.planning.mapper.AppointmentReservationMapper;
import com.xiaowang.fingertipdesigner.core.modules.planning.service.AppointmentCapacityService;
import com.xiaowang.fingertipdesigner.core.modules.product.entity.ProductDO;
import com.xiaowang.fingertipdesigner.core.modules.product.mapper.ProductMapper;
import com.xiaowang.fingertipdesigner.core.modules.security.support.AdminScopeHelper;
import com.xiaowang.fingertipdesigner.core.modules.shop.entity.ShopDO;
import com.xiaowang.fingertipdesigner.core.modules.shop.mapper.ShopMapper;
import com.xiaowang.fingertipdesigner.core.modules.user.entity.UserDO;
import com.xiaowang.fingertipdesigner.core.modules.user.mapper.UserMapper;
import com.xiaowang.fingertipdesigner.core.support.id.TimeOrderedSnowflakeIdGenerator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class PlanningServiceImplTest {
@Mock
private AdminScopeHelper adminScopeHelper;
@Mock
private UserMapper userMapper;
@Mock
private NailArtistInfoMapper nailArtistInfoMapper;
@Mock
private ArtistScheduleMapper artistScheduleMapper;
@Mock
private AppointmentReservationMapper appointmentReservationMapper;
@Mock
private OrderMapper orderMapper;
@Mock
private OrderItemMapper orderItemMapper;
@Mock
private ProductMapper productMapper;
@Mock
private ShopMapper shopMapper;
@Mock
private AppointmentCapacityService appointmentCapacityService;
@Mock
private OrderService orderService;
@Mock
private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
private PlanningServiceImpl planningService;
@BeforeEach
void setUp() {
planningService = new PlanningServiceImpl(
adminScopeHelper,
userMapper,
nailArtistInfoMapper,
artistScheduleMapper,
appointmentReservationMapper,
orderMapper,
orderItemMapper,
productMapper,
shopMapper,
appointmentCapacityService,
orderService,
snowflakeIdGenerator
);
}
@Test
void createAppointmentShouldHideManualProductFromFront() {
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("10:00-22:00");
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
dto.setCustomerUserId(30L);
dto.setArtistId(20L);
dto.setAppointmentDate("2026-06-26");
dto.setAppointmentTime("13:00");
dto.setDurationMinutes(90);
dto.setManualProductTitle(" 日落贝壳 ");
dto.setManualProductPrice(new BigDecimal("168.00"));
dto.setClientRequestId("manual-product-test");
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
return 1;
});
when(userMapper.selectById(20L)).thenReturn(artist);
when(userMapper.selectById(30L)).thenReturn(customer);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(snowflakeIdGenerator.nextIdString()).thenReturn("202606260001");
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);
return 1;
});
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> {
OrderItemDO item = new OrderItemDO();
item.setId(300L);
item.setOrderId(200L);
item.setProductId(100L);
item.setArtistId(20L);
item.setQuantity(1);
item.setAppointmentTime(LocalDateTime.of(2026, 6, 26, 13, 0));
item.setIsDelete(0);
return item;
});
when(orderMapper.selectById(200L)).thenAnswer(invocation -> {
OrderDO order = new OrderDO();
order.setId(200L);
order.setUserId(30L);
order.setShopId(8L);
order.setStatus(1);
order.setIsDelete(0);
return order;
});
when(productMapper.selectById(100L)).thenAnswer(invocation -> {
ProductDO product = new ProductDO();
product.setId(100L);
product.setShopId(8L);
product.setTitle("日落贝壳");
product.setPrice(new BigDecimal("168.00"));
product.setApproximateDuration("90分钟");
product.setFrontVisible(0);
product.setSourceType("MANAGER_APPOINTMENT");
product.setIsDelete(0);
return product;
});
AppointmentReservationDO reservation = new AppointmentReservationDO();
reservation.setOrderItemId(300L);
reservation.setArtistId(20L);
reservation.setProductTitle("日落贝壳");
reservation.setAppointmentStartTime(LocalDateTime.of(2026, 6, 26, 13, 0));
reservation.setAppointmentEndTime(LocalDateTime.of(2026, 6, 26, 14, 30));
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
planningService.createAppointment(manager, dto);
ArgumentCaptor<ProductDO> captor = ArgumentCaptor.forClass(ProductDO.class);
org.mockito.Mockito.verify(productMapper).insert(captor.capture());
ProductDO product = captor.getValue();
assertThat(product.getTitle()).isEqualTo("日落贝壳");
assertThat(product.getFrontVisible()).isZero();
assertThat(product.getSourceType()).isEqualTo("MANAGER_APPOINTMENT");
assertThat(product.getImageFileIds()).isNull();
}
private UserDO user(Integer type, Long shopId) {
UserDO user = new UserDO();
user.setId(10L + type);
user.setType(type);
user.setShopId(shopId);
user.setIsDelete(0);
user.setNickname("测试用户");
user.setPhone("13800138000");
return user;
}
}
@@ -0,0 +1,20 @@
package com.xiaowang.fingertipdesigner.core.utils;
import com.xiaowang.fingertipdesigner.core.config.JwtProperties;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class JwtUtilTest {
@Test
void resolveAccessTokenExpirationSecondsShouldUseRememberMeSeconds() {
JwtProperties properties = new JwtProperties();
properties.setAccessTokenExpirationSeconds(120L);
properties.setRememberMeAccessTokenExpirationSeconds(3600L);
JwtUtil jwtUtil = new JwtUtil(properties);
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(false)).isEqualTo(120L);
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(true)).isEqualTo(3600L);
}
}