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