抢购配置读取从表

This commit is contained in:
2026-05-31 07:56:33 +08:00
parent 76297caa81
commit e3e47dab48
9 changed files with 102 additions and 10 deletions

View File

@@ -399,16 +399,39 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
}
@Override
public Map<String, Object> rushBuy(String token, Integer maxBuyCount) {
public Map<String, Object> rushBuy(String tenantId, String token, Integer maxBuyCount) {
Map<String, Object> result = new HashMap<>();
try {
if (tenantId == null || tenantId.trim().isEmpty()) {
result.put("success", false);
result.put("message", "tenantId不能为空");
return result;
}
if (maxBuyCount == null || maxBuyCount <= 0) {
result.put("success", false);
result.put("message", "maxBuyCount必须大于0");
return result;
}
String tid = tenantId.trim();
Optional<HxrGoodsApiContext> apiContextOpt =
lbThirdIntegrationConfigService.resolveGoodsApiContext(tid, token);
if (apiContextOpt.isEmpty()) {
result.put("success", false);
result.put("message",
"未找到该租户的第三方集成配置或配置未启用、URL/凭证不完整(请检查 lb_third_integration_config");
result.put("successCount", 0);
result.put("failCount", 0);
result.put("details", List.of());
return result;
}
HxrGoodsApiContext apiContext = apiContextOpt.get();
String previousTenantId = TenantContextHolder.getTenantId();
TenantContextHolder.setTenantId(tid);
try {
LambdaQueryWrapper<LbGoods> w = new LambdaQueryWrapper<>();
w.eq(LbGoods::getTenantId, tid);
w.isNotNull(LbGoods::getSellerId);
w.lt(LbGoods::getTotalMoney, RUSH_BUY_MAX_TOTAL_MONEY);
w.orderByDesc(LbGoods::getTotalMoney).orderByDesc(LbGoods::getId);
@@ -451,7 +474,7 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
item.put("totalMoney", goods.getTotalMoney());
log.info("正在抢购货品是:{}",item.toString());
HxrAdminBuyService.BuyApiResult buyResult =
hxrAdminBuyService.buy(goods.getId(), goods.getSellerId(), token);
hxrAdminBuyService.buy(goods.getId(), goods.getSellerId(), apiContext);
item.put("apiCode", buyResult.apiCode());
item.put("message", buyResult.apiMsg());
item.put("success", buyResult.success());
@@ -476,6 +499,13 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
result.put("stoppedByMaxAttempts", stoppedByMaxAttempts);
result.put("details", details);
return result;
} finally {
if (previousTenantId != null) {
TenantContextHolder.setTenantId(previousTenantId);
} else {
TenantContextHolder.clear();
}
}
} catch (Exception e) {
log.error("rushBuy failed", e);
result.put("success", false);

View File

@@ -330,6 +330,7 @@ public class LbThirdIntegrationConfigServiceImpl
try {
return Optional.of(new HxrGoodsApiContext(
LbThirdIntegrationConfigUtil.resolveGoodsApiBaseUrl(config),
LbThirdIntegrationConfigUtil.resolveBuyApiUrl(config),
LbThirdIntegrationConfigUtil.resolveGoodsPageLimit(config),
LbThirdIntegrationConfigUtil.resolveGoodsApiOrigin(config),
LbThirdIntegrationConfigUtil.resolveGoodsApiReferer(config),