diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/dto/NailArtistInfoDTO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/dto/NailArtistInfoDTO.java index cce66ebe..965b9b84 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/dto/NailArtistInfoDTO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/dto/NailArtistInfoDTO.java @@ -110,6 +110,21 @@ public class NailArtistInfoDTO { */ private String avatar; + /** + * 登录手机号 + */ + private String phone; + + /** + * 联系电话 + */ + private String contactPhone; + + /** + * 微信号 + */ + private String wechatId; + /** * 排班模式摘要 */ diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java index 8a6c032f..2028120d 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImpl.java @@ -197,16 +197,11 @@ public class NailArtistInfoServiceImpl extends ServiceImpl() .eq(NailArtistInfoDO::getUserId, dto.getUserId()) .eq(NailArtistInfoDO::getIsDelete, 0) .last("LIMIT 1")); - if (existing != null) { - entity.setId(existing.getId()); - } + NailArtistInfoDO entity = existing == null ? buildNewArtistInfoEntity(dto) : mergeArtistInfoEntity(existing, dto); if (entity.getStatus() == null) { entity.setStatus(1); } @@ -232,6 +227,46 @@ public class NailArtistInfoServiceImpl extends ServiceImpl saveEmployee(HttpServletRequest request, @RequestBody NailArtistInfoDTO dto) { UserDO currentUser = adminScopeHelper.getCurrentUser(request); + if (dto.getUserId() == null) { + throw new RuntimeException("员工用户ID不能为空"); + } if (!adminScopeHelper.isPlatformAdmin(currentUser)) { adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, dto.getUserId(), "无权编辑其他店铺员工"); } - return Result.success(nailArtistInfoService.saveOrUpdateNailArtistInfo(dto)); + syncEmployeeUserBasics(dto); + return Result.success(nailArtistInfoService.saveOrUpdateNailArtistInfo(buildEmployeeArtistSaveDTO(dto))); + } + + @PostMapping("/employees/{userId}/reset-password") + @RequirePermission("user:reset_password") + @OperationGuard(action = "manager-employee-reset-password", ttlSeconds = 10, message = "密码重置处理中,请勿重复点击") + public Result resetEmployeePassword(HttpServletRequest request, + @PathVariable Long userId) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + if (!adminScopeHelper.isPlatformAdmin(currentUser)) { + adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权重置其他店铺员工密码"); + } + UserVO targetUser = userService.getUserById(userId); + if (targetUser == null) { + throw new RuntimeException("目标员工不存在"); + } + adminScopeHelper.ensureAssignableUserType(currentUser, targetUser.getType()); + if (!Integer.valueOf(3).equals(targetUser.getType())) { + throw new RuntimeException("只能重置员工密码"); + } + return Result.success(userService.resetManagedEmployeePassword(userId, currentUser.getId())); } @PostMapping("/employees/users") @@ -318,4 +343,62 @@ public class AdminManagerController { adminScopeHelper.requireShopContext(currentUser); return Result.success(shopService.saveScheduleException(dto)); } + + private void syncEmployeeUserBasics(NailArtistInfoDTO dto) { + if (!hasEmployeeUserBasicChanges(dto)) { + return; + } + UserDTO userDTO = new UserDTO(); + if (dto.getNickname() != null) { + if (!StringUtils.hasText(dto.getNickname())) { + throw new RuntimeException("员工昵称不能为空"); + } + userDTO.setNickname(dto.getNickname().trim()); + } + if (dto.getAvatar() != null) { + userDTO.setAvatar(dto.getAvatar().trim()); + } + if (dto.getPhone() != null) { + if (!StringUtils.hasText(dto.getPhone())) { + throw new RuntimeException("登录手机号不能为空"); + } + userDTO.setPhone(dto.getPhone().trim()); + } + if (dto.getContactPhone() != null) { + userDTO.setContactPhone(trimProvided(dto.getContactPhone())); + } + if (dto.getWechatId() != null) { + userDTO.setWechatId(trimProvided(dto.getWechatId())); + } + boolean updated = userService.updateUser(dto.getUserId(), userDTO); + if (!updated) { + throw new RuntimeException("员工账号不存在,无法保存基础信息"); + } + } + + private boolean hasEmployeeUserBasicChanges(NailArtistInfoDTO dto) { + return dto.getNickname() != null + || dto.getAvatar() != null + || dto.getPhone() != null + || dto.getContactPhone() != null + || dto.getWechatId() != null; + } + + private NailArtistInfoDTO buildEmployeeArtistSaveDTO(NailArtistInfoDTO dto) { + NailArtistInfoDTO artistDTO = new NailArtistInfoDTO(); + artistDTO.setId(dto.getId()); + artistDTO.setUserId(dto.getUserId()); + artistDTO.setIdentity(trimProvided(dto.getIdentity())); + artistDTO.setExperience(dto.getExperience()); + artistDTO.setSkills(trimProvided(dto.getSkills())); + artistDTO.setRating(dto.getRating()); + artistDTO.setStatus(dto.getStatus()); + artistDTO.setColor(trimProvided(dto.getColor())); + artistDTO.setPortfolio(trimProvided(dto.getPortfolio())); + return artistDTO; + } + + private String trimProvided(String value) { + return value == null ? null : value.trim(); + } } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java index f30e3332..a8651ecd 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/UserService.java @@ -252,6 +252,15 @@ public interface UserService extends IService { */ boolean resetPassword(Long targetUserId, Long currentUserId); + /** + * 重置店务员工密码 + * + * @param targetUserId 目标员工用户ID + * @param currentUserId 当前操作用户ID + * @return 重置是否成功 + */ + boolean resetManagedEmployeePassword(Long targetUserId, Long currentUserId); + /** * Run business method `resetPasswordByPhone`. * Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result. diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java index 16a45b00..0d2b3dfd 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/user/service/impl/UserServiceImpl.java @@ -1836,6 +1836,32 @@ public class UserServiceImpl extends ServiceImpl implements } return updated; } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean resetManagedEmployeePassword(Long targetUserId, Long currentUserId) { + UserDO targetUser = userMapper.selectById(targetUserId); + if (targetUser == null || Integer.valueOf(1).equals(targetUser.getIsDelete())) { + throw new RuntimeException("目标员工不存在"); + } + UserDO currentUser = userMapper.selectById(currentUserId); + if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) { + throw new RuntimeException("当前用户不存在"); + } + if (!Integer.valueOf(2).equals(currentUser.getType()) && !Integer.valueOf(4).equals(currentUser.getType())) { + throw new RuntimeException("当前账号无权重置员工密码"); + } + if (!Integer.valueOf(3).equals(targetUser.getType())) { + throw new RuntimeException("只能重置员工密码"); + } + targetUser.setPassword(passwordEncoder.encode(resolveAdminDefaultPassword())); + targetUser.setUpdateTime(LocalDateTime.now()); + boolean updated = userMapper.updateById(targetUser) > 0; + if (updated) { + userSessionService.revokeAllUserSessions(targetUserId); + } + return updated; + } @Override /** diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImplTest.java index b999fa6c..ed5917df 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/artist/service/impl/NailArtistInfoServiceImplTest.java @@ -94,10 +94,47 @@ class NailArtistInfoServiceImplTest { ReflectionTestUtils.setField(service, "artistScheduleMapper", artistScheduleMapper); ReflectionTestUtils.setField(service, "appointmentReservationMapper", appointmentReservationMapper); when(userShopBindingSupport.listShopOptionsByUserId(any(), anyBoolean(), anyBoolean())).thenReturn(List.of()); + when(objectStorageUrlSupport.toAccessibleUrl(any(String.class))) + .thenAnswer(invocation -> invocation.getArgument(0, String.class)); when(objectStorageUrlSupport.toAccessibleUrl(any(ObjectStorageFileVO.class))) .thenAnswer(invocation -> invocation.getArgument(0, ObjectStorageFileVO.class).getFileUrl()); } + @Test + void getByUserIdReturnsUserContactFields() { + NailArtistInfoDO artistInfo = new NailArtistInfoDO(); + artistInfo.setId(11L); + artistInfo.setUserId(7L); + artistInfo.setIdentity("高级美甲师"); + artistInfo.setStatus(1); + artistInfo.setIsDelete(0); + when(nailArtistInfoMapper.selectOne(any())).thenReturn(artistInfo); + + UserDO user = new UserDO(); + user.setId(7L); + user.setNickname("Mina"); + user.setAvatar("https://img.test/mina.jpg"); + user.setPhone("13800138000"); + user.setContactPhone("13900139000"); + user.setWechatId("wx_mina"); + user.setType(3); + user.setShopId(9L); + user.setIsDelete(0); + when(userMapper.selectById(7L)).thenReturn(user); + ShopDO shop = new ShopDO(); + shop.setId(9L); + shop.setShopName("测试门店"); + when(shopMapper.selectById(9L)).thenReturn(shop); + + NailArtistInfoDTO dto = service.getByUserId(7L); + + assertThat(dto.getPhone()).isEqualTo("13800138000"); + assertThat(dto.getContactPhone()).isEqualTo("13900139000"); + assertThat(dto.getWechatId()).isEqualTo("wx_mina"); + assertThat(dto.getAvatar()).isEqualTo("https://img.test/mina.jpg"); + assertThat(dto.getShopName()).isEqualTo("测试门店"); + } + @Test void saveOrUpdateNailArtistInfoSyncsNicknameToUser() { NailArtistInfoDO existing = new NailArtistInfoDO(); diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java index d1da0d9e..e76d0376 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerControllerTest.java @@ -36,7 +36,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -165,6 +169,112 @@ class AdminManagerControllerTest { )); } + @Test + void saveEmployeeShouldSyncUserBasicsAndArtistInfo() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + manager.setType(2); + NailArtistInfoDTO dto = new NailArtistInfoDTO(); + dto.setId(11L); + dto.setUserId(7L); + dto.setNickname(" 新员工 "); + dto.setAvatar(" https://img.test/a.jpg "); + dto.setPhone(" 13800138000 "); + dto.setContactPhone(" 13900139000 "); + dto.setWechatId(" wx_mina "); + dto.setIdentity("高级美甲师"); + dto.setStatus(1); + dto.setParticipateProduction(0); + NailArtistInfoDTO saved = new NailArtistInfoDTO(); + saved.setUserId(7L); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false); + when(userService.updateUser(any(), any(UserDTO.class))).thenReturn(true); + when(nailArtistInfoService.saveOrUpdateNailArtistInfo(any())).thenReturn(saved); + + Result result = controller.saveEmployee(request, dto); + + assertThat(result.getData()).isSameAs(saved); + verify(adminScopeHelper).ensureUserAccessibleInCurrentShop(manager, 7L, "无权编辑其他店铺员工"); + verify(userService).updateUser(argThat(userId -> Long.valueOf(7L).equals(userId)), argThat(userDTO -> + "新员工".equals(userDTO.getNickname()) + && "https://img.test/a.jpg".equals(userDTO.getAvatar()) + && "13800138000".equals(userDTO.getPhone()) + && "13900139000".equals(userDTO.getContactPhone()) + && "wx_mina".equals(userDTO.getWechatId()) + )); + verify(nailArtistInfoService).saveOrUpdateNailArtistInfo(argThat(artistDTO -> + Long.valueOf(11L).equals(artistDTO.getId()) + && Long.valueOf(7L).equals(artistDTO.getUserId()) + && "高级美甲师".equals(artistDTO.getIdentity()) + && Integer.valueOf(1).equals(artistDTO.getStatus()) + && artistDTO.getNickname() == null + && artistDTO.getPhone() == null + && artistDTO.getParticipateProduction() == null + && artistDTO.getWorkStartTime() == null + && artistDTO.getWorkEndTime() == null + )); + } + + @Test + void saveEmployeeShouldStopWhenUserOutOfScope() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + NailArtistInfoDTO dto = new NailArtistInfoDTO(); + dto.setUserId(7L); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false); + doThrow(new RuntimeException("无权编辑其他店铺员工")) + .when(adminScopeHelper).ensureUserAccessibleInCurrentShop(manager, 7L, "无权编辑其他店铺员工"); + + assertThatThrownBy(() -> controller.saveEmployee(request, dto)) + .isInstanceOf(RuntimeException.class) + .hasMessage("无权编辑其他店铺员工"); + verify(userService, never()).updateUser(any(), any(UserDTO.class)); + verify(nailArtistInfoService, never()).saveOrUpdateNailArtistInfo(any()); + } + + @Test + void resetEmployeePasswordShouldUseManagerScope() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + manager.setId(5L); + manager.setType(2); + UserVO targetUser = new UserVO(); + targetUser.setId(7L); + targetUser.setType(3); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false); + when(userService.getUserById(7L)).thenReturn(targetUser); + when(userService.resetManagedEmployeePassword(7L, 5L)).thenReturn(true); + + Result result = controller.resetEmployeePassword(request, 7L); + + assertThat(result.getData()).isTrue(); + verify(adminScopeHelper).ensureUserAccessibleInCurrentShop(manager, 7L, "无权重置其他店铺员工密码"); + verify(adminScopeHelper).ensureAssignableUserType(manager, 3); + verify(userService).resetManagedEmployeePassword(7L, 5L); + } + + @Test + void resetEmployeePasswordShouldRejectNonEmployee() { + MockHttpServletRequest request = new MockHttpServletRequest(); + UserDO manager = new UserDO(); + manager.setId(5L); + manager.setType(2); + UserVO targetUser = new UserVO(); + targetUser.setId(7L); + targetUser.setType(0); + when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager); + when(adminScopeHelper.isPlatformAdmin(manager)).thenReturn(false); + when(userService.getUserById(7L)).thenReturn(targetUser); + + assertThatThrownBy(() -> controller.resetEmployeePassword(request, 7L)) + .isInstanceOf(RuntimeException.class) + .hasMessage("只能重置员工密码"); + verify(userService, never()).resetManagedEmployeePassword(any(), any()); + } + @Test void saveScheduleShouldResolveShopScopeBeforeSaving() { MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/JY-Salon-Front/src/api/managerEmployees.ts b/JY-Salon-Front/src/api/managerEmployees.ts index 509ee92f..46169973 100644 --- a/JY-Salon-Front/src/api/managerEmployees.ts +++ b/JY-Salon-Front/src/api/managerEmployees.ts @@ -19,6 +19,9 @@ export const managerEmployeesApi = { save(data: Partial): Promise { return adminApi.post('/manager/employees', data) }, + resetPassword(userId: IdType): Promise { + return adminApi.post(`/manager/employees/${userId}/reset-password`) + }, createUser(data: EmployeeCreateRequest): Promise { return adminApi.post('/manager/employees/users', data) }, diff --git a/JY-Salon-Front/src/types/manager.ts b/JY-Salon-Front/src/types/manager.ts index 226424f2..1fbdf8bc 100644 --- a/JY-Salon-Front/src/types/manager.ts +++ b/JY-Salon-Front/src/types/manager.ts @@ -6,6 +6,8 @@ export interface Artist { name: string nickname?: string phone?: string + contactPhone?: string + wechatId?: string color?: string shortName?: string avatar?: string diff --git a/JY-Salon-Front/src/views/ColorSettingView.vue b/JY-Salon-Front/src/views/ColorSettingView.vue index 7cdd256f..2a37c686 100644 --- a/JY-Salon-Front/src/views/ColorSettingView.vue +++ b/JY-Salon-Front/src/views/ColorSettingView.vue @@ -121,7 +121,7 @@ const save = async (): Promise => { try { const color = selected.value const saved = await managerEmployeesApi.save({ - ...employee.value, + id: employee.value.id, userId: employee.value.userId || employeeId.value, color }) diff --git a/JY-Salon-Front/src/views/EmployeeDetailView.vue b/JY-Salon-Front/src/views/EmployeeDetailView.vue index f60f0e9f..376f001f 100644 --- a/JY-Salon-Front/src/views/EmployeeDetailView.vue +++ b/JY-Salon-Front/src/views/EmployeeDetailView.vue @@ -9,7 +9,7 @@

{{ employee.name || employee.nickname || '未命名员工' }}

-

{{ employee.phone || '未填写手机号' }}

+

{{ employee.phone || '未填写登录手机号' }}

+ + + +
+
+
+
@@ -52,16 +74,30 @@
-
- - + +
+
+ 重置登录密码 +

重置后员工可使用系统默认密码登录。

+
+
-
-
- +
+

确定要把该员工密码重置为系统默认密码吗?

+
+ + +
+
+ +
@@ -70,11 +106,12 @@