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 e142c1d..67f2f18 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/ConsMsgConsumer.java @@ -11,6 +11,7 @@ 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 lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; @@ -19,10 +20,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.math.BigDecimal; +import java.util.*; @Slf4j @Component @@ -192,44 +191,88 @@ public class ConsMsgConsumer { + + + + JSONObject getAccessToken1() { + String requestUrl = "https://api.weixin.qq.com/cgi-bin/token"; + Map requestUrlParam = new HashMap<>(); + + + requestUrlParam.put("appid", "wxcf0fe8cdba153fd6"); + //小程序secret + requestUrlParam.put("secret", "c33e06467c6879a62af633d50ed6b720"); + //默认参数 + requestUrlParam.put("grant_type", "client_credential"); + JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl, requestUrlParam)); + return jsonObject; + } + + @Data + static class MsgInfo{ + private String openId; + private String shopName; + + private String productName; + + private BigDecimal amount; + + + public MsgInfo(String openId, String shopName, String productName, BigDecimal amount) { + this.openId = openId; + this.shopName = shopName; + this.productName = productName; + this.amount = amount; + } + } + public static void main(String[] args){ - JSONObject access_token = new ConsMsgConsumer().getAccessToken(); - String accessToken = String.valueOf(access_token.get("access_token")); - JSONObject object1 = new JSONObject(); + List list=new ArrayList<>(); - object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY"); - object1.put("touser", "oeQYq5CAuSpdeX9uZz52DJiSUO9M"); + list.add(new MsgInfo("oeQYq5KEjN1-laurB3oRbqEllVzs","双屿Pisces","茄汁肉酱意面",new BigDecimal(24))); + list.add(new MsgInfo("oeQYq5KEjN1-laurB3oRbqEllVzs","森食界创意轻食(未央店)","番茄鸳鸯锅",new BigDecimal(36))); + + for (MsgInfo msgInfo : list) { + JSONObject access_token = new ConsMsgConsumer().getAccessToken1(); + String accessToken = String.valueOf(access_token.get("access_token")); + + JSONObject object1 = new JSONObject(); + + object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY"); + object1.put("touser", msgInfo.getOpenId()); - JSONObject data = new JSONObject(); + JSONObject data = new JSONObject(); - JSONObject thing1 = new JSONObject(); - thing1.put("value", "水"); + JSONObject thing1 = new JSONObject(); + thing1.put("value", msgInfo.getShopName()); - JSONObject thing5 = new JSONObject(); - thing5.put("value", "耗材库存不足,请及时补充。"); + JSONObject thing5 = new JSONObject(); + thing5.put("value", "耗材库存不足,请及时补充。"); - JSONObject thing6 = new JSONObject(); - thing6.put("value", "咖啡"); + JSONObject thing6 = new JSONObject(); + thing6.put("value", msgInfo.getProductName()); - JSONObject thing7 = new JSONObject(); - thing7.put("value", "3.2"); + JSONObject thing7 = new JSONObject(); + thing7.put("value", msgInfo.getAmount().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", "trial"); - object1.put("lang", "zh_CN"); + object1.put("miniprogram_state", "formal"); + 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); + } - 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); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java index 8199561..8ede030 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java @@ -101,7 +101,7 @@ public class RabbitConfig { @Bean public Binding bindingcons_Register() { - return BindingBuilder.bind(queuePrint_Register()).to(printExchange_Register()).with(RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT); + return BindingBuilder.bind(queuecons_Register()).to(consExchange_Register()).with(RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT); } @@ -120,12 +120,11 @@ public class RabbitConfig { @Bean public Binding bindingcons_msg_Register() { - return BindingBuilder.bind(queuePrint_Register()).to(printExchange_Register()).with(RabbitConstants.CONS_MSG_COLLECT_ROUTINGKEY_PUT); + return BindingBuilder.bind(queuecons_msg_Register()).to(cons_msg_Exchange_Register()).with(RabbitConstants.CONS_MSG_COLLECT_ROUTINGKEY_PUT); } - } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 4d89e44..e5c2536 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -45,9 +45,6 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { - - - public void con_msg(String content){ CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); rabbitTemplate.convertAndSend(RabbitConstants.CONS_MSG_COLLECT_PUT, RabbitConstants.CONS_MSG_COLLECT_ROUTINGKEY_PUT, content, correlationId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java index bbc4e0d..ef03b96 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ConsService.java @@ -98,7 +98,7 @@ public class ConsService { if("delete".equals(type)){ - List jsonArray= Arrays.asList(jsonObject.getJSONArray("skuIds")); + List jsonArray= jsonObject.getJSONArray("skuIds").toJavaList(Integer.class); String shopId= jsonObject.getString("shopId"); if(Objects.isNull(jsonArray)||jsonArray.size()<=0){ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 15a4d7e..74d36c1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -188,6 +188,7 @@ public class OrderService { cashierCart.setCategoryId(product.getCategoryId()); list.add(cashierCart); cashierCartMapper.insert(cashierCart); + cart=cashierCart; } else { if (type.equals("add")) { cashierCart.setNumber(cashierCart.getNumber() + number); @@ -206,6 +207,8 @@ public class OrderService { } else { cashierCartMapper.updateStatus(cashierCart.getId(), "close"); } + + cart=cashierCart; } @@ -724,12 +727,13 @@ public class OrderService { for (TbCashierCart cashierCart : list) { if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { orderId = Integer.valueOf(cashierCart.getOrderId()); - skuIds.add(cashierCart.getSkuId()); + } TbProductWithBLOBs product= tbProductMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getProductId())); if(ObjectUtil.isNotEmpty(product)&&"1".equals(product.getIsStock().toString())){ ProductSkuPo skuPo=new ProductSkuPo(Integer.valueOf(cashierCart.getSkuId()),cashierCart.getTotalNumber()); productSkuPos.add(skuPo); + skuIds.add(cashierCart.getSkuId()); } diff --git a/src/main/resources/mapper/TbConsInfoFlowMapper.xml b/src/main/resources/mapper/TbConsInfoFlowMapper.xml index a8a95c8..c4ef232 100644 --- a/src/main/resources/mapper/TbConsInfoFlowMapper.xml +++ b/src/main/resources/mapper/TbConsInfoFlowMapper.xml @@ -163,15 +163,17 @@ - + insert into tb_cons_info_flow (shop_id, cons_id, con_name, amount, balance, biz_code, biz_name, biz_type, - create_time, update_time) - values #{item.shopId,jdbcType=INTEGER}, #{item.consId,jdbcType=INTEGER}, + create_time) + values + + ( #{item.shopId,jdbcType=INTEGER}, #{item.consId,jdbcType=INTEGER}, #{item.conName,jdbcType=VARCHAR}, #{item.amount,jdbcType=DECIMAL}, #{item.balance,jdbcType=DECIMAL}, #{item.bizCode,jdbcType=VARCHAR}, #{item.bizName,jdbcType=VARCHAR}, #{item.bizType,jdbcType=VARCHAR}, - #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}) + now()) diff --git a/src/main/resources/mapper/TbProskuConMapper.xml b/src/main/resources/mapper/TbProskuConMapper.xml index 19ba0fe..7b7fbae 100644 --- a/src/main/resources/mapper/TbProskuConMapper.xml +++ b/src/main/resources/mapper/TbProskuConMapper.xml @@ -119,7 +119,7 @@