| | |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.other.api.domain.TChargeAuthorization; |
| | | import com.ruoyi.other.api.domain.TFleet; |
| | | import com.ruoyi.other.api.domain.TGroupCompany; |
| | | import com.ruoyi.other.api.feignClient.FleetOrderAggregateClient; |
| | | import com.ruoyi.other.api.vo.FleetOrderAggregateVO; |
| | | import com.ruoyi.other.mapper.TChargeAuthorizationMapper; |
| | | import com.ruoyi.other.service.TGroupCompanyService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.mockito.Mockito; |
| | |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| | | import static org.junit.jupiter.api.Assertions.assertNull; |
| | | import static org.junit.jupiter.api.Assertions.assertSame; |
| | | import static org.junit.jupiter.api.Assertions.assertThrows; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void fillsCompanyBalanceForSharedAccountMode() { |
| | | VinManagementClient client = Mockito.mock(VinManagementClient.class); |
| | | Page<TVinManagement> page = new Page<>(1, 10); |
| | | page.setRecords(Collections.singletonList(vehicle())); |
| | | Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page)); |
| | | |
| | | TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(7); |
| | | company.setAccountMode(1); |
| | | company.setAvailableBalance(new BigDecimal("500.00")); |
| | | Mockito.when(groupCompanyService.getById(7)).thenReturn(company); |
| | | |
| | | TFleet fleet = fleet(4); |
| | | fleet.setCompanyId(7); |
| | | |
| | | buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10); |
| | | |
| | | // 共享模式展示公司当前可用余额,而非 VIN 自身余额(vehicle() balance=30.00) |
| | | assertEquals(0, new BigDecimal("500.00").compareTo(page.getRecords().get(0).getAvailableBalance())); |
| | | } |
| | | |
| | | @Test |
| | | void fillsVinBalanceForAllocationAccountMode() { |
| | | VinManagementClient client = Mockito.mock(VinManagementClient.class); |
| | | Page<TVinManagement> page = new Page<>(1, 10); |
| | | page.setRecords(Collections.singletonList(vehicle())); |
| | | Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page)); |
| | | |
| | | TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(7); |
| | | company.setAccountMode(2); |
| | | company.setAvailableBalance(new BigDecimal("500.00")); |
| | | Mockito.when(groupCompanyService.getById(7)).thenReturn(company); |
| | | |
| | | TFleet fleet = fleet(4); |
| | | fleet.setCompanyId(7); |
| | | |
| | | buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10); |
| | | |
| | | // 分配模式展示 VIN 自身余额 |
| | | assertEquals(0, new BigDecimal("30.00").compareTo(page.getRecords().get(0).getAvailableBalance())); |
| | | } |
| | | |
| | | @Test |
| | | void treatsNullAccountModeAsSharedAndKeepsNullWhenCompanyMissing() { |
| | | VinManagementClient client = Mockito.mock(VinManagementClient.class); |
| | | Page<TVinManagement> page = new Page<>(1, 10); |
| | | TVinManagement first = vehicle(); |
| | | page.setRecords(Collections.singletonList(first)); |
| | | Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page)); |
| | | |
| | | TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(7); |
| | | company.setAccountMode(null); |
| | | company.setAvailableBalance(new BigDecimal("88.00")); |
| | | Mockito.when(groupCompanyService.getById(7)).thenReturn(company); |
| | | |
| | | TFleet fleet = fleet(4); |
| | | fleet.setCompanyId(7); |
| | | buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10); |
| | | |
| | | // 历史数据账户模式为 null 时按共享模式展示公司余额(与系统"仅 ==2 为分配"口径一致) |
| | | assertEquals(0, new BigDecimal("88.00").compareTo(first.getAvailableBalance())); |
| | | |
| | | // 公司不存在(如已被删除)→ 保持 null,前端显示 '-' |
| | | Mockito.when(groupCompanyService.getById(8)).thenReturn(null); |
| | | TFleet other = fleet(6); |
| | | other.setCompanyId(8); |
| | | Page<TVinManagement> otherPage = new Page<>(1, 10); |
| | | TVinManagement third = vehicle(); |
| | | third.setId(3L); |
| | | otherPage.setRecords(Collections.singletonList(third)); |
| | | Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(otherPage)); |
| | | |
| | | buildService(other, client, null, null, groupCompanyService).selectVinPage(6, 1, 10); |
| | | |
| | | assertNull(third.getAvailableBalance()); |
| | | } |
| | | |
| | | @Test |
| | | void fillAggregatesPopulatesAllFiveFields() { |
| | | VinManagementClient vinClient = Mockito.mock(VinManagementClient.class); |
| | | FleetOrderAggregateClient aggClient = Mockito.mock(FleetOrderAggregateClient.class); |
| | |
| | | private TFleetServiceImpl buildService(TFleet fleet, VinManagementClient client, |
| | | FleetOrderAggregateClient aggClient, |
| | | TChargeAuthorizationMapper authMapper) { |
| | | return buildService(fleet, client, aggClient, authMapper, Mockito.mock(TGroupCompanyService.class)); |
| | | } |
| | | |
| | | private TFleetServiceImpl buildService(TFleet fleet, VinManagementClient client, |
| | | FleetOrderAggregateClient aggClient, |
| | | TChargeAuthorizationMapper authMapper, |
| | | TGroupCompanyService groupCompanyService) { |
| | | TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl()); |
| | | Mockito.doReturn(fleet).when(service).getById(Mockito.any()); |
| | | ReflectionTestUtils.setField(service, "vinManagementClient", client); |
| | | ReflectionTestUtils.setField(service, "fleetOrderAggregateClient", aggClient); |
| | | ReflectionTestUtils.setField(service, "chargeAuthorizationMapper", authMapper); |
| | | ReflectionTestUtils.setField(service, "groupCompanyService", groupCompanyService); |
| | | return service; |
| | | } |
| | | |