This commit is contained in:
@@ -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/**",
|
||||
|
||||
+15
-2
@@ -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
-4
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+58
-11
@@ -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()
|
||||
|
||||
+22
@@ -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")
|
||||
/**
|
||||
|
||||
+5
@@ -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);
|
||||
|
||||
+54
@@ -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.
|
||||
|
||||
+25
@@ -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;
|
||||
+93
-10
@@ -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.DialMode;
|
||||
@@ -26,7 +28,7 @@ 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.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -38,6 +40,7 @@ class CustomerDialServiceImplTest {
|
||||
@Mock private AdminScopeHelper adminScopeHelper;
|
||||
@Mock private UserService userService;
|
||||
@Mock private OrderMapper orderMapper;
|
||||
@Mock private OrderItemMapper orderItemMapper;
|
||||
@Mock private RequestThrottleService requestThrottleService;
|
||||
@Mock private SecurityAuditSupport securityAuditSupport;
|
||||
@Mock private PhoneCrypto phoneCrypto;
|
||||
@@ -54,7 +57,7 @@ class CustomerDialServiceImplTest {
|
||||
List<DialTargetProvider> providers = List.of(
|
||||
new DirectDialTargetProvider(phoneCrypto),
|
||||
new PlaceholderPrivacyNumberProvider());
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper,
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, orderItemMapper,
|
||||
requestThrottleService, securityAuditSupport, properties, providers);
|
||||
|
||||
currentUser = new UserDO();
|
||||
@@ -81,7 +84,7 @@ class CustomerDialServiceImplTest {
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, 10L, request);
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, null, 10L, request);
|
||||
|
||||
assertEquals(DialMode.DIRECT, result.getMode());
|
||||
assertEquals("13800138000", result.getDialNumber());
|
||||
@@ -90,13 +93,94 @@ class CustomerDialServiceImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsOrderOfAnotherShop() {
|
||||
order.setShopId(2L);
|
||||
void guestOrderUsesSnapshotWithoutRequiringCustomerAccount() {
|
||||
order.setUserId(null);
|
||||
order.setCustomerPhoneSnapshot("encrypted-snapshot");
|
||||
when(phoneCrypto.decrypt("encrypted-snapshot")).thenReturn("13900139000");
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, null, null, 10L, request);
|
||||
|
||||
assertEquals("13900139000", result.getDialNumber());
|
||||
assertEquals(DialMode.DIRECT, result.getMode());
|
||||
verify(securityAuditSupport).success(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderSnapshotTakesPriorityOverCustomerProfile() {
|
||||
order.setCustomerPhoneSnapshot("encrypted-snapshot");
|
||||
customer.setPhone("encrypted-customer-phone");
|
||||
when(phoneCrypto.decrypt("encrypted-snapshot")).thenReturn("13900139000");
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, 100L, null, 10L, request);
|
||||
|
||||
assertEquals("13900139000", result.getDialNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
void appointmentLocatorResolvesOrderItemThenOrder() {
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setId(5L);
|
||||
item.setOrderId(10L);
|
||||
item.setIsDelete(0);
|
||||
when(orderItemMapper.selectById(5L)).thenReturn(item);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
when(userService.getById(100L)).thenReturn(customer);
|
||||
customer.setPhone("encrypted-phone");
|
||||
when(phoneCrypto.decrypt("encrypted-phone")).thenReturn("13800138000");
|
||||
|
||||
CustomerDialVO result = service.dial(currentUser, null, 5L, null, request);
|
||||
|
||||
assertEquals("13800138000", result.getDialNumber());
|
||||
verify(securityAuditSupport).success(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsWhenAppointmentAndOrderDoNotMatch() {
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setId(5L);
|
||||
item.setOrderId(10L);
|
||||
item.setIsDelete(0);
|
||||
when(orderItemMapper.selectById(5L)).thenReturn(item);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, 10L, request));
|
||||
() -> service.dial(currentUser, null, 5L, 11L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void guestOrderWithoutAnyPhoneReturnsExplicitBusinessCode() {
|
||||
order.setUserId(null);
|
||||
order.setCustomerPhoneSnapshot(null);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, null, null, 10L, request));
|
||||
|
||||
assertEquals(DirectDialTargetProvider.NUMBER_UNAVAILABLE_CODE, error.getCode());
|
||||
assertTrue(error.getMessage().contains(DirectDialTargetProvider.NUMBER_UNAVAILABLE_BUSINESS_CODE));
|
||||
verify(securityAuditSupport).fail(eq(request), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsWhenNoLocatorProvided() {
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, null, null, null, request));
|
||||
|
||||
assertEquals(400, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsOrderOfAnotherShop() {
|
||||
order.setShopId(2L);
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
@@ -104,18 +188,17 @@ class CustomerDialServiceImplTest {
|
||||
@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));
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(403, error.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void privacyNumberProviderReportsNotConfiguredWithoutFallingBackToRealNumber() {
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper,
|
||||
service = new CustomerDialServiceImpl(adminScopeHelper, userService, orderMapper, orderItemMapper,
|
||||
requestThrottleService, securityAuditSupport, privacyProperties(), List.of(
|
||||
new DirectDialTargetProvider(phoneCrypto),
|
||||
new PlaceholderPrivacyNumberProvider()));
|
||||
@@ -124,7 +207,7 @@ class CustomerDialServiceImplTest {
|
||||
when(orderMapper.selectById(10L)).thenReturn(order);
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.dial(currentUser, 100L, 10L, request));
|
||||
() -> service.dial(currentUser, 100L, null, 10L, request));
|
||||
|
||||
assertEquals(PlaceholderPrivacyNumberProvider.NOT_CONFIGURED_CODE, error.getCode());
|
||||
verify(securityAuditSupport).fail(eq(request), anyString(), anyString());
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.entity.LegalAgreementDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.mapper.LegalAgreementMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.AgreementPendingVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserAgreementConsentDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserAgreementConsentMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
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 LegalAgreementServiceImplTest {
|
||||
|
||||
private static final String CURRENT_VERSION = "2026.11.04-R2";
|
||||
|
||||
@Mock private LegalAgreementMapper agreementMapper;
|
||||
@Mock private UserAgreementConsentMapper consentMapper;
|
||||
@Mock private HttpServletRequest request;
|
||||
|
||||
private LegalAgreementServiceImpl service;
|
||||
private LegalAgreementDO userTerms;
|
||||
private LegalAgreementDO privacyPolicy;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new LegalAgreementServiceImpl(agreementMapper, consentMapper);
|
||||
userTerms = currentAgreement(LegalAgreementServiceImpl.USER_TERMS);
|
||||
privacyPolicy = currentAgreement(LegalAgreementServiceImpl.PRIVACY_POLICY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anonymousPendingReturnsCurrentVersionsOnly() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(null);
|
||||
|
||||
assertEquals(CURRENT_VERSION, result.getCurrentVersions().get(LegalAgreementServiceImpl.USER_TERMS));
|
||||
assertEquals(CURRENT_VERSION, result.getCurrentVersions().get(LegalAgreementServiceImpl.PRIVACY_POLICY));
|
||||
assertTrue(result.getAcceptedVersions().isEmpty());
|
||||
assertNull(result.getPending());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggedInUserWithoutConsentIsPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(new ArrayList<>());
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.TRUE, result.getPending());
|
||||
assertEquals(List.of(LegalAgreementServiceImpl.USER_TERMS, LegalAgreementServiceImpl.PRIVACY_POLICY),
|
||||
result.getPendingTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void oldVersionConsentIsPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(List.of(
|
||||
consent(LegalAgreementServiceImpl.USER_TERMS, "2026.11.04"),
|
||||
consent(LegalAgreementServiceImpl.PRIVACY_POLICY, "2026.11.04")));
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.TRUE, result.getPending());
|
||||
assertEquals("2026.11.04", result.getAcceptedVersions().get(LegalAgreementServiceImpl.USER_TERMS));
|
||||
assertEquals(2, result.getPendingTypes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptedCurrentVersionsAreNotPending() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectList(any())).thenReturn(List.of(
|
||||
consent(LegalAgreementServiceImpl.USER_TERMS, CURRENT_VERSION),
|
||||
consent(LegalAgreementServiceImpl.PRIVACY_POLICY, CURRENT_VERSION)));
|
||||
|
||||
AgreementPendingVO result = service.getPendingAgreements(8L);
|
||||
|
||||
assertEquals(Boolean.FALSE, result.getPending());
|
||||
assertTrue(result.getPendingTypes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptRecordsBothCurrentVersions() {
|
||||
when(agreementMapper.selectOne(any())).thenReturn(userTerms, privacyPolicy);
|
||||
when(consentMapper.selectOne(any())).thenReturn(null);
|
||||
|
||||
service.acceptCurrentAgreements(8L, "WECHAT_MINI", request);
|
||||
|
||||
ArgumentCaptor<UserAgreementConsentDO> captor = ArgumentCaptor.forClass(UserAgreementConsentDO.class);
|
||||
verify(consentMapper, times(2)).insert(captor.capture());
|
||||
assertEquals(8L, captor.getAllValues().get(0).getUserId());
|
||||
assertEquals(CURRENT_VERSION, captor.getAllValues().get(0).getVersion());
|
||||
assertEquals(CURRENT_VERSION, captor.getAllValues().get(1).getVersion());
|
||||
assertEquals("WECHAT_MINI", captor.getAllValues().get(0).getClientType());
|
||||
assertEquals("agreement-gate", captor.getAllValues().get(0).getEntry());
|
||||
}
|
||||
|
||||
private LegalAgreementDO currentAgreement(String type) {
|
||||
LegalAgreementDO agreement = new LegalAgreementDO();
|
||||
agreement.setAgreementType(type);
|
||||
agreement.setVersion(CURRENT_VERSION);
|
||||
agreement.setStatus(1);
|
||||
agreement.setIsDelete(0);
|
||||
return agreement;
|
||||
}
|
||||
|
||||
private UserAgreementConsentDO consent(String type, String version) {
|
||||
UserAgreementConsentDO consent = new UserAgreementConsentDO();
|
||||
consent.setUserId(8L);
|
||||
consent.setAgreementType(type);
|
||||
consent.setVersion(version);
|
||||
return consent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user