| | |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.vo.VinChargingStatusVO; |
| | | import com.ruoyi.other.api.domain.TFleet; |
| | | import com.ruoyi.other.api.domain.TGroupCompany; |
| | | import com.ruoyi.other.api.feignClient.GroupCompanyClient; |
| | | import org.junit.jupiter.api.AfterEach; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertFalse; |
| | | 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; |
| | |
| | | dto.setPlateNumber(" 川A12345 "); |
| | | dto.setPhone("13800138000"); |
| | | dto.setCompanyName(" 测试公司 "); |
| | | dto.setRemark(" 备注 "); |
| | | |
| | | boolean result = service.saveVin(dto); |
| | | |
| | |
| | | assertEquals("川A12345", saved.getPlateNumber()); |
| | | assertEquals("13800138000", saved.getPhone()); |
| | | assertEquals("测试公司", saved.getCompanyName()); |
| | | assertEquals("备注", saved.getRemark()); |
| | | assertNull(saved.getRemark()); |
| | | assertEquals(Integer.valueOf(1), saved.getStatus()); |
| | | assertEquals(Integer.valueOf(0), saved.getDelFlag()); |
| | | assertNotNull(saved.getCreateTime()); |
| | |
| | | assertTrue(sqlSet.contains("status=")); |
| | | assertTrue(sqlSet.contains("update_time=")); |
| | | assertTrue(sqlSet.contains("update_by=")); |
| | | // 备注已从表单下线,编辑不再写入 remark,历史备注不会被清空 |
| | | assertFalse(sqlSet.contains("remark=")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | assertNotNull(queryCaptor.getValue()); |
| | | } |
| | | |
| | | // ---------------- 账户信息回填(列表/导出) ---------------- |
| | | |
| | | @Test |
| | | void selectPageListFillsSharedAccountInfoFromCompanyBalance() { |
| | | TVinManagement record = new TVinManagement(); |
| | | record.setId(1L); |
| | | record.setCompanyId(8); |
| | | record.setBalance(new BigDecimal("5.00")); |
| | | Page<TVinManagement> expected = new Page<>(1, 10); |
| | | expected.setRecords(Collections.singletonList(record)); |
| | | when(mapper.selectPageList(any(Page.class), any())).thenReturn(expected); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(8); |
| | | company.setAccountMode(1); |
| | | company.setAvailableBalance(new BigDecimal("88.60")); |
| | | when(groupCompanyClient.listCompaniesByIds(Collections.singletonList(8))) |
| | | .thenReturn(R.ok(Collections.singletonList(company))); |
| | | |
| | | IPage<TVinManagement> result = service.selectPageList(new VinManagementQueryDTO()); |
| | | |
| | | TVinManagement filled = result.getRecords().get(0); |
| | | assertEquals(Integer.valueOf(1), filled.getAccountMode()); |
| | | assertEquals(new BigDecimal("88.60"), filled.getAvailableBalance()); |
| | | assertNull(filled.getOverrun()); |
| | | assertEquals(Integer.valueOf(1), filled.getAccountStatus()); |
| | | } |
| | | |
| | | @Test |
| | | void selectPageListUsesOwnBalanceAndFlagsOverrunForAllocationMode() { |
| | | TVinManagement record = new TVinManagement(); |
| | | record.setId(2L); |
| | | record.setCompanyId(9); |
| | | record.setBalance(new BigDecimal("-12.345")); |
| | | Page<TVinManagement> expected = new Page<>(1, 10); |
| | | expected.setRecords(Collections.singletonList(record)); |
| | | when(mapper.selectPageList(any(Page.class), any())).thenReturn(expected); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(9); |
| | | company.setAccountMode(2); |
| | | company.setAvailableBalance(new BigDecimal("1000.00")); |
| | | when(groupCompanyClient.listCompaniesByIds(Collections.singletonList(9))) |
| | | .thenReturn(R.ok(Collections.singletonList(company))); |
| | | |
| | | IPage<TVinManagement> result = service.selectPageList(new VinManagementQueryDTO()); |
| | | |
| | | TVinManagement filled = result.getRecords().get(0); |
| | | assertEquals(Integer.valueOf(2), filled.getAccountMode()); |
| | | assertEquals(new BigDecimal("-12.345"), filled.getAvailableBalance()); |
| | | assertEquals(new BigDecimal("12.35"), filled.getOverrun()); |
| | | assertEquals(Integer.valueOf(2), filled.getAccountStatus()); |
| | | } |
| | | |
| | | @Test |
| | | void selectPageListLeavesAccountFieldsEmptyWhenCompanyLookupFails() { |
| | | TVinManagement record = new TVinManagement(); |
| | | record.setId(3L); |
| | | record.setCompanyId(10); |
| | | record.setBalance(new BigDecimal("1.00")); |
| | | Page<TVinManagement> expected = new Page<>(1, 10); |
| | | expected.setRecords(Collections.singletonList(record)); |
| | | when(mapper.selectPageList(any(Page.class), any())).thenReturn(expected); |
| | | when(groupCompanyClient.listCompaniesByIds(Collections.singletonList(10))) |
| | | .thenReturn(R.fail("other service unavailable")); |
| | | |
| | | IPage<TVinManagement> result = service.selectPageList(new VinManagementQueryDTO()); |
| | | |
| | | TVinManagement filled = result.getRecords().get(0); |
| | | assertNull(filled.getAccountMode()); |
| | | assertNull(filled.getAvailableBalance()); |
| | | assertNull(filled.getOverrun()); |
| | | assertNull(filled.getAccountStatus()); |
| | | } |
| | | |
| | | @Test |
| | | void selectExportListFillsFleetNameAndAccountInfo() { |
| | | VinManagementExcelDTO item = new VinManagementExcelDTO(); |
| | | item.setVin("LSVAM4187C2184842"); |
| | | item.setCompanyId(8); |
| | | item.setFleetId(3); |
| | | item.setBalance(new BigDecimal("7.00")); |
| | | when(mapper.selectExportList(any())).thenReturn(Collections.singletonList(item)); |
| | | TFleet fleet = new TFleet(); |
| | | fleet.setId(3); |
| | | fleet.setFleetName("测试车队"); |
| | | when(groupCompanyClient.listFleetsByIds(Collections.singletonList(3))) |
| | | .thenReturn(R.ok(Collections.singletonList(fleet))); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(8); |
| | | company.setAccountMode(1); |
| | | company.setAvailableBalance(new BigDecimal("66.00")); |
| | | when(groupCompanyClient.listCompaniesByIds(Collections.singletonList(8))) |
| | | .thenReturn(R.ok(Collections.singletonList(company))); |
| | | |
| | | List<VinManagementExcelDTO> result = service.selectExportList(new VinManagementQueryDTO()); |
| | | |
| | | assertEquals("测试车队", result.get(0).getFleetName()); |
| | | assertEquals(Integer.valueOf(1), result.get(0).getAccountMode()); |
| | | assertEquals(new BigDecimal("66.00"), result.get(0).getAvailableBalance()); |
| | | assertNull(result.get(0).getOverrun()); |
| | | assertEquals(Integer.valueOf(1), result.get(0).getAccountStatus()); |
| | | } |
| | | |
| | | @Test |
| | | void selectExportListKeepsRowsWhenRemoteLookupsFail() { |
| | | VinManagementExcelDTO item = new VinManagementExcelDTO(); |
| | | item.setVin("LSVAM4187C2184842"); |
| | | item.setCompanyId(8); |
| | | item.setFleetId(3); |
| | | when(mapper.selectExportList(any())).thenReturn(Collections.singletonList(item)); |
| | | when(groupCompanyClient.listFleetsByIds(Collections.singletonList(3))) |
| | | .thenThrow(new ServiceException("fleet service unavailable")); |
| | | when(groupCompanyClient.listCompaniesByIds(Collections.singletonList(8))) |
| | | .thenThrow(new ServiceException("company service unavailable")); |
| | | |
| | | List<VinManagementExcelDTO> result = service.selectExportList(new VinManagementQueryDTO()); |
| | | |
| | | assertEquals(1, result.size()); |
| | | assertNull(result.get(0).getFleetName()); |
| | | assertNull(result.get(0).getAccountMode()); |
| | | assertNull(result.get(0).getAvailableBalance()); |
| | | } |
| | | |
| | | // ---------------- importVins ---------------- |
| | | |
| | | @Test |
| | |
| | | first.setPlateNumber(" 川A12345 "); |
| | | first.setPhone("13800138000"); |
| | | first.setCompanyName(" 公司A "); |
| | | first.setRemark(" 备注A "); |
| | | first.setStatus("启用"); |
| | | |
| | | VinManagementExcelDTO second = new VinManagementExcelDTO(); |
| | |
| | | assertEquals("LSVAM4187C2184842", saved.get(0).getVin()); |
| | | assertEquals("川A12345", saved.get(0).getPlateNumber()); |
| | | assertEquals("公司A", saved.get(0).getCompanyName()); |
| | | assertEquals("备注A", saved.get(0).getRemark()); |
| | | assertNull(saved.get(0).getRemark()); |
| | | assertEquals(Integer.valueOf(1), saved.get(0).getStatus()); |
| | | assertEquals(Integer.valueOf(2), saved.get(1).getStatus()); |
| | | assertEquals(Integer.valueOf(1), saved.get(2).getStatus()); |