| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.dto.SixCircleDto; |
| | | import com.ruoyi.order.mapper.TChargingOrderMapper; |
| | | import com.ruoyi.order.dto.SixChargingDto; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private TChargingOrderServiceImpl service; |
| | | private TChargingOrderMapper mapper; |
| | | private List<Integer> siteIds; |
| | | private LocalDate sixBefore; |
| | | |
| | | @BeforeEach |
| | | void setUp() { |
| | |
| | | siteIds = new ArrayList<>(); |
| | | siteIds.add(122); |
| | | siteIds.add(123); |
| | | sixBefore = LocalDate.of(2026, 1, 1); |
| | | ReflectionTestUtils.setField(service, "baseMapper", mapper); |
| | | } |
| | | |
| | |
| | | void platformViewAddsSuccessfulPartnerShareAmount() { |
| | | Map<String, Object> totals = new HashMap<>(); |
| | | totals.put("electrovalence", new BigDecimal("100.00")); |
| | | when(mapper.countAll(siteIds, false)).thenReturn(totals); |
| | | when(mapper.sumSuccessfulShareAmount(siteIds)).thenReturn(new BigDecimal("12.34")); |
| | | when(mapper.countAll(siteIds, false, sixBefore)).thenReturn(totals); |
| | | when(mapper.sumSuccessfulShareAmount(siteIds, sixBefore)).thenReturn(new BigDecimal("12.34")); |
| | | |
| | | Map<String, Object> result = service.countAll(siteIds, false); |
| | | Map<String, Object> result = service.countAll(siteIds, false, sixBefore); |
| | | |
| | | assertSame(totals, result); |
| | | assertEquals(new BigDecimal("12.34"), result.get("commission_amount")); |
| | | verify(mapper).sumSuccessfulShareAmount(siteIds); |
| | | verify(mapper).sumSuccessfulShareAmount(siteIds, sixBefore); |
| | | } |
| | | |
| | | @Test |
| | | void partnerViewUsesShareRecordTotalsWithoutASecondQuery() { |
| | | Map<String, Object> totals = new HashMap<>(); |
| | | totals.put("commission_amount", new BigDecimal("8.90")); |
| | | when(mapper.countAll(siteIds, true)).thenReturn(totals); |
| | | when(mapper.countAll(siteIds, true, sixBefore)).thenReturn(totals); |
| | | |
| | | Map<String, Object> result = service.countAll(siteIds, true); |
| | | Map<String, Object> result = service.countAll(siteIds, true, sixBefore); |
| | | |
| | | assertSame(totals, result); |
| | | assertEquals(new BigDecimal("8.90"), result.get("commission_amount")); |
| | | verify(mapper, never()).sumSuccessfulShareAmount(siteIds); |
| | | verify(mapper, never()).sumSuccessfulShareAmount(siteIds, sixBefore); |
| | | } |
| | | |
| | | @Test |
| | | void chargeSplitsSettlementAndCurrentMonthQueriesForMycatCompatibility() { |
| | | SixChargingDto settlement = new SixChargingDto(); |
| | | settlement.setMonth("6"); |
| | | settlement.setElectrovalence(new BigDecimal("1.234")); |
| | | settlement.setServiceCharge(new BigDecimal("2.345")); |
| | | SixChargingDto currentMonth = new SixChargingDto(); |
| | | currentMonth.setMonth("7"); |
| | | currentMonth.setElectrovalence(new BigDecimal("3.456")); |
| | | currentMonth.setServiceCharge(new BigDecimal("4.567")); |
| | | when(mapper.chargeSettlement("2026-01-01", siteIds)).thenReturn(Arrays.asList(settlement)); |
| | | when(mapper.chargeCurrentMonth("122,123")).thenReturn(Arrays.asList(currentMonth)); |
| | | |
| | | List<SixChargingDto> result = service.charge(LocalDate.of(2026, 1, 1), siteIds, false); |
| | | |
| | | assertEquals(2, result.size()); |
| | | assertEquals("06", result.get(0).getMonth()); |
| | | assertEquals(new BigDecimal("1.23"), result.get(0).getElectrovalence()); |
| | | assertEquals(new BigDecimal("2.35"), result.get(0).getServiceCharge()); |
| | | assertEquals("07", result.get(1).getMonth()); |
| | | assertEquals(new BigDecimal("3.46"), result.get(1).getElectrovalence()); |
| | | assertEquals(new BigDecimal("4.57"), result.get(1).getServiceCharge()); |
| | | verify(mapper).chargeCurrentMonth("122,123"); |
| | | } |
| | | |
| | | @Test |
| | | void chargePartnerUsesOnlyShareRecordQuery() { |
| | | SixChargingDto item = new SixChargingDto(); |
| | | item.setMonth("7"); |
| | | when(mapper.chargePartner("2026-01-01", siteIds)).thenReturn(Arrays.asList(item)); |
| | | |
| | | List<SixChargingDto> result = service.charge(LocalDate.of(2026, 1, 1), siteIds, true); |
| | | |
| | | assertEquals("07", result.get(0).getMonth()); |
| | | verify(mapper, never()).chargeSettlement("2026-01-01", siteIds); |
| | | verify(mapper, never()).chargeCurrentMonth("122,123"); |
| | | } |
| | | |
| | | @Test |
| | | void circleRoundsMapperTotalsInJavaForMycatCompatibility() { |
| | | SixCircleDto item = new SixCircleDto(); |
| | | item.setPaymentAmount(new BigDecimal("12.345")); |
| | | when(mapper.circle(siteIds, LocalDate.of(2026, 1, 1), false)).thenReturn(Arrays.asList(item)); |
| | | |
| | | List<SixCircleDto> result = service.circle(siteIds, LocalDate.of(2026, 1, 1), false); |
| | | |
| | | assertEquals(new BigDecimal("12.35"), result.get(0).getPaymentAmount()); |
| | | } |
| | | |
| | | @Test |
| | | void incomeCircleFallsBackWhenLegacyThirdPaySplitAmountIsZero() { |
| | | TChargingOrder order = new TChargingOrder(); |
| | | order.setPayMethod(3); |
| | | order.setThirdPayAmount(BigDecimal.ZERO); |
| | | order.setPaymentAmount(new BigDecimal("26.80")); |
| | | order.setThirdRefundAmount(BigDecimal.ZERO); |
| | | |
| | | BigDecimal amount = ReflectionTestUtils.invokeMethod(service, "getThirdPayNetAmount", order); |
| | | |
| | | assertEquals(new BigDecimal("26.80"), amount); |
| | | } |
| | | |
| | | @Test |
| | | void incomeCircleFallsBackWhenLegacyBalanceSplitAmountIsZero() { |
| | | TChargingOrder order = new TChargingOrder(); |
| | | order.setPayMethod(1); |
| | | order.setBalancePayAmount(BigDecimal.ZERO); |
| | | order.setPaymentAmount(new BigDecimal("18.60")); |
| | | order.setBalanceRefundAmount(BigDecimal.ZERO); |
| | | |
| | | BigDecimal amount = ReflectionTestUtils.invokeMethod(service, "getBalancePayNetAmount", order); |
| | | |
| | | assertEquals(new BigDecimal("18.60"), amount); |
| | | } |
| | | } |