feat(salon): 支持散客预约拨号并发布协议新版本强制重新同意
自动发布开发环境 Nacos 配置 / publish (push) Successful in 23s

This commit is contained in:
2026-11-04 23:38:42 +08:00
parent 114a8a423c
commit 88589e2575
22 changed files with 602 additions and 44 deletions
@@ -55,8 +55,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
"/user/reset-password-by-phone",
"/legal-agreement/current",
"/legal-agreement/current/**",
"/legal-agreement/pending",
"/api/legal-agreement/current",
"/api/legal-agreement/current/**",
"/api/legal-agreement/pending",
"/product/get/**",
"/product/list/**",
"/comment/list/product/**",
@@ -188,10 +188,23 @@ public class AdminManagerController {
public Result<CustomerDialVO> dialCustomer(HttpServletRequest request,
HttpServletResponse response,
@PathVariable Long customerId,
@RequestParam Long orderId) {
@RequestParam(required = false) Long appointmentId,
@RequestParam(required = false) Long orderId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
response.setHeader("Cache-Control", "no-store");
return Result.success(customerDialService.dial(currentUser, customerId, orderId, request));
return Result.success(customerDialService.dial(currentUser, customerId, appointmentId, orderId, request));
}
@PostMapping("/customers/dial")
@RequirePermission("user:view")
public Result<CustomerDialVO> dialCustomerForGuest(HttpServletRequest request,
HttpServletResponse response,
@RequestParam(required = false) Long customerId,
@RequestParam(required = false) Long appointmentId,
@RequestParam(required = false) Long orderId) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
response.setHeader("Cache-Control", "no-store");
return Result.success(customerDialService.dial(currentUser, customerId, appointmentId, orderId, request));
}
@GetMapping("/customers/{id}")
@@ -15,6 +15,10 @@ import org.springframework.util.StringUtils;
@RequiredArgsConstructor
public class DirectDialTargetProvider implements DialTargetProvider {
public static final int NUMBER_UNAVAILABLE_CODE = 422;
public static final String NUMBER_UNAVAILABLE_BUSINESS_CODE = "DIAL_NUMBER_UNAVAILABLE";
private final PhoneCrypto phoneCrypto;
@Override
@@ -26,12 +30,22 @@ public class DirectDialTargetProvider implements DialTargetProvider {
public DialTarget resolve(UserDO customer, OrderDO order) {
String plainPhone = resolvePlainPhone(customer, order);
if (!StringUtils.hasText(plainPhone) || plainPhone.contains("*")) {
throw new BusinessException(422, "该客户未登记可拨打的手机号");
throw new BusinessException(NUMBER_UNAVAILABLE_CODE,
"该预约/订单未登记可拨打的手机号(" + NUMBER_UNAVAILABLE_BUSINESS_CODE + ")");
}
return new DialTarget(DialMode.DIRECT, plainPhone.trim(), 0);
}
/**
* 号码来源优先级:订单/预约上的客户手机号快照优先,其次客户档案。
*/
private String resolvePlainPhone(UserDO customer, OrderDO order) {
if (order != null && StringUtils.hasText(order.getCustomerPhoneSnapshot())) {
String snapshot = phoneCrypto.decrypt(order.getCustomerPhoneSnapshot());
if (StringUtils.hasText(snapshot)) {
return snapshot;
}
}
if (customer != null) {
if (StringUtils.hasText(customer.getContactPhone())) {
String contactPhone = phoneCrypto.decrypt(customer.getContactPhone());
@@ -46,9 +60,6 @@ public class DirectDialTargetProvider implements DialTargetProvider {
}
}
}
if (order != null && StringUtils.hasText(order.getCustomerPhoneSnapshot())) {
return phoneCrypto.decrypt(order.getCustomerPhoneSnapshot());
}
return null;
}
}
@@ -10,5 +10,5 @@ import javax.servlet.http.HttpServletRequest;
*/
public interface CustomerDialService {
CustomerDialVO dial(UserDO currentUser, Long customerId, Long orderId, HttpServletRequest request);
CustomerDialVO dial(UserDO currentUser, Long customerId, Long appointmentId, Long orderId, HttpServletRequest request);
}
@@ -2,6 +2,8 @@ package com.xiaowang.jayucloud.salon.core.modules.privacy.service.impl;
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderItemDO;
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderItemMapper;
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.DialProperties;
import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialTarget;
@@ -34,33 +36,56 @@ public class CustomerDialServiceImpl implements CustomerDialService {
private final AdminScopeHelper adminScopeHelper;
private final UserService userService;
private final OrderMapper orderMapper;
private final OrderItemMapper orderItemMapper;
private final RequestThrottleService requestThrottleService;
private final SecurityAuditSupport securityAuditSupport;
private final DialProperties dialProperties;
private final List<DialTargetProvider> providers;
@Override
public CustomerDialVO dial(UserDO currentUser, Long customerId, Long orderId, HttpServletRequest request) {
public CustomerDialVO dial(UserDO currentUser, Long customerId, Long appointmentId, Long orderId, HttpServletRequest request) {
adminScopeHelper.requireShopContext(currentUser, "请先选择店铺后再拨号");
Long currentShopId = currentUser.getShopId();
requestThrottleService.checkCustomerDial(request, currentUser.getId());
UserDO customer = userService.getById(customerId);
if (customer == null || Objects.equals(1, customer.getIsDelete()) || !Objects.equals(0, customer.getType())) {
throw new BusinessException(404, "客户不存在");
if (customerId == null && appointmentId == null && orderId == null) {
throw new BusinessException(400, "请提供预约或订单信息后再拨号(DIAL_TARGET_REQUIRED)");
}
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, customerId, "无权拨打其他店铺客户");
OrderDO order = orderMapper.selectById(orderId);
if (order == null || Objects.equals(1, order.getIsDelete()) || !Objects.equals(customerId, order.getUserId())) {
throw new BusinessException(403, "该客户与订单不匹配,或无权拨打");
OrderDO order = null;
if (appointmentId != null) {
OrderItemDO item = orderItemMapper.selectById(appointmentId);
if (item == null || Objects.equals(1, item.getIsDelete())) {
throw new BusinessException(404, "预约不存在");
}
order = orderMapper.selectById(item.getOrderId());
if (order == null || Objects.equals(1, order.getIsDelete())) {
throw new BusinessException(404, "预约关联订单不存在");
}
}
if (!Objects.equals(currentShopId, order.getShopId())) {
throw new BusinessException(403, "无权拨打其他店铺订单客户");
if (orderId != null) {
if (order != null && !Objects.equals(orderId, order.getId())) {
throw new BusinessException(403, "预约与订单不匹配,或无权拨打");
}
if (order == null) {
order = orderMapper.selectById(orderId);
if (order == null || Objects.equals(1, order.getIsDelete())) {
throw new BusinessException(404, "订单不存在");
}
}
}
if (order != null && !Objects.equals(currentShopId, order.getShopId())) {
throw new BusinessException(403, "无权拨打其他店铺预约/订单客户");
}
UserDO customer = resolveCustomer(currentUser, customerId, order);
Long auditCustomerId = customer == null ? null : customer.getId();
DialTargetProvider provider = resolveProvider();
String reason = "customerId=" + customerId + ";orderId=" + orderId + ";provider=" + provider.providerKey();
String reason = "customerId=" + auditCustomerId
+ ";appointmentId=" + appointmentId
+ ";orderId=" + (order == null ? null : order.getId())
+ ";provider=" + provider.providerKey();
try {
DialTarget target = provider.resolve(customer, order);
securityAuditSupport.success(request, AUDIT_ACTION, reason + ";mode=" + target.getMode() + ";result=SUCCESS");
@@ -80,6 +105,28 @@ public class CustomerDialServiceImpl implements CustomerDialService {
}
}
/**
* 解析目标客户:优先使用显式 customerId,其次订单关联客户;散客预约返回 null,不要求客户有账号。
*/
private UserDO resolveCustomer(UserDO currentUser, Long customerId, OrderDO order) {
Long targetCustomerId = customerId;
if (targetCustomerId == null && order != null) {
targetCustomerId = order.getUserId();
}
if (targetCustomerId == null) {
return null;
}
if (order != null && !Objects.equals(targetCustomerId, order.getUserId())) {
throw new BusinessException(403, "该客户与预约/订单不匹配,或无权拨打");
}
UserDO customer = userService.getById(targetCustomerId);
if (customer == null || Objects.equals(1, customer.getIsDelete()) || !Objects.equals(0, customer.getType())) {
throw new BusinessException(404, "客户不存在");
}
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, targetCustomerId, "无权拨打其他店铺客户");
return customer;
}
private DialTargetProvider resolveProvider() {
String configured = StringUtils.hasText(dialProperties.getProvider())
? dialProperties.getProvider().trim()
@@ -9,6 +9,7 @@ import com.xiaowang.jayucloud.salon.core.modules.system.service.LegalAgreementSe
import com.xiaowang.jayucloud.salon.core.modules.security.service.SecurityAuditLogService;
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
import lombok.RequiredArgsConstructor;
@@ -68,6 +69,27 @@ public class LegalAgreementController {
return Result.success(legalAgreementService.getCurrentAgreement(type));
}
@GetMapping("/pending")
/**
* Purpose: pending 返回当前协议版本;登录用户额外返回是否已同意新版本。免登录只返回当前版本。
*/
public Result<AgreementPendingVO> pending(HttpServletRequest request) {
requestThrottleService.checkAgreementRead(request, "PENDING");
Long userId = (Long) request.getAttribute("userId");
return Result.success(legalAgreementService.getPendingAgreements(userId));
}
@PostMapping("/accept")
/**
* Purpose: accept 记录登录用户对当前发布协议版本的同意。
*/
public Result<AgreementPendingVO> accept(HttpServletRequest request,
@RequestParam(required = false) String clientType) {
Long userId = (Long) request.getAttribute("userId");
legalAgreementService.acceptCurrentAgreements(userId, clientType, request);
return Result.success(legalAgreementService.getPendingAgreements(userId));
}
@GetMapping("/admin/list")
@RequirePermission("legal_agreement:manage")
/**
@@ -3,6 +3,7 @@ package com.xiaowang.jayucloud.salon.core.modules.system.service;
import com.xiaowang.jayucloud.salon.core.common.dto.AgreementAwareRequest;
import com.xiaowang.jayucloud.salon.core.modules.system.dto.LegalAgreementDTO;
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
@@ -31,6 +32,10 @@ public interface LegalAgreementService {
UserAgreementConsentVO getMyConsent(Long userId);
AgreementPendingVO getPendingAgreements(Long userId);
void acceptCurrentAgreements(Long userId, String clientType, HttpServletRequest httpRequest);
void requireAccepted(AgreementAwareRequest request);
void recordConsent(Long userId, AgreementAwareRequest request, String entry, HttpServletRequest httpRequest);
@@ -11,6 +11,7 @@ import com.xiaowang.jayucloud.salon.core.modules.system.mapper.LegalAgreementMap
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserAgreementConsentMapper;
import com.xiaowang.jayucloud.salon.core.modules.system.service.LegalAgreementService;
import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
import com.xiaowang.jayucloud.salon.core.modules.system.vo.LegalAgreementVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserAgreementConsentVO;
import lombok.RequiredArgsConstructor;
@@ -20,6 +21,8 @@ import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -170,6 +173,57 @@ public class LegalAgreementServiceImpl implements LegalAgreementService {
return new UserAgreementConsentVO(versions);
}
@Override
/**
* Purpose: getPendingAgreements 返回当前协议版本与该用户的同意状态;未登录时只返回当前版本。
*/
public AgreementPendingVO getPendingAgreements(Long userId) {
Map<String, String> currentVersions = new LinkedHashMap<>();
Map<String, String> acceptedVersions = new LinkedHashMap<>();
List<String> pendingTypes = new ArrayList<>();
Map<String, String> accepted = userId == null
? Collections.emptyMap()
: getMyConsent(userId).getConsentVersions();
for (String type : List.of(USER_TERMS, PRIVACY_POLICY)) {
LegalAgreementDO current = findCurrentAgreement(type);
if (current == null) {
continue;
}
currentVersions.put(type, current.getVersion());
String acceptedVersion = accepted == null ? null : accepted.get(type);
if (StringUtils.hasText(acceptedVersion)) {
acceptedVersions.put(type, acceptedVersion);
}
if (!StringUtils.hasText(acceptedVersion) || !current.getVersion().equals(acceptedVersion)) {
pendingTypes.add(type);
}
}
Boolean pending = userId == null ? null : !pendingTypes.isEmpty();
return new AgreementPendingVO(pending, currentVersions, acceptedVersions, pendingTypes);
}
@Override
@Transactional(rollbackFor = Exception.class)
/**
* Purpose: acceptCurrentAgreements 记录用户对当前发布版本的同意,不依赖客户端上报版本。
*/
public void acceptCurrentAgreements(Long userId, String clientType, HttpServletRequest httpRequest) {
if (userId == null) {
throw new RuntimeException("请先登录后再同意协议");
}
String normalizedClientType = StringUtils.hasText(clientType)
? clientType.trim().toUpperCase()
: "WEB";
String ip = resolveClientIp(httpRequest);
for (String type : List.of(USER_TERMS, PRIVACY_POLICY)) {
LegalAgreementDO current = findCurrentAgreement(type);
if (current == null) {
throw new RuntimeException("当前协议未配置,请联系管理员");
}
upsertConsent(userId, type, current.getVersion(), "agreement-gate", normalizedClientType, ip);
}
}
@Override
/**
* Purpose: requireAccepted supports LegalAgreementServiceImpl.java by holding or executing the require accepted business role.
@@ -0,0 +1,25 @@
package com.xiaowang.jayucloud.salon.core.modules.system.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* 协议重新同意状态:未登录时只返回当前版本,登录后额外返回已同意版本与待同意类型。
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AgreementPendingVO {
private Boolean pending;
private Map<String, String> currentVersions;
private Map<String, String> acceptedVersions;
private List<String> pendingTypes;
}
@@ -0,0 +1,30 @@
-- 隐私政策与用户协议新版本发布:停用当前生效版本,并从停用前正文复制新版本
-- 版本:2026.11.04-R2
-- 说明:正文通过 INSERT ... SELECT 复制 V18 已修订的当前生效文本,不在 SQL 中重复维护长文本;
-- V18 已在任一环境执行后不得修改,本文件仅新增版本。
UPDATE t_legal_agreement
SET status = 0, update_time = NOW()
WHERE agreement_type IN ('USER_TERMS', 'PRIVACY_POLICY')
AND is_delete = 0
AND status = 1;
INSERT INTO t_legal_agreement
(id, agreement_type, title, version, content, status, effective_time, create_time, update_time, is_delete)
SELECT 313931273555140005, 'USER_TERMS', title, '2026.11.04-R2', content, 1,
'2026-11-04 00:00:00', NOW(), NOW(), 0
FROM t_legal_agreement
WHERE agreement_type = 'USER_TERMS'
AND is_delete = 0
ORDER BY effective_time DESC, create_time DESC
LIMIT 1;
INSERT INTO t_legal_agreement
(id, agreement_type, title, version, content, status, effective_time, create_time, update_time, is_delete)
SELECT 313931273555140006, 'PRIVACY_POLICY', title, '2026.11.04-R2', content, 1,
'2026-11-04 00:00:00', NOW(), NOW(), 0
FROM t_legal_agreement
WHERE agreement_type = 'PRIVACY_POLICY'
AND is_delete = 0
ORDER BY effective_time DESC, create_time DESC
LIMIT 1;