保存客户资料与员工排班改造阶段成果

This commit is contained in:
2026-10-29 18:32:45 +08:00
parent 762be0d907
commit 369f58d24e
11 changed files with 152 additions and 18 deletions
@@ -41,6 +41,7 @@ import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningDaySummaryV
import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningScheduleVO;
import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningTodayOverviewVO;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -1,6 +1,7 @@
package com.xiaowang.jayucloud.salon.core.modules.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -3325,8 +3326,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
private void addPhoneMatch(LambdaQueryWrapper<UserDO> wrapper, String phone) {
String hash = phoneCrypto.index(phone.trim());
List<Long> legacyIds = new ArrayList<>();
Long legacyPhoneId = userMapper.findLegacyIdByPhone(phone.trim());
if (legacyPhoneId != null) legacyIds.add(legacyPhoneId);
QueryWrapper<UserDO> legacyPhoneQuery = new QueryWrapper<>();
legacyPhoneQuery.select("id")
.eq("phone", phone.trim())
.isNull("phone_hash")
.eq("type", 0)
.eq("is_delete", 0);
for (UserDO legacyCustomer : userMapper.selectList(legacyPhoneQuery)) {
if (legacyCustomer.getId() != null && !legacyIds.contains(legacyCustomer.getId())) {
legacyIds.add(legacyCustomer.getId());
}
}
for (Long legacyContactId : userMapper.findLegacyIdsByContactPhone(phone.trim())) {
if (!legacyIds.contains(legacyContactId)) legacyIds.add(legacyContactId);
}
@@ -15,9 +15,8 @@ public final class UserProfileFieldSupport {
}
public static void requireWechatIdForServiceUser(Integer userType, String wechatId) {
if ((Integer.valueOf(2).equals(userType) || Integer.valueOf(3).equals(userType))
&& !StringUtils.hasText(wechatId)) {
throw new IllegalArgumentException("店长和美甲师的微信号不能为空");
if (Integer.valueOf(2).equals(userType) && !StringUtils.hasText(wechatId)) {
throw new IllegalArgumentException("店长的微信号不能为空");
}
}
}
@@ -0,0 +1,76 @@
package com.xiaowang.jayucloud.salon.core.modules.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.salon.core.support.privacy.PhoneCrypto;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class UserServiceCustomerMatchingTest {
@Mock private UserMapper userMapper;
@Mock private PhoneCrypto phoneCrypto;
@InjectMocks private UserServiceImpl userService;
@Test
void findsLegacyCustomerPhoneWithoutUsingServicePhoneLookup() {
UserDO customer = new UserDO();
customer.setId(91L);
customer.setNickname("周女士");
customer.setType(0);
customer.setIsDelete(0);
customer.setPhone("13800138000");
when(phoneCrypto.index("13800138000")).thenReturn("phone-hash");
when(phoneCrypto.decrypt("13800138000")).thenReturn("13800138000");
when(userMapper.selectList(any(Wrapper.class))).thenReturn(List.of(customer), List.of(customer));
when(userMapper.findLegacyIdsByContactPhone("13800138000")).thenReturn(List.of());
assertEquals(1, userService.findCustomerMatches("周女士", "13800138000", null).size());
org.mockito.ArgumentCaptor<Wrapper<UserDO>> queries = org.mockito.ArgumentCaptor.forClass((Class) Wrapper.class);
verify(userMapper, times(2)).selectList(queries.capture());
QueryWrapper<UserDO> legacyPhoneQuery = (QueryWrapper<UserDO>) queries.getAllValues().get(0);
assertTrue(legacyPhoneQuery.getSqlSegment().contains("phone"));
assertTrue(legacyPhoneQuery.getSqlSegment().contains("phone_hash"));
assertTrue(legacyPhoneQuery.getSqlSegment().contains("type"));
assertTrue(legacyPhoneQuery.getParamNameValuePairs().containsValue("13800138000"));
}
@Test
void rejectsOnlyAnExactNameWechatAndPhoneDuplicate() throws Exception {
UserDO existing = new UserDO();
existing.setId(91L);
existing.setNickname("周女士");
existing.setWechatId("wx-existing");
existing.setPhone("encrypted-phone");
when(phoneCrypto.decrypt("encrypted-phone")).thenReturn("13800138000");
when(userMapper.selectList(any(Wrapper.class))).thenReturn(List.of(existing));
Method ensureUnique = UserServiceImpl.class.getDeclaredMethod(
"ensureCustomerUnique", String.class, String.class, String.class, Long.class);
ensureUnique.setAccessible(true);
ensureUnique.invoke(userService, "周女士", "wx-other", "13800138000", null);
InvocationTargetException duplicate = assertThrows(InvocationTargetException.class,
() -> ensureUnique.invoke(userService, "周女士", "wx-existing", "13800138000", null));
assertEquals("客户已存在,请选择已有客户", duplicate.getCause().getMessage());
}
}
@@ -0,0 +1,20 @@
package com.xiaowang.jayucloud.salon.core.modules.user.support;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
class UserProfileFieldSupportTest {
@Test
void nailArtistWechatIdIsOptional() {
assertDoesNotThrow(() -> UserProfileFieldSupport.requireWechatIdForServiceUser(3, null));
}
@Test
void managerWechatIdRemainsRequired() {
assertThrows(IllegalArgumentException.class,
() -> UserProfileFieldSupport.requireWechatIdForServiceUser(2, null));
}
}