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

This commit is contained in:
2026-10-29 17:36:42 +08:00
parent b3a8c7e01c
commit 762be0d907
8 changed files with 66 additions and 32 deletions
@@ -370,10 +370,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
@Override
@Transactional(rollbackFor = Exception.class)
public Long createUser(UserDTO userDTO) {
return createUserInternal(userDTO, false);
return createUserInternal(userDTO);
}
private Long createUserInternal(UserDTO userDTO, boolean allowMissingCustomerPhone) {
private Long createUserInternal(UserDTO userDTO) {
String validatedAccount = AccountValidationUtils.requireValidAccount(userDTO.getAccount());
// 检查账号是否已存在
UserDO existingUser = findUserByAccount(validatedAccount);
@@ -390,7 +390,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
Long validatedShopId = pickPrimaryShopId(validatedShopIds);
Integer userType = userDTO.getType();
String validatedPhone = Integer.valueOf(0).equals(userType)
? validateCustomerPhone(userDTO.getPhone(), !(allowMissingCustomerPhone && Integer.valueOf(0).equals(userType)))
? validateCustomerPhone(userDTO.getPhone(), false)
: validateUserPhone(userDTO.getPhone(), null, true);
String validatedWechatId = UserProfileFieldSupport.normalizeOptionalText(userDTO.getWechatId());
if (Integer.valueOf(0).equals(userType)) {
@@ -532,7 +532,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
customer.setShopIds(List.of(shopId));
customer.setLevel(VIP_LEVEL_NORMAL);
customer.setVipId(0L);
return createUserInternal(customer, true);
return createUserInternal(customer);
}
@Override
@@ -665,7 +665,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
}
if (userDTO.getPhone() != null) {
userDO.setPhone(validateUserPhone(userDTO.getPhone(), id, true));
userDO.setPhone(Integer.valueOf(0).equals(userDO.getType())
? validateCustomerPhone(userDTO.getPhone(), false)
: validateUserPhone(userDTO.getPhone(), id, true));
}
if (userDTO.getContactPhone() != null) {
userDO.setContactPhone(UserProfileFieldSupport.normalizeOptionalText(userDTO.getContactPhone()));
@@ -733,6 +735,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
userDO.setCustomerIdentityHash(customerIdentityHash(userDO.getNickname(), userDO.getWechatId(), customerPhone));
} else {
userDO.setCustomerIdentityHash(null);
if (StringUtils.hasText(userDO.getPhone()) && !isDeletedPlaceholderPhone(userDO.getPhone())) {
ensurePhoneNotUsed(userDO.getPhone(), id);
}
}
List<Long> validatedShopIds = null;
boolean shopBindingChanged = userDTO.getShopIds() != null || userDTO.getShopId() != null;
@@ -3234,6 +3239,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
private void ensurePhoneNotUsed(String phone, Long currentUserId) {
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getPhoneHash, phoneCrypto.index(phone))
.ne(UserDO::getType, 0)
.eq(UserDO::getIsDelete, 0);
if (currentUserId != null) {
wrapper.ne(UserDO::getId, currentUserId);
@@ -3347,6 +3353,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
String normalized = phone.trim();
UserDO user = userMapper.selectOne(Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getPhoneHash, phoneCrypto.index(normalized))
.ne(UserDO::getType, 0)
.eq(UserDO::getIsDelete, 0)
.last("limit 1"));
if (user == null) {
@@ -93,6 +93,10 @@ CALL salon_v8_add_column_if_missing(
't_user', 'active_customer_identity_hash',
'char(64) GENERATED ALWAYS AS (CASE WHEN type = 0 AND COALESCE(is_delete, 0) = 0 THEN customer_identity_hash ELSE NULL END) STORED COMMENT ''有效客户组合身份索引'''
);
CALL salon_v8_add_column_if_missing(
't_user', 'active_service_phone_hash',
'char(64) GENERATED ALWAYS AS (CASE WHEN type <> 0 AND COALESCE(is_delete, 0) = 0 THEN phone_hash ELSE NULL END) STORED COMMENT ''有效員工和管理員手机号唯一索引'''
);
CALL salon_v8_add_column_if_missing(
't_nail_artist_info', 'color',
'varchar(7) NULL COMMENT ''美甲师规划专属颜色'''
@@ -103,6 +107,9 @@ CALL salon_v8_add_index_if_missing('t_user', 'idx_user_phone_hash', '(`phone_has
CALL salon_v8_add_unique_index_if_missing(
't_user', 'uk_user_active_customer_identity_hash', '(`active_customer_identity_hash`)'
);
CALL salon_v8_add_unique_index_if_missing(
't_user', 'uk_user_active_service_phone_hash', '(`active_service_phone_hash`)'
);
DROP PROCEDURE IF EXISTS salon_v8_add_column_if_missing;
DROP PROCEDURE IF EXISTS salon_v8_add_index_if_missing;