新增下单库存预警消息推送
This commit is contained in:
@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -64,10 +65,19 @@ public class OrderService {
|
||||
@Autowired
|
||||
RabbitProducer producer;
|
||||
|
||||
private final WechatUtil wechatUtil;
|
||||
|
||||
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
|
||||
|
||||
private static ConcurrentHashMap<String, HashSet<Integer>> codeMap = new ConcurrentHashMap<>();
|
||||
private static ConcurrentHashMap<String, HashSet<String>> userMap = new ConcurrentHashMap<>();
|
||||
|
||||
public OrderService(WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper) {
|
||||
this.wechatUtil = wechatUtil;
|
||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number,
|
||||
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type) {
|
||||
@@ -220,10 +230,39 @@ public class OrderService {
|
||||
jsonObject.put("cartId",cart.getId());
|
||||
jsonObject.put("type","create");
|
||||
producer.cons(jsonObject.toString());
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(skuWithBLOBs, product, shopInfo));
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, masterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品库存警戒线并通知商户
|
||||
* @param productSku sku
|
||||
*/
|
||||
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, TbShopInfo shopInfo) {
|
||||
if (productSku.getWarnLine() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (productSku.getStockNumber() == null) {
|
||||
productSku.setStockNumber((double) 0);
|
||||
}
|
||||
|
||||
if (product.getStockNumber() == null) {
|
||||
product.setStockNumber(0);
|
||||
}
|
||||
if (
|
||||
(product.getIsDistribute() == 1 && productSku.getStockNumber() <= productSku.getWarnLine())
|
||||
|| (product.getIsDistribute() != 1) && product.getStockNumber() <= productSku.getWarnLine()
|
||||
) {
|
||||
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByShopId(productSku.getShopId());
|
||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
||||
product.getIsDistribute() == 1 ? productSku.getStockNumber().toString() : product.getStockNumber().toString(),
|
||||
"耗材库存不足,请及时补充。", tbUserShopMsg.getOpenId());
|
||||
}
|
||||
}
|
||||
|
||||
public Result queryCart(String masterId, String shopId) {
|
||||
if (StringUtils.isEmpty(shopId)) {
|
||||
return Result.fail(CodeEnum.SHOPINFONOEXIST);
|
||||
|
||||
Reference in New Issue
Block a user