From 05493923e45a218066c1c44484d85b6ba137da4f Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Wed, 4 Nov 2026 22:02:51 +0800 Subject: [PATCH] =?UTF-8?q?Salon=20=E4=BE=A7=E5=85=A8=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E8=84=B1=E6=95=8F=E4=B8=8E=E6=8B=A8=E5=8F=B7=E5=8D=95=E6=AC=A1?= =?UTF-8?q?=E5=8F=96=E5=8F=B7=E6=94=B9=E9=80=A0=EF=BC=9A=E6=94=B6=E6=8E=89?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E9=80=89=E6=8B=A9=E5=AE=A2=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=87=BA=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=8C=89=E9=97=A8=E5=BA=97=E4=B8=8E?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=B8=8A=E4=B8=8B=E6=96=87=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=9A=84=E6=8B=A8=E5=8F=B7=E5=8F=96=E5=8F=B7=E7=AB=AF=E7=82=B9?= =?UTF-8?q?=E5=8F=8A=E9=9A=90=E7=A7=81=E5=8F=B7=E5=8D=A0=E4=BD=8D=E6=B8=A0?= =?UTF-8?q?=E9=81=93=EF=BC=8C=E5=89=8D=E7=AB=AF=E6=94=B9=E4=B8=BA=E8=84=B1?= =?UTF-8?q?=E6=95=8F=E5=B1=95=E7=A4=BA=E5=8A=A0=E5=91=BC=E5=8F=AB=E5=8F=96?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=B9=B6=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=9D=A1=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/config/RateLimitProperties.java | 2 + .../admin/AdminManagerController.java | 15 ++ .../vo/AppointmentCustomerOptionVO.java | 3 + .../service/impl/PlanningServiceImpl.java | 8 +- .../planning/vo/PlanningAppointmentVO.java | 3 + .../privacy/config/DialProperties.java | 17 +++ .../core/modules/privacy/dial/DialMode.java | 14 ++ .../core/modules/privacy/dial/DialTarget.java | 29 ++++ .../privacy/dial/DialTargetProvider.java | 20 +++ .../dial/DirectDialTargetProvider.java | 54 +++++++ .../PlaceholderPrivacyNumberProvider.java | 28 ++++ .../privacy/service/CustomerDialService.java | 14 ++ .../service/impl/CustomerDialServiceImpl.java | 94 ++++++++++++ .../modules/privacy/vo/CustomerDialVO.java | 19 +++ .../support/SecurityAuditActions.java | 1 + .../user/service/impl/UserServiceImpl.java | 8 +- .../security/RequestThrottleService.java | 8 + ...与用户协议全场景脱敏条款修订_20261104.sql | 51 +++++++ .../service/impl/PlanningServiceImplTest.java | 8 +- .../impl/CustomerDialServiceImplTest.java | 138 ++++++++++++++++++ .../impl/UserServiceCustomerMatchingTest.java | 12 +- JC-Salon-Frontend/src/api/user.ts | 17 +++ .../src/views/ArtistOrderView.vue | 28 ++++ JC-Salon-WeChat/api/customers.js | 12 ++ .../pages/appointment-detail/index.js | 23 +++ .../pages/appointment-detail/index.wxml | 11 +- .../pages/appointment-detail/index.wxss | 18 +++ .../appointment-form/entity-selector.test.js | 9 +- .../pages/appointment-form/index.js | 41 ++++-- JC-Salon-WeChat/pages/backfill-order/index.js | 2 +- .../jayucloud-salon/DEFAULT_GROUP/core.yaml | 6 + .../jayucloud-salon/DEFAULT_GROUP/core.yaml | 6 + .../jayucloud-salon/DEFAULT_GROUP/core.yaml | 6 + 33 files changed, 697 insertions(+), 28 deletions(-) create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/config/DialProperties.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialMode.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTarget.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTargetProvider.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DirectDialTargetProvider.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/PlaceholderPrivacyNumberProvider.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/CustomerDialService.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImpl.java create mode 100644 JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/vo/CustomerDialVO.java create mode 100644 JC-Salon-Core/src/main/resources/db/migration/V18__隐私政策与用户协议全场景脱敏条款修订_20261104.sql create mode 100644 JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImplTest.java diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/config/RateLimitProperties.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/config/RateLimitProperties.java index 2784dc7c..30ce8c5f 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/config/RateLimitProperties.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/config/RateLimitProperties.java @@ -28,6 +28,8 @@ public class RateLimitProperties { private LimitRule orderCreate = new LimitRule(10, 60); + private LimitRule customerDial = new LimitRule(10, 60); + @Data /** * Purpose: LimitRule supports RateLimitProperties.java by holding or executing the limit rule business role. diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/controller/admin/AdminManagerController.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/controller/admin/AdminManagerController.java index 81194408..1703a4a2 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/controller/admin/AdminManagerController.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/controller/admin/AdminManagerController.java @@ -33,6 +33,8 @@ import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopService; import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopVO; import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO; import com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO; +import com.xiaowang.jayucloud.salon.core.modules.privacy.service.CustomerDialService; +import com.xiaowang.jayucloud.salon.core.modules.privacy.vo.CustomerDialVO; import com.xiaowang.jayucloud.salon.core.modules.user.dto.UserDTO; import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO; import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService; @@ -49,6 +51,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.time.LocalDate; import java.util.List; @@ -65,6 +68,7 @@ public class AdminManagerController { private final ProductService productService; private final ShopService shopService; private final AdminScopeHelper adminScopeHelper; + private final CustomerDialService customerDialService; @GetMapping("/planning/calendar") @RequirePermission("schedule:view") @@ -179,6 +183,17 @@ public class AdminManagerController { return Result.success(userService.listCustomersForAppointment(page, size, keyword, shopId)); } + @PostMapping("/customers/{customerId}/dial") + @RequirePermission("user:view") + public Result dialCustomer(HttpServletRequest request, + HttpServletResponse response, + @PathVariable Long customerId, + @RequestParam Long orderId) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + response.setHeader("Cache-Control", "no-store"); + return Result.success(customerDialService.dial(currentUser, customerId, orderId, request)); + } + @GetMapping("/customers/{id}") @RequirePermission("user:view") public Result customer(HttpServletRequest request, @PathVariable Long id) { diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/vo/AppointmentCustomerOptionVO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/vo/AppointmentCustomerOptionVO.java index 3831ab2f..2bf1f36b 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/vo/AppointmentCustomerOptionVO.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/manager/vo/AppointmentCustomerOptionVO.java @@ -11,7 +11,10 @@ public class AppointmentCustomerOptionVO { @JsonSerialize(using = ToStringSerializer.class) private Long id; private String name; + /** 脱敏后的手机号,永不返回完整号码 */ private String phone; + /** 是否存在可拨打的手机号,呼叫按钮据此展示 */ + private Boolean phoneAvailable; private String avatar; private LocalDateTime createdAt; } diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java index 7a77525e..d5120bdd 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -37,6 +37,7 @@ import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSu import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningCalendarSupport; import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningTodayOverviewSupport; import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator; +import com.xiaowang.jayucloud.salon.core.support.privacy.PhoneCrypto; import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO; import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningArtistCountVO; import com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningArtistVO; @@ -103,6 +104,7 @@ public class PlanningServiceImpl implements PlanningService { private final WechatSubscribeMessageService wechatSubscribeMessageService; private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator; private final ObjectStorageUrlSupport objectStorageUrlSupport; + private final PhoneCrypto phoneCrypto; @Override public PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId) { @@ -621,7 +623,11 @@ public class PlanningServiceImpl implements PlanningService { vo.setOrderItemId(item == null ? reservation == null ? null : reservation.getOrderItemId() : item.getId()); vo.setCustomerId(customer == null ? order == null ? null : order.getUserId() : customer.getId()); vo.setCustomerName(customer == null ? firstNonBlank(order == null ? null : order.getCustomerNameSnapshot(), "散客") : firstNonBlank(customer.getNickname(), customer.getAccount(), "到店客户")); - vo.setCustomerPhone(customer == null ? order == null ? null : order.getCustomerPhoneSnapshot() : firstNonBlank(customer.getContactPhone(), customer.getPhone(), "")); + String plainPhone = customer == null + ? (order == null ? null : order.getCustomerPhoneSnapshot()) + : firstNonBlank(customer.getContactPhone(), customer.getPhone(), ""); + vo.setCustomerPhone(phoneCrypto.mask(plainPhone)); + vo.setCustomerPhoneAvailable(StringUtils.hasText(plainPhone) && !plainPhone.contains("*")); vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId()); vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle()) ? reservation.getProductTitle() diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/vo/PlanningAppointmentVO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/vo/PlanningAppointmentVO.java index edd3899a..b7f2ebdd 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/vo/PlanningAppointmentVO.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/planning/vo/PlanningAppointmentVO.java @@ -11,7 +11,10 @@ public class PlanningAppointmentVO { private Long orderItemId; private Long customerId; private String customerName; + /** 脱敏后的客户手机号,完整号码仅通过拨号取号端点单次获取 */ private String customerPhone; + /** 是否存在可拨打的手机号,呼叫按钮据此展示 */ + private Boolean customerPhoneAvailable; private Long productId; private String productTitle; private Long artistId; diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/config/DialProperties.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/config/DialProperties.java new file mode 100644 index 00000000..04e21159 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/config/DialProperties.java @@ -0,0 +1,17 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 拨号取号配置。 + * provider 取值:direct(直拨真实号码)或 privacy-number(隐私号码,暂未对接)。 + */ +@Data +@Configuration +@ConfigurationProperties(prefix = "jayucloud-salon.dial") +public class DialProperties { + + private String provider = "direct"; +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialMode.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialMode.java new file mode 100644 index 00000000..8d80a3e8 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialMode.java @@ -0,0 +1,14 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.dial; + +/** + * 拨号返回模式。 + */ +public final class DialMode { + + public static final String DIRECT = "DIRECT"; + + public static final String PRIVACY_NUMBER = "PRIVACY_NUMBER"; + + private DialMode() { + } +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTarget.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTarget.java new file mode 100644 index 00000000..c85f9bd0 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTarget.java @@ -0,0 +1,29 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.dial; + +/** + * 单次取号结果,仅在本次响应中返回,不落库、不写日志、不缓存。 + */ +public class DialTarget { + + private final String mode; + private final String dialNumber; + private final int expiresInSeconds; + + public DialTarget(String mode, String dialNumber, int expiresInSeconds) { + this.mode = mode; + this.dialNumber = dialNumber; + this.expiresInSeconds = expiresInSeconds; + } + + public String getMode() { + return mode; + } + + public String getDialNumber() { + return dialNumber; + } + + public int getExpiresInSeconds() { + return expiresInSeconds; + } +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTargetProvider.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTargetProvider.java new file mode 100644 index 00000000..9732b4f3 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DialTargetProvider.java @@ -0,0 +1,20 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.dial; + +import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO; +import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO; + +/** + * 拨号目标渠道。不同渠道返回不同的号码类型,调用方不得自行降级为真实号码。 + */ +public interface DialTargetProvider { + + /** + * 配置项中使用的渠道标识,例如 direct、privacy-number。 + */ + String providerKey(); + + /** + * 解析本次拨号目标。 + */ + DialTarget resolve(UserDO customer, OrderDO order); +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DirectDialTargetProvider.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DirectDialTargetProvider.java new file mode 100644 index 00000000..0b1fd44d --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/DirectDialTargetProvider.java @@ -0,0 +1,54 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.dial; + +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.user.entity.UserDO; +import com.xiaowang.jayucloud.salon.core.support.privacy.PhoneCrypto; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +/** + * 直拨渠道:实时读取客户档案中的号码,仅在本次响应返回。 + */ +@Component +@RequiredArgsConstructor +public class DirectDialTargetProvider implements DialTargetProvider { + + private final PhoneCrypto phoneCrypto; + + @Override + public String providerKey() { + return "direct"; + } + + @Override + public DialTarget resolve(UserDO customer, OrderDO order) { + String plainPhone = resolvePlainPhone(customer, order); + if (!StringUtils.hasText(plainPhone) || plainPhone.contains("*")) { + throw new BusinessException(422, "该客户未登记可拨打的手机号"); + } + return new DialTarget(DialMode.DIRECT, plainPhone.trim(), 0); + } + + private String resolvePlainPhone(UserDO customer, OrderDO order) { + if (customer != null) { + if (StringUtils.hasText(customer.getContactPhone())) { + String contactPhone = phoneCrypto.decrypt(customer.getContactPhone()); + if (StringUtils.hasText(contactPhone)) { + return contactPhone; + } + } + if (StringUtils.hasText(customer.getPhone())) { + String phone = phoneCrypto.decrypt(customer.getPhone()); + if (StringUtils.hasText(phone)) { + return phone; + } + } + } + if (order != null && StringUtils.hasText(order.getCustomerPhoneSnapshot())) { + return phoneCrypto.decrypt(order.getCustomerPhoneSnapshot()); + } + return null; + } +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/PlaceholderPrivacyNumberProvider.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/PlaceholderPrivacyNumberProvider.java new file mode 100644 index 00000000..ff689af5 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/dial/PlaceholderPrivacyNumberProvider.java @@ -0,0 +1,28 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.dial; + +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.user.entity.UserDO; +import org.springframework.stereotype.Component; + +/** + * 隐私号码占位渠道:未对接时明确报错,绝不静默回退为真实号码。 + */ +@Component +public class PlaceholderPrivacyNumberProvider implements DialTargetProvider { + + public static final int NOT_CONFIGURED_CODE = 4250; + + public static final String NOT_CONFIGURED_BUSINESS_CODE = "DIAL_PRIVACY_NUMBER_NOT_CONFIGURED"; + + @Override + public String providerKey() { + return "privacy-number"; + } + + @Override + public DialTarget resolve(UserDO customer, OrderDO order) { + throw new BusinessException(NOT_CONFIGURED_CODE, + "隐私号码服务未配置(" + NOT_CONFIGURED_BUSINESS_CODE + "),请联系平台开通"); + } +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/CustomerDialService.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/CustomerDialService.java new file mode 100644 index 00000000..bd2db693 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/CustomerDialService.java @@ -0,0 +1,14 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.service; + +import com.xiaowang.jayucloud.salon.core.modules.privacy.vo.CustomerDialVO; +import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO; + +import javax.servlet.http.HttpServletRequest; + +/** + * 客户拨号取号服务:按门店范围与订单上下文单次授权,号码不落库、不写日志、不缓存。 + */ +public interface CustomerDialService { + + CustomerDialVO dial(UserDO currentUser, Long customerId, Long orderId, HttpServletRequest request); +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImpl.java new file mode 100644 index 00000000..abf0ec56 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImpl.java @@ -0,0 +1,94 @@ +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.mapper.OrderMapper; +import com.xiaowang.jayucloud.salon.core.modules.privacy.config.DialProperties; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialTarget; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialTargetProvider; +import com.xiaowang.jayucloud.salon.core.modules.privacy.service.CustomerDialService; +import com.xiaowang.jayucloud.salon.core.modules.privacy.vo.CustomerDialVO; +import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditActions; +import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditSupport; +import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO; +import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService; +import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Objects; + +/** + * 客户拨号取号实现:先校验门店范围与订单归属,再按配置渠道单次取号并记录审计。 + */ +@Service +@RequiredArgsConstructor +public class CustomerDialServiceImpl implements CustomerDialService { + + private static final String AUDIT_ACTION = SecurityAuditActions.CUSTOMER_DIAL; + + private final AdminScopeHelper adminScopeHelper; + private final UserService userService; + private final OrderMapper orderMapper; + private final RequestThrottleService requestThrottleService; + private final SecurityAuditSupport securityAuditSupport; + private final DialProperties dialProperties; + private final List providers; + + @Override + public CustomerDialVO dial(UserDO currentUser, Long customerId, 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, "客户不存在"); + } + 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, "该客户与订单不匹配,或无权拨打"); + } + if (!Objects.equals(currentShopId, order.getShopId())) { + throw new BusinessException(403, "无权拨打其他店铺订单客户"); + } + + DialTargetProvider provider = resolveProvider(); + String reason = "customerId=" + customerId + ";orderId=" + orderId + ";provider=" + provider.providerKey(); + try { + DialTarget target = provider.resolve(customer, order); + securityAuditSupport.success(request, AUDIT_ACTION, reason + ";mode=" + target.getMode() + ";result=SUCCESS"); + CustomerDialVO vo = new CustomerDialVO(); + vo.setMode(target.getMode()); + vo.setDialNumber(target.getDialNumber()); + vo.setExpiresInSeconds(target.getExpiresInSeconds()); + return vo; + } catch (BusinessException exception) { + securityAuditSupport.fail(request, AUDIT_ACTION, + reason + ";result=FAIL;errorCode=" + exception.getCode()); + throw exception; + } catch (RuntimeException exception) { + securityAuditSupport.fail(request, AUDIT_ACTION, + reason + ";result=FAIL;errorType=" + exception.getClass().getSimpleName()); + throw exception; + } + } + + private DialTargetProvider resolveProvider() { + String configured = StringUtils.hasText(dialProperties.getProvider()) + ? dialProperties.getProvider().trim() + : "direct"; + for (DialTargetProvider provider : providers) { + if (configured.equalsIgnoreCase(provider.providerKey())) { + return provider; + } + } + throw new BusinessException(500, "拨号渠道配置无效(jayucloud-salon.dial.provider=" + configured + ")"); + } +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/vo/CustomerDialVO.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/vo/CustomerDialVO.java new file mode 100644 index 00000000..a62bc030 --- /dev/null +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/privacy/vo/CustomerDialVO.java @@ -0,0 +1,19 @@ +package com.xiaowang.jayucloud.salon.core.modules.privacy.vo; + +import lombok.Data; + +/** + * 单次拨号取号响应。 + */ +@Data +public class CustomerDialVO { + + /** DIRECT:真实号码;PRIVACY_NUMBER:隐私号码 */ + private String mode; + + /** 本次可拨打的号码,仅用于当前客户端一次性拨号 */ + private String dialNumber; + + /** 号码有效秒数,DIRECT 为 0 表示不设时效 */ + private Integer expiresInSeconds; +} diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/security/support/SecurityAuditActions.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/security/support/SecurityAuditActions.java index a581544f..83ed716f 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/security/support/SecurityAuditActions.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/security/support/SecurityAuditActions.java @@ -108,6 +108,7 @@ public final class SecurityAuditActions { public static final String ANALYTICS_VIEW = "ANALYTICS_VIEW"; public static final String PERFORMANCE_VIEW = "PERFORMANCE_VIEW"; public static final String SECURE_CONFIG_UPDATE = "SECURE_CONFIG_UPDATE"; + public static final String CUSTOMER_DIAL = "CUSTOMER_DIAL"; private SecurityAuditActions() { } diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java index 158af818..ec8e200e 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceImpl.java @@ -629,7 +629,9 @@ public class UserServiceImpl extends ServiceImpl implements AppointmentCustomerOptionVO customer = new AppointmentCustomerOptionVO(); customer.setId(user.getId()); customer.setName(user.getNickname()); - customer.setPhone(resolveCustomerPhone(user)); + String plainPhone = resolveCustomerPhone(user); + customer.setPhone(phoneCrypto.mask(plainPhone)); + customer.setPhoneAvailable(StringUtils.hasText(plainPhone)); customer.setAvatar(resolveAccessibleAvatar(user.getAvatar())); customer.setCreatedAt(user.getCreateTime()); return customer; @@ -658,7 +660,9 @@ public class UserServiceImpl extends ServiceImpl implements AppointmentCustomerOptionVO option = new AppointmentCustomerOptionVO(); option.setId(user.getId()); option.setName(user.getNickname()); - option.setPhone(resolveCustomerPhone(user)); + String plainPhone = resolveCustomerPhone(user); + option.setPhone(phoneCrypto.mask(plainPhone)); + option.setPhoneAvailable(StringUtils.hasText(plainPhone)); option.setAvatar(resolveAccessibleAvatar(user.getAvatar())); option.setCreatedAt(user.getCreateTime()); return option; diff --git a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/support/security/RequestThrottleService.java b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/support/security/RequestThrottleService.java index 59c2c8d1..2f895c52 100644 --- a/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/support/security/RequestThrottleService.java +++ b/JC-Salon-Core/src/main/java/com/xiaowang/jayucloud/salon/core/support/security/RequestThrottleService.java @@ -90,6 +90,14 @@ public class RequestThrottleService { assertAllowed("agreement-read", request, sanitize(agreementType), rateLimitProperties.getAgreementRead(), "协议读取过于频繁,请稍后再试"); } + /** + * 客户拨号取号按用户维度限流,避免管理员批量拉取完整号码。 + */ + public void checkCustomerDial(HttpServletRequest request, Long userId) { + assertAllowed("customer-dial", request, userId == null ? "" : String.valueOf(userId), + rateLimitProperties.getCustomerDial(), "拨号取号过于频繁,请稍后再试"); + } + /** * Purpose: checkAuthenticatedWrite supports RequestThrottleService.java by holding or executing the check authenticated write business role. * Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state. diff --git a/JC-Salon-Core/src/main/resources/db/migration/V18__隐私政策与用户协议全场景脱敏条款修订_20261104.sql b/JC-Salon-Core/src/main/resources/db/migration/V18__隐私政策与用户协议全场景脱敏条款修订_20261104.sql new file mode 100644 index 00000000..95a9601b --- /dev/null +++ b/JC-Salon-Core/src/main/resources/db/migration/V18__隐私政策与用户协议全场景脱敏条款修订_20261104.sql @@ -0,0 +1,51 @@ +-- 隐私政策与用户协议条款修订:对齐“全场景脱敏 + 拨号按需单次取号 + 可接隐私号码”口径 +-- 版本:2026.11.04(V18) +-- 说明:仅更新当前生效版本的条款正文,不新增协议版本、不触发重新同意;静态 HTML 正文由 public/legal 读库渲染,不再维护副本。 + +UPDATE t_legal_agreement +SET content = REPLACE( + content, + '常规页面展示脱敏号码,完整号码仅在必要业务场景和权限校验通过时展示。', + '所有页面统一脱敏展示;确需联系客户时,须通过门店数据权限与预约/订单上下文校验后按需单次取号拨号,不批量展示完整号码;接入隐私号码服务时返回临时隐私号码。' + ), + update_time = NOW() +WHERE agreement_type = 'USER_TERMS' + AND status = 1 + AND is_delete = 0 + AND content LIKE '%常规页面展示脱敏号码,完整号码仅在必要业务场景和权限校验通过时展示。%'; + +UPDATE t_legal_agreement +SET content = REPLACE( + content, + '常规客户列表、详情页、日志、导出文件、通知消息及面向第三方的展示,手机号一律脱敏。', + '全部客户列表、详情页、日志、导出文件、通知消息及面向第三方的展示,手机号一律脱敏。' + ), + update_time = NOW() +WHERE agreement_type = 'PRIVACY_POLICY' + AND status = 1 + AND is_delete = 0 + AND content LIKE '%常规客户列表、详情页、日志、导出文件、通知消息及面向第三方的展示,手机号一律脱敏。%'; + +UPDATE t_legal_agreement +SET content = REPLACE( + content, + '仅在门店预约选择客户、需要与客户进行业务联系等必要场景,且请求通过门店数据权限校验时,才向授权人员展示完整号码。', + '确需与客户进行业务联系时,由授权人员在门店数据权限和预约/订单上下文校验通过后按需单次取号:直拨模式仅返回本次拨号号码,隐私号码模式返回临时隐私号码;完整号码不下发列表、不落库、不写日志、不进入缓存,且隐私号码未开通时不会回退为真实号码。' + ), + update_time = NOW() +WHERE agreement_type = 'PRIVACY_POLICY' + AND status = 1 + AND is_delete = 0 + AND content LIKE '%仅在门店预约选择客户、需要与客户进行业务联系等必要场景,且请求通过门店数据权限校验时,才向授权人员展示完整号码。%'; + +UPDATE t_legal_agreement +SET content = REPLACE( + content, + '客户本人资料页、员工账号资料页默认展示脱敏号码;', + '客户本人资料页、员工账号资料页一律展示脱敏号码;' + ), + update_time = NOW() +WHERE agreement_type = 'PRIVACY_POLICY' + AND status = 1 + AND is_delete = 0 + AND content LIKE '%客户本人资料页、员工账号资料页默认展示脱敏号码;%'; diff --git a/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImplTest.java index 46273f97..1c1c1121 100644 --- a/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -29,6 +29,7 @@ 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.modules.user.service.UserService; import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator; +import com.xiaowang.jayucloud.salon.core.support.privacy.PhoneCrypto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -69,6 +70,7 @@ class PlanningServiceImplTest { @Mock private WechatSubscribeMessageService wechatSubscribeMessageService; @Mock private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator; @Mock private ObjectStorageUrlSupport objectStorageUrlSupport; + @Mock private PhoneCrypto phoneCrypto; private PlanningServiceImpl service; @@ -77,7 +79,7 @@ class PlanningServiceImplTest { service = new PlanningServiceImpl(adminScopeHelper, userMapper, userService, nailArtistInfoMapper, artistScheduleMapper, artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper, productMapper, shopMapper, shopBusinessExpiryService, shopBusinessScheduleService, appointmentCapacityService, orderService, wechatSubscribeMessageService, snowflakeIdGenerator, - objectStorageUrlSupport); + objectStorageUrlSupport, phoneCrypto); ShopBusinessHoursDayVO defaultOpenDay = new ShopBusinessHoursDayVO(); defaultOpenDay.setOpen(true); defaultOpenDay.setStartTime("10:00"); @@ -514,13 +516,15 @@ class PlanningServiceImplTest { when(orderItemMapper.selectById(64L)).thenReturn(item); when(orderMapper.selectById(54L)).thenReturn(order); when(userMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of()); + when(phoneCrypto.mask("13800138000")).thenReturn("138****8000"); com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO result = service.getAppointment(operator, 64L); assertNull(result.getCustomerId()); assertEquals("散客预约", result.getCustomerName()); - assertEquals("13800138000", result.getCustomerPhone()); + assertEquals("138****8000", result.getCustomerPhone()); + assertEquals(Boolean.TRUE, result.getCustomerPhoneAvailable()); assertEquals("门店临时闭店", result.getCancelReason()); verify(userMapper, never()).selectById(org.mockito.ArgumentMatchers.isNull()); } diff --git a/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImplTest.java b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImplTest.java new file mode 100644 index 00000000..a3e11b63 --- /dev/null +++ b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/privacy/service/impl/CustomerDialServiceImplTest.java @@ -0,0 +1,138 @@ +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.mapper.OrderMapper; +import com.xiaowang.jayucloud.salon.core.modules.privacy.config.DialProperties; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialMode; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DialTargetProvider; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.DirectDialTargetProvider; +import com.xiaowang.jayucloud.salon.core.modules.privacy.dial.PlaceholderPrivacyNumberProvider; +import com.xiaowang.jayucloud.salon.core.modules.privacy.vo.CustomerDialVO; +import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper; +import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditSupport; +import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO; +import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService; +import com.xiaowang.jayucloud.salon.core.support.privacy.PhoneCrypto; +import com.xiaowang.jayucloud.salon.core.support.security.RequestThrottleService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class CustomerDialServiceImplTest { + + @Mock private AdminScopeHelper adminScopeHelper; + @Mock private UserService userService; + @Mock private OrderMapper orderMapper; + @Mock private RequestThrottleService requestThrottleService; + @Mock private SecurityAuditSupport securityAuditSupport; + @Mock private PhoneCrypto phoneCrypto; + @Mock private HttpServletRequest request; + + private CustomerDialServiceImpl service; + private UserDO currentUser; + private UserDO customer; + private OrderDO order; + + @BeforeEach + void setUp() { + DialProperties properties = new DialProperties(); + List providers = List.of( + new DirectDialTargetProvider(phoneCrypto), + new PlaceholderPrivacyNumberProvider()); + service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, + requestThrottleService, securityAuditSupport, properties, providers); + + currentUser = new UserDO(); + currentUser.setId(9L); + currentUser.setType(2); + currentUser.setShopId(1L); + + customer = new UserDO(); + customer.setId(100L); + customer.setType(0); + customer.setIsDelete(0); + + order = new OrderDO(); + order.setId(10L); + order.setUserId(100L); + order.setShopId(1L); + order.setIsDelete(0); + } + + @Test + void directProviderReturnsFullNumberOnceAndWritesAudit() { + customer.setPhone("encrypted-phone"); + when(phoneCrypto.decrypt("encrypted-phone")).thenReturn("13800138000"); + when(userService.getById(100L)).thenReturn(customer); + when(orderMapper.selectById(10L)).thenReturn(order); + + CustomerDialVO result = service.dial(currentUser, 100L, 10L, request); + + assertEquals(DialMode.DIRECT, result.getMode()); + assertEquals("13800138000", result.getDialNumber()); + verify(requestThrottleService).checkCustomerDial(request, 9L); + verify(securityAuditSupport).success(eq(request), anyString(), anyString()); + } + + @Test + void rejectsOrderOfAnotherShop() { + order.setShopId(2L); + when(userService.getById(100L)).thenReturn(customer); + when(orderMapper.selectById(10L)).thenReturn(order); + + BusinessException error = assertThrows(BusinessException.class, + () -> service.dial(currentUser, 100L, 10L, request)); + + assertEquals(403, error.getCode()); + } + + @Test + void rejectsOrderThatDoesNotBelongToCustomer() { + order.setUserId(101L); + when(userService.getById(100L)).thenReturn(customer); + when(orderMapper.selectById(10L)).thenReturn(order); + + BusinessException error = assertThrows(BusinessException.class, + () -> service.dial(currentUser, 100L, 10L, request)); + + assertEquals(403, error.getCode()); + } + + @Test + void privacyNumberProviderReportsNotConfiguredWithoutFallingBackToRealNumber() { + service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, + requestThrottleService, securityAuditSupport, privacyProperties(), List.of( + new DirectDialTargetProvider(phoneCrypto), + new PlaceholderPrivacyNumberProvider())); + customer.setPhone("encrypted-phone"); + when(userService.getById(100L)).thenReturn(customer); + when(orderMapper.selectById(10L)).thenReturn(order); + + BusinessException error = assertThrows(BusinessException.class, + () -> service.dial(currentUser, 100L, 10L, request)); + + assertEquals(PlaceholderPrivacyNumberProvider.NOT_CONFIGURED_CODE, error.getCode()); + verify(securityAuditSupport).fail(eq(request), anyString(), anyString()); + } + + private DialProperties privacyProperties() { + DialProperties properties = new DialProperties(); + properties.setProvider("privacy-number"); + return properties; + } +} diff --git a/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceCustomerMatchingTest.java b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceCustomerMatchingTest.java index f32bae0f..35d9b893 100644 --- a/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceCustomerMatchingTest.java +++ b/JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/user/service/impl/UserServiceCustomerMatchingTest.java @@ -75,7 +75,7 @@ class UserServiceCustomerMatchingTest { } @Test - void appointmentIdentityLookupReturnsOnlyExactTupleAndFullPhone() { + void appointmentIdentityLookupReturnsOnlyExactTupleAndMaskedPhone() { UserDO existing = new UserDO(); existing.setId(92L); existing.setNickname("周女士"); @@ -85,6 +85,7 @@ class UserServiceCustomerMatchingTest { existing.setIsDelete(0); when(userMapper.selectList(any(Wrapper.class))).thenReturn(List.of(existing)); when(phoneCrypto.decrypt("encrypted-phone")).thenReturn("13800138000"); + when(phoneCrypto.mask("13800138000")).thenReturn("138****8000"); List matches = userService.findCustomerIdentityMatches("周女士", "wx-zhou", "13800138000", null); @@ -92,12 +93,13 @@ class UserServiceCustomerMatchingTest { userService.findCustomerIdentityMatches("周女士", "wx-another", "13800138000", null); assertEquals(1, matches.size()); - assertEquals("13800138000", matches.get(0).getPhone()); + assertEquals("138****8000", matches.get(0).getPhone()); + assertEquals(Boolean.TRUE, matches.get(0).getPhoneAvailable()); assertTrue(wrongWechat.isEmpty()); } @Test - void appointmentIdentityLookupFallsBackToLegacyContactPhone() { + void appointmentIdentityLookupFallsBackToLegacyContactPhoneWithMaskedPhone() { UserDO existing = new UserDO(); existing.setId(93L); existing.setNickname("周女士"); @@ -107,11 +109,13 @@ class UserServiceCustomerMatchingTest { existing.setIsDelete(0); when(userMapper.selectList(any(Wrapper.class))).thenReturn(List.of(existing)); when(phoneCrypto.decrypt("encrypted-contact-phone")).thenReturn("13800138000"); + when(phoneCrypto.mask("13800138000")).thenReturn("138****8000"); List matches = userService.findCustomerIdentityMatches("周女士", "wx-zhou", "13800138000", null); assertEquals(1, matches.size()); - assertEquals("13800138000", matches.get(0).getPhone()); + assertEquals("138****8000", matches.get(0).getPhone()); + assertEquals(Boolean.TRUE, matches.get(0).getPhoneAvailable()); } } diff --git a/JC-Salon-Frontend/src/api/user.ts b/JC-Salon-Frontend/src/api/user.ts index 53072cd9..0bc9418e 100644 --- a/JC-Salon-Frontend/src/api/user.ts +++ b/JC-Salon-Frontend/src/api/user.ts @@ -261,11 +261,28 @@ export interface ContactInfoVO { platformContactText?: string } +/** + * 后台单次拨号取号响应。 + */ +export interface CustomerDialResult { + mode: 'DIRECT' | 'PRIVACY_NUMBER' + dialNumber: string + expiresInSeconds: number +} + /** * userApi groups all API calls for this page domain. * Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script. */ export const userApi = { + /** + * 后台管理员按预约/订单上下文单次取号,号码不入库、不缓存。 + */ + dialCustomer: async (customerId: IdType, orderId: IdType): Promise => { + return await api.post(`/manager/customers/${customerId}/dial`, null, { + params: { orderId } + }) as unknown as CustomerDialResult + }, getUserInfo: async (): Promise => { return await api.get('/user/info') as unknown as UserVO }, diff --git a/JC-Salon-Frontend/src/views/ArtistOrderView.vue b/JC-Salon-Frontend/src/views/ArtistOrderView.vue index 557989ef..c990f035 100644 --- a/JC-Salon-Frontend/src/views/ArtistOrderView.vue +++ b/JC-Salon-Frontend/src/views/ArtistOrderView.vue @@ -67,6 +67,13 @@
预约用户:{{ order.customerNickname || '用户' }} 联系电话:{{ order.customerPhoneMasked }} + 呼叫
@@ -215,6 +222,7 @@ const route = useRoute() * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. */ const orders = ref([]) +const dialingOrderId = ref(null) /** * Purpose: orderRefs supports ArtistOrderView.vue by holding or executing the order refs page or API role. * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. @@ -659,6 +667,26 @@ const confirmQuote = async () => { } } +/** 按订单上下文单次取号后发起拨号,号码不落库、不缓存。 */ +const dialCustomer = async (order: any) => { + if (!order?.userId || !order?.id) { + message.warning('缺少订单上下文,无法取号') + return + } + dialingOrderId.value = order.id + try { + const result = await userApi.dialCustomer(order.userId, order.id) + if (!result?.dialNumber) { + throw new Error('未获取到可拨打号码') + } + window.location.href = `tel:${result.dialNumber}` + } catch (error: any) { + message.error(error?.message || '取号失败') + } finally { + dialingOrderId.value = null + } +} + /** completeOrder is a local helper used by this page script. */ const completeOrder = (orderId: IdType) => { Modal.confirm({ diff --git a/JC-Salon-WeChat/api/customers.js b/JC-Salon-WeChat/api/customers.js index c76e2c53..1eff37c0 100644 --- a/JC-Salon-WeChat/api/customers.js +++ b/JC-Salon-WeChat/api/customers.js @@ -46,6 +46,18 @@ module.exports = { }) }, + /** + * 后台按预约/订单上下文单次取号,号码不入库、不缓存。 + */ + dialCustomer(customerId, orderId) { + return request({ + url: `/manager/customers/${customerId}/dial`, + method: 'POST', + data: {}, + params: { orderId } + }) + }, + create(data) { return request({ url: '/manager/customers', diff --git a/JC-Salon-WeChat/pages/appointment-detail/index.js b/JC-Salon-WeChat/pages/appointment-detail/index.js index c49e37eb..8bf5f75f 100644 --- a/JC-Salon-WeChat/pages/appointment-detail/index.js +++ b/JC-Salon-WeChat/pages/appointment-detail/index.js @@ -1,4 +1,5 @@ const planningApi = require('../../api/planning') +const customersApi = require('../../api/customers') const { markPlanningRefresh } = require('../../utils/planning-refresh') function displayValue(value, fallback) { @@ -24,6 +25,7 @@ Page({ showComplete: false, showCancel: false, updating: false, + dialing: false, loadError: '' }, @@ -130,6 +132,27 @@ Page({ }) }, + async dialCustomer() { + const appointment = this.data.appointment || {} + if (this.data.dialing) return + if (!appointment.customerPhoneAvailable || !appointment.customerId || !appointment.orderId) { + wx.showToast({ title: '该客户暂无可拨打的手机号', icon: 'none' }) + return + } + this.setData({ dialing: true }) + try { + const result = await customersApi.dialCustomer(appointment.customerId, appointment.orderId) + if (!result || !result.dialNumber) { + throw new Error('未获取到可拨打号码') + } + wx.makePhoneCall({ phoneNumber: result.dialNumber }) + } catch (error) { + wx.showToast({ title: error.message || '取号失败', icon: 'none' }) + } finally { + this.setData({ dialing: false }) + } + }, + goTransfer() { if (!this.data.showTransfer) return wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` }) diff --git a/JC-Salon-WeChat/pages/appointment-detail/index.wxml b/JC-Salon-WeChat/pages/appointment-detail/index.wxml index 97af5b86..aa8bdacb 100644 --- a/JC-Salon-WeChat/pages/appointment-detail/index.wxml +++ b/JC-Salon-WeChat/pages/appointment-detail/index.wxml @@ -10,7 +10,16 @@ {{avatarText}} {{appointment.customerNameText}} - {{appointment.customerPhoneText}} + + {{appointment.customerPhoneText}} + + {{appointment.historicalBackfill ? '历史补单 · ' : ''}}{{appointment.statusText}} diff --git a/JC-Salon-WeChat/pages/appointment-detail/index.wxss b/JC-Salon-WeChat/pages/appointment-detail/index.wxss index 54a5b15e..2df450ce 100644 --- a/JC-Salon-WeChat/pages/appointment-detail/index.wxss +++ b/JC-Salon-WeChat/pages/appointment-detail/index.wxss @@ -67,6 +67,24 @@ font-size: 24rpx; } +.phone-row { + display: flex; + align-items: center; + gap: 12rpx; +} + +.call-btn { + flex-shrink: 0; + margin: 0; + padding: 0 18rpx; + border-radius: 999rpx; + background: #edf6ef; + color: #247b63; + font-size: 22rpx; + font-weight: 800; + line-height: 44rpx; +} + .status-tag { flex-shrink: 0; padding: 8rpx 14rpx; diff --git a/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js b/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js index a09e6503..4aa8b0a4 100644 --- a/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js +++ b/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js @@ -36,17 +36,17 @@ function createPage() { async function run() { const page = createPage() - page.selectCustomer({ detail: { item: { id: 18, name: '小周', phone: '13800138000' } } }) + page.selectCustomer({ detail: { item: { id: 18, name: '小周', phone: '138****8000' } } }) assert.strictEqual(page.data.form.customerUserId, 18) assert.strictEqual(page.data.form.customerName, '小周') - assert.strictEqual(page.data.form.phone, '13800138000') + assert.strictEqual(page.data.form.phone, '') assert.strictEqual(page.data.customerSheetVisible, false) page.data.form.customerUserId = 18 page.onCustomerInput({ currentTarget: { dataset: { field: 'customerName' } }, detail: { value: '新客户' } }) assert.strictEqual(page.data.form.customerUserId, '') assert.strictEqual(page.data.form.customerName, '新客户') - assert.strictEqual(page.data.form.phone, '13800138000') + assert.strictEqual(page.data.form.phone, '') customersApi.matchIdentityForAppointment = async () => [] customersApi.create = async () => { throw new Error('预约客户建档应随预约请求提交') } @@ -61,10 +61,11 @@ async function run() { assert.strictEqual(name, '小周') assert.strictEqual(wechatId, undefined) assert.strictEqual(phone, '13800138000') - return [{ id: '18', name: '小周', phone: '13800138000' }] + return [{ id: '18', name: '小周', phone: '138****8000' }] } assert.strictEqual(await page.ensureCustomerBeforeSubmit(), true) assert.strictEqual(page.data.form.customerUserId, '18') + assert.strictEqual(page.data.form.phone, '13800138000') page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }] page.onArtistSearch({ detail: { value: '李' } }) diff --git a/JC-Salon-WeChat/pages/appointment-form/index.js b/JC-Salon-WeChat/pages/appointment-form/index.js index 1709fc88..ae28ef55 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.js +++ b/JC-Salon-WeChat/pages/appointment-form/index.js @@ -520,6 +520,7 @@ function normalizeCustomer(customer) { id: customer.id, name, phone, + phoneAvailable: customer.phoneAvailable === true || (Boolean(phone) && !String(phone).includes('*')), displayName: name || phone || '客户', displayPhone: phone || '未填写手机号', createdAt: customerCreatedAt(customer) @@ -952,7 +953,7 @@ Page({ if (requestSeq !== this._customerSuggestionSeq) return const rows = Array.isArray(result) ? result : (result.list || []) const remoteSuggestions = rows.map(normalizeCustomer) - .filter(customer => (!name || customer.name.toLowerCase().includes(name)) && (!phone || customer.phone.toLowerCase().includes(phone))) + .filter(customer => !name || customer.name.toLowerCase().includes(name)) .slice(0, 3) .map(buildCustomerSelectorItem) this.setData({ customerSuggestions: remoteSuggestions }) @@ -971,7 +972,8 @@ Page({ this.setData({ 'form.customerUserId': customer.id, 'form.customerName': customer.name, - 'form.phone': customer.phone || '', + // 后端仅返回脱敏号码,不回填到表单,避免把脱敏值当真实号码提交 + 'form.phone': '', 'form.createCustomerRecord': false, customerSuggestions: [], customerSheetVisible: false, @@ -1000,11 +1002,25 @@ Page({ return } const keyword = String(keywordValue === undefined ? this.data.customerKeyword : keywordValue || '').trim() + if (keyword) { + // 号码已全场景脱敏,按手机号检索必须交给后端精确匹配 + try { + const result = await customersApi.listForAppointment({ page: 1, size: 100, keyword }) + const rows = Array.isArray(result) ? result : (result.list || []) + this.setData({ + customerOptions: this.sortCustomerOptions(rows.map(normalizeCustomer)), + customerError: '' + }) + } catch (error) { + this.setData({ customerOptions: [], customerError: error.message || '客户加载失败' }) + } + return + } if (this.data.customerDirectory.length === 0) await this.loadCustomerDirectory() - const matches = this.data.customerDirectory.filter(customer => - !keyword || `${customer.name} ${customer.phone}`.toLowerCase().includes(keyword.toLowerCase()) - ) - this.setData({ customerOptions: this.sortCustomerOptions(matches), customerError: '' }) + this.setData({ + customerOptions: this.sortCustomerOptions(this.data.customerDirectory), + customerError: '' + }) }, changeCustomerView(event) { @@ -1013,11 +1029,10 @@ Page({ toggleCustomerSort() { const customerNewestFirst = !this.data.customerNewestFirst - const keyword = String(this.data.customerKeyword || '').trim().toLowerCase() - const matches = this.data.customerDirectory.filter(customer => - !keyword || `${customer.name} ${customer.phone}`.toLowerCase().includes(keyword) - ) - this.setData({ customerNewestFirst, customerOptions: this.sortCustomerOptions(matches, customerNewestFirst) }) + this.setData({ + customerNewestFirst, + customerOptions: this.sortCustomerOptions(this.data.customerOptions, customerNewestFirst) + }) }, retryCustomerSearch() { @@ -1032,7 +1047,8 @@ Page({ this.setData({ 'form.customerUserId': customer.id, 'form.customerName': customer.name, - 'form.phone': customer.phone || '', + // 选择已有客户时不回填脱敏号码,手机号仅在用户主动修改时提交 + 'form.phone': '', 'form.createCustomerRecord': false, customerSheetVisible: false, customerKeyword: '', @@ -1925,7 +1941,6 @@ Page({ this.setData({ 'form.customerUserId': customer.id, 'form.customerName': customer.name, - 'form.phone': customer.phone, 'form.createCustomerRecord': false }) } else { diff --git a/JC-Salon-WeChat/pages/backfill-order/index.js b/JC-Salon-WeChat/pages/backfill-order/index.js index 665c051d..2ad1fe72 100644 --- a/JC-Salon-WeChat/pages/backfill-order/index.js +++ b/JC-Salon-WeChat/pages/backfill-order/index.js @@ -114,7 +114,7 @@ Page({ searchCustomers(event) { const keyword = String(event.detail.value || '').toLowerCase(); this.setData({ customerKeyword: keyword, customerOptions: this.data.allCustomerOptions.filter(item => !keyword || `${item.name} ${item.phone}`.toLowerCase().includes(keyword)) }) }, selectProduct(event) { const item = event.detail.item || {}; const duration = String(item.serviceDurationMinutes || String(item.approximateDuration || '').replace(/[^0-9]/g, '') || '60'); this.setData({ 'form.productId': item.id, 'form.manualProductTitle': '', 'form.amount': item.price == null ? this.data.form.amount : String(item.price), 'form.durationMinutes': duration, selectedProduct: item, selectedProductTitle: item.title, selectedProductPriceText: item.priceText || '价格待定', manualProductDraft: { title: '', price: '', durationMinutes: duration, description: '' }, productSelectorVisible: false, manualProductSheetVisible: false }) }, selectArtist(event) { const item = event.detail.item; this.setData({ 'form.artistId': item.id, selectedArtistName: item.title, artistSelectorVisible: false }) }, - selectCustomer(event) { const item = event.detail.item || {}; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.name || item.title, 'form.phone': item.phone || '', customerSelectorVisible: false }) }, + selectCustomer(event) { const item = event.detail.item || {}; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.name || item.title, 'form.phone': '', customerSelectorVisible: false }) }, useWalkIn() { this.setData({ 'form.customerUserId': '', 'form.customerName': '', 'form.wechatId': '', 'form.phone': '', customerSelectorVisible: false }) }, onCustomerInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value, 'form.customerUserId': '' }) }, useManualProduct() { const title = String(this.data.manualProductDraft.title || '').trim(); const priceText = String(this.data.manualProductDraft.price || this.data.form.amount || '').trim(); const price = Number(priceText); const images = this.data.form.manualProductImages || []; if (this.data.form.productId) { if (!priceText || !Number.isFinite(price) || price < 0) { wx.showToast({ title: '请输入正确的款式价格', icon: 'none' }); return } this.setData({ 'form.amount': priceText, 'form.durationMinutes': String(this.data.manualProductDraft.durationMinutes || '60'), manualProductSheetVisible: false }); return } if (!title && !images.length) { wx.showToast({ title: '请填写款式名称或添加图片', icon: 'none' }); return } if (!priceText || !Number.isFinite(price) || price < 0) { wx.showToast({ title: '请输入正确的款式价格', icon: 'none' }); return } const duration = String(this.data.manualProductDraft.durationMinutes || '60'); this.setData({ 'form.productId': '', 'form.manualProductTitle': title, 'form.manualProductDescription': this.data.manualProductDraft.description || '', 'form.manualProductPrice': priceText, 'form.amount': priceText, 'form.durationMinutes': duration, 'manualProductDraft.price': priceText, selectedProduct: {}, selectedProductTitle: title, selectedProductPriceText: `¥${price}`, productSelectorVisible: false, manualProductSheetVisible: false }) }, diff --git a/nacos/namespaces/dev/jayucloud-salon/DEFAULT_GROUP/core.yaml b/nacos/namespaces/dev/jayucloud-salon/DEFAULT_GROUP/core.yaml index 5f789af5..fa31fa5e 100644 --- a/nacos/namespaces/dev/jayucloud-salon/DEFAULT_GROUP/core.yaml +++ b/nacos/namespaces/dev/jayucloud-salon/DEFAULT_GROUP/core.yaml @@ -51,6 +51,9 @@ jayucloud-salon: brand: message-template-name: JayuCloud-Salon manager-register-shop-description: 甲屿店务注册店铺 + dial: + # direct:直拨真实号码;privacy-number:隐私号码(未对接时明确报错,绝不回退真实号码) + provider: direct privacy: content-moderation: # 仅 DEV 允许在后台设置中使用本地模拟审核;SIT/PROD 继续失败关闭。 @@ -87,6 +90,9 @@ jayucloud-salon: order-create: limit: 10 window-seconds: 60 + customer-dial: + limit: 10 + window-seconds: 60 cache: local-max-size: 2048 product-detail: diff --git a/nacos/namespaces/prod/jayucloud-salon/DEFAULT_GROUP/core.yaml b/nacos/namespaces/prod/jayucloud-salon/DEFAULT_GROUP/core.yaml index deb8140e..1fb6193b 100644 --- a/nacos/namespaces/prod/jayucloud-salon/DEFAULT_GROUP/core.yaml +++ b/nacos/namespaces/prod/jayucloud-salon/DEFAULT_GROUP/core.yaml @@ -50,6 +50,9 @@ jayucloud-salon: brand: message-template-name: JayuCloud-Salon manager-register-shop-description: 甲屿店务注册店铺 + dial: + # direct:直拨真实号码;privacy-number:隐私号码(未对接时明确报错,绝不回退真实号码) + provider: direct privacy: content-moderation: # 微信审核平台接入前失败关闭,内容进入隔离/人工复核,不自动放行。 @@ -87,6 +90,9 @@ jayucloud-salon: order-create: limit: 10 window-seconds: 60 + customer-dial: + limit: 10 + window-seconds: 60 cache: local-max-size: 2048 product-detail: diff --git a/nacos/namespaces/sit/jayucloud-salon/DEFAULT_GROUP/core.yaml b/nacos/namespaces/sit/jayucloud-salon/DEFAULT_GROUP/core.yaml index 43316412..7db07310 100644 --- a/nacos/namespaces/sit/jayucloud-salon/DEFAULT_GROUP/core.yaml +++ b/nacos/namespaces/sit/jayucloud-salon/DEFAULT_GROUP/core.yaml @@ -50,6 +50,9 @@ jayucloud-salon: brand: message-template-name: JayuCloud-Salon manager-register-shop-description: 甲屿店务注册店铺 + dial: + # direct:直拨真实号码;privacy-number:隐私号码(未对接时明确报错,绝不回退真实号码) + provider: direct privacy: content-moderation: # 仅 DEV 允许模拟审核;SIT 必须在后台配置微信审核并保持失败关闭。 @@ -86,6 +89,9 @@ jayucloud-salon: order-create: limit: 10 window-seconds: 60 + customer-dial: + limit: 10 + window-seconds: 60 cache: local-max-size: 2048 product-detail: