添加耗材警告

This commit is contained in:
韩鹏辉
2024-07-05 10:20:09 +08:00
parent 781a4baa81
commit d772c63ee5
6 changed files with 79 additions and 55 deletions

View File

@@ -1,13 +1,10 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
@@ -19,7 +16,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.*;

View File

@@ -6,16 +6,18 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Mapper
public interface TbUserShopMsgMapper {
int deleteByPrimaryKey(Integer shopId);
int deleteByPrimaryKey(Integer id);
int insert(TbUserShopMsg record);
int insertSelective(TbUserShopMsg record);
TbUserShopMsg selectByPrimaryKey(Integer shopId);
TbUserShopMsg selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(TbUserShopMsg record);
@@ -23,4 +25,7 @@ public interface TbUserShopMsgMapper {
@Select("select * from tb_user_shop_msg where shop_id=#{shopId}")
TbUserShopMsg selectByShopId(@Param("shopId") String shopId);
}
List<TbUserShopMsg> selectByShopId(@Param("shopId") Integer shopId);
}

View File

@@ -4,6 +4,8 @@ import java.io.Serializable;
import java.util.Date;
public class TbUserShopMsg implements Serializable {
private Integer id;
private Integer shopId;
private String openId;
@@ -18,6 +20,14 @@ public class TbUserShopMsg implements Serializable {
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getShopId() {
return shopId;
}

View File

@@ -116,48 +116,52 @@ public class ConsMsgConsumer {
String key = redisUtil.getMessage(RedisCst.ORDER_MESSAGE.concat(tbConsInfo.getShopId().toString()).concat("#").concat(tbConsInfo.getId().toString()));
if (Objects.isNull(key)) {
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByPrimaryKey(tbConsInfo.getShopId());
if (Objects.nonNull(tbUserShopMsg) && Objects.nonNull(tbUserShopMsg.getOpenId())) {
JSONObject access_token = getAccessToken();
String accessToken = String.valueOf(access_token.get("access_token"));
List<TbUserShopMsg> tbUserShopMsgs = tbUserShopMsgMapper.selectByShopId(tbConsInfo.getShopId());
if (Objects.nonNull(tbUserShopMsgs) && tbUserShopMsgs.size()>0) {
JSONObject object1 = new JSONObject();
for (TbUserShopMsg tbUserShopMsg : tbUserShopMsgs) {
JSONObject access_token = getAccessToken();
String accessToken = String.valueOf(access_token.get("access_token"));
object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY");
object1.put("touser", tbUserShopMsg.getOpenId());
JSONObject object1 = new JSONObject();
object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY");
object1.put("touser", tbUserShopMsg.getOpenId());
JSONObject data = new JSONObject();
JSONObject data = new JSONObject();
JSONObject thing1 = new JSONObject();
thing1.put("value", shopInfo.getShopName());
JSONObject thing1 = new JSONObject();
thing1.put("value", shopInfo.getShopName());
JSONObject thing5 = new JSONObject();
thing5.put("value", "耗材库存不足,请及时补充。");
JSONObject thing5 = new JSONObject();
thing5.put("value", "耗材库存不足,请及时补充。");
JSONObject thing6 = new JSONObject();
thing6.put("value", product.getName());
JSONObject thing6 = new JSONObject();
thing6.put("value", product.getName());
JSONObject thing7 = new JSONObject();
thing7.put("value", tbConsInfo.getStockNumber().toPlainString());
JSONObject thing7 = new JSONObject();
thing7.put("value", tbConsInfo.getStockNumber().toPlainString());
data.put("thing1", thing1);
data.put("thing6", thing6);
data.put("number7", thing7);
data.put("thing5", thing5);
data.put("thing1", thing1);
data.put("thing6", thing6);
data.put("number7", thing7);
data.put("thing5", thing5);
object1.put("data", data);
object1.put("data", data);
object1.put("miniprogram_state", miniprogramState);
object1.put("lang", "zh_CN");
object1.put("miniprogram_state", miniprogramState);
object1.put("lang", "zh_CN");
String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
log.info("返回结果:{}", response);
JSONObject resObj = JSONObject.parseObject(response);
if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(String.valueOf(resObj.get("errcode")))) {
redisUtil.saveMessage(key, object1.toString(),10*60*1000);
String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
log.info("返回结果:{}", response);
JSONObject resObj = JSONObject.parseObject(response);
if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(String.valueOf(resObj.get("errcode")))) {
redisUtil.saveMessage(key, object1.toString(),10*60*1000);
}
}
}
}