From 3821d0506d92a971cb3c234a6fc3cdc80f428cb5 Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Thu, 28 Nov 2024 15:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eredis=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/SpringBootTestController.java | 53 ++++++++++++++++++- .../jsowell/common/core/redis/RedisCache.java | 14 ++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 27ce2fa2c..fd2e7047f 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -28,6 +28,7 @@ import com.jsowell.adapay.vo.DrawCashDetailVO; import com.jsowell.adapay.vo.PaymentInfo; import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.Constants; +import com.jsowell.common.constant.RabbitConstants; import com.jsowell.common.core.domain.entity.SysDictData; import com.jsowell.common.core.domain.ykc.LoginRequestData; import com.jsowell.common.core.domain.ykc.TransactionRecordsData; @@ -91,6 +92,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; @@ -270,10 +272,13 @@ public class SpringBootTestController { private CarCouponRecordService carCouponRecordService; @Autowired + private RabbitTemplate rabbitTemplate; + @Qualifier("zhongDianLianPlatformServiceImpl") private ThirdPartyPlatformService platformLogic; - @Test + + public void saveSOCTest() { String transactionCode = "12345"; YKCUtils.saveSOC(transactionCode, "4"); @@ -324,6 +329,43 @@ public class SpringBootTestController { Map pileStatusV2 = pileConnectorInfoService.getPileStatusV2(pileSnList); } + @Test + public void sendRabbitMqTest() { + OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + .orderCode("C123456789") + .merchantId("1") + .stationId("2") + .payAmount(new BigDecimal(100)) + .orderAmount(new BigDecimal(100)) + .settleAmount(new BigDecimal(100)) + .refundAmount(new BigDecimal(0)) + .build(); + OrderDetail orderDetail = OrderDetail.builder() + .totalElectricityAmount(new BigDecimal(50)) + .discountElectricityAmount(new BigDecimal(0)) + .totalServiceAmount(new BigDecimal(50)) + .discountElectricityAmount(new BigDecimal(0)) + .build(); + + AfterSettleOrderDTO afterSettleOrderDTO = AfterSettleOrderDTO.builder() + .orderCode(orderBasicInfo.getOrderCode()) + .merchantId(orderBasicInfo.getMerchantId()) + .stationId(orderBasicInfo.getStationId()) + .orderPayAmount(orderBasicInfo.getPayAmount()) + .orderConsumeAmount(orderBasicInfo.getOrderAmount()) + .orderSettleAmount(orderBasicInfo.getSettleAmount()) + .orderElectricityAmount(orderDetail.getTotalElectricityAmount()) + .orderElectricityDiscountAmount(orderDetail.getDiscountElectricityAmount()) + .orderServiceAmount(orderDetail.getTotalServiceAmount()) + .orderServiceDiscountAmount(orderDetail.getDiscountServiceAmount()) + .orderRefundAmount(orderBasicInfo.getRefundAmount()) + .build(); + + for (int i = 0; i < 10; i++) { + rabbitTemplate.convertAndSend(RabbitConstants.YKC_EXCHANGE_NAME, RabbitConstants.QUEUE_CHARGE_ORDER_DATA, afterSettleOrderDTO); + } + } + @Test public void getEBikePileSnTest() { List strings = pileSnGenerateService.generateEBikeSN(8); @@ -3843,4 +3885,13 @@ public class SpringBootTestController { System.out.println(StringUtils.equals(encryptData2, str)); } + @Test + public void addPileMsgTest() { + String redisKey = "pile_msg_list:" + "88000000000002"; + for (int i = 0; i < 30; i++) { + redisCache.addPileMsg(redisKey, "充电桩报文第" + i + "条") ; + } + System.out.println(redisCache.getCacheList(redisKey)); + } + } diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java index 2af1cd5d0..bb68aec62 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java +++ b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java @@ -1,7 +1,6 @@ package com.jsowell.common.core.redis; import com.jsowell.common.util.StringUtils; -import org.apache.poi.ss.formula.functions.T; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,7 @@ public class RedisCache { public RedisTemplate redisTemplate; // redis锁获取超时时间 - private long timeout = 500l; + private long timeout = 500L; /** * 缓存基本的对象,Integer、String、实体类等 @@ -593,4 +592,15 @@ public class RedisCache { return redisTemplate.opsForHash().increment(key, item, -by); } + /** + * 添加充电桩消息到redis + */ + public void addPileMsg(String redisKey, String newData) { + // 执行左推操作 + redisTemplate.opsForList().leftPush(redisKey, newData); + + // 执行修剪操作,限制列表的最大长度为10 + redisTemplate.opsForList().trim(redisKey, 0, 9); + } + }