ReconciliationRulePublishRealDataTest.java
5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.youjia.store.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youjia.store.entity.StoreListing;
import com.youjia.store.entity.StoreListingItem;
import com.youjia.store.mapper.StoreListingItemMapper;
import com.youjia.store.mapper.StoreListingMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.util.List;
/**
* 对账规则发布集成测试:<b>按 listingId 查库取真实数据</b>,触发向 D+(嘀加)发布对账规则。
*
* <p><b>不使用 mock 数据</b>:门店上架主表与明细表均从 dev 库读取真实记录,
* 便于按真实数据核对发布报文。</p>
*
* <p>用法:修改下面的 {@link #LISTING_ID} 为目标门店上架记录ID 后执行即可。</p>
*
* <p><b>⚠️ 本测试会真实调用 D+ 接口并写入对账规则表,请在测试环境执行,勿在生产库使用。</b></p>
*
* <p>数据源走 Nacos(见 {@code application-dev.yml}),需保证 dev 配置可用。</p>
*/
@Slf4j
@DisplayName("对账规则发布(真实数据)")
@SpringBootTest
@ActiveProfiles("dev")
class ReconciliationRulePublishRealDataTest {
/** 待发布的门店上架记录ID,可按需修改 */
private static final Long LISTING_ID = 26L;
/** 操作人,写入对账规则的 updatedBy */
private static final String OPERATOR = "zhoulm";
@Autowired
private StoreListingMapper storeListingMapper;
@Autowired
private StoreListingItemMapper storeListingItemMapper;
@Autowired
private ReconciliationRulePublishService reconciliationRulePublishService;
/**
* 查询门店上架主表。
*/
private StoreListing loadListing(Long listingId) {
StoreListing listing = storeListingMapper.selectOne(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getListingId, listingId)
.eq(StoreListing::getIsDeleted, 0));
if (listing == null) {
throw new IllegalStateException("门店上架记录不存在,listingId=" + listingId);
}
return listing;
}
/**
* 查询门店上架明细(过滤逻辑删除)。
*/
private List<StoreListingItem> loadItems(Long listingId) {
return storeListingItemMapper.selectList(new LambdaQueryWrapper<StoreListingItem>()
.eq(StoreListingItem::getListingId, listingId)
.eq(StoreListingItem::getIsDeleted, 0));
}
@Test
@DisplayName("按 listingId 查库并发布对账规则")
void publishByListingId() {
StoreListing listing = loadListing(LISTING_ID);
List<StoreListingItem> items = loadItems(LISTING_ID);
log.info("门店上架信息: listingId={}, merchantNo={}, storeName={}, businessSceneCode={}, 明细行数={}",
listing.getListingId(), listing.getMerchantNo(), listing.getStoreName(),
listing.getBusinessSceneCode(), items.size());
for (StoreListingItem item : items) {
log.info("明细: itemId={}, 品类={}({}), 市场费1={}/{}/{}, 市场费2={}/{}/{}, "
+ "阳光1={}/{}/{}(线上积分={}), 阳光2={}/{}/{}(线上积分={})",
item.getItemId(), item.getProductCategory(), item.getProductCategoryId(),
item.getMarketFee1Value(), item.getMarketFee1CalcWay(), item.getMarketFee1CalcMode(),
item.getMarketFee2Value(), item.getMarketFee2CalcWay(), item.getMarketFee2CalcMode(),
item.getSunshine1Value(), item.getSunshine1CalcWay(), item.getSunshine1CalcMode(),
item.getSunshine1OnlinePoint(),
item.getSunshine2Value(), item.getSunshine2CalcWay(), item.getSunshine2CalcMode(),
item.getSunshine2OnlinePoint());
}
boolean published = reconciliationRulePublishService.publish(listing, items, OPERATOR);
log.info("对账规则发布结果: published={}, listingId={}, merchantNo={}, businessSceneCode={}",
published, listing.getListingId(), listing.getMerchantNo(), listing.getBusinessSceneCode());
}
@Test
@DisplayName("门店上架记录不存在时抛出明确异常")
void publishWithNonExistListing() {
Long notExistId = -999999L;
StoreListing listing = storeListingMapper.selectOne(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getListingId, notExistId)
.eq(StoreListing::getIsDeleted, 0));
if (listing != null) {
throw new IllegalStateException("测试数据异常:listingId=" + notExistId + " 竟然存在");
}
List<StoreListingItem> items = loadItems(notExistId);
if (!items.isEmpty()) {
throw new IllegalStateException("测试数据异常:listingId=" + notExistId + " 竟然有明细");
}
log.info("确认 listingId={} 不存在,测试前置条件成立", notExistId);
}
}