购物管理添加租户ID

This commit is contained in:
2026-06-07 09:43:06 +08:00
parent 2b026cba2c
commit dd0cf8d74d
3 changed files with 40 additions and 4 deletions

View File

@@ -62,7 +62,6 @@ public class MybatisPlusConfig {
ignoreTables.add("ai_prompts"); // AI 提示词全局配置,表无 tenant_id 字段 ignoreTables.add("ai_prompts"); // AI 提示词全局配置,表无 tenant_id 字段
ignoreTables.add("lb_third_integration_config"); // 每租户一条,按 tenant_id 显式查询,不走插件自动拼接 ignoreTables.add("lb_third_integration_config"); // 每租户一条,按 tenant_id 显式查询,不走插件自动拼接
ignoreTables.add("lb_buy_account"); // 抢单账号跨租户管理;分页/批量抢单按记录 tenant_id 业务处理 ignoreTables.add("lb_buy_account"); // 抢单账号跨租户管理;分页/批量抢单按记录 tenant_id 业务处理
ignoreTables.add("lb_buyer_shopping"); // 买方购物表无 tenant_id 字段
return new TenantLineHandler() { return new TenantLineHandler() {

View File

@@ -30,6 +30,10 @@ public class LbBuyerShopping implements Serializable {
@Schema(description = "订单ID外部系统主键") @Schema(description = "订单ID外部系统主键")
private Long id; private Long id;
@TableField("tenant_id")
@Schema(description = "租户ID")
private String tenantId;
@TableField("seller_id") @TableField("seller_id")
@Schema(description = "卖家ID") @Schema(description = "卖家ID")
private Long sellerId; private Long sellerId;

View File

@@ -13,6 +13,7 @@ import com.rj.service.HxrAdminBuyerOrderSelectService;
import com.rj.service.HxrAdminUserLoginService; import com.rj.service.HxrAdminUserLoginService;
import com.rj.service.ILbBuyerShoppingService; import com.rj.service.ILbBuyerShoppingService;
import com.rj.service.ILbThirdIntegrationConfigService; import com.rj.service.ILbThirdIntegrationConfigService;
import com.rj.tenant.TenantContextHolder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
@@ -81,6 +82,13 @@ public class LbBuyerShoppingServiceImpl
return result; return result;
} }
trimStringFields(entity); trimStringFields(entity);
fillTenantIdIfAbsent(entity);
if (entity.getTenantId() == null || entity.getTenantId().isBlank()) {
result.put("success", false);
result.put("message", "tenantId不能为空");
return result;
}
entity.setTenantId(entity.getTenantId().trim());
if (this.getById(entity.getId()) != null) { if (this.getById(entity.getId()) != null) {
result.put("success", false); result.put("success", false);
result.put("message", "该订单 id 已存在"); result.put("message", "该订单 id 已存在");
@@ -133,6 +141,7 @@ public class LbBuyerShoppingServiceImpl
if (entity.getDataType() == null || entity.getDataType().isBlank()) { if (entity.getDataType() == null || entity.getDataType().isBlank()) {
entity.setDataType(existing.getDataType()); entity.setDataType(existing.getDataType());
} }
entity.setTenantId(existing.getTenantId());
boolean ok = this.updateById(entity); boolean ok = this.updateById(entity);
result.put("success", ok); result.put("success", ok);
@@ -291,8 +300,7 @@ public class LbBuyerShoppingServiceImpl
queryWrapper.le(LbBuyerShopping::getConfirmTime, confirmEnd); queryWrapper.le(LbBuyerShopping::getConfirmTime, confirmEnd);
} }
queryWrapper.orderByDesc(LbBuyerShopping::getBuyTime) queryWrapper.orderByDesc(LbBuyerShopping::getBuyTime) ;
.orderByDesc(LbBuyerShopping::getCreatedAt);
Page<LbBuyerShopping> page = this.page(new Page<>(current, size), queryWrapper); Page<LbBuyerShopping> page = this.page(new Page<>(current, size), queryWrapper);
result.put("success", true); result.put("success", true);
@@ -342,6 +350,9 @@ public class LbBuyerShoppingServiceImpl
} }
HxrUserLoginApiContext loginCtx = loginCtxOpt.get(); HxrUserLoginApiContext loginCtx = loginCtxOpt.get();
String previousTenantId = TenantContextHolder.getTenantId();
TenantContextHolder.setTenantId(tenantId);
try {
Set<String> cacheSellerPhones = new LinkedHashSet<>(); Set<String> cacheSellerPhones = new LinkedHashSet<>();
Set<String> processedMobiles = new LinkedHashSet<>(); Set<String> processedMobiles = new LinkedHashSet<>();
@@ -442,6 +453,13 @@ public class LbBuyerShoppingServiceImpl
result.put("processedMobiles", new ArrayList<>(processedMobiles)); result.put("processedMobiles", new ArrayList<>(processedMobiles));
result.put("loginApiUrl", loginCtx.loginApiUrl()); result.put("loginApiUrl", loginCtx.loginApiUrl());
return result; return result;
} finally {
if (previousTenantId != null) {
TenantContextHolder.setTenantId(previousTenantId);
} else {
TenantContextHolder.clear();
}
}
} catch (Exception e) { } catch (Exception e) {
log.error("买方购物第三方拉取异常", e); log.error("买方购物第三方拉取异常", e);
result.put("success", false); result.put("success", false);
@@ -502,7 +520,7 @@ public class LbBuyerShoppingServiceImpl
item.put("buyerOrderListUrl", orderCtx.buyerOrderListBaseUrl()); item.put("buyerOrderListUrl", orderCtx.buyerOrderListBaseUrl());
Map<String, Object> fetchResult = Map<String, Object> fetchResult =
fetchAndSaveBuyerOrders(orderCtx, mobile, sellerPhoneCollector, processedMobiles); fetchAndSaveBuyerOrders(orderCtx, tenantId, mobile, sellerPhoneCollector, processedMobiles);
item.putAll(fetchResult); item.putAll(fetchResult);
} catch (Exception e) { } catch (Exception e) {
log.warn("买方购物第三方拉取异常 mobile={} tenantId={}", mobile, tenantId, e); log.warn("买方购物第三方拉取异常 mobile={} tenantId={}", mobile, tenantId, e);
@@ -516,6 +534,7 @@ public class LbBuyerShoppingServiceImpl
private Map<String, Object> fetchAndSaveBuyerOrders( private Map<String, Object> fetchAndSaveBuyerOrders(
HxrBuyerOrderApiContext ctx, HxrBuyerOrderApiContext ctx,
String tenantId,
String loginMobile, String loginMobile,
Set<String> sellerPhoneCollector, Set<String> sellerPhoneCollector,
Set<String> processedMobiles) { Set<String> processedMobiles) {
@@ -576,6 +595,7 @@ public class LbBuyerShoppingServiceImpl
if (entity.getBuyerMobile() == null || entity.getBuyerMobile().isBlank()) { if (entity.getBuyerMobile() == null || entity.getBuyerMobile().isBlank()) {
entity.setBuyerMobile(loginMobile); entity.setBuyerMobile(loginMobile);
} }
entity.setTenantId(tenantId);
applyDefaults(entity); applyDefaults(entity);
if (entity.getCreatedAt() == null) { if (entity.getCreatedAt() == null) {
entity.setCreatedAt(LocalDateTime.now()); entity.setCreatedAt(LocalDateTime.now());
@@ -809,6 +829,7 @@ public class LbBuyerShoppingServiceImpl
} }
target.setBuyerNickname(sample.getBuyerNickname()); target.setBuyerNickname(sample.getBuyerNickname());
target.setBuyerMobile(sample.getBuyerMobile()); target.setBuyerMobile(sample.getBuyerMobile());
target.setTenantId(sample.getTenantId());
} }
private Long resolveDayStatRowId(Long buyerId, LocalDate day) { private Long resolveDayStatRowId(Long buyerId, LocalDate day) {
@@ -908,7 +929,19 @@ public class LbBuyerShoppingServiceImpl
} }
} }
private void fillTenantIdIfAbsent(LbBuyerShopping entity) {
if (entity.getTenantId() == null || entity.getTenantId().isBlank()) {
String tenantId = TenantContextHolder.getTenantId();
if (tenantId != null && !tenantId.isBlank()) {
entity.setTenantId(tenantId.trim());
}
}
}
private void trimStringFields(LbBuyerShopping entity) { private void trimStringFields(LbBuyerShopping entity) {
if (entity.getTenantId() != null) {
entity.setTenantId(entity.getTenantId().trim());
}
if (entity.getOrderSn() != null) { if (entity.getOrderSn() != null) {
entity.setOrderSn(entity.getOrderSn().trim()); entity.setOrderSn(entity.getOrderSn().trim());
} }