|
|
@@ -52,6 +52,11 @@ import static org.mockito.Mockito.when;
|
|
|
* <p>SQL 本身的形状(净额公式逐窗口、finish_time 窗口列、占位符状态集合)由
|
|
|
* {@code LsyOrderMapperSqlTest} 用 MyBatis 真求值来钉 —— 这里 mapper 是 mock,
|
|
|
* 注解 SQL 在这个测试里**完全不可见**。
|
|
|
+ *
|
|
|
+ * <p>【企业参数不存在,是这张卡能出数的前提】乐收赢无企业维度(2026-09-30 去企业化后
|
|
|
+ * 新单 enterprise_id 恒 NULL)⇒ 服务层签名里就没有 enterpriseId,只透传 tenantId
|
|
|
+ * (见 {@link #乐收赢统计_租户参数仍然透传()})。谁把企业筛选加回来,
|
|
|
+ * {@code LsyOrderMapperSqlTest.企业条件传了也不出现} 会红。
|
|
|
*/
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
class AccountServiceStatTest {
|
|
|
@@ -83,13 +88,13 @@ class AccountServiceStatTest {
|
|
|
/** 库里是分,卡片上是元:12345 分 = 123.45 元;整百分位保留两位(100000 分 = 1000.00 元)。 */
|
|
|
@Test
|
|
|
void 乐收赢统计_分转元并保留两位() {
|
|
|
- when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any(), any()))
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any()))
|
|
|
.thenReturn(Map.of(
|
|
|
"amount_of_today", new BigDecimal("12345"),
|
|
|
"amount_of_7days", new BigDecimal("100000"),
|
|
|
"amount_of_all", new BigDecimal("0")));
|
|
|
|
|
|
- Map<String, String> r = service.statLsyCollectedAmount(null, null);
|
|
|
+ Map<String, String> r = service.statLsyCollectedAmount(null);
|
|
|
|
|
|
assertEquals("123.45", r.get("amount_of_today"));
|
|
|
assertEquals("1000.00", r.get("amount_of_7days"));
|
|
|
@@ -99,10 +104,10 @@ class AccountServiceStatTest {
|
|
|
/** 空表 / 键缺失时是 0.00 而不是 null 或异常 —— 首页任何一块统计都不该让整页报错。 */
|
|
|
@Test
|
|
|
void 乐收赢统计_键缺失时按零() {
|
|
|
- when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any(), any()))
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any()))
|
|
|
.thenReturn(Map.of("amount_of_all", new BigDecimal("250")));
|
|
|
|
|
|
- Map<String, String> r = service.statLsyCollectedAmount(null, null);
|
|
|
+ Map<String, String> r = service.statLsyCollectedAmount(null);
|
|
|
|
|
|
assertEquals("0.00", r.get("amount_of_today"));
|
|
|
assertEquals("0.00", r.get("amount_of_7days"));
|
|
|
@@ -115,30 +120,48 @@ class AccountServiceStatTest {
|
|
|
*/
|
|
|
@Test
|
|
|
void 乐收赢统计_状态集合取自PAY_RECORDED() {
|
|
|
- when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any(), any()))
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any()))
|
|
|
.thenReturn(Map.of("amount_of_today", BigDecimal.ZERO,
|
|
|
"amount_of_7days", BigDecimal.ZERO, "amount_of_all", BigDecimal.ZERO));
|
|
|
|
|
|
- service.statLsyCollectedAmount(null, null);
|
|
|
+ service.statLsyCollectedAmount(null);
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
ArgumentCaptor<Collection<String>> captor = ArgumentCaptor.forClass(Collection.class);
|
|
|
- verify(lsyOrderMapper).statCollectedAmount(isNull(), isNull(), captor.capture(), any(), any());
|
|
|
+ verify(lsyOrderMapper).statCollectedAmount(isNull(), captor.capture(), any(), any());
|
|
|
assertEquals(Set.copyOf(LsyOrderStatus.PAY_RECORDED), Set.copyOf(captor.getValue()));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 租户参数**照旧透传**(正面控制)—— 去掉企业筛选时不能顺手把租户筛也去掉:
|
|
|
+ * 这条与 {@code LsyOrderMapperSqlTest} 的「企业条件传了也不出现」是一对,
|
|
|
+ * 一个钉「不许少」,一个钉「不许多」。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void 乐收赢统计_租户参数仍然透传() {
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any()))
|
|
|
+ .thenReturn(Map.of("amount_of_today", BigDecimal.ZERO,
|
|
|
+ "amount_of_7days", BigDecimal.ZERO, "amount_of_all", BigDecimal.ZERO));
|
|
|
+
|
|
|
+ service.statLsyCollectedAmount(7L);
|
|
|
+
|
|
|
+ ArgumentCaptor<Long> tenant = ArgumentCaptor.forClass(Long.class);
|
|
|
+ verify(lsyOrderMapper).statCollectedAmount(tenant.capture(), any(), any(), any());
|
|
|
+ assertEquals(7L, tenant.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
/** 时间窗:北京时间当日零点起的「今日」,近 7 日 = 今日减 7 天(与另外三块统计同一口径)。 */
|
|
|
@Test
|
|
|
void 乐收赢统计_时间窗是北京时间当日零点() {
|
|
|
- when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any(), any()))
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any()))
|
|
|
.thenReturn(Map.of("amount_of_today", BigDecimal.ZERO,
|
|
|
"amount_of_7days", BigDecimal.ZERO, "amount_of_all", BigDecimal.ZERO));
|
|
|
|
|
|
- service.statLsyCollectedAmount(null, null);
|
|
|
+ service.statLsyCollectedAmount(null);
|
|
|
|
|
|
ArgumentCaptor<OffsetDateTime> today = ArgumentCaptor.forClass(OffsetDateTime.class);
|
|
|
ArgumentCaptor<OffsetDateTime> weekAgo = ArgumentCaptor.forClass(OffsetDateTime.class);
|
|
|
- verify(lsyOrderMapper).statCollectedAmount(isNull(), isNull(), any(),
|
|
|
+ verify(lsyOrderMapper).statCollectedAmount(isNull(), any(),
|
|
|
today.capture(), weekAgo.capture());
|
|
|
assertEquals(ZoneOffset.ofHours(8), today.getValue().getOffset());
|
|
|
assertEquals(0, today.getValue().getHour());
|
|
|
@@ -165,7 +188,7 @@ class AccountServiceStatTest {
|
|
|
"amount_of_today", new BigDecimal("50"),
|
|
|
"amount_of_7days", new BigDecimal("60"),
|
|
|
"amount_of_all", new BigDecimal("70")));
|
|
|
- when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any(), any())).thenReturn(Map.of(
|
|
|
+ when(lsyOrderMapper.statCollectedAmount(any(), any(), any(), any())).thenReturn(Map.of(
|
|
|
"amount_of_today", new BigDecimal("2500"),
|
|
|
"amount_of_7days", new BigDecimal("3000"),
|
|
|
"amount_of_all", new BigDecimal("4000")));
|