1.耗材预警推送
This commit is contained in:
@@ -7,10 +7,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
import com.chaozhanggui.system.cashierservice.util.HttpClientUtil;
|
import com.chaozhanggui.system.cashierservice.util.*;
|
||||||
import com.chaozhanggui.system.cashierservice.util.N;
|
|
||||||
import com.chaozhanggui.system.cashierservice.util.RedisCst;
|
|
||||||
import com.chaozhanggui.system.cashierservice.util.RedisUtil;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||||
@@ -50,6 +47,8 @@ public class ConsMsgConsumer {
|
|||||||
@Autowired
|
@Autowired
|
||||||
TbProductMapper tbProductMapper;
|
TbProductMapper tbProductMapper;
|
||||||
|
|
||||||
|
private final WxAccountUtil wxAccountUtil;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
@@ -65,6 +64,10 @@ public class ConsMsgConsumer {
|
|||||||
@Value("${subscribe.message.miniprogramState}")
|
@Value("${subscribe.message.miniprogramState}")
|
||||||
private String miniprogramState;
|
private String miniprogramState;
|
||||||
|
|
||||||
|
public ConsMsgConsumer(WxAccountUtil wxAccountUtil) {
|
||||||
|
this.wxAccountUtil = wxAccountUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@RabbitHandler
|
@RabbitHandler
|
||||||
public void listener(String message) {
|
public void listener(String message) {
|
||||||
@@ -124,47 +127,10 @@ public class ConsMsgConsumer {
|
|||||||
String value = redisUtil.getMessage(key);
|
String value = redisUtil.getMessage(key);
|
||||||
log.info("redis_key:{}",value);
|
log.info("redis_key:{}",value);
|
||||||
if (Objects.isNull(value)) {
|
if (Objects.isNull(value)) {
|
||||||
JSONObject access_token = getAccessToken();
|
wxAccountUtil.sendStockWarnMsg(shopInfo.getShopName(), "耗材库存不足: " + tbConsInfo.getConName(),
|
||||||
String accessToken = String.valueOf(access_token.get("access_token"));
|
tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).setScale(2,BigDecimal.ROUND_DOWN).toPlainString(), tbUserShopMsg.getOpenId());
|
||||||
|
log.info("写入redis:{}",key);
|
||||||
JSONObject object1 = new JSONObject();
|
redisUtil.saveMessage(key, "1", 10 * 60);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class WxAccountUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
|
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRadarQrCode(Integer shopId) {
|
public static String getRadarQrCode(Integer shopId) {
|
||||||
@@ -97,7 +97,7 @@ public class WxAccountUtil {
|
|||||||
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
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>() {{
|
Map<String, Object> data = new HashMap<String, Object>() {{
|
||||||
put("thing22", new HashMap<String, Object>(){{
|
put("thing22", new HashMap<String, Object>(){{
|
||||||
put("value", shopName);
|
put("value", shopName);
|
||||||
|
|||||||
Reference in New Issue
Block a user