diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/QrCodeController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/QrCodeController.java index 7994adb..2ce3ff6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/QrCodeController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/QrCodeController.java @@ -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.*; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserShopMsgMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserShopMsgMapper.java index 53731d9..dfaaee9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserShopMsgMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserShopMsgMapper.java @@ -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 selectByShopId(@Param("shopId") Integer shopId); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserShopMsg.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserShopMsg.java index 70e45dd..e1bedc8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserShopMsg.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserShopMsg.java @@ -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; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java index 67f2f18..c8712a0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java @@ -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 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); + } } + } } diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index b024f20..295ab1d 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -52,14 +52,8 @@ - -
- - -
diff --git a/src/main/resources/mapper/TbUserShopMsgMapper.xml b/src/main/resources/mapper/TbUserShopMsgMapper.xml index 5b2d1f4..092e67e 100644 --- a/src/main/resources/mapper/TbUserShopMsgMapper.xml +++ b/src/main/resources/mapper/TbUserShopMsgMapper.xml @@ -2,7 +2,8 @@ - + + @@ -10,29 +11,32 @@ - shop_id, open_id, remark, status, create_time, update_time + id, shop_id, open_id, remark, status, create_time, update_time delete from tb_user_shop_msg - where shop_id = #{shopId,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} - insert into tb_user_shop_msg (shop_id, open_id, remark, - status, create_time, update_time - ) - values (#{shopId,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, - #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} - ) + insert into tb_user_shop_msg (id, shop_id, open_id, + remark, status, create_time, + update_time) + values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, + #{remark,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}) insert into tb_user_shop_msg + + id, + shop_id, @@ -53,6 +57,9 @@ + + #{id,jdbcType=INTEGER}, + #{shopId,jdbcType=INTEGER}, @@ -76,6 +83,9 @@ update tb_user_shop_msg + + shop_id = #{shopId,jdbcType=INTEGER}, + open_id = #{openId,jdbcType=VARCHAR}, @@ -92,15 +102,20 @@ update_time = #{updateTime,jdbcType=TIMESTAMP}, - where shop_id = #{shopId,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} update tb_user_shop_msg - set open_id = #{openId,jdbcType=VARCHAR}, + set shop_id = #{shopId,jdbcType=INTEGER}, + open_id = #{openId,jdbcType=VARCHAR}, remark = #{remark,jdbcType=VARCHAR}, status = #{status,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP} - where shop_id = #{shopId,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file