库存预警支持多用户提醒
This commit is contained in:
@@ -60,15 +60,18 @@ public class CartService {
|
||||
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
private final WechatUtil wechatUtil;
|
||||
|
||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
||||
|
||||
@Autowired
|
||||
private RabbitProducer producer;
|
||||
@Qualifier("tbShopInfoMapper")
|
||||
@Autowired
|
||||
private TbShopInfoMapper tbShopInfoMapper;
|
||||
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil) {
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, TbShopOpenIdMapper shopOpenIdMapper) {
|
||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||
this.wechatUtil = wechatUtil;
|
||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||
}
|
||||
|
||||
public void initCart(JSONObject jsonObject) {
|
||||
@@ -402,7 +405,7 @@ public class CartService {
|
||||
redisUtil.getIncrNum(key, "2");
|
||||
}
|
||||
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product));
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, num));
|
||||
|
||||
}
|
||||
|
||||
@@ -410,7 +413,7 @@ public class CartService {
|
||||
* 校验商品库存警戒线并通知商户
|
||||
* @param productSku sku
|
||||
*/
|
||||
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product) {
|
||||
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer num) {
|
||||
if (productSku.getWarnLine() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -432,10 +435,12 @@ public class CartService {
|
||||
(product.getIsDistribute() == 1 && product.getStockNumber() <= productSku.getWarnLine())
|
||||
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() <= productSku.getWarnLine()
|
||||
) {
|
||||
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByShopId(productSku.getShopId());
|
||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
||||
product.getIsDistribute() == 1 ? product.getStockNumber().toString() : productSku.getStockNumber().toString(),
|
||||
"耗材库存不足,请及时补充。", tbUserShopMsg.getOpenId());
|
||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
|
||||
shopOpenIds.forEach(item -> {
|
||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
||||
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber()-num) : String.valueOf(productSku.getStockNumber() - num),
|
||||
"耗材库存不足,请及时补充。", item.getOpenId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -56,8 +57,11 @@ public class LoginService {
|
||||
@Autowired
|
||||
TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
|
||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
||||
|
||||
|
||||
public LoginService(TbShopOpenIdMapper shopOpenIdMapper) {
|
||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||
}
|
||||
|
||||
|
||||
public Result wxBusinessLogin(String openId,String shopId){
|
||||
@@ -69,13 +73,22 @@ public class LoginService {
|
||||
shopMsg.setOpenId(openId);
|
||||
shopMsg.setCreateTime(new Date());
|
||||
shopMsg.setStatus("1");
|
||||
|
||||
|
||||
tbUserShopMsgMapper.insert(shopMsg);
|
||||
}else {
|
||||
shopMsg.setOpenId(openId);
|
||||
shopMsg.setUpdateTime(new Date());
|
||||
tbUserShopMsgMapper.updateByPrimaryKey(shopMsg);
|
||||
}
|
||||
|
||||
// 为商家绑定openid
|
||||
if (shopOpenIdMapper.countByOpenId(openId) == null) {
|
||||
TbShopOpenId shopOpenId = new TbShopOpenId();
|
||||
shopOpenId.setOpenId(openId);
|
||||
shopOpenId.setCreateTime(DateUtil.date());
|
||||
shopOpenId.setShopId(Integer.valueOf(shopId));
|
||||
shopOpenIdMapper.insert(shopOpenId);
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS,shopMsg);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user