新增redis方法

This commit is contained in:
Guoqs
2024-11-28 15:35:48 +08:00
parent 963e86db2a
commit 3821d0506d
2 changed files with 64 additions and 3 deletions

View File

@@ -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<String, String> 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<String> 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));
}
}

View File

@@ -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);
}
}