配置迁移到表
This commit is contained in:
@@ -3,6 +3,7 @@ package com.rj.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.dto.hxr.HxrGoodsApiContext;
|
||||
import com.rj.dto.hxr.HxrLbGoodsPageData;
|
||||
import com.rj.dto.hxr.HxrLbGoodsSelectResponse;
|
||||
import com.rj.entity.LbGoods;
|
||||
@@ -10,6 +11,7 @@ import com.rj.mapper.LbGoodsMapper;
|
||||
import com.rj.service.HxrAdminBuyService;
|
||||
import com.rj.service.HxrAdminGoodsService;
|
||||
import com.rj.service.ILbGoodsService;
|
||||
import com.rj.service.ILbThirdIntegrationConfigService;
|
||||
import com.rj.tenant.TenantContextHolder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -40,6 +42,8 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
|
||||
private final HxrAdminBuyService hxrAdminBuyService;
|
||||
|
||||
private final ILbThirdIntegrationConfigService lbThirdIntegrationConfigService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(LbGoods entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -260,6 +264,17 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
}
|
||||
|
||||
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("synced", 0);
|
||||
return result;
|
||||
}
|
||||
HxrGoodsApiContext apiContext = apiContextOpt.get();
|
||||
|
||||
String previousTenantId = TenantContextHolder.getTenantId();
|
||||
TenantContextHolder.setTenantId(tid);
|
||||
try {
|
||||
@@ -268,11 +283,12 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
int totalSynced = 0;
|
||||
while (true) {
|
||||
Optional<HxrLbGoodsSelectResponse> opt =
|
||||
hxrAdminGoodsService.fetchGoodsPage(page, token);
|
||||
hxrAdminGoodsService.fetchGoodsPage(page, apiContext);
|
||||
if (opt.isEmpty()) {
|
||||
if (page == 1) {
|
||||
result.put("success", false);
|
||||
result.put("message", "未拉取到货品(请检查 hxr.admin.goods-api-token、goods-api-app-str 或网络)");
|
||||
result.put("message",
|
||||
"未拉取到货品(请检查 lb_third_integration_config 中 token、appStr、URL 或网络)");
|
||||
result.put("synced", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.common.LbThirdIntegrationConstants;
|
||||
import com.rj.common.PasswordUtil;
|
||||
import com.rj.dto.LbThirdIntegrationCredentialUpdateRequest;
|
||||
import com.rj.dto.hxr.HxrGoodsApiContext;
|
||||
import com.rj.entity.LbThirdIntegrationConfig;
|
||||
import com.rj.mapper.LbThirdIntegrationConfigMapper;
|
||||
import com.rj.service.ILbThirdIntegrationConfigService;
|
||||
import com.rj.util.LbThirdIntegrationConfigUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -18,6 +20,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -306,6 +309,40 @@ public class LbThirdIntegrationConfigServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HxrGoodsApiContext> resolveGoodsApiContext(String tenantId, String tokenOverride) {
|
||||
if (!StringUtils.hasText(tenantId)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
LbThirdIntegrationConfig config = getByTenantIdOrNull(tenantId.trim());
|
||||
if (config == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (config.getEnabled() == null || config.getEnabled() != 1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String token = StringUtils.hasText(tokenOverride)
|
||||
? tokenOverride.trim()
|
||||
: decryptFromBytes(config.getGoodsApiTokenCipher());
|
||||
String appStr = decryptFromBytes(config.getGoodsApiAppStrCipher());
|
||||
if (!StringUtils.hasText(token) || !StringUtils.hasText(appStr)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
return Optional.of(new HxrGoodsApiContext(
|
||||
LbThirdIntegrationConfigUtil.resolveGoodsApiBaseUrl(config),
|
||||
LbThirdIntegrationConfigUtil.resolveGoodsPageLimit(config),
|
||||
LbThirdIntegrationConfigUtil.resolveGoodsApiOrigin(config),
|
||||
LbThirdIntegrationConfigUtil.resolveGoodsApiReferer(config),
|
||||
token.trim(),
|
||||
appStr.trim()));
|
||||
} catch (IllegalStateException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private LbThirdIntegrationConfig getByTenantIdOrNull(String tenantId) {
|
||||
return this.getOne(new LambdaQueryWrapper<LbThirdIntegrationConfig>()
|
||||
.eq(LbThirdIntegrationConfig::getTenantId, tenantId)
|
||||
|
||||
Reference in New Issue
Block a user