库存警戒线

This commit is contained in:
2024-10-08 11:29:06 +08:00
parent 011273f123
commit b57aa1d4c4
5 changed files with 166 additions and 184 deletions

View File

@@ -140,6 +140,9 @@ public class TbProduct implements Serializable {
//是否可售 1 可售 0非可售
private Integer isSale = 1;
private Integer warnLine = 0;
public String getImages() {
return images;
@@ -683,4 +686,12 @@ public class TbProduct implements Serializable {
public void setIsSale(Integer isSale) {
this.isSale = isSale;
}
public Integer getWarnLine() {
return warnLine;
}
public void setWarnLine(Integer warnLine) {
this.warnLine = warnLine;
}
}

View File

@@ -32,7 +32,6 @@ public class TbProductSku implements Serializable {
private String coverImg;
private Integer warnLine;
private Double weight;
@@ -175,14 +174,6 @@ public class TbProductSku implements Serializable {
this.coverImg = coverImg == null ? null : coverImg.trim();
}
public Integer getWarnLine() {
return warnLine;
}
public void setWarnLine(Integer warnLine) {
this.warnLine = warnLine;
}
public Double getWeight() {
return weight;
}

View File

@@ -329,22 +329,9 @@ public class CartService {
* @param num 库存数
*/
private void updateProductStock(TbProduct product, TbProductSkuWithBLOBs productSku, Integer num) {
String key = RedisCst.PRODUCT + product.getShopId() + ":product" + product.getId();
double stock = num;
if (product.getIsDistribute() == 1) {
productMapper.updateStockById(product.getId().toString(), num);
stock = (double) (product.getStockNumber() - num);
} else {
key = RedisCst.PRODUCT + product.getShopId() + ":" + productSku.getId();
productSkuMapper.updateStockById(productSku.getId().toString(), num);
stock = productSku.getStockNumber() - num;
}
if (num > 0) {
redisUtil.getIncrNum(key, "1");
} else {
redisUtil.getIncrNum(key, "2");
}
productMapper.updateStockById(product.getId().toString(), num);
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, num));
@@ -356,7 +343,7 @@ public class CartService {
* @param productSku sku
*/
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer num) {
if (productSku.getWarnLine() == null) {
if (product.getWarnLine() == null) {
return;
}
@@ -370,23 +357,17 @@ public class CartService {
return;
}
if (productSku.getStockNumber() == null) {
productSku.setStockNumber((double) 0);
}
if (product.getStockNumber() == null) {
product.setStockNumber(0);
}
if (
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
if (product.getStockNumber() - num <= product.getWarnLine()) {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
if (message == null) {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
product.getStockNumber() - num
, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId());
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
}else {