fix: fix performance salary calculation
Some checks failed
Build and Push Backend / docker (push) Failing after 6s

This commit is contained in:
irving
2025-10-31 21:31:56 -04:00
parent e7ccadaea0
commit 8f89955405
9 changed files with 227 additions and 61 deletions

View File

@@ -22,15 +22,18 @@ import com.starry.admin.modules.statistics.module.vo.ClerkPerformanceOverviewRes
import com.starry.admin.modules.statistics.module.vo.ClerkPerformanceOverviewSummaryVo;
import com.starry.admin.modules.statistics.module.vo.ClerkPerformanceSnapshotVo;
import com.starry.admin.modules.statistics.service.impl.PlayClerkPerformanceServiceImpl;
import com.starry.admin.modules.withdraw.mapper.EarningsLineMapper;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -55,6 +58,9 @@ class PlayClerkPerformanceServiceImplTest {
@Mock
private IPlayPersonnelGroupInfoService playPersonnelGroupInfoService;
@Mock
private EarningsLineMapper earningsLineMapper;
@InjectMocks
private PlayClerkPerformanceServiceImpl service;
@@ -89,6 +95,10 @@ class PlayClerkPerformanceServiceImplTest {
when(playOrderInfoService.clerkSelectOrderInfoList(eq("c1"), anyString(), anyString())).thenReturn(ordersA);
when(playOrderInfoService.clerkSelectOrderInfoList(eq("c2"), anyString(), anyString())).thenReturn(ordersB);
when(earningsLineMapper.sumAmountByClerkAndOrderIds(eq("c1"), anyCollection(), any(), any()))
.thenReturn(new BigDecimal("170.00"));
when(earningsLineMapper.sumAmountByClerkAndOrderIds(eq("c2"), anyCollection(), any(), any()))
.thenReturn(new BigDecimal("55.00"));
setAuthentication();
try {
@@ -109,6 +119,8 @@ class PlayClerkPerformanceServiceImplTest {
assertEquals(2, top.getContinuedOrderCount());
assertEquals(new BigDecimal("66.67"), top.getContinuedRate());
assertEquals(new BigDecimal("100.00"), top.getAverageTicketPrice());
assertEquals(new BigDecimal("170.00"), top.getEstimatedRevenue());
assertEquals(new BigDecimal("55.00"), response.getRankings().get(1).getEstimatedRevenue());
ClerkPerformanceOverviewSummaryVo summary = response.getSummary();
assertEquals(new BigDecimal("380.00"), summary.getTotalGmv());
@@ -117,6 +129,7 @@ class PlayClerkPerformanceServiceImplTest {
assertEquals(2, summary.getTotalContinuedOrderCount());
assertEquals(new BigDecimal("50.00"), summary.getContinuedRate());
assertEquals(new BigDecimal("95.00"), summary.getAverageTicketPrice());
assertEquals(new BigDecimal("225.00"), summary.getTotalEstimatedRevenue());
} finally {
clearAuthentication();
}
@@ -146,6 +159,8 @@ class PlayClerkPerformanceServiceImplTest {
withRefund(order("c1", "userB", "0", "2", "1", new BigDecimal("60.00"), new BigDecimal("30.00"),
LocalDateTime.of(2024, Month.AUGUST, 2, 18, 0)), new BigDecimal("20.00")));
when(playOrderInfoService.clerkSelectOrderInfoList(eq("c1"), anyString(), anyString())).thenReturn(orders);
when(earningsLineMapper.sumAmountByClerkAndOrderIds(eq("c1"), anyCollection(), any(), any()))
.thenReturn(new BigDecimal("110.00"));
setAuthentication();
try {
@@ -158,6 +173,7 @@ class PlayClerkPerformanceServiceImplTest {
assertEquals(3, response.getSnapshot().getOrderCount());
assertEquals(new BigDecimal("66.67"), response.getSnapshot().getContinuedRate());
assertEquals(new BigDecimal("86.67"), response.getSnapshot().getAverageTicketPrice());
assertEquals(new BigDecimal("110.00"), response.getSnapshot().getEstimatedRevenue());
assertNotNull(response.getComposition());
assertEquals(4, response.getComposition().getOrderComposition().size());
@@ -191,6 +207,30 @@ class PlayClerkPerformanceServiceImplTest {
}
}
@Test
@DisplayName("getClerkPerformanceInfo aligns earnings lookup with purchaser time")
void getClerkPerformanceInfoAlignsEarningsLookupWithPurchaserTime() {
PlayClerkUserInfoEntity clerk = buildClerk("c3", "Carol", "g3", "l3");
List<PlayOrderInfoEntity> orders = Collections.singletonList(
order("c3", "userX", "1", "0", "0", new BigDecimal("99.00"), new BigDecimal("50.00"),
LocalDateTime.of(2024, Month.AUGUST, 1, 15, 30)));
when(earningsLineMapper.sumAmountByClerkAndOrderIds(eq("c3"), anyCollection(), any(), any()))
.thenReturn(new BigDecimal("80.00"));
service.getClerkPerformanceInfo(clerk, orders, Collections.singletonList(level("l3", "钻石")),
Collections.singletonList(group("g3", "三组")), "2024-08-01", "2024-08-02");
ArgumentCaptor<Collection<String>> orderIdsCaptor = ArgumentCaptor.forClass(Collection.class);
ArgumentCaptor<String> startCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> endCaptor = ArgumentCaptor.forClass(String.class);
verify(earningsLineMapper).sumAmountByClerkAndOrderIds(eq("c3"), orderIdsCaptor.capture(),
startCaptor.capture(), endCaptor.capture());
assertTrue(orderIdsCaptor.getValue().contains(orders.get(0).getId()));
assertEquals("2024-08-01 00:00:00", startCaptor.getValue());
assertEquals("2024-08-02 23:59:59", endCaptor.getValue());
}
private PlayClerkUserInfoEntity buildClerk(String id, String name, String groupId, String levelId) {
PlayClerkUserInfoEntity entity = new PlayClerkUserInfoEntity();
entity.setId(id);
@@ -229,6 +269,7 @@ class PlayClerkPerformanceServiceImplTest {
order.setEstimatedRevenue(estimatedRevenue);
order.setOrdersExpiredState("1".equals(refundType) ? "1" : "0");
order.setPurchaserTime(purchaserTime);
order.setId(clerkId + "-" + purchaser + "-" + purchaserTime.toString());
return order;
}