From 88580dae55106dcf4a8f80693b90638e07af02fa Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 14 十月 2026 09:20:23 +0800
Subject: [PATCH] 修改bug
---
ruoyi-service/ruoyi-account/src/test/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImplTest.java | 123 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/test/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImplTest.java b/ruoyi-service/ruoyi-account/src/test/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImplTest.java
index b15bec9..e763e60 100644
--- a/ruoyi-service/ruoyi-account/src/test/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImplTest.java
+++ b/ruoyi-service/ruoyi-account/src/test/java/com/ruoyi/account/service/impl/TAppUserWhitelistServiceImplTest.java
@@ -14,6 +14,7 @@
import com.ruoyi.account.api.vo.AppUserWhitelistImportResultVO;
import com.ruoyi.account.api.vo.AppUserWhitelistMatchVO;
import com.ruoyi.account.mapper.TAppUserWhitelistMapper;
+import com.ruoyi.account.service.PartnerAppUserAccessService;
import com.ruoyi.account.service.TAppUserService;
import com.ruoyi.account.service.TAppUserWhitelistSiteService;
import com.ruoyi.account.service.TCompanyAllocateRecordService;
@@ -49,6 +50,7 @@
import java.util.concurrent.atomic.AtomicLong;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -57,6 +59,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -76,6 +79,7 @@
@Mock private GroupCompanyClient groupCompanyClient;
@Mock private RedissonClient redissonClient;
@Mock private TCompanyAllocateRecordService companyAllocateRecordService;
+ @Mock private PartnerAppUserAccessService partnerAppUserAccessService;
private TAppUserWhitelistServiceImpl service;
@@ -100,6 +104,10 @@
ReflectionTestUtils.setField(service, "groupCompanyClient", groupCompanyClient);
ReflectionTestUtils.setField(service, "redissonClient", redissonClient);
ReflectionTestUtils.setField(service, "companyAllocateRecordService", companyAllocateRecordService);
+ ReflectionTestUtils.setField(service, "partnerAppUserAccessService", partnerAppUserAccessService);
+ // 默认透传(模拟非公司账号),公司账号隔离场景由具体用例覆盖打桩
+ lenient().when(partnerAppUserAccessService.resolveCompanyFilter(any())).thenAnswer(invocation -> invocation.getArgument(0));
+ lenient().when(partnerAppUserAccessService.getCurrentCompanyId()).thenReturn(null);
RLock lock = mock(RLock.class);
// 并发锁仅在额度相关场景使用,宽松桩避免严格模式下未使用即报错
lenient().when(redissonClient.getLock(any())).thenReturn(lock);
@@ -250,6 +258,83 @@
assertTrue(result.getMatched());
assertEquals(null, result.getCompanyId());
assertEquals(null, result.getFleetId());
+ }
+
+ // ---------------- 白名单账户可用余额解析(充电页余额显示) ----------------
+
+ @Test
+ void resolveWhitelistAccountBalanceReturnsCompanyBalanceForSharedMode() {
+ TGroupCompany company = new TGroupCompany();
+ company.setAccountMode(1);
+ company.setAvailableBalance(new BigDecimal("500.50"));
+ when(groupCompanyClient.getCompanyById(12)).thenReturn(R.ok(company));
+
+ AppUserWhitelistMatchVO match = new AppUserWhitelistMatchVO();
+ match.setMatched(true);
+ match.setCompanyId(12);
+ match.setBalance(new BigDecimal("100.00"));
+
+ BigDecimal result = service.resolveWhitelistAccountBalance(match);
+
+ assertEquals(new BigDecimal("500.50"), result);
+ }
+
+ @Test
+ void resolveWhitelistAccountBalanceReturnsWhitelistBalanceForAllocationMode() {
+ TGroupCompany company = new TGroupCompany();
+ company.setAccountMode(2);
+ company.setAvailableBalance(new BigDecimal("500.50"));
+ when(groupCompanyClient.getCompanyById(12)).thenReturn(R.ok(company));
+
+ AppUserWhitelistMatchVO match = new AppUserWhitelistMatchVO();
+ match.setMatched(true);
+ match.setCompanyId(12);
+ match.setBalance(new BigDecimal("100.00"));
+
+ BigDecimal result = service.resolveWhitelistAccountBalance(match);
+
+ assertEquals(new BigDecimal("100.00"), result);
+ }
+
+ @Test
+ void resolveWhitelistAccountBalanceTreatsNullAccountModeAsShared() {
+ TGroupCompany company = new TGroupCompany();
+ company.setAccountMode(null);
+ company.setAvailableBalance(new BigDecimal("500.50"));
+ when(groupCompanyClient.getCompanyById(12)).thenReturn(R.ok(company));
+
+ AppUserWhitelistMatchVO match = new AppUserWhitelistMatchVO();
+ match.setMatched(true);
+ match.setCompanyId(12);
+ match.setBalance(new BigDecimal("100.00"));
+
+ BigDecimal result = service.resolveWhitelistAccountBalance(match);
+
+ assertEquals(new BigDecimal("500.50"), result);
+ }
+
+ @Test
+ void resolveWhitelistAccountBalanceReturnsNullWhenCompanyQueryFails() {
+ when(groupCompanyClient.getCompanyById(12)).thenReturn(R.fail("公司信息查询失败"));
+
+ AppUserWhitelistMatchVO match = new AppUserWhitelistMatchVO();
+ match.setMatched(true);
+ match.setCompanyId(12);
+ match.setBalance(new BigDecimal("100.00"));
+
+ BigDecimal result = service.resolveWhitelistAccountBalance(match);
+
+ assertNull(result);
+ }
+
+ @Test
+ void resolveWhitelistAccountBalanceReturnsNullWhenNotMatched() {
+ AppUserWhitelistMatchVO match = new AppUserWhitelistMatchVO();
+ match.setMatched(false);
+
+ BigDecimal result = service.resolveWhitelistAccountBalance(match);
+
+ assertNull(result);
}
// ---------------- 额度分配 ----------------
@@ -512,4 +597,42 @@
row.createCell(1).setCellValue(benefitType);
row.createCell(2).setCellValue(whitelistSite);
}
+
+ // ==================== 公司账号数据隔离 ====================
+
+ @Test
+ void getAllocateOverviewForcesCompanyFilterForCompanyAccount() {
+ // 公司账号:额度概览的公司参数被强制覆盖为本公司
+ when(partnerAppUserAccessService.resolveCompanyFilter(9)).thenReturn(2);
+ TGroupCompany company = new TGroupCompany();
+ company.setId(2);
+ company.setName("本公司");
+ company.setAccountMode(2);
+ company.setAvailableBalance(new BigDecimal("100.00"));
+ when(groupCompanyClient.getCompanyById(2)).thenReturn(R.ok(company));
+
+ AppUserWhitelistAllocateVO vo = service.getAllocateOverview(9);
+
+ assertEquals(Integer.valueOf(2), vo.getCompanyId());
+ verify(groupCompanyClient).getCompanyById(2);
+ }
+
+ @Test
+ void updateStatusRejectsCrossCompanyRecord() {
+ // 公司账号:启停其他公司的白名单被越权校验拦截
+ TAppUserWhitelist existing = new TAppUserWhitelist();
+ existing.setId(1L);
+ existing.setStatus(1);
+ existing.setCompanyId(9);
+ when(mapper.selectById(1L)).thenReturn(existing);
+ doThrow(new ServiceException("无权操作其他公司的数据")).when(partnerAppUserAccessService).assertCompanyVisible(9);
+ AppUserWhitelistStatusDTO dto = new AppUserWhitelistStatusDTO();
+ dto.setId(1L);
+ dto.setStatus(2);
+
+ ServiceException exception = assertThrows(ServiceException.class, () -> service.updateStatus(dto));
+
+ assertEquals("无权操作其他公司的数据", exception.getMessage());
+ verify(mapper, never()).update(isNull(), any(Wrapper.class));
+ }
}
--
Gitblit v1.7.1