1.耗材预警推送

This commit is contained in:
2024-07-25 14:19:23 +08:00
parent 5cb005ccd0
commit b864c24f2f
2 changed files with 13 additions and 47 deletions

View File

@@ -7,10 +7,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.util.HttpClientUtil;
import com.chaozhanggui.system.cashierservice.util.N;
import com.chaozhanggui.system.cashierservice.util.RedisCst;
import com.chaozhanggui.system.cashierservice.util.RedisUtil;
import com.chaozhanggui.system.cashierservice.util.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
@@ -50,6 +47,8 @@ public class ConsMsgConsumer {
@Autowired
TbProductMapper tbProductMapper;
private final WxAccountUtil wxAccountUtil;
@Autowired
RedisUtil redisUtil;
@@ -65,6 +64,10 @@ public class ConsMsgConsumer {
@Value("${subscribe.message.miniprogramState}")
private String miniprogramState;
public ConsMsgConsumer(WxAccountUtil wxAccountUtil) {
this.wxAccountUtil = wxAccountUtil;
}
@RabbitHandler
public void listener(String message) {
@@ -124,47 +127,10 @@ public class ConsMsgConsumer {
String value = redisUtil.getMessage(key);
log.info("redis_key:{}",value);
if (Objects.isNull(value)) {
JSONObject access_token = getAccessToken();
String accessToken = String.valueOf(access_token.get("access_token"));
JSONObject object1 = new JSONObject();
object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY");
object1.put("touser", tbUserShopMsg.getOpenId());
JSONObject data = new JSONObject();
JSONObject thing1 = new JSONObject();
thing1.put("value", shopInfo.getShopName());
JSONObject thing5 = new JSONObject();
thing5.put("value", "耗材库存不足,请及时补充。");
JSONObject thing6 = new JSONObject();
thing6.put("value", tbConsInfo.getConName());
JSONObject thing7 = new JSONObject();
thing7.put("value", tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
data.put("thing1", thing1);
data.put("thing6", thing6);
data.put("number7", thing7);
data.put("thing5", thing5);
object1.put("data", data);
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("openId:{},请求参数:{},返回结果:{}",tbUserShopMsg.getOpenId(),object1.toString(), response);
JSONObject resObj = JSONObject.parseObject(response);
if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(String.valueOf(resObj.get("errcode")))) {
log.info("写入redis:{}",key);
redisUtil.saveMessage(key, object1.toString(), 10 * 60);
}
wxAccountUtil.sendStockWarnMsg(shopInfo.getShopName(), "耗材库存不足: " + tbConsInfo.getConName(),
tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).setScale(2,BigDecimal.ROUND_DOWN).toPlainString(), tbUserShopMsg.getOpenId());
log.info("写入redis:{}",key);
redisUtil.saveMessage(key, "1", 10 * 60);
}
});

View File

@@ -43,7 +43,7 @@ public class WxAccountUtil {
}
public static void main(String[] args) {
sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
}
public static String getRadarQrCode(Integer shopId) {
@@ -97,7 +97,7 @@ public class WxAccountUtil {
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
}
public static JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String toUserOpenId) {
public JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String toUserOpenId) {
Map<String, Object> data = new HashMap<String, Object>() {{
put("thing22", new HashMap<String, Object>(){{
put("value", shopName);