## 全网产品库存同步;
This commit is contained in:
parent
0b71fbbc5b
commit
3979aaffc2
|
@ -1,15 +1,20 @@
|
|||
package com.hzs.retail.sale.controller.service.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64Encoder;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.hzs.common.core.config.BdConfig;
|
||||
import com.hzs.common.core.constant.*;
|
||||
import com.hzs.common.core.domain.R;
|
||||
import com.hzs.common.core.enums.*;
|
||||
import com.hzs.common.core.exception.ServiceException;
|
||||
import com.hzs.common.core.service.RedisService;
|
||||
import com.hzs.common.core.utils.*;
|
||||
import com.hzs.common.core.web.domain.AjaxResult;
|
||||
import com.hzs.common.domain.member.account.CuMemberAccount;
|
||||
import com.hzs.common.domain.member.base.CuMember;
|
||||
import com.hzs.common.domain.member.ext.CuMemberAccountExt;
|
||||
|
@ -17,6 +22,7 @@ import com.hzs.common.domain.sale.ext.BdWaresDetailExt;
|
|||
import com.hzs.common.domain.sale.ext.SaOrderExt;
|
||||
import com.hzs.common.domain.sale.ext.SaOrderWaresLimitExt;
|
||||
import com.hzs.common.domain.sale.order.*;
|
||||
import com.hzs.common.domain.sale.product.BdProduct;
|
||||
import com.hzs.common.domain.sale.wares.BdWaresRange;
|
||||
import com.hzs.common.domain.system.base.BdStorehouse;
|
||||
import com.hzs.common.domain.system.config.BdAwards;
|
||||
|
@ -34,6 +40,7 @@ import com.hzs.sale.order.param.OrderItemsParam;
|
|||
import com.hzs.sale.order.param.WaresNumberParam;
|
||||
import com.hzs.sale.order.service.*;
|
||||
import com.hzs.sale.order.service.impl.SaOrderHandle;
|
||||
import com.hzs.sale.product.service.IBdProductService;
|
||||
import com.hzs.sale.wares.service.IBdWaresDetailService;
|
||||
import com.hzs.sale.wares.service.IBdWaresExtendService;
|
||||
import com.hzs.sale.wares.service.IBdWaresRangeService;
|
||||
|
@ -84,6 +91,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
|||
private ISaOrderTempService iSaOrderTempService;
|
||||
@Autowired
|
||||
private ISaOrderWaresLimitService iSaOrderWaresLimitService;
|
||||
@Autowired
|
||||
private IBdProductService iBdProductService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
@ -704,6 +713,9 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
|||
*/
|
||||
private void pushOrderMq(SaOrderExt saOrderExt) {
|
||||
try {
|
||||
// 同步全网产品库存
|
||||
this.allProductSync(saOrderExt);
|
||||
|
||||
if (EOrderType.RETAIL_REGISTER.getValue() == saOrderExt.getOrderType()
|
||||
|| EOrderType.RETAIL_UPGRADE.getValue() == saOrderExt.getOrderType()
|
||||
|| EOrderType.RETAIL_REPURCHASE.getValue() == saOrderExt.getOrderType()
|
||||
|
@ -723,8 +735,6 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
|||
@Override
|
||||
public String onlinePaymentCallBack(Long pkMember, String orderCode) {
|
||||
String resultStr;
|
||||
// 临时订单信息
|
||||
SaOrderTemp saOrderTemp = null;
|
||||
|
||||
// 获取缓存订单
|
||||
SaOrderExt saOrderExt = redisService.getCacheObject(CacheConstants.RETAIL_TEMP_ORDER + pkMember + orderCode);
|
||||
|
@ -1045,4 +1055,53 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步全网产品库存
|
||||
*
|
||||
* @param saOrderExt
|
||||
*/
|
||||
private void allProductSync(SaOrderExt saOrderExt) {
|
||||
if (EYesNo.NO.getIntValue() == BdConfig.getProductSync()) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, BdProduct> productMap = iBdProductService.queryProductMap(saOrderExt.getOrderItemsList().stream().map(SaOrderItems::getPkProduct).collect(Collectors.toSet()), null);
|
||||
// 开启线程调用全网产品库存
|
||||
// 请求参数
|
||||
Map<String, Object> bodyMap = new HashMap<>();
|
||||
bodyMap.put("source", BdConfig.getSysName());
|
||||
bodyMap.put("orderCode", saOrderExt.getOrderCode());
|
||||
List<Map<String, Object>> bodyDetailList = new ArrayList<>();
|
||||
for (SaOrderItems saOrderItems : saOrderExt.getOrderItemsList()) {
|
||||
Map<String, Object> detailMap = new HashMap<>();
|
||||
detailMap.put("wmsCode", productMap.get(saOrderItems.getPkProduct()).getWmsCode());
|
||||
detailMap.put("changeNum", saOrderItems.getQuantity());
|
||||
bodyDetailList.add(detailMap);
|
||||
}
|
||||
bodyMap.put("detailList", bodyDetailList);
|
||||
// 请求头
|
||||
String header = Base64Encoder.encode(BdConfig.getSysName() + "!" + saOrderExt.getOrderCode());
|
||||
ThreadUtils.threadPoolExecutor.submit(() -> {
|
||||
log.info("同步产品,header: {}", header);
|
||||
log.info("同步产品,bodyMap: {}", bodyMap);
|
||||
HttpRequest httpRequest = HttpUtil.createPost(BdConfig.getProductSyncUrl());
|
||||
httpRequest.header("authorization", header);
|
||||
httpRequest.body(JSONUtil.toJsonStr(bodyMap));
|
||||
httpRequest.setReadTimeout(5000);
|
||||
String resultStr;
|
||||
try {
|
||||
resultStr = httpRequest.execute().body();
|
||||
AjaxResult ajaxResult = JSONUtil.toBean(resultStr, AjaxResult.class);
|
||||
log.info("同步产品,resultStr: {}", resultStr);
|
||||
if (!ajaxResult.isSuccess()) {
|
||||
resultStr = httpRequest.execute().body();
|
||||
log.info("同步产品失败重试,resultStr: {}", resultStr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("同步产品库存失败", e);
|
||||
resultStr = httpRequest.execute().body();
|
||||
log.info("同步产品异常重试,resultStr: {}", resultStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ import org.springframework.stereotype.Component;
|
|||
@ConfigurationProperties(prefix = "bd")
|
||||
public class BdConfig {
|
||||
|
||||
/**
|
||||
* 系统名称(ESysName)
|
||||
*/
|
||||
private static String sysName;
|
||||
|
||||
/**
|
||||
* 当前环境
|
||||
*/
|
||||
|
@ -34,6 +39,23 @@ public class BdConfig {
|
|||
|
||||
private static Integer enable;
|
||||
|
||||
/**
|
||||
* 商品同步是否开启(0=开启,1=不开启)
|
||||
*/
|
||||
private static Integer productSync;
|
||||
/**
|
||||
* 商品同步地址
|
||||
*/
|
||||
private static String productSyncUrl;
|
||||
|
||||
public static String getSysName() {
|
||||
return sysName;
|
||||
}
|
||||
|
||||
public void setSysName(String sysName) {
|
||||
BdConfig.sysName = sysName;
|
||||
}
|
||||
|
||||
public static String getEnv() {
|
||||
return env;
|
||||
}
|
||||
|
@ -81,4 +103,22 @@ public class BdConfig {
|
|||
public void setEnable(Integer enable) {
|
||||
BdConfig.enable = enable;
|
||||
}
|
||||
|
||||
|
||||
public static Integer getProductSync() {
|
||||
return productSync;
|
||||
}
|
||||
|
||||
public void setProductSync(Integer productSync) {
|
||||
BdConfig.productSync = productSync;
|
||||
}
|
||||
|
||||
public static String getProductSyncUrl() {
|
||||
return productSyncUrl;
|
||||
}
|
||||
|
||||
public void setProductSyncUrl(String productSyncUrl) {
|
||||
BdConfig.productSyncUrl = productSyncUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ import lombok.experimental.Accessors;
|
|||
|
||||
/**
|
||||
* 订单缓存数据临时表
|
||||
*
|
||||
* @author hzs
|
||||
* @since 2025-02-25
|
||||
*/
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
|
|
Loading…
Reference in New Issue